@@ -22,62 +22,70 @@ import sys
2222import socket
2323from cloudutils .cloudException import CloudRuntimeException , CloudInternalException
2424from cloudutils .utilities import initLoging , bash
25- from cloudutils .configFileOps import configFileOps
25+ from cloudutils .configFileOps import configFileOps
2626from cloudutils .globalEnv import globalEnv
2727from cloudutils .networkConfig import networkConfig
2828from cloudutils .syscfg import sysConfigFactory
2929from cloudutils .serviceConfig import configureLibvirtConfig , configure_libvirt_tls
3030
3131from optparse import OptionParser
3232
33+
3334def getUserInputs ():
3435 print ("Welcome to the CloudStack Agent Setup:" )
3536
3637 cfo = configFileOps ("@AGENTSYSCONFDIR@/agent.properties" )
3738 oldMgt = cfo .getEntry ("host" )
3839
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+ )
4043 if mgtSvr == "" :
4144 mgtSvr = oldMgt
4245 try :
4346 socket .getaddrinfo (mgtSvr , 443 )
4447 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+ )
4652 exit (1 )
4753
4854 oldToken = cfo .getEntry ("zone" )
49- zoneToken = input ("Please input the Zone Id:[%s]" % oldToken )
55+ zoneToken = input ("Please input the Zone Id:[%s]" % oldToken )
5056
5157 if zoneToken == "" :
5258 zoneToken = oldToken
5359
5460 oldPod = cfo .getEntry ("pod" )
55- podId = input ("Please input the Pod Id:[%s]" % oldPod )
61+ podId = input ("Please input the Pod Id:[%s]" % oldPod )
5662
5763 if podId == "" :
58- podId = oldToken
64+ podId = oldToken
5965
6066 oldCluster = cfo .getEntry ("cluster" )
61- clusterId = input ("Please input the Cluster Id:[%s]" % oldCluster )
67+ clusterId = input ("Please input the Cluster Id:[%s]" % oldCluster )
6268 if clusterId == "" :
6369 clusterId = oldCluster
6470
6571 oldHypervisor = cfo .getEntry ("hypervisor" )
6672 if oldHypervisor == "" :
6773 oldHypervisor = "kvm"
6874
69- hypervisor = input ("Please input the Hypervisor type kvm/lxc:[%s]" % oldHypervisor )
75+ hypervisor = input ("Please input the Hypervisor type kvm/lxc:[%s]" % oldHypervisor )
7076 if hypervisor == "" :
7177 hypervisor = oldHypervisor
7278
7379 try :
7480 defaultNic = networkConfig .getDefaultNetwork ()
7581 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+ )
7785 exit (1 )
7886
7987 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 )
8189 if network == "" :
8290 if defNic == "" :
8391 print ("You need to specify one of Nic or bridge on your system" )
@@ -87,21 +95,32 @@ def getUserInputs():
8795
8896 return [mgtSvr , zoneToken , network , podId , clusterId , hypervisor ]
8997
90- if __name__ == '__main__' :
98+
99+ if __name__ == "__main__" :
91100 initLoging ("@AGENTLOGDIR@/setup.log" )
92101 glbEnv = globalEnv ()
93102
94103 glbEnv .mode = "Agent"
95104 glbEnv .agentMode = "Agent"
96105 parser = OptionParser ()
97106 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+ )
99110 parser .add_option ("-z" , "--zone" , dest = "zone" , help = "zone id" )
100111 parser .add_option ("-p" , "--pod" , dest = "pod" , help = "pod id" )
101112 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+ )
103116 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+ )
105124 parser .add_option ("--pubNic" , dest = "pubNic" , help = "Public traffic interface" )
106125 parser .add_option ("--prvNic" , dest = "prvNic" , help = "Private traffic interface" )
107126 parser .add_option ("--guestNic" , dest = "guestNic" , help = "Guest traffic interface" )
@@ -127,15 +146,15 @@ if __name__ == '__main__':
127146 glbEnv .pod = userInputs [3 ]
128147 glbEnv .cluster = userInputs [4 ]
129148 glbEnv .hypervisor = userInputs [5 ]
130- #generate UUID
149+ # generate UUID
131150 glbEnv .uuid = old_config .getEntry ("guid" )
132151 if glbEnv .uuid == "" :
133152 glbEnv .uuid = bash ("uuidgen" ).getStdout ()
134153 else :
135154 for para , value in list (options .__dict__ .items ()):
136155 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 ])
139158 sys .exit (1 )
140159
141160 glbEnv .uuid = options .guid
@@ -155,7 +174,7 @@ if __name__ == '__main__':
155174 try :
156175 syscfg .config ()
157176 print ("CloudStack Agent setup is done!" )
158- except (CloudRuntimeException ,CloudInternalException ) as e :
177+ except (CloudRuntimeException , CloudInternalException ) as e :
159178 print (e )
160179 print ("Try to restore your system:" )
161180 try :
0 commit comments