forked from d0c-s4vage/talus_client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
114 lines (89 loc) · 3.21 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
# encoding: utf-8
import os
import time
import talus.api
from talus.models import *
import talus.models
talus.models.set_base("http://localhost:8001")
def test_os_and_image_models():
existing_os = OS.find_one(name="testing os")
if existing_os is None:
new_os = OS("http://localhost:8001")
new_os.name = "testing os"
new_os.arch = "x86"
new_os.type = "windows"
new_os.version = "10"
new_os.save()
existing_os = new_os
new_image = Image("http://localhost:8001")
new_image.name = "test image"
new_image.os = existing_os
new_image.desc = "this is a description"
new_image.tags = ["these", "are", "some", "tags"]
new_image.status = dict(name="importing", tmpfile="/tmp/blah")
new_image.base_image = None
new_image.save()
new_image.delete()
def test_image_import(image_path, image_name):
def progress_callback():
sys.stdout.write(".")
sys.stdout.flush()
existing_os = OS.find_one(name="testing os")
if existing_os is None:
new_os = OS("http://localhost:8001")
new_os.name = "testing os"
new_os.arch = "x86"
new_os.type = "windows"
new_os.version = "10"
new_os.save()
existing_os = new_os
client = talus.api.TalusClient("http://localhost:8001")
client.image_delete(None, name=image_name)
image = client.image_import(image_path, image_name, existing_os.id, "some description", ["windows", "7", "x64"])
while image.status["name"] != "configuring":
time.sleep(5)
image.refresh()
print("image is running and waiting to be configured!")
print(image.status)
print("shut down the VM when ready!, be sure the firewall is open and virtio drivers are installed!")
print("a CD-ROM should be mounted in the VM containing the virtio drivers")
def test_image_configure_with_interaction(image_name):
client = talus.api.TalusClient("http://localhost:8001")
image = talus.models.Image.find_one(name=image_name)
image = client.image_configure(
image.id,
user_interaction=True,
vagrantfile=None
)
while image.status["name"] != "configuring":
time.sleep(5)
image.refresh()
print("ready to interact with!")
def test_image_configure_without_interaction(image_name):
image = talus.models.Image.find_one(name=image_name)
client = talus.api.TalusClient("http://localhost:8001")
image = client.image_configure(
image.id,
user_interaction=False,
vagrantfile="""
Vagrant.configure("2") do |config|
config.vm.box = "blah"
config.winrm.username = "user"
config.winrm.password = "password"
config.vm.provision "shell", inline: "echo blah >> C:\\\\Users\\\\user\\\\Desktop\\\\FROM_VAGRANT1.txt"
config.vm.provision "shell", inline: "echo blah >> C:\\\\Users\\\\user\\\\Desktop\\\\FROM_VAGRANT2.txt"
config.vm.provision "shell", inline: "echo blah >> C:\\\\Users\\\\user\\\\Desktop\\\\FROM_VAGRANT3.txt"
config.vm.provision "shell", inline: "echo blah >> C:\\\\Users\\\\user\\\\Desktop\\\\FROM_VAGRANT4.txt"
end
"""
)
while image.status["name"] != "ready":
time.sleep(5)
image.refresh()
print("update complete!")
if __name__ == "__main__":
image_name = "win7pro_testing7",
test_image_import("~/images/win7pro_x64-disk1.vmdk", image_name)
#test_image_configure_with_interaction(image_name)
#test_image_configure_without_interaction(image_name)