@@ -22,62 +22,70 @@ import sys
22
22
import socket
23
23
from cloudutils .cloudException import CloudRuntimeException , CloudInternalException
24
24
from cloudutils .utilities import initLoging , bash
25
- from cloudutils .configFileOps import configFileOps
25
+ from cloudutils .configFileOps import configFileOps
26
26
from cloudutils .globalEnv import globalEnv
27
27
from cloudutils .networkConfig import networkConfig
28
28
from cloudutils .syscfg import sysConfigFactory
29
29
from cloudutils .serviceConfig import configureLibvirtConfig , configure_libvirt_tls
30
30
31
31
from optparse import OptionParser
32
32
33
+
33
34
def getUserInputs ():
34
35
print ("Welcome to the CloudStack Agent Setup:" )
35
36
36
37
cfo = configFileOps ("@AGENTSYSCONFDIR@/agent.properties" )
37
38
oldMgt = cfo .getEntry ("host" )
38
39
39
- mgtSvr = input ("Please input the Management Server Hostname/IP-Address:[%s]" % oldMgt )
40
+ mgtSvr = input (
41
+ "Please input the Management Server Hostname/IP-Address:[%s]" % oldMgt
42
+ )
40
43
if mgtSvr == "" :
41
44
mgtSvr = oldMgt
42
45
try :
43
46
socket .getaddrinfo (mgtSvr , 443 )
44
47
except :
45
- print ("Failed to resolve %s. Please input a valid hostname or IP-Address." % mgtSvr )
48
+ print (
49
+ "Failed to resolve %s. Please input a valid hostname or IP-Address."
50
+ % mgtSvr
51
+ )
46
52
exit (1 )
47
53
48
54
oldToken = cfo .getEntry ("zone" )
49
- zoneToken = input ("Please input the Zone Id:[%s]" % oldToken )
55
+ zoneToken = input ("Please input the Zone Id:[%s]" % oldToken )
50
56
51
57
if zoneToken == "" :
52
58
zoneToken = oldToken
53
59
54
60
oldPod = cfo .getEntry ("pod" )
55
- podId = input ("Please input the Pod Id:[%s]" % oldPod )
61
+ podId = input ("Please input the Pod Id:[%s]" % oldPod )
56
62
57
63
if podId == "" :
58
- podId = oldToken
64
+ podId = oldToken
59
65
60
66
oldCluster = cfo .getEntry ("cluster" )
61
- clusterId = input ("Please input the Cluster Id:[%s]" % oldCluster )
67
+ clusterId = input ("Please input the Cluster Id:[%s]" % oldCluster )
62
68
if clusterId == "" :
63
69
clusterId = oldCluster
64
70
65
71
oldHypervisor = cfo .getEntry ("hypervisor" )
66
72
if oldHypervisor == "" :
67
73
oldHypervisor = "kvm"
68
74
69
- hypervisor = input ("Please input the Hypervisor type kvm/lxc:[%s]" % oldHypervisor )
75
+ hypervisor = input ("Please input the Hypervisor type kvm/lxc:[%s]" % oldHypervisor )
70
76
if hypervisor == "" :
71
77
hypervisor = oldHypervisor
72
78
73
79
try :
74
80
defaultNic = networkConfig .getDefaultNetwork ()
75
81
except :
76
- print ("Failed to get default route. Please configure your network to have a default route" )
82
+ print (
83
+ "Failed to get default route. Please configure your network to have a default route"
84
+ )
77
85
exit (1 )
78
86
79
87
defNic = defaultNic .name
80
- network = input ("Please choose which network used to create VM:[%s]" % defNic )
88
+ network = input ("Please choose which network used to create VM:[%s]" % defNic )
81
89
if network == "" :
82
90
if defNic == "" :
83
91
print ("You need to specify one of Nic or bridge on your system" )
@@ -87,21 +95,32 @@ def getUserInputs():
87
95
88
96
return [mgtSvr , zoneToken , network , podId , clusterId , hypervisor ]
89
97
90
- if __name__ == '__main__' :
98
+
99
+ if __name__ == "__main__" :
91
100
initLoging ("@AGENTLOGDIR@/setup.log" )
92
101
glbEnv = globalEnv ()
93
102
94
103
glbEnv .mode = "Agent"
95
104
glbEnv .agentMode = "Agent"
96
105
parser = OptionParser ()
97
106
parser .add_option ("-a" , action = "store_true" , dest = "auto" , help = "auto mode" )
98
- parser .add_option ("-m" , "--host" , dest = "mgt" , help = "Management server hostname or IP-Address" )
107
+ parser .add_option (
108
+ "-m" , "--host" , dest = "mgt" , help = "Management server hostname or IP-Address"
109
+ )
99
110
parser .add_option ("-z" , "--zone" , dest = "zone" , help = "zone id" )
100
111
parser .add_option ("-p" , "--pod" , dest = "pod" , help = "pod id" )
101
112
parser .add_option ("-c" , "--cluster" , dest = "cluster" , help = "cluster id" )
102
- parser .add_option ("-t" , "--hypervisor" , default = "kvm" , dest = "hypervisor" , help = "hypervisor type" )
113
+ parser .add_option (
114
+ "-t" , "--hypervisor" , default = "kvm" , dest = "hypervisor" , help = "hypervisor type"
115
+ )
103
116
parser .add_option ("-g" , "--guid" , dest = "guid" , help = "guid" )
104
- parser .add_option ("-s" , action = "store_true" , default = False , dest = "secure" , help = "Secure and enable TLS for libvirtd" )
117
+ parser .add_option (
118
+ "-s" ,
119
+ action = "store_true" ,
120
+ default = False ,
121
+ dest = "secure" ,
122
+ help = "Secure and enable TLS for libvirtd" ,
123
+ )
105
124
parser .add_option ("--pubNic" , dest = "pubNic" , help = "Public traffic interface" )
106
125
parser .add_option ("--prvNic" , dest = "prvNic" , help = "Private traffic interface" )
107
126
parser .add_option ("--guestNic" , dest = "guestNic" , help = "Guest traffic interface" )
@@ -127,15 +146,15 @@ if __name__ == '__main__':
127
146
glbEnv .pod = userInputs [3 ]
128
147
glbEnv .cluster = userInputs [4 ]
129
148
glbEnv .hypervisor = userInputs [5 ]
130
- #generate UUID
149
+ # generate UUID
131
150
glbEnv .uuid = old_config .getEntry ("guid" )
132
151
if glbEnv .uuid == "" :
133
152
glbEnv .uuid = bash ("uuidgen" ).getStdout ()
134
153
else :
135
154
for para , value in list (options .__dict__ .items ()):
136
155
if value is None :
137
- print ("Missing operand:%s" % para )
138
- print ("Try %s --help for more information" % sys .argv [0 ])
156
+ print ("Missing operand:%s" % para )
157
+ print ("Try %s --help for more information" % sys .argv [0 ])
139
158
sys .exit (1 )
140
159
141
160
glbEnv .uuid = options .guid
@@ -155,7 +174,7 @@ if __name__ == '__main__':
155
174
try :
156
175
syscfg .config ()
157
176
print ("CloudStack Agent setup is done!" )
158
- except (CloudRuntimeException ,CloudInternalException ) as e :
177
+ except (CloudRuntimeException , CloudInternalException ) as e :
159
178
print (e )
160
179
print ("Try to restore your system:" )
161
180
try :
0 commit comments