forked from canonical/pylxd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-http-test.py
executable file
·54 lines (43 loc) · 1.39 KB
/
local-http-test.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
import datetime
import time
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import pylxd
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def log(s):
now = datetime.datetime.utcnow()
print("{} - {}".format(now, s))
def create_and_update(client):
log("Creating...")
base = client.containers.create(
{
"name": "ubuntu-1604",
"source": {
"type": "image",
"protocol": "simplestreams",
"server": "https://images.linuxcontainers.org",
"alias": "ubuntu/xenial/amd64",
},
},
wait=True,
)
log("starting...")
base.start(wait=True)
while len(base.state().network["eth0"]["addresses"]) < 2:
time.sleep(1)
commands = [
["apt-get", "update"],
["apt-get", "install", "openssh-server", "sudo", "man", "-y"],
]
for command in commands:
log("command: {}".format(command))
result = base.execute(command)
log("result: {}".format(result.exit_code))
log("stdout: {}".format(result.stdout))
log("stderr: {}".format(result.stderr))
if __name__ == "__main__":
client = pylxd.Client("https://127.0.0.1:8443/", verify=False)
log("Authenticating...")
client.authenticate("password")
create_and_update(client)