Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add #7

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 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,17 @@ 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}")
clouds_yaml_data = { "clouds": clouds_yaml_data }
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
Loading