55import argparse
66import logging
77import time
8+ from typing import Any
89
10+ import yaml
911from openstack .connection import Connection
1012from openstack .config import loader
1113
4446 help = "Dump the created servers as an ansible inventory to the specified directory, "
4547 "adds a ssh proxy jump for the hosts without a floating ip" )
4648
49+ parser .add_argument ('--clouds_yaml' , type = str , nargs = "?" ,
50+ help = "Generate a openstack clouds.yaml file" )
51+
4752parser .add_argument ('--wait_for_machines' , action = "store_true" ,
4853 help = "Wait for every machine to be created "
4954 "(normally the provisioning only waits for machines which use floating ips)" )
@@ -105,6 +110,7 @@ def establish_connection():
105110if args .create_domains :
106111 conn = establish_connection ()
107112 workload_domains : dict [str , WorkloadGeneratorDomain ] = dict ()
113+ clouds_yaml_data : dict [str , dict [str , Any ]] = dict ()
108114 for domain_name in args .create_domains :
109115 domain = WorkloadGeneratorDomain (conn , domain_name )
110116 domain .create_and_get_domain ()
@@ -120,9 +126,17 @@ def establish_connection():
120126 workload_project .get_and_create_machines (args .create_machines , args .wait_for_machines )
121127 if args .ansible_inventory :
122128 workload_project .dump_inventory_hosts (args .ansible_inventory )
129+ if args .clouds_yaml :
130+ clouds_yaml_data [f"{ workload_domain .domain_name } -{ workload_project .project_name } " ] \
131+ = workload_project .get_clouds_yaml_data ()
123132 elif args .delete_machines :
124133 for machine_obj in workload_project .get_machines (args .delete_machines ):
125134 machine_obj .delete_machine ()
135+ if args .clouds_yaml :
136+ LOGGER .info (f"Creating a a clouds yaml : { args .clouds_yaml } " )
137+ clouds_yaml_data = { "clouds" : clouds_yaml_data }
138+ with open (args .clouds_yaml , 'w' ) as file :
139+ yaml .dump (clouds_yaml_data , file , default_flow_style = False , explicit_start = True )
126140 sys .exit (0 )
127141 elif args .delete_projects :
128142 conn = establish_connection ()
0 commit comments