Make local storage work as expected

This commit is contained in:
Micke Nordin 2024-12-05 10:39:19 +01:00
parent df681e23dc
commit f61f706bff
Signed by: Micke
GPG key ID: 0DA0A7A5708FE257

View file

@ -84,7 +84,8 @@ def get_options() -> dict:
"--sgroup-policy", "--sgroup-policy",
dest="sgroup_policy", dest="sgroup_policy",
help="Set security group policy for machine", help="Set security group policy for machine",
choices=["affinity", "anti-affinity", "soft-affinity", "soft-anti-affinity"], choices=["affinity", "anti-affinity",
"soft-affinity", "soft-anti-affinity"],
default="anti-affinity", default="anti-affinity",
) )
create_parser.add_argument( create_parser.add_argument(
@ -232,7 +233,10 @@ def get_options() -> dict:
options["key"] = args.key options["key"] = args.key
options["network"] = args.network options["network"] = args.network
options["sgroup_policy"] = args.sgroup_policy options["sgroup_policy"] = args.sgroup_policy
options["volume_size"] = args.volume_size if args.flavor.startswith("b"):
options["volume_size"] = args.volume_size
else:
options["volume_size"] = "volume_empty"
if args.command == "delete": if args.command == "delete":
options["preserve_port"] = args.preserve_port options["preserve_port"] = args.preserve_port
options["preserve_cosmos_overlay"] = args.preserve_cosmos_overlay options["preserve_cosmos_overlay"] = args.preserve_cosmos_overlay
@ -365,21 +369,25 @@ def setup_key(in_key: str, rc_file: str, with_tsocks: bool) -> str:
keypair_exists = keypair_existence(key_name) keypair_exists = keypair_existence(key_name)
if not keypair_exists: if not keypair_exists:
# We cannot proceed without a public key # We cannot proceed without a public key
print('{"ERROR": "No keypair exists and I could not create a new one :("}') print(
'{"ERROR": "No keypair exists and I could not create a new one :("}')
sys.exit(3) sys.exit(3)
return key_name return key_name
def setup_rc_file(options: dict) -> str: def setup_rc_file(options: dict) -> str:
config_basepath = path_join(path_join(os.environ["HOME"], ".config"), "sunet") config_basepath = path_join(
path_join(os.environ["HOME"], ".config"), "sunet")
rc_file = path_join( rc_file = path_join(
config_basepath, config_basepath,
f"app-cred-{options['service']}-{options['location']}-{options['environment']}-openrc.sh", f"app-cred-{options['service']}-{options['location']
}-{options['environment']}-openrc.sh",
) )
if not isfile(rc_file): if not isfile(rc_file):
print( print(
f"You need to download an openrc file from openstack and save it as {rc_file}" f"You need to download an openrc file from openstack and save it as {
rc_file}"
) )
sys.exit(2) sys.exit(2)
return rc_file return rc_file
@ -446,7 +454,8 @@ def create(options: dict) -> int:
# We will bail out early if the server allready exists, and just print out what we know about it # We will bail out early if the server allready exists, and just print out what we know about it
if server_exists: if server_exists:
if dns_record: if dns_record:
addresses = json.loads(server_output_error[0])["addresses"][network] addresses = json.loads(server_output_error[0])[
"addresses"][network]
print(get_dns_records(addresses, fqdn)) print(get_dns_records(addresses, fqdn))
else: else:
@ -478,7 +487,8 @@ def create(options: dict) -> int:
run_in_openstack(show_port_command, rc_file, with_tsocks) run_in_openstack(show_port_command, rc_file, with_tsocks)
) )
if not port_exists: if not port_exists:
create_port_command = ["port", "create", "--network", network, port_name] create_port_command = ["port", "create",
"--network", network, port_name]
run_in_openstack(create_port_command, rc_file, with_tsocks) run_in_openstack(create_port_command, rc_file, with_tsocks)
# Finaly set up is done, and we can create server # Finaly set up is done, and we can create server
@ -499,9 +509,13 @@ def create(options: dict) -> int:
f"group={sgroup_id}", f"group={sgroup_id}",
fqdn, fqdn,
] ]
if volume_size == 'volume_empty':
create_server_command.remove("--boot-from-volume")
create_server_command.remove("volume_empty")
run_in_openstack(create_server_command, rc_file, with_tsocks) run_in_openstack(create_server_command, rc_file, with_tsocks)
timeout = 360 timeout = 360
succeed = wait_for_server(fqdn, rc_file, network, with_tsocks, timeout=timeout) succeed = wait_for_server(
fqdn, rc_file, network, with_tsocks, timeout=timeout)
if not succeed: if not succeed:
print(f"Wait for server: {fqdn} timed out in {timeout}") print(f"Wait for server: {fqdn} timed out in {timeout}")
return 4 return 4
@ -566,7 +580,8 @@ def show(options: dict) -> None:
if options["format"] == "bind": if options["format"] == "bind":
# We assume that only public addresses go in dns # We assume that only public addresses go in dns
addresses = json.loads( addresses = json.loads(
show_server(options["fqdn"], options["rc_file"], options["with_tsocks"])[0] show_server(options["fqdn"], options["rc_file"],
options["with_tsocks"])[0]
)["addresses"]["public"] )["addresses"]["public"]
print(get_dns_records(addresses, options["fqdn"])) print(get_dns_records(addresses, options["fqdn"]))