@@ -35,62 +35,70 @@ for pythonpath in (
3535
3636from cloudutils .cloudException import CloudRuntimeException , CloudInternalException
3737from cloudutils .utilities import initLoging , bash
38- from cloudutils .configFileOps import configFileOps
38+ from cloudutils .configFileOps import configFileOps
3939from cloudutils .globalEnv import globalEnv
4040from cloudutils .networkConfig import networkConfig
4141from cloudutils .syscfg import sysConfigFactory
4242from cloudutils .serviceConfig import configureLibvirtConfig , configure_libvirt_tls
4343
4444from optparse import OptionParser
4545
46+
4647def getUserInputs ():
4748 print ("Welcome to the CloudStack Agent Setup:" )
4849
4950 cfo = configFileOps ("@AGENTSYSCONFDIR@/agent.properties" )
5051 oldMgt = cfo .getEntry ("host" )
5152
52- mgtSvr = input ("Please input the Management Server Hostname/IP-Address:[%s]" % oldMgt )
53+ mgtSvr = input (
54+ "Please input the Management Server Hostname/IP-Address:[%s]" % oldMgt
55+ )
5356 if mgtSvr == "" :
5457 mgtSvr = oldMgt
5558 try :
5659 socket .getaddrinfo (mgtSvr , 443 )
5760 except :
58- print ("Failed to resolve %s. Please input a valid hostname or IP-Address." % mgtSvr )
61+ print (
62+ "Failed to resolve %s. Please input a valid hostname or IP-Address."
63+ % mgtSvr
64+ )
5965 exit (1 )
6066
6167 oldToken = cfo .getEntry ("zone" )
62- zoneToken = input ("Please input the Zone Id:[%s]" % oldToken )
68+ zoneToken = input ("Please input the Zone Id:[%s]" % oldToken )
6369
6470 if zoneToken == "" :
6571 zoneToken = oldToken
6672
6773 oldPod = cfo .getEntry ("pod" )
68- podId = input ("Please input the Pod Id:[%s]" % oldPod )
74+ podId = input ("Please input the Pod Id:[%s]" % oldPod )
6975
7076 if podId == "" :
71- podId = oldToken
77+ podId = oldToken
7278
7379 oldCluster = cfo .getEntry ("cluster" )
74- clusterId = input ("Please input the Cluster Id:[%s]" % oldCluster )
80+ clusterId = input ("Please input the Cluster Id:[%s]" % oldCluster )
7581 if clusterId == "" :
7682 clusterId = oldCluster
7783
7884 oldHypervisor = cfo .getEntry ("hypervisor" )
7985 if oldHypervisor == "" :
8086 oldHypervisor = "kvm"
8187
82- hypervisor = input ("Please input the Hypervisor type kvm/lxc:[%s]" % oldHypervisor )
88+ hypervisor = input ("Please input the Hypervisor type kvm/lxc:[%s]" % oldHypervisor )
8389 if hypervisor == "" :
8490 hypervisor = oldHypervisor
8591
8692 try :
8793 defaultNic = networkConfig .getDefaultNetwork ()
8894 except :
89- print ("Failed to get default route. Please configure your network to have a default route" )
95+ print (
96+ "Failed to get default route. Please configure your network to have a default route"
97+ )
9098 exit (1 )
9199
92100 defNic = defaultNic .name
93- network = input ("Please choose which network used to create VM:[%s]" % defNic )
101+ network = input ("Please choose which network used to create VM:[%s]" % defNic )
94102 if network == "" :
95103 if defNic == "" :
96104 print ("You need to specify one of Nic or bridge on your system" )
@@ -100,21 +108,32 @@ def getUserInputs():
100108
101109 return [mgtSvr , zoneToken , network , podId , clusterId , hypervisor ]
102110
103- if __name__ == '__main__' :
111+
112+ if __name__ == "__main__" :
104113 initLoging ("@AGENTLOGDIR@/setup.log" )
105114 glbEnv = globalEnv ()
106115
107116 glbEnv .mode = "Agent"
108117 glbEnv .agentMode = "Agent"
109118 parser = OptionParser ()
110119 parser .add_option ("-a" , action = "store_true" , dest = "auto" , help = "auto mode" )
111- parser .add_option ("-m" , "--host" , dest = "mgt" , help = "Management server hostname or IP-Address" )
120+ parser .add_option (
121+ "-m" , "--host" , dest = "mgt" , help = "Management server hostname or IP-Address"
122+ )
112123 parser .add_option ("-z" , "--zone" , dest = "zone" , help = "zone id" )
113124 parser .add_option ("-p" , "--pod" , dest = "pod" , help = "pod id" )
114125 parser .add_option ("-c" , "--cluster" , dest = "cluster" , help = "cluster id" )
115- parser .add_option ("-t" , "--hypervisor" , default = "kvm" , dest = "hypervisor" , help = "hypervisor type" )
126+ parser .add_option (
127+ "-t" , "--hypervisor" , default = "kvm" , dest = "hypervisor" , help = "hypervisor type"
128+ )
116129 parser .add_option ("-g" , "--guid" , dest = "guid" , help = "guid" )
117- parser .add_option ("-s" , action = "store_true" , default = False , dest = "secure" , help = "Secure and enable TLS for libvirtd" )
130+ parser .add_option (
131+ "-s" ,
132+ action = "store_true" ,
133+ default = False ,
134+ dest = "secure" ,
135+ help = "Secure and enable TLS for libvirtd" ,
136+ )
118137 parser .add_option ("--pubNic" , dest = "pubNic" , help = "Public traffic interface" )
119138 parser .add_option ("--prvNic" , dest = "prvNic" , help = "Private traffic interface" )
120139 parser .add_option ("--guestNic" , dest = "guestNic" , help = "Guest traffic interface" )
@@ -140,15 +159,15 @@ if __name__ == '__main__':
140159 glbEnv .pod = userInputs [3 ]
141160 glbEnv .cluster = userInputs [4 ]
142161 glbEnv .hypervisor = userInputs [5 ]
143- #generate UUID
162+ # generate UUID
144163 glbEnv .uuid = old_config .getEntry ("guid" )
145164 if glbEnv .uuid == "" :
146165 glbEnv .uuid = bash ("uuidgen" ).getStdout ()
147166 else :
148167 for para , value in list (options .__dict__ .items ()):
149168 if value is None :
150- print ("Missing operand:%s" % para )
151- print ("Try %s --help for more information" % sys .argv [0 ])
169+ print ("Missing operand:%s" % para )
170+ print ("Try %s --help for more information" % sys .argv [0 ])
152171 sys .exit (1 )
153172
154173 glbEnv .uuid = options .guid
@@ -168,7 +187,7 @@ if __name__ == '__main__':
168187 try :
169188 syscfg .config ()
170189 print ("CloudStack Agent setup is done!" )
171- except (CloudRuntimeException ,CloudInternalException ) as e :
190+ except (CloudRuntimeException , CloudInternalException ) as e :
172191 print (e )
173192 print ("Try to restore your system:" )
174193 try :
0 commit comments