3131
3232LOGGER = logging .getLogger ()
3333
34- parser = argparse .ArgumentParser (
35- prog = 'Create workloads on openstack installations' )
36-
37- parser .add_argument ('--log_level' , metavar = 'loglevel' , type = str ,
38- default = "INFO" , help = 'The loglevel' )
39-
40- parser .add_argument ('--os_cloud' , type = cloud_checker ,
41- default = os .environ .get ("OS_CLOUD" , "admin" ),
42- help = 'The openstack config to use, defaults to the value of the OS_CLOUD '
43- 'environment variable or "admin" if the variable is not set' )
44-
45- parser .add_argument ('--ansible_inventory' , type = str , nargs = "?" ,
46- help = "Dump the created servers as an ansible inventory to the specified directory, "
47- "adds a ssh proxy jump for the hosts without a floating ip" )
48-
49- parser .add_argument ('--clouds_yaml' , type = str , nargs = "?" ,
50- help = "Use a specific clouds.yaml file" )
51-
52- parser .add_argument ('--wait_for_machines' , action = "store_true" ,
53- help = "Wait for every machine to be created "
54- "(normally the provisioning only waits for machines which use floating ips)" )
55-
56- parser .add_argument ('--generate_clouds_yaml' , type = str , nargs = "?" ,
57- help = "Generate a openstack clouds.yaml file" )
58-
59-
60- parser .add_argument ('--config' , type = str ,
61- default = "default.yaml" ,
62- help = 'The config file for environment creation, define a path to the'
63- ' yaml file or a subpath in the profiles folder' )
34+ parser = argparse .ArgumentParser (prog = "Create workloads on openstack installations" )
35+
36+ parser .add_argument (
37+ "--log_level" , metavar = "loglevel" , type = str , default = "INFO" , help = "The loglevel"
38+ )
39+
40+ parser .add_argument (
41+ "--os_cloud" ,
42+ type = cloud_checker ,
43+ default = os .environ .get ("OS_CLOUD" , "admin" ),
44+ help = "The openstack config to use, defaults to the value of the OS_CLOUD "
45+ 'environment variable or "admin" if the variable is not set' ,
46+ )
47+
48+ parser .add_argument (
49+ "--ansible_inventory" ,
50+ type = str ,
51+ nargs = "?" ,
52+ help = "Dump the created servers as an ansible inventory to the specified directory, "
53+ "adds a ssh proxy jump for the hosts without a floating ip" ,
54+ )
55+
56+ parser .add_argument (
57+ "--clouds_yaml" , type = str , nargs = "?" , help = "Use a specific clouds.yaml file"
58+ )
59+
60+ parser .add_argument (
61+ "--wait_for_machines" ,
62+ action = "store_true" ,
63+ help = "Wait for every machine to be created "
64+ "(normally the provisioning only waits for machines which use floating ips)" ,
65+ )
66+
67+ parser .add_argument (
68+ "--generate_clouds_yaml" ,
69+ type = str ,
70+ nargs = "?" ,
71+ help = "Generate a openstack clouds.yaml file" ,
72+ )
73+
74+
75+ parser .add_argument (
76+ "--config" ,
77+ type = str ,
78+ default = "default.yaml" ,
79+ help = "The config file for environment creation, define a path to the"
80+ " yaml file or a subpath in the profiles folder" ,
81+ )
6482
6583exclusive_group_domain = parser .add_mutually_exclusive_group (required = True )
6684
67- exclusive_group_domain .add_argument ('--create_domains' , type = item_checker , nargs = "+" , default = None ,
68- metavar = "DOMAINNAME" ,
69- help = 'A list of domains to be created' )
70-
71- exclusive_group_domain .add_argument ('--delete_domains' , type = item_checker , nargs = "+" , default = None ,
72- metavar = "DOMAINNAME" ,
73- help = 'A list of domains to be deleted, all child elements are recursively deleted' )
85+ exclusive_group_domain .add_argument (
86+ "--create_domains" ,
87+ type = item_checker ,
88+ nargs = "+" ,
89+ default = None ,
90+ metavar = "DOMAINNAME" ,
91+ help = "A list of domains to be created" ,
92+ )
93+
94+ exclusive_group_domain .add_argument (
95+ "--delete_domains" ,
96+ type = item_checker ,
97+ nargs = "+" ,
98+ default = None ,
99+ metavar = "DOMAINNAME" ,
100+ help = "A list of domains to be deleted, all child elements are recursively deleted" ,
101+ )
74102
75103exclusive_group_project = parser .add_mutually_exclusive_group (required = False )
76104
77- exclusive_group_project .add_argument ('--create_projects' , type = item_checker , nargs = "+" , default = None ,
78- metavar = "PROJECTNAME" ,
79- help = 'A list of projects to be created in the created domains' )
80-
81- exclusive_group_project .add_argument ('--delete_projects' , type = item_checker , nargs = "+" , default = None ,
82- metavar = "PROJECTNAME" ,
83- help = 'A list of projects to be deleted in the created '
84- 'domains, all child elements are recursively deleted' )
105+ exclusive_group_project .add_argument (
106+ "--create_projects" ,
107+ type = item_checker ,
108+ nargs = "+" ,
109+ default = None ,
110+ metavar = "PROJECTNAME" ,
111+ help = "A list of projects to be created in the created domains" ,
112+ )
113+
114+ exclusive_group_project .add_argument (
115+ "--delete_projects" ,
116+ type = item_checker ,
117+ nargs = "+" ,
118+ default = None ,
119+ metavar = "PROJECTNAME" ,
120+ help = "A list of projects to be deleted in the created "
121+ "domains, all child elements are recursively deleted" ,
122+ )
85123
86124exclusive_group_machines = parser .add_mutually_exclusive_group (required = False )
87- exclusive_group_machines .add_argument ('--create_machines' , type = item_checker , nargs = "+" , default = None ,
88- metavar = "SERVERNAME" ,
89- help = 'A list of vms to be created in the created domains' )
90-
91- exclusive_group_machines .add_argument ('--delete_machines' , type = item_checker , nargs = "+" , default = None ,
92- metavar = "SERVERNAME" ,
93- help = 'A list of vms to be deleted in the created projects' )
125+ exclusive_group_machines .add_argument (
126+ "--create_machines" ,
127+ type = item_checker ,
128+ nargs = "+" ,
129+ default = None ,
130+ metavar = "SERVERNAME" ,
131+ help = "A list of vms to be created in the created domains" ,
132+ )
133+
134+ exclusive_group_machines .add_argument (
135+ "--delete_machines" ,
136+ type = item_checker ,
137+ nargs = "+" ,
138+ default = None ,
139+ metavar = "SERVERNAME" ,
140+ help = "A list of vms to be deleted in the created projects" ,
141+ )
94142
95143args = parser .parse_args ()
96144
@@ -109,6 +157,7 @@ def establish_connection():
109157 cloud_config = config .get_one (args .os_cloud )
110158 return Connection (config = cloud_config )
111159
160+
112161time_start = time .time ()
113162
114163Config .load_config (args .config )
@@ -130,20 +179,30 @@ def establish_connection():
130179 for workload_domain in workload_domains .values ():
131180 for workload_project in workload_domain .get_projects (args .create_projects ):
132181 if args .create_machines :
133- workload_project .get_and_create_machines (args .create_machines , args .wait_for_machines )
182+ workload_project .get_and_create_machines (
183+ args .create_machines , args .wait_for_machines
184+ )
134185 if args .ansible_inventory :
135186 workload_project .dump_inventory_hosts (args .ansible_inventory )
136187 if args .clouds_yaml :
137- clouds_yaml_data [f"{ workload_domain .domain_name } -{ workload_project .project_name } " ] \
138- = workload_project .get_clouds_yaml_data ()
188+ clouds_yaml_data [
189+ f"{ workload_domain .domain_name } -{ workload_project .project_name } "
190+ ] = workload_project .get_clouds_yaml_data ()
139191 elif args .delete_machines :
140- for machine_obj in workload_project .get_machines (args .delete_machines ):
192+ for machine_obj in workload_project .get_machines (
193+ args .delete_machines
194+ ):
141195 machine_obj .delete_machine ()
142196 if args .generate_clouds_yaml :
143197 LOGGER .info (f"Creating a a clouds yaml : { args .generate_clouds_yaml } " )
144198 clouds_yaml_data = {"clouds" : clouds_yaml_data }
145- with open (args .generate_clouds_yaml , 'w' ) as file :
146- yaml .dump (clouds_yaml_data , file , default_flow_style = False , explicit_start = True )
199+ with open (args .generate_clouds_yaml , "w" ) as file :
200+ yaml .dump (
201+ clouds_yaml_data ,
202+ file ,
203+ default_flow_style = False ,
204+ explicit_start = True ,
205+ )
147206 sys .exit (0 )
148207 elif args .delete_projects :
149208 conn = establish_connection ()
0 commit comments