Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Schöchlin <[email protected]>
  • Loading branch information
scoopex committed Dec 5, 2024
1 parent 5ec3679 commit 487729e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/openstack_workload_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import argparse
import logging
import time
from typing import Any

import yaml
from openstack.connection import Connection
from openstack.config import loader

Expand Down Expand Up @@ -44,6 +46,9 @@
help="Dump the created servers as an ansible inventory to the specified directory, "
"adds a ssh proxy jump for the hosts without a floating ip")

parser.add_argument('--clouds_yaml', type=str, nargs="?",
help="Generate a openstack clouds.yaml file")

parser.add_argument('--wait_for_machines', action="store_true",
help="Wait for every machine to be created "
"(normally the provisioning only waits for machines which use floating ips)")
Expand Down Expand Up @@ -105,6 +110,7 @@ def establish_connection():
if args.create_domains:
conn = establish_connection()
workload_domains: dict[str, WorkloadGeneratorDomain] = dict()
clouds_yaml_data: dict[str, dict[str, Any]] = dict()
for domain_name in args.create_domains:
domain = WorkloadGeneratorDomain(conn, domain_name)
domain.create_and_get_domain()
Expand All @@ -120,9 +126,16 @@ def establish_connection():
workload_project.get_and_create_machines(args.create_machines, args.wait_for_machines)
if args.ansible_inventory:
workload_project.dump_inventory_hosts(args.ansible_inventory)
if args.clouds_yaml:
clouds_yaml_data[f"{workload_domain.domain_name}-{workload_project.project_name}"] \
= workload_project.get_clouds_yaml_data()
elif args.delete_machines:
for machine_obj in workload_project.get_machines(args.delete_machines):
machine_obj.delete_machine()
if args.clouds_yaml:
LOGGER.info(f"Creating a a clouds yaml : {args.clouds_yaml}")
with open(args.clouds_yaml, 'w') as file:
yaml.dump(clouds_yaml_data, file, default_flow_style=False, explicit_start=True)
sys.exit(0)
elif args.delete_projects:
conn = establish_connection()
Expand Down
16 changes: 16 additions & 0 deletions src/openstack_workload_generator/entities/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,19 @@ def close_connection(self):
if self._project_conn:
self._project_conn.close()
self._project_conn = None

def get_clouds_yaml_data(self) -> dict[str, str | dict[str, str]]:
data: dict[str, str | dict[str, str]] = {
"auth": {
"username": self.user.user_name,
"project_name": self.project_name,
"auth_url": self.project_conn.session.auth.auth_url,
"project_domain_name": self.domain.name,
"user_domain_name": self.domain.name,
"password": self.user.user_password,
},
"cacert": self.project_conn.verify,
"identity_api_version": "3",
"endpoint_type": "internalURL"
}
return data

0 comments on commit 487729e

Please sign in to comment.