diff --git a/scripts/openstack-server b/scripts/openstack-server index 3cb5f3f..a4ee5af 100755 --- a/scripts/openstack-server +++ b/scripts/openstack-server @@ -84,7 +84,8 @@ def get_options() -> dict: "--sgroup-policy", dest="sgroup_policy", 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", ) create_parser.add_argument( @@ -232,7 +233,10 @@ def get_options() -> dict: options["key"] = args.key options["network"] = args.network 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": options["preserve_port"] = args.preserve_port 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) if not keypair_exists: # 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) return key_name 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( 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): 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) 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 if server_exists: 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)) else: @@ -478,7 +487,8 @@ def create(options: dict) -> int: run_in_openstack(show_port_command, rc_file, with_tsocks) ) 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) # Finaly set up is done, and we can create server @@ -499,9 +509,13 @@ def create(options: dict) -> int: f"group={sgroup_id}", 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) 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: print(f"Wait for server: {fqdn} timed out in {timeout}") return 4 @@ -566,7 +580,8 @@ def show(options: dict) -> None: if options["format"] == "bind": # We assume that only public addresses go in dns 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"] print(get_dns_records(addresses, options["fqdn"]))