FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python/python_tips/linode_api.py at main · miltozz/learn-python · GitHub
miltozz
/
learn-python
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python
/
python_tips
/
linode_api.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (30 loc) · 1.1 KB
Breadcrumbs
learn-python
/
python_tips
/
linode_api.py
Copy path
File metadata and controls
40 lines (30 loc) · 1.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Needs cleaning
#restart linode server
import
linode_api4
#pip install linode-api4
import
os
import
paramiko
import
time
LINODE_TOKEN
=
os
.
getenv
(
'LINODE_TOKEN'
)
#env var for LINODE ACCESS TOKEN
def
restart_container
():
ssh
=
paramiko
.
SSHClient
()
# known_hosts prompt
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
# connect as ec2-user with .pem | root connection might require priv-key pub-key.pub
ssh
.
connect
(
hostname
=
'18.184.246.158'
,
username
=
"ec2-user"
,
key_filename
=
'/home/mltamd/.ssh/ec2-key-pair-frankfurt.pem'
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
'docker start 06b420614a68'
)
print
(
stdout
.
readlines
())
ssh
.
close
()
#restart linode server
client
=
linode_api4
.
LinodeClient
(
LINODE_TOKEN
)
nginx_server
=
client
.
load
(
linode_api4
.
Instance
,
123456789
)
#linode server id
nginx_server
.
reboot
()
#restart the app container
while
True
:
nginx_server
=
client
.
load
(
linode_api4
.
Instance
,
123456789
)
#linode server id
time
.
sleep
(
5
)
if
nginx_server
.
status
==
'running'
:
time
.
sleep
(
10
)
restart_container
()
break
Back
|
FazBrowse Home
|
New Git URL