-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloudlet.py
executable file
·102 lines (82 loc) · 2.67 KB
/
cloudlet.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
#!/usr/bin/env /usr/local/bin/python
# encoding: utf-8
import sys
import logging
from cloudlet_check import cloudlet_check
from cloudlet_overlay import overlay
from cloudlet_handoff import handoff
from cloudlet_daemon import daemon
cloudlet_version = '0.1'
cloudlet_info = 'Dev container based cloudlet'
def help():
print('cloudlet: ')
print('usage: cloudlet [opt] [argv]')
print('usage: cloudlet check')
print('usage: cloudlet -h')
print(' service -l #listeng to the connections ')
print(' fetch [service name] #get overlay image')
print(' overlay [new image] [base image] #create overlay image')
print(' migrate [container name]] -t [des ip] #migrate container ')
def parase(argv):
argv_len = len(argv)
logging.debug(argv_len)
ret = True
opt = argv[0]
if argv_len == 1:
if opt == 'check':
ret = cloudlet_check()
if argv_len == 2:
if opt == 'service' and argv[1] == '-l':
clet = daemon()
clet.run()
elif opt == 'fetch':
overlay_name = argv[1]
ovlay = overlay(overlay_name, None)
ovlay.fetch()
# ovlay.sythesis()
elif opt == 'search':
print(" to be implement.")
if argv_len == 3:
if opt == 'overlay':
modified_image = argv[1]
base_image = argv[2]
logging.info(modified_image)
logging.info(base_image)
ol = overlay(modified_image, base_image)
ret = ol.generate()
if argv_len == 4:
if opt == 'migrate':
con = argv[1]
cmd_option = argv[2]
dst_ip = argv[3]
if cmd_option != '-t':
logging.error('please follow opt format:')
logging.error(' migrate [container] -t [dst ip]')
return False
# handoff
hdoff = handoff(con, dst_ip)
ret = hdoff.run()
if ret is False:
logging.error('service failed')
return False
return True
if __name__ == '__main__':
# log control.
logging.basicConfig(level=logging.INFO)
if len(sys.argv) > 5:
logging.error("too many input arguments.")
logging.debug(sys.argv)
# help info and version info
opt = sys.argv[1]
if opt == '-h' or opt == '-help' or opt == 'help':
help()
sys.exit(0)
elif opt == '-v' or opt == 'version':
print('cloudlet_version: ' + cloudlet_version)
print('cloudlet_info: ' + cloudlet_info)
sys.exit(0)
ret = parase(sys.argv[1:])
if ret is False:
logging.error("service faliled")
sys.exit(-1)
sys.exit(0)