From 6edf86d35d07e6fb7bd07a01b08babd80b137927 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Wed, 11 Sep 2024 14:58:02 +0200 Subject: [PATCH 1/8] feat(Metadata):set metadata endpoint and update script --- portal_client.thrift | 5 +- simple_vm_client/VirtualMachineHandler.py | 4 + simple_vm_client/VirtualMachineService-remote | 23 ++-- simple_vm_client/VirtualMachineService.py | 116 ++++++++++++++++-- .../openstack_connector.py | 20 +-- .../scripts/bash/save_metadata_auth_token.sh | 35 +++++- 6 files changed, 176 insertions(+), 27 deletions(-) diff --git a/portal_client.thrift b/portal_client.thrift index cbdea1e..7cd2f5c 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -466,6 +466,7 @@ service VirtualMachineService { 11:optional list additional_security_group_ids, 12:optional string slurm_version, 13:optional string metadata_token, + 14:optional string metadata_endpoint ) @@ -500,6 +501,8 @@ service VirtualMachineService { 8:list> volume_ids_path_attach, 9:optional list additional_security_group_ids, 10:optional string metadata_token, + 11:optional string metadata_endpoint + ) throws (1:NameAlreadyUsedException e,2:ResourceNotAvailableException r,3: ImageNotFoundException i,4: FlavorNotFoundException f,5:DefaultException d) @@ -558,7 +561,7 @@ service VirtualMachineService { ) throws (1:BackendNotFoundException b,2:DefaultException d) - void set_metadata_server_data(1:string ip,2:VirtualMachineServerMetadata metadata) throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b) + void set_metadata_server_data(1:string ip,2:string endpoint,3:VirtualMachineServerMetadata metadata) throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b) void remove_metadata_server_data(1:string ip) throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b) void is_metadata_server_available() throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b) diff --git a/simple_vm_client/VirtualMachineHandler.py b/simple_vm_client/VirtualMachineHandler.py index 77601f4..1f01dca 100644 --- a/simple_vm_client/VirtualMachineHandler.py +++ b/simple_vm_client/VirtualMachineHandler.py @@ -383,6 +383,7 @@ def start_server( additional_security_group_ids: list[str], slurm_version: str = None, metadata_token: str = None, + metadata_endpoint: str = None, ) -> str: if research_environment: research_environment_metadata = ( @@ -405,6 +406,7 @@ def start_server( additional_security_group_ids=additional_security_group_ids, slurm_version=slurm_version, metadata_token=metadata_token, + metadata_endpoint=metadata_endpoint, ) def start_server_with_custom_key( @@ -418,6 +420,7 @@ def start_server_with_custom_key( volume_ids_path_attach: list[dict[str, str]], additional_security_group_ids: list[str], metadata_token: str = None, + metadata_endpoint: str = None, ) -> str: if research_environment: research_environment_metadata = ( @@ -437,6 +440,7 @@ def start_server_with_custom_key( volume_ids_path_attach=volume_ids_path_attach, additional_security_group_ids=additional_security_group_ids, metadata_token=metadata_token, + metadata_endpoint=metadata_endpoint, ) self.forc_connector.set_vm_wait_for_playbook( openstack_id=openstack_id, private_key=private_key, name=servername diff --git a/simple_vm_client/VirtualMachineService-remote b/simple_vm_client/VirtualMachineService-remote index f4c80ed..bbf9029 100755 --- a/simple_vm_client/VirtualMachineService-remote +++ b/simple_vm_client/VirtualMachineService-remote @@ -53,12 +53,12 @@ if len(sys.argv) <= 1 or sys.argv[1] == "--help": print(" void delete_security_group_rule(string openstack_id)") print(" void delete_server(string openstack_id)") print( - " string start_server(string flavor_name, string image_name, string public_key, string servername, metadata, volume_ids_path_new, volume_ids_path_attach, additional_keys, string research_environment, additional_security_group_ids, string slurm_version, string metadata_token)" + " string start_server(string flavor_name, string image_name, string public_key, string servername, metadata, volume_ids_path_new, volume_ids_path_attach, additional_keys, string research_environment, additional_security_group_ids, string slurm_version, string metadata_token, string metadata_endpoint)" ) print(" bool is_bibigrid_available()") print(" void detach_ip_from_server(string server_id, string floating_ip)") print( - " string start_server_with_custom_key(string flavor_name, string image_name, string servername, metadata, string research_environment, volume_ids_path_new, volume_ids_path_attach, additional_security_group_ids, string metadata_token)" + " string start_server_with_custom_key(string flavor_name, string image_name, string servername, metadata, string research_environment, volume_ids_path_new, volume_ids_path_attach, additional_security_group_ids, string metadata_token, string metadata_endpoint)" ) print(" bool exist_server(string name)") print( @@ -75,7 +75,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == "--help": print(" get_backends_by_template(string template)") print(" Backend get_backend_by_id(i64 id)") print( - " void set_metadata_server_data(string ip, VirtualMachineServerMetadata metadata)" + " void set_metadata_server_data(string ip, string endpoint, VirtualMachineServerMetadata metadata)" ) print(" void remove_metadata_server_data(string ip)") print(" void is_metadata_server_available()") @@ -396,8 +396,8 @@ elif cmd == "delete_server": ) elif cmd == "start_server": - if len(args) != 12: - print("start_server requires 12 args") + if len(args) != 13: + print("start_server requires 13 args") sys.exit(1) pp.pprint( client.start_server( @@ -413,6 +413,7 @@ elif cmd == "start_server": eval(args[9]), args[10], args[11], + args[12], ) ) @@ -434,8 +435,8 @@ elif cmd == "detach_ip_from_server": ) elif cmd == "start_server_with_custom_key": - if len(args) != 9: - print("start_server_with_custom_key requires 9 args") + if len(args) != 10: + print("start_server_with_custom_key requires 10 args") sys.exit(1) pp.pprint( client.start_server_with_custom_key( @@ -448,6 +449,7 @@ elif cmd == "start_server_with_custom_key": eval(args[6]), eval(args[7]), args[8], + args[9], ) ) @@ -549,13 +551,14 @@ elif cmd == "get_backend_by_id": ) elif cmd == "set_metadata_server_data": - if len(args) != 2: - print("set_metadata_server_data requires 2 args") + if len(args) != 3: + print("set_metadata_server_data requires 3 args") sys.exit(1) pp.pprint( client.set_metadata_server_data( args[0], - eval(args[1]), + args[1], + eval(args[2]), ) ) diff --git a/simple_vm_client/VirtualMachineService.py b/simple_vm_client/VirtualMachineService.py index 3b088fe..87dcb82 100644 --- a/simple_vm_client/VirtualMachineService.py +++ b/simple_vm_client/VirtualMachineService.py @@ -204,6 +204,7 @@ def start_server( additional_security_group_ids, slurm_version, metadata_token, + metadata_endpoint, ): """ Parameters: @@ -219,6 +220,7 @@ def start_server( - additional_security_group_ids - slurm_version - metadata_token + - metadata_endpoint """ @@ -244,6 +246,7 @@ def start_server_with_custom_key( volume_ids_path_attach, additional_security_group_ids, metadata_token, + metadata_endpoint, ): """ Start a new server with custom key for ansible. @@ -258,6 +261,7 @@ def start_server_with_custom_key( - volume_ids_path_attach - additional_security_group_ids - metadata_token + - metadata_endpoint """ @@ -357,10 +361,11 @@ def get_backend_by_id(self, id): """ - def set_metadata_server_data(self, ip, metadata): + def set_metadata_server_data(self, ip, endpoint, metadata): """ Parameters: - ip + - endpoint - metadata """ @@ -1498,6 +1503,7 @@ def start_server( additional_security_group_ids, slurm_version, metadata_token, + metadata_endpoint, ): """ Parameters: @@ -1513,6 +1519,7 @@ def start_server( - additional_security_group_ids - slurm_version - metadata_token + - metadata_endpoint """ self.send_start_server( @@ -1528,6 +1535,7 @@ def start_server( additional_security_group_ids, slurm_version, metadata_token, + metadata_endpoint, ) return self.recv_start_server() @@ -1545,6 +1553,7 @@ def send_start_server( additional_security_group_ids, slurm_version, metadata_token, + metadata_endpoint, ): self._oprot.writeMessageBegin("start_server", TMessageType.CALL, self._seqid) args = start_server_args() @@ -1560,6 +1569,7 @@ def send_start_server( args.additional_security_group_ids = additional_security_group_ids args.slurm_version = slurm_version args.metadata_token = metadata_token + args.metadata_endpoint = metadata_endpoint args.write(self._oprot) self._oprot.writeMessageEnd() self._oprot.trans.flush() @@ -1669,6 +1679,7 @@ def start_server_with_custom_key( volume_ids_path_attach, additional_security_group_ids, metadata_token, + metadata_endpoint, ): """ Start a new server with custom key for ansible. @@ -1683,6 +1694,7 @@ def start_server_with_custom_key( - volume_ids_path_attach - additional_security_group_ids - metadata_token + - metadata_endpoint """ self.send_start_server_with_custom_key( @@ -1695,6 +1707,7 @@ def start_server_with_custom_key( volume_ids_path_attach, additional_security_group_ids, metadata_token, + metadata_endpoint, ) return self.recv_start_server_with_custom_key() @@ -1709,6 +1722,7 @@ def send_start_server_with_custom_key( volume_ids_path_attach, additional_security_group_ids, metadata_token, + metadata_endpoint, ): self._oprot.writeMessageBegin( "start_server_with_custom_key", TMessageType.CALL, self._seqid @@ -1723,6 +1737,7 @@ def send_start_server_with_custom_key( args.volume_ids_path_attach = volume_ids_path_attach args.additional_security_group_ids = additional_security_group_ids args.metadata_token = metadata_token + args.metadata_endpoint = metadata_endpoint args.write(self._oprot) self._oprot.writeMessageEnd() self._oprot.trans.flush() @@ -2177,22 +2192,24 @@ def recv_get_backend_by_id(self): "get_backend_by_id failed: unknown result", ) - def set_metadata_server_data(self, ip, metadata): + def set_metadata_server_data(self, ip, endpoint, metadata): """ Parameters: - ip + - endpoint - metadata """ - self.send_set_metadata_server_data(ip, metadata) + self.send_set_metadata_server_data(ip, endpoint, metadata) self.recv_set_metadata_server_data() - def send_set_metadata_server_data(self, ip, metadata): + def send_set_metadata_server_data(self, ip, endpoint, metadata): self._oprot.writeMessageBegin( "set_metadata_server_data", TMessageType.CALL, self._seqid ) args = set_metadata_server_data_args() args.ip = ip + args.endpoint = endpoint args.metadata = metadata args.write(self._oprot) self._oprot.writeMessageEnd() @@ -4463,6 +4480,7 @@ def process_start_server(self, seqid, iprot, oprot): args.additional_security_group_ids, args.slurm_version, args.metadata_token, + args.metadata_endpoint, ) msg_type = TMessageType.REPLY except TTransport.TTransportException: @@ -4566,6 +4584,7 @@ def process_start_server_with_custom_key(self, seqid, iprot, oprot): args.volume_ids_path_attach, args.additional_security_group_ids, args.metadata_token, + args.metadata_endpoint, ) msg_type = TMessageType.REPLY except TTransport.TTransportException: @@ -4893,7 +4912,9 @@ def process_set_metadata_server_data(self, seqid, iprot, oprot): iprot.readMessageEnd() result = set_metadata_server_data_result() try: - self._handler.set_metadata_server_data(args.ip, args.metadata) + self._handler.set_metadata_server_data( + args.ip, args.endpoint, args.metadata + ) msg_type = TMessageType.REPLY except TTransport.TTransportException: raise @@ -9569,6 +9590,7 @@ class start_server_args(object): - additional_security_group_ids - slurm_version - metadata_token + - metadata_endpoint """ @@ -9586,6 +9608,7 @@ def __init__( additional_security_group_ids=None, slurm_version=None, metadata_token=None, + metadata_endpoint=None, ): self.flavor_name = flavor_name self.image_name = image_name @@ -9599,6 +9622,7 @@ def __init__( self.additional_security_group_ids = additional_security_group_ids self.slurm_version = slurm_version self.metadata_token = metadata_token + self.metadata_endpoint = metadata_endpoint def read(self, iprot): if ( @@ -9771,6 +9795,15 @@ def read(self, iprot): ) else: iprot.skip(ftype) + elif fid == 14: + if ftype == TType.STRING: + self.metadata_endpoint = ( + iprot.readString().decode("utf-8", errors="replace") + if sys.version_info[0] == 2 + else iprot.readString() + ) + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -9907,6 +9940,14 @@ def write(self, oprot): else self.metadata_token ) oprot.writeFieldEnd() + if self.metadata_endpoint is not None: + oprot.writeFieldBegin("metadata_endpoint", TType.STRING, 14) + oprot.writeString( + self.metadata_endpoint.encode("utf-8") + if sys.version_info[0] == 2 + else self.metadata_endpoint + ) + oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() @@ -10012,6 +10053,13 @@ def __ne__(self, other): "UTF8", None, ), # 13 + ( + 14, + TType.STRING, + "metadata_endpoint", + "UTF8", + None, + ), # 14 ) @@ -10521,6 +10569,7 @@ class start_server_with_custom_key_args(object): - volume_ids_path_attach - additional_security_group_ids - metadata_token + - metadata_endpoint """ @@ -10535,6 +10584,7 @@ def __init__( volume_ids_path_attach=None, additional_security_group_ids=None, metadata_token=None, + metadata_endpoint=None, ): self.flavor_name = flavor_name self.image_name = image_name @@ -10545,6 +10595,7 @@ def __init__( self.volume_ids_path_attach = volume_ids_path_attach self.additional_security_group_ids = additional_security_group_ids self.metadata_token = metadata_token + self.metadata_endpoint = metadata_endpoint def read(self, iprot): if ( @@ -10685,6 +10736,15 @@ def read(self, iprot): ) else: iprot.skip(ftype) + elif fid == 11: + if ftype == TType.STRING: + self.metadata_endpoint = ( + iprot.readString().decode("utf-8", errors="replace") + if sys.version_info[0] == 2 + else iprot.readString() + ) + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -10796,6 +10856,14 @@ def write(self, oprot): else self.metadata_token ) oprot.writeFieldEnd() + if self.metadata_endpoint is not None: + oprot.writeFieldBegin("metadata_endpoint", TType.STRING, 11) + oprot.writeString( + self.metadata_endpoint.encode("utf-8") + if sys.version_info[0] == 2 + else self.metadata_endpoint + ) + oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() @@ -10880,6 +10948,13 @@ def __ne__(self, other): "UTF8", None, ), # 10 + ( + 11, + TType.STRING, + "metadata_endpoint", + "UTF8", + None, + ), # 11 ) @@ -13002,6 +13077,7 @@ class set_metadata_server_data_args(object): """ Attributes: - ip + - endpoint - metadata """ @@ -13009,9 +13085,11 @@ class set_metadata_server_data_args(object): def __init__( self, ip=None, + endpoint=None, metadata=None, ): self.ip = ip + self.endpoint = endpoint self.metadata = metadata def read(self, iprot): @@ -13037,6 +13115,15 @@ def read(self, iprot): else: iprot.skip(ftype) elif fid == 2: + if ftype == TType.STRING: + self.endpoint = ( + iprot.readString().decode("utf-8", errors="replace") + if sys.version_info[0] == 2 + else iprot.readString() + ) + else: + iprot.skip(ftype) + elif fid == 3: if ftype == TType.STRUCT: self.metadata = VirtualMachineServerMetadata() self.metadata.read(iprot) @@ -13060,8 +13147,16 @@ def write(self, oprot): self.ip.encode("utf-8") if sys.version_info[0] == 2 else self.ip ) oprot.writeFieldEnd() + if self.endpoint is not None: + oprot.writeFieldBegin("endpoint", TType.STRING, 2) + oprot.writeString( + self.endpoint.encode("utf-8") + if sys.version_info[0] == 2 + else self.endpoint + ) + oprot.writeFieldEnd() if self.metadata is not None: - oprot.writeFieldBegin("metadata", TType.STRUCT, 2) + oprot.writeFieldBegin("metadata", TType.STRUCT, 3) self.metadata.write(oprot) oprot.writeFieldEnd() oprot.writeFieldStop() @@ -13093,11 +13188,18 @@ def __ne__(self, other): ), # 1 ( 2, + TType.STRING, + "endpoint", + "UTF8", + None, + ), # 2 + ( + 3, TType.STRUCT, "metadata", [VirtualMachineServerMetadata, None], None, - ), # 2 + ), # 3 ) diff --git a/simple_vm_client/openstack_connector/openstack_connector.py b/simple_vm_client/openstack_connector/openstack_connector.py index b73b010..1816307 100644 --- a/simple_vm_client/openstack_connector/openstack_connector.py +++ b/simple_vm_client/openstack_connector/openstack_connector.py @@ -4,9 +4,9 @@ import os import socket import sys +import threading import urllib import urllib.parse -import threading from contextlib import closing from typing import Union from uuid import uuid4 @@ -485,7 +485,9 @@ def create_add_keys_script(self, keys: list[str]) -> str: key_script = text return key_script - def create_save_metadata_auth_token_script(self, token: str) -> str: + def create_save_metadata_auth_token_script( + self, token: str, metadata_endpoint: str + ) -> str: logger.info("create save metadata auth token script") file_dir = os.path.dirname(os.path.abspath(__file__)) metadata_token_script_path = os.path.join( @@ -1063,7 +1065,7 @@ def get_or_create_project_security_group(self, project_name, project_id): if security_group_name not in lock_dict: lock_dict[security_group_name] = threading.Lock() lock = lock_dict[security_group_name] - + with lock: logger.info( f"Check if Security Group for project - [{project_name}-{project_id}] exists... " @@ -1092,7 +1094,6 @@ def get_or_create_project_security_group(self, project_name, project_id): remote_group_id=new_security_group["id"], ) return new_security_group["id"] - def get_limits(self) -> dict[str, str]: logger.info("Get Limits") @@ -1322,16 +1323,17 @@ def create_userdata( volume_ids_path_new: list[dict[str, str]], volume_ids_path_attach: list[dict[str, str]], additional_keys: list[str], - metadata_token=None, + metadata_token: str = None, + metadata_endpoint: str = None, ) -> str: unlock_ubuntu_user_script = "#!/bin/bash\npasswd -u ubuntu\n" unlock_ubuntu_user_script_encoded = encodeutils.safe_encode( unlock_ubuntu_user_script.encode("utf-8") ) init_script = unlock_ubuntu_user_script_encoded - if metadata_token: + if metadata_token and metadata_endpoint: save_metadata_token_script = self.create_save_metadata_auth_token_script( - token=metadata_token + token=metadata_token, metadata_endpoint=metadata_endpoint ) init_script = ( init_script @@ -1371,6 +1373,7 @@ def start_server( additional_security_group_ids: Union[list[str], None] = None, slurm_version: str = None, metadata_token: str = None, + metadata_endpoint: str = None, ) -> str: logger.info(f"Start Server {servername}") @@ -1414,6 +1417,7 @@ def start_server( volume_ids_path_attach=volume_ids_path_attach, additional_keys=additional_keys, metadata_token=metadata_token, + metadata_endpoint=metadata_endpoint, ) logger.info(f"Starting Server {servername}...") server = self.openstack_connection.create_server( @@ -1498,6 +1502,7 @@ def start_server_with_playbook( additional_keys: list[str] = None, # type: ignore additional_security_group_ids=None, # type: ignore metadata_token: str = None, + metadata_endpoint: str = None, ) -> tuple[str, str]: logger.info(f"Start Server {servername}") @@ -1532,6 +1537,7 @@ def start_server_with_playbook( volume_ids_path_attach=volume_ids_path_attach, additional_keys=additional_keys, metadata_token=metadata_token, + metadata_endpoint=metadata_endpoint, ) server = self.openstack_connection.create_server( name=servername, diff --git a/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh b/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh index 68dee29..2600646 100644 --- a/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh +++ b/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh @@ -1,17 +1,48 @@ #!/bin/bash -# Use a clear placeholder that will be replaced in the Python script +# Use clear placeholders that will be replaced in the Python script TOKEN_ESCAPED='REPLACE_WITH_ACTUAL_TOKEN' +ENDPOINT_ESCAPED='REPLACE_WITH_ACTUAL_ENDPOINT' # Create a configuration file with the token in the ubuntu user's home directory UBUNTU_HOME_DIR="/home/ubuntu" CONFIG_FILE_PATH="$UBUNTU_HOME_DIR/.metadata_config.env" echo "METADATA_ACCESS_TOKEN='$TOKEN_ESCAPED'" > "$CONFIG_FILE_PATH" +echo "METADATA_SERVER_ENDPOINT='$ENDPOINT_ESCAPED'" >> "$CONFIG_FILE_PATH" # Secure the file permissions so only the ubuntu user can read it chmod 600 "$CONFIG_FILE_PATH" chown ubuntu:ubuntu "$CONFIG_FILE_PATH" +# Create the ~/.get_metadata.sh script to fetch metadata using the saved token +SCRIPT_DIR="$UBUNTU_HOME_DIR" +SCRIPT_NAME=".get_metadata.sh" +SCRIPT_PATH="$SCRIPT_DIR/$SCRIPT_NAME" + +echo "#!/bin/bash" > "$SCRIPT_PATH" +echo "source ~/.metadata_config.env" >> "$SCRIPT_PATH" +echo "" >> "$SCRIPT_PATH" +echo "# Define the metadata server endpoint and local machine IP" >> "$SCRIPT_PATH" +echo "SERVER_ENDPOINT=\\"$METADATA_SERVER_ENDPOINT\\"" >> "$SCRIPT_PATH" +echo "LOCAL_IP=\\$(ip route get 8.8.8.8 | awk '{print \\$7}' | tr -d '\\n')" >> "$SCRIPT_PATH" +echo "" >> "$SCRIPT_PATH" +echo "# Construct the URL" >> "$SCRIPT_PATH" +echo "URL=\\"\\${SERVER_ENDPOINT}/\\${LOCAL_IP}\\"" >> "$SCRIPT_PATH" +echo "" >> "$SCRIPT_PATH" +echo "# Define the auth header with the token" >> "$SCRIPT_PATH" +echo "AUTH_HEADER=\\"auth_token: \\${METADATA_ACCESS_TOKEN}\\"" >> "$SCRIPT_PATH" +echo "" >> "$SCRIPT_PATH" +echo "# Fetch the JSON response from the URL" >> "$SCRIPT_PATH" +echo "response=\\$(curl -s -X GET \\"\\$URL\\" -H \\"\\$AUTH_HEADER\\")" >> "$SCRIPT_PATH" +echo "" >> "$SCRIPT_PATH" +echo "echo \\"Response:\\"" >> "$SCRIPT_PATH" +echo "echo \\"\\$response\\"" >> "$SCRIPT_PATH" + +# Make the script executable +chmod 700 "$SCRIPT_PATH" +chown ubuntu:ubuntu "$SCRIPT_PATH" + # Print a message to indicate completion -echo "Token has been set and configuration file created at $CONFIG_FILE_PATH with restricted access." +echo "Token has been set, configuration file created at $CONFIG_FILE_PATH with restricted access." +echo "~/.get_metadata.sh script created to fetch metadata using the saved token." From 001ef1eeee55bf6af62895793ff2533e390bc9d9 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Mon, 16 Sep 2024 07:22:35 +0200 Subject: [PATCH 2/8] updtead metadataservice --- portal_client.thrift | 19 +- simple_vm_client/VirtualMachineService.py | 728 +++++++++--------- .../openstack_connector.py | 1 + .../scripts/bash/save_metadata_auth_token.sh | 36 +- simple_vm_client/ttypes.py | 372 +++++++-- 5 files changed, 714 insertions(+), 442 deletions(-) diff --git a/portal_client.thrift b/portal_client.thrift index 7cd2f5c..69cf5e1 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -7,11 +7,24 @@ typedef i32 int const string VERSION= '1.0.0' +struct User { + 1: optional string username, + 2: required string user_id, + 3: optional list public_keys, +} + +struct UserData { + 2: required map data = {}, +} + struct VirtualMachineServerMetadata { - 1: list public_keys - 2: string hashed_auth_token - 3: string ip + 1: required string ip, + 2: required string hashed_auth_token, + 3: optional UserData userdata, + 4: required i64 last_time_updated, } + + struct Backend { 1: i64 id, 2: string owner, diff --git a/simple_vm_client/VirtualMachineService.py b/simple_vm_client/VirtualMachineService.py index 87dcb82..1818692 100644 --- a/simple_vm_client/VirtualMachineService.py +++ b/simple_vm_client/VirtualMachineService.py @@ -6401,19 +6401,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype40, _vtype41, _size39) = iprot.readMapBegin() - for _i43 in range(_size39): - _key44 = ( + (_ktype49, _vtype50, _size48) = iprot.readMapBegin() + for _i52 in range(_size48): + _key53 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val45 = ( + _val54 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key44] = _val45 + self.success[_key53] = _val54 iprot.readMapEnd() else: iprot.skip(ftype) @@ -6432,12 +6432,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter46, viter47 in self.success.items(): + for kiter55, viter56 in self.success.items(): oprot.writeString( - kiter46.encode("utf-8") if sys.version_info[0] == 2 else kiter46 + kiter55.encode("utf-8") if sys.version_info[0] == 2 else kiter55 ) oprot.writeString( - viter47.encode("utf-8") if sys.version_info[0] == 2 else viter47 + viter56.encode("utf-8") if sys.version_info[0] == 2 else viter56 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -6547,19 +6547,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype49, _vtype50, _size48) = iprot.readMapBegin() - for _i52 in range(_size48): - _key53 = ( + (_ktype58, _vtype59, _size57) = iprot.readMapBegin() + for _i61 in range(_size57): + _key62 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val54 = ( + _val63 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key53] = _val54 + self.success[_key62] = _val63 iprot.readMapEnd() else: iprot.skip(ftype) @@ -6578,12 +6578,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter55, viter56 in self.success.items(): + for kiter64, viter65 in self.success.items(): oprot.writeString( - kiter55.encode("utf-8") if sys.version_info[0] == 2 else kiter55 + kiter64.encode("utf-8") if sys.version_info[0] == 2 else kiter64 ) oprot.writeString( - viter56.encode("utf-8") if sys.version_info[0] == 2 else viter56 + viter65.encode("utf-8") if sys.version_info[0] == 2 else viter65 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -6929,19 +6929,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype58, _vtype59, _size57) = iprot.readMapBegin() - for _i61 in range(_size57): - _key62 = ( + (_ktype67, _vtype68, _size66) = iprot.readMapBegin() + for _i70 in range(_size66): + _key71 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val63 = ( + _val72 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key62] = _val63 + self.success[_key71] = _val72 iprot.readMapEnd() else: iprot.skip(ftype) @@ -6965,12 +6965,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter64, viter65 in self.success.items(): + for kiter73, viter74 in self.success.items(): oprot.writeString( - kiter64.encode("utf-8") if sys.version_info[0] == 2 else kiter64 + kiter73.encode("utf-8") if sys.version_info[0] == 2 else kiter73 ) oprot.writeString( - viter65.encode("utf-8") if sys.version_info[0] == 2 else viter65 + viter74.encode("utf-8") if sys.version_info[0] == 2 else viter74 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -7444,19 +7444,19 @@ def read(self, iprot): elif fid == 2: if ftype == TType.MAP: self.metadata = {} - (_ktype67, _vtype68, _size66) = iprot.readMapBegin() - for _i70 in range(_size66): - _key71 = ( + (_ktype76, _vtype77, _size75) = iprot.readMapBegin() + for _i79 in range(_size75): + _key80 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val72 = ( + _val81 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.metadata[_key71] = _val72 + self.metadata[_key80] = _val81 iprot.readMapEnd() else: iprot.skip(ftype) @@ -7483,12 +7483,12 @@ def write(self, oprot): if self.metadata is not None: oprot.writeFieldBegin("metadata", TType.MAP, 2) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.metadata)) - for kiter73, viter74 in self.metadata.items(): + for kiter82, viter83 in self.metadata.items(): oprot.writeString( - kiter73.encode("utf-8") if sys.version_info[0] == 2 else kiter73 + kiter82.encode("utf-8") if sys.version_info[0] == 2 else kiter82 ) oprot.writeString( - viter74.encode("utf-8") if sys.version_info[0] == 2 else viter74 + viter83.encode("utf-8") if sys.version_info[0] == 2 else viter83 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -7702,11 +7702,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype78, _size75) = iprot.readListBegin() - for _i79 in range(_size75): - _elem80 = Flavor() - _elem80.read(iprot) - self.success.append(_elem80) + (_etype87, _size84) = iprot.readListBegin() + for _i88 in range(_size84): + _elem89 = Flavor() + _elem89.read(iprot) + self.success.append(_elem89) iprot.readListEnd() else: iprot.skip(ftype) @@ -7725,8 +7725,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter81 in self.success: - iter81.write(oprot) + for iter90 in self.success: + iter90.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -7835,11 +7835,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype85, _size82) = iprot.readListBegin() - for _i86 in range(_size82): - _elem87 = Image() - _elem87.read(iprot) - self.success.append(_elem87) + (_etype94, _size91) = iprot.readListBegin() + for _i95 in range(_size91): + _elem96 = Image() + _elem96.read(iprot) + self.success.append(_elem96) iprot.readListEnd() else: iprot.skip(ftype) @@ -7858,8 +7858,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter88 in self.success: - iter88.write(oprot) + for iter97 in self.success: + iter97.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -7968,11 +7968,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype92, _size89) = iprot.readListBegin() - for _i93 in range(_size89): - _elem94 = Image() - _elem94.read(iprot) - self.success.append(_elem94) + (_etype101, _size98) = iprot.readListBegin() + for _i102 in range(_size98): + _elem103 = Image() + _elem103.read(iprot) + self.success.append(_elem103) iprot.readListEnd() else: iprot.skip(ftype) @@ -7991,8 +7991,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter95 in self.success: - iter95.write(oprot) + for iter104 in self.success: + iter104.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -8101,11 +8101,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype99, _size96) = iprot.readListBegin() - for _i100 in range(_size96): - _elem101 = Image() - _elem101.read(iprot) - self.success.append(_elem101) + (_etype108, _size105) = iprot.readListBegin() + for _i109 in range(_size105): + _elem110 = Image() + _elem110.read(iprot) + self.success.append(_elem110) iprot.readListEnd() else: iprot.skip(ftype) @@ -8124,8 +8124,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter102 in self.success: - iter102.write(oprot) + for iter111 in self.success: + iter111.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -8567,14 +8567,14 @@ def read(self, iprot): if fid == 1: if ftype == TType.LIST: self.volume_ids = [] - (_etype106, _size103) = iprot.readListBegin() - for _i107 in range(_size103): - _elem108 = ( + (_etype115, _size112) = iprot.readListBegin() + for _i116 in range(_size112): + _elem117 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.volume_ids.append(_elem108) + self.volume_ids.append(_elem117) iprot.readListEnd() else: iprot.skip(ftype) @@ -8593,9 +8593,9 @@ def write(self, oprot): if self.volume_ids is not None: oprot.writeFieldBegin("volume_ids", TType.LIST, 1) oprot.writeListBegin(TType.STRING, len(self.volume_ids)) - for iter109 in self.volume_ids: + for iter118 in self.volume_ids: oprot.writeString( - iter109.encode("utf-8") if sys.version_info[0] == 2 else iter109 + iter118.encode("utf-8") if sys.version_info[0] == 2 else iter118 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -8658,11 +8658,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype113, _size110) = iprot.readListBegin() - for _i114 in range(_size110): - _elem115 = Volume() - _elem115.read(iprot) - self.success.append(_elem115) + (_etype122, _size119) = iprot.readListBegin() + for _i123 in range(_size119): + _elem124 = Volume() + _elem124.read(iprot) + self.success.append(_elem124) iprot.readListEnd() else: iprot.skip(ftype) @@ -8681,8 +8681,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter116 in self.success: - iter116.write(oprot) + for iter125 in self.success: + iter125.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -9676,81 +9676,81 @@ def read(self, iprot): elif fid == 5: if ftype == TType.MAP: self.metadata = {} - (_ktype118, _vtype119, _size117) = iprot.readMapBegin() - for _i121 in range(_size117): - _key122 = ( + (_ktype127, _vtype128, _size126) = iprot.readMapBegin() + for _i130 in range(_size126): + _key131 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val123 = ( + _val132 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.metadata[_key122] = _val123 + self.metadata[_key131] = _val132 iprot.readMapEnd() else: iprot.skip(ftype) elif fid == 7: if ftype == TType.LIST: self.volume_ids_path_new = [] - (_etype127, _size124) = iprot.readListBegin() - for _i128 in range(_size124): - _elem129 = {} - (_ktype131, _vtype132, _size130) = iprot.readMapBegin() - for _i134 in range(_size130): - _key135 = ( + (_etype136, _size133) = iprot.readListBegin() + for _i137 in range(_size133): + _elem138 = {} + (_ktype140, _vtype141, _size139) = iprot.readMapBegin() + for _i143 in range(_size139): + _key144 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val136 = ( + _val145 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _elem129[_key135] = _val136 + _elem138[_key144] = _val145 iprot.readMapEnd() - self.volume_ids_path_new.append(_elem129) + self.volume_ids_path_new.append(_elem138) iprot.readListEnd() else: iprot.skip(ftype) elif fid == 8: if ftype == TType.LIST: self.volume_ids_path_attach = [] - (_etype140, _size137) = iprot.readListBegin() - for _i141 in range(_size137): - _elem142 = {} - (_ktype144, _vtype145, _size143) = iprot.readMapBegin() - for _i147 in range(_size143): - _key148 = ( + (_etype149, _size146) = iprot.readListBegin() + for _i150 in range(_size146): + _elem151 = {} + (_ktype153, _vtype154, _size152) = iprot.readMapBegin() + for _i156 in range(_size152): + _key157 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val149 = ( + _val158 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _elem142[_key148] = _val149 + _elem151[_key157] = _val158 iprot.readMapEnd() - self.volume_ids_path_attach.append(_elem142) + self.volume_ids_path_attach.append(_elem151) iprot.readListEnd() else: iprot.skip(ftype) elif fid == 9: if ftype == TType.LIST: self.additional_keys = [] - (_etype153, _size150) = iprot.readListBegin() - for _i154 in range(_size150): - _elem155 = ( + (_etype162, _size159) = iprot.readListBegin() + for _i163 in range(_size159): + _elem164 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.additional_keys.append(_elem155) + self.additional_keys.append(_elem164) iprot.readListEnd() else: iprot.skip(ftype) @@ -9766,14 +9766,14 @@ def read(self, iprot): elif fid == 11: if ftype == TType.LIST: self.additional_security_group_ids = [] - (_etype159, _size156) = iprot.readListBegin() - for _i160 in range(_size156): - _elem161 = ( + (_etype168, _size165) = iprot.readListBegin() + for _i169 in range(_size165): + _elem170 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.additional_security_group_ids.append(_elem161) + self.additional_security_group_ids.append(_elem170) iprot.readListEnd() else: iprot.skip(ftype) @@ -9851,30 +9851,30 @@ def write(self, oprot): if self.metadata is not None: oprot.writeFieldBegin("metadata", TType.MAP, 5) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.metadata)) - for kiter162, viter163 in self.metadata.items(): + for kiter171, viter172 in self.metadata.items(): oprot.writeString( - kiter162.encode("utf-8") if sys.version_info[0] == 2 else kiter162 + kiter171.encode("utf-8") if sys.version_info[0] == 2 else kiter171 ) oprot.writeString( - viter163.encode("utf-8") if sys.version_info[0] == 2 else viter163 + viter172.encode("utf-8") if sys.version_info[0] == 2 else viter172 ) oprot.writeMapEnd() oprot.writeFieldEnd() if self.volume_ids_path_new is not None: oprot.writeFieldBegin("volume_ids_path_new", TType.LIST, 7) oprot.writeListBegin(TType.MAP, len(self.volume_ids_path_new)) - for iter164 in self.volume_ids_path_new: - oprot.writeMapBegin(TType.STRING, TType.STRING, len(iter164)) - for kiter165, viter166 in iter164.items(): + for iter173 in self.volume_ids_path_new: + oprot.writeMapBegin(TType.STRING, TType.STRING, len(iter173)) + for kiter174, viter175 in iter173.items(): oprot.writeString( - kiter165.encode("utf-8") + kiter174.encode("utf-8") if sys.version_info[0] == 2 - else kiter165 + else kiter174 ) oprot.writeString( - viter166.encode("utf-8") + viter175.encode("utf-8") if sys.version_info[0] == 2 - else viter166 + else viter175 ) oprot.writeMapEnd() oprot.writeListEnd() @@ -9882,18 +9882,18 @@ def write(self, oprot): if self.volume_ids_path_attach is not None: oprot.writeFieldBegin("volume_ids_path_attach", TType.LIST, 8) oprot.writeListBegin(TType.MAP, len(self.volume_ids_path_attach)) - for iter167 in self.volume_ids_path_attach: - oprot.writeMapBegin(TType.STRING, TType.STRING, len(iter167)) - for kiter168, viter169 in iter167.items(): + for iter176 in self.volume_ids_path_attach: + oprot.writeMapBegin(TType.STRING, TType.STRING, len(iter176)) + for kiter177, viter178 in iter176.items(): oprot.writeString( - kiter168.encode("utf-8") + kiter177.encode("utf-8") if sys.version_info[0] == 2 - else kiter168 + else kiter177 ) oprot.writeString( - viter169.encode("utf-8") + viter178.encode("utf-8") if sys.version_info[0] == 2 - else viter169 + else viter178 ) oprot.writeMapEnd() oprot.writeListEnd() @@ -9901,9 +9901,9 @@ def write(self, oprot): if self.additional_keys is not None: oprot.writeFieldBegin("additional_keys", TType.LIST, 9) oprot.writeListBegin(TType.STRING, len(self.additional_keys)) - for iter170 in self.additional_keys: + for iter179 in self.additional_keys: oprot.writeString( - iter170.encode("utf-8") if sys.version_info[0] == 2 else iter170 + iter179.encode("utf-8") if sys.version_info[0] == 2 else iter179 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -9918,9 +9918,9 @@ def write(self, oprot): if self.additional_security_group_ids is not None: oprot.writeFieldBegin("additional_security_group_ids", TType.LIST, 11) oprot.writeListBegin(TType.STRING, len(self.additional_security_group_ids)) - for iter171 in self.additional_security_group_ids: + for iter180 in self.additional_security_group_ids: oprot.writeString( - iter171.encode("utf-8") if sys.version_info[0] == 2 else iter171 + iter180.encode("utf-8") if sys.version_info[0] == 2 else iter180 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -10640,19 +10640,19 @@ def read(self, iprot): elif fid == 4: if ftype == TType.MAP: self.metadata = {} - (_ktype173, _vtype174, _size172) = iprot.readMapBegin() - for _i176 in range(_size172): - _key177 = ( + (_ktype182, _vtype183, _size181) = iprot.readMapBegin() + for _i185 in range(_size181): + _key186 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val178 = ( + _val187 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.metadata[_key177] = _val178 + self.metadata[_key186] = _val187 iprot.readMapEnd() else: iprot.skip(ftype) @@ -10668,62 +10668,62 @@ def read(self, iprot): elif fid == 7: if ftype == TType.LIST: self.volume_ids_path_new = [] - (_etype182, _size179) = iprot.readListBegin() - for _i183 in range(_size179): - _elem184 = {} - (_ktype186, _vtype187, _size185) = iprot.readMapBegin() - for _i189 in range(_size185): - _key190 = ( + (_etype191, _size188) = iprot.readListBegin() + for _i192 in range(_size188): + _elem193 = {} + (_ktype195, _vtype196, _size194) = iprot.readMapBegin() + for _i198 in range(_size194): + _key199 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val191 = ( + _val200 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _elem184[_key190] = _val191 + _elem193[_key199] = _val200 iprot.readMapEnd() - self.volume_ids_path_new.append(_elem184) + self.volume_ids_path_new.append(_elem193) iprot.readListEnd() else: iprot.skip(ftype) elif fid == 8: if ftype == TType.LIST: self.volume_ids_path_attach = [] - (_etype195, _size192) = iprot.readListBegin() - for _i196 in range(_size192): - _elem197 = {} - (_ktype199, _vtype200, _size198) = iprot.readMapBegin() - for _i202 in range(_size198): - _key203 = ( + (_etype204, _size201) = iprot.readListBegin() + for _i205 in range(_size201): + _elem206 = {} + (_ktype208, _vtype209, _size207) = iprot.readMapBegin() + for _i211 in range(_size207): + _key212 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val204 = ( + _val213 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _elem197[_key203] = _val204 + _elem206[_key212] = _val213 iprot.readMapEnd() - self.volume_ids_path_attach.append(_elem197) + self.volume_ids_path_attach.append(_elem206) iprot.readListEnd() else: iprot.skip(ftype) elif fid == 9: if ftype == TType.LIST: self.additional_security_group_ids = [] - (_etype208, _size205) = iprot.readListBegin() - for _i209 in range(_size205): - _elem210 = ( + (_etype217, _size214) = iprot.readListBegin() + for _i218 in range(_size214): + _elem219 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.additional_security_group_ids.append(_elem210) + self.additional_security_group_ids.append(_elem219) iprot.readListEnd() else: iprot.skip(ftype) @@ -10784,12 +10784,12 @@ def write(self, oprot): if self.metadata is not None: oprot.writeFieldBegin("metadata", TType.MAP, 4) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.metadata)) - for kiter211, viter212 in self.metadata.items(): + for kiter220, viter221 in self.metadata.items(): oprot.writeString( - kiter211.encode("utf-8") if sys.version_info[0] == 2 else kiter211 + kiter220.encode("utf-8") if sys.version_info[0] == 2 else kiter220 ) oprot.writeString( - viter212.encode("utf-8") if sys.version_info[0] == 2 else viter212 + viter221.encode("utf-8") if sys.version_info[0] == 2 else viter221 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -10804,18 +10804,18 @@ def write(self, oprot): if self.volume_ids_path_new is not None: oprot.writeFieldBegin("volume_ids_path_new", TType.LIST, 7) oprot.writeListBegin(TType.MAP, len(self.volume_ids_path_new)) - for iter213 in self.volume_ids_path_new: - oprot.writeMapBegin(TType.STRING, TType.STRING, len(iter213)) - for kiter214, viter215 in iter213.items(): + for iter222 in self.volume_ids_path_new: + oprot.writeMapBegin(TType.STRING, TType.STRING, len(iter222)) + for kiter223, viter224 in iter222.items(): oprot.writeString( - kiter214.encode("utf-8") + kiter223.encode("utf-8") if sys.version_info[0] == 2 - else kiter214 + else kiter223 ) oprot.writeString( - viter215.encode("utf-8") + viter224.encode("utf-8") if sys.version_info[0] == 2 - else viter215 + else viter224 ) oprot.writeMapEnd() oprot.writeListEnd() @@ -10823,18 +10823,18 @@ def write(self, oprot): if self.volume_ids_path_attach is not None: oprot.writeFieldBegin("volume_ids_path_attach", TType.LIST, 8) oprot.writeListBegin(TType.MAP, len(self.volume_ids_path_attach)) - for iter216 in self.volume_ids_path_attach: - oprot.writeMapBegin(TType.STRING, TType.STRING, len(iter216)) - for kiter217, viter218 in iter216.items(): + for iter225 in self.volume_ids_path_attach: + oprot.writeMapBegin(TType.STRING, TType.STRING, len(iter225)) + for kiter226, viter227 in iter225.items(): oprot.writeString( - kiter217.encode("utf-8") + kiter226.encode("utf-8") if sys.version_info[0] == 2 - else kiter217 + else kiter226 ) oprot.writeString( - viter218.encode("utf-8") + viter227.encode("utf-8") if sys.version_info[0] == 2 - else viter218 + else viter227 ) oprot.writeMapEnd() oprot.writeListEnd() @@ -10842,9 +10842,9 @@ def write(self, oprot): if self.additional_security_group_ids is not None: oprot.writeFieldBegin("additional_security_group_ids", TType.LIST, 9) oprot.writeListBegin(TType.STRING, len(self.additional_security_group_ids)) - for iter219 in self.additional_security_group_ids: + for iter228 in self.additional_security_group_ids: oprot.writeString( - iter219.encode("utf-8") if sys.version_info[0] == 2 else iter219 + iter228.encode("utf-8") if sys.version_info[0] == 2 else iter228 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -11361,11 +11361,11 @@ def read(self, iprot): elif fid == 3: if ftype == TType.LIST: self.conda_packages = [] - (_etype223, _size220) = iprot.readListBegin() - for _i224 in range(_size220): - _elem225 = CondaPackage() - _elem225.read(iprot) - self.conda_packages.append(_elem225) + (_etype232, _size229) = iprot.readListBegin() + for _i233 in range(_size229): + _elem234 = CondaPackage() + _elem234.read(iprot) + self.conda_packages.append(_elem234) iprot.readListEnd() else: iprot.skip(ftype) @@ -11381,14 +11381,14 @@ def read(self, iprot): elif fid == 5: if ftype == TType.LIST: self.apt_packages = [] - (_etype229, _size226) = iprot.readListBegin() - for _i230 in range(_size226): - _elem231 = ( + (_etype238, _size235) = iprot.readListBegin() + for _i239 in range(_size235): + _elem240 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.apt_packages.append(_elem231) + self.apt_packages.append(_elem240) iprot.readListEnd() else: iprot.skip(ftype) @@ -11437,8 +11437,8 @@ def write(self, oprot): if self.conda_packages is not None: oprot.writeFieldBegin("conda_packages", TType.LIST, 3) oprot.writeListBegin(TType.STRUCT, len(self.conda_packages)) - for iter232 in self.conda_packages: - iter232.write(oprot) + for iter241 in self.conda_packages: + iter241.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() if self.research_environment_template is not None: @@ -11452,9 +11452,9 @@ def write(self, oprot): if self.apt_packages is not None: oprot.writeFieldBegin("apt_packages", TType.LIST, 5) oprot.writeListBegin(TType.STRING, len(self.apt_packages)) - for iter233 in self.apt_packages: + for iter242 in self.apt_packages: oprot.writeString( - iter233.encode("utf-8") if sys.version_info[0] == 2 else iter233 + iter242.encode("utf-8") if sys.version_info[0] == 2 else iter242 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -12433,11 +12433,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype237, _size234) = iprot.readListBegin() - for _i238 in range(_size234): - _elem239 = Backend() - _elem239.read(iprot) - self.success.append(_elem239) + (_etype246, _size243) = iprot.readListBegin() + for _i247 in range(_size243): + _elem248 = Backend() + _elem248.read(iprot) + self.success.append(_elem248) iprot.readListEnd() else: iprot.skip(ftype) @@ -12461,8 +12461,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter240 in self.success: - iter240.write(oprot) + for iter249 in self.success: + iter249.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() if self.d is not None: @@ -12620,11 +12620,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype244, _size241) = iprot.readListBegin() - for _i245 in range(_size241): - _elem246 = Backend() - _elem246.read(iprot) - self.success.append(_elem246) + (_etype253, _size250) = iprot.readListBegin() + for _i254 in range(_size250): + _elem255 = Backend() + _elem255.read(iprot) + self.success.append(_elem255) iprot.readListEnd() else: iprot.skip(ftype) @@ -12648,8 +12648,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter247 in self.success: - iter247.write(oprot) + for iter256 in self.success: + iter256.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() if self.d is not None: @@ -12809,11 +12809,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype251, _size248) = iprot.readListBegin() - for _i252 in range(_size248): - _elem253 = Backend() - _elem253.read(iprot) - self.success.append(_elem253) + (_etype260, _size257) = iprot.readListBegin() + for _i261 in range(_size257): + _elem262 = Backend() + _elem262.read(iprot) + self.success.append(_elem262) iprot.readListEnd() else: iprot.skip(ftype) @@ -12837,8 +12837,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter254 in self.success: - iter254.write(oprot) + for iter263 in self.success: + iter263.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() if self.d is not None: @@ -13912,19 +13912,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype256, _vtype257, _size255) = iprot.readMapBegin() - for _i259 in range(_size255): - _key260 = ( + (_ktype265, _vtype266, _size264) = iprot.readMapBegin() + for _i268 in range(_size264): + _key269 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val261 = ( + _val270 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key260] = _val261 + self.success[_key269] = _val270 iprot.readMapEnd() else: iprot.skip(ftype) @@ -13948,12 +13948,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter262, viter263 in self.success.items(): + for kiter271, viter272 in self.success.items(): oprot.writeString( - kiter262.encode("utf-8") if sys.version_info[0] == 2 else kiter262 + kiter271.encode("utf-8") if sys.version_info[0] == 2 else kiter271 ) oprot.writeString( - viter263.encode("utf-8") if sys.version_info[0] == 2 else viter263 + viter272.encode("utf-8") if sys.version_info[0] == 2 else viter272 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -14106,14 +14106,14 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype267, _size264) = iprot.readListBegin() - for _i268 in range(_size264): - _elem269 = ( + (_etype276, _size273) = iprot.readListBegin() + for _i277 in range(_size273): + _elem278 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success.append(_elem269) + self.success.append(_elem278) iprot.readListEnd() else: iprot.skip(ftype) @@ -14137,9 +14137,9 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRING, len(self.success)) - for iter270 in self.success: + for iter279 in self.success: oprot.writeString( - iter270.encode("utf-8") if sys.version_info[0] == 2 else iter270 + iter279.encode("utf-8") if sys.version_info[0] == 2 else iter279 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -14319,19 +14319,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype272, _vtype273, _size271) = iprot.readMapBegin() - for _i275 in range(_size271): - _key276 = ( + (_ktype281, _vtype282, _size280) = iprot.readMapBegin() + for _i284 in range(_size280): + _key285 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val277 = ( + _val286 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key276] = _val277 + self.success[_key285] = _val286 iprot.readMapEnd() else: iprot.skip(ftype) @@ -14355,12 +14355,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter278, viter279 in self.success.items(): + for kiter287, viter288 in self.success.items(): oprot.writeString( - kiter278.encode("utf-8") if sys.version_info[0] == 2 else kiter278 + kiter287.encode("utf-8") if sys.version_info[0] == 2 else kiter287 ) oprot.writeString( - viter279.encode("utf-8") if sys.version_info[0] == 2 else viter279 + viter288.encode("utf-8") if sys.version_info[0] == 2 else viter288 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -14481,11 +14481,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype283, _size280) = iprot.readListBegin() - for _i284 in range(_size280): - _elem285 = ResearchEnvironmentTemplate() - _elem285.read(iprot) - self.success.append(_elem285) + (_etype292, _size289) = iprot.readListBegin() + for _i293 in range(_size289): + _elem294 = ResearchEnvironmentTemplate() + _elem294.read(iprot) + self.success.append(_elem294) iprot.readListEnd() else: iprot.skip(ftype) @@ -14504,8 +14504,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter286 in self.success: - iter286.write(oprot) + for iter295 in self.success: + iter295.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -14614,11 +14614,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype290, _size287) = iprot.readListBegin() - for _i291 in range(_size287): - _elem292 = VM() - _elem292.read(iprot) - self.success.append(_elem292) + (_etype299, _size296) = iprot.readListBegin() + for _i300 in range(_size296): + _elem301 = VM() + _elem301.read(iprot) + self.success.append(_elem301) iprot.readListEnd() else: iprot.skip(ftype) @@ -14637,8 +14637,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter293 in self.success: - iter293.write(oprot) + for iter302 in self.success: + iter302.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -14699,14 +14699,14 @@ def read(self, iprot): if fid == 1: if ftype == TType.LIST: self.server_ids = [] - (_etype297, _size294) = iprot.readListBegin() - for _i298 in range(_size294): - _elem299 = ( + (_etype306, _size303) = iprot.readListBegin() + for _i307 in range(_size303): + _elem308 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.server_ids.append(_elem299) + self.server_ids.append(_elem308) iprot.readListEnd() else: iprot.skip(ftype) @@ -14725,9 +14725,9 @@ def write(self, oprot): if self.server_ids is not None: oprot.writeFieldBegin("server_ids", TType.LIST, 1) oprot.writeListBegin(TType.STRING, len(self.server_ids)) - for iter300 in self.server_ids: + for iter309 in self.server_ids: oprot.writeString( - iter300.encode("utf-8") if sys.version_info[0] == 2 else iter300 + iter309.encode("utf-8") if sys.version_info[0] == 2 else iter309 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -14790,11 +14790,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype304, _size301) = iprot.readListBegin() - for _i305 in range(_size301): - _elem306 = VM() - _elem306.read(iprot) - self.success.append(_elem306) + (_etype313, _size310) = iprot.readListBegin() + for _i314 in range(_size310): + _elem315 = VM() + _elem315.read(iprot) + self.success.append(_elem315) iprot.readListEnd() else: iprot.skip(ftype) @@ -14813,8 +14813,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter307 in self.success: - iter307.write(oprot) + for iter316 in self.success: + iter316.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -14960,11 +14960,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype311, _size308) = iprot.readListBegin() - for _i312 in range(_size308): - _elem313 = VM() - _elem313.read(iprot) - self.success.append(_elem313) + (_etype320, _size317) = iprot.readListBegin() + for _i321 in range(_size317): + _elem322 = VM() + _elem322.read(iprot) + self.success.append(_elem322) iprot.readListEnd() else: iprot.skip(ftype) @@ -14983,8 +14983,8 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter314 in self.success: - iter314.write(oprot) + for iter323 in self.success: + iter323.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() oprot.writeFieldStop() @@ -15095,14 +15095,14 @@ def read(self, iprot): elif fid == 5: if ftype == TType.LIST: self.names = [] - (_etype318, _size315) = iprot.readListBegin() - for _i319 in range(_size315): - _elem320 = ( + (_etype327, _size324) = iprot.readListBegin() + for _i328 in range(_size324): + _elem329 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.names.append(_elem320) + self.names.append(_elem329) iprot.readListEnd() else: iprot.skip(ftype) @@ -15159,9 +15159,9 @@ def write(self, oprot): if self.names is not None: oprot.writeFieldBegin("names", TType.LIST, 5) oprot.writeListBegin(TType.STRING, len(self.names)) - for iter321 in self.names: + for iter330 in self.names: oprot.writeString( - iter321.encode("utf-8") if sys.version_info[0] == 2 else iter321 + iter330.encode("utf-8") if sys.version_info[0] == 2 else iter330 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -15274,24 +15274,24 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype323, _vtype324, _size322) = iprot.readMapBegin() - for _i326 in range(_size322): - _key327 = ( + (_ktype332, _vtype333, _size331) = iprot.readMapBegin() + for _i335 in range(_size331): + _key336 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val328 = [] - (_etype332, _size329) = iprot.readListBegin() - for _i333 in range(_size329): - _elem334 = ( + _val337 = [] + (_etype341, _size338) = iprot.readListBegin() + for _i342 in range(_size338): + _elem343 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val328.append(_elem334) + _val337.append(_elem343) iprot.readListEnd() - self.success[_key327] = _val328 + self.success[_key336] = _val337 iprot.readMapEnd() else: iprot.skip(ftype) @@ -15310,14 +15310,14 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.LIST, len(self.success)) - for kiter335, viter336 in self.success.items(): + for kiter344, viter345 in self.success.items(): oprot.writeString( - kiter335.encode("utf-8") if sys.version_info[0] == 2 else kiter335 + kiter344.encode("utf-8") if sys.version_info[0] == 2 else kiter344 ) - oprot.writeListBegin(TType.STRING, len(viter336)) - for iter337 in viter336: + oprot.writeListBegin(TType.STRING, len(viter345)) + for iter346 in viter345: oprot.writeString( - iter337.encode("utf-8") if sys.version_info[0] == 2 else iter337 + iter346.encode("utf-8") if sys.version_info[0] == 2 else iter346 ) oprot.writeListEnd() oprot.writeMapEnd() @@ -16016,19 +16016,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype339, _vtype340, _size338) = iprot.readMapBegin() - for _i342 in range(_size338): - _key343 = ( + (_ktype348, _vtype349, _size347) = iprot.readMapBegin() + for _i351 in range(_size347): + _key352 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val344 = ( + _val353 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key343] = _val344 + self.success[_key352] = _val353 iprot.readMapEnd() else: iprot.skip(ftype) @@ -16052,12 +16052,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter345, viter346 in self.success.items(): + for kiter354, viter355 in self.success.items(): oprot.writeString( - kiter345.encode("utf-8") if sys.version_info[0] == 2 else kiter345 + kiter354.encode("utf-8") if sys.version_info[0] == 2 else kiter354 ) oprot.writeString( - viter346.encode("utf-8") if sys.version_info[0] == 2 else viter346 + viter355.encode("utf-8") if sys.version_info[0] == 2 else viter355 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -17176,14 +17176,14 @@ def read(self, iprot): elif fid == 4: if ftype == TType.LIST: self.base_tags = [] - (_etype350, _size347) = iprot.readListBegin() - for _i351 in range(_size347): - _elem352 = ( + (_etype359, _size356) = iprot.readListBegin() + for _i360 in range(_size356): + _elem361 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.base_tags.append(_elem352) + self.base_tags.append(_elem361) iprot.readListEnd() else: iprot.skip(ftype) @@ -17233,9 +17233,9 @@ def write(self, oprot): if self.base_tags is not None: oprot.writeFieldBegin("base_tags", TType.LIST, 4) oprot.writeListBegin(TType.STRING, len(self.base_tags)) - for iter353 in self.base_tags: + for iter362 in self.base_tags: oprot.writeString( - iter353.encode("utf-8") if sys.version_info[0] == 2 else iter353 + iter362.encode("utf-8") if sys.version_info[0] == 2 else iter362 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -17504,19 +17504,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype355, _vtype356, _size354) = iprot.readMapBegin() - for _i358 in range(_size354): - _key359 = ( + (_ktype364, _vtype365, _size363) = iprot.readMapBegin() + for _i367 in range(_size363): + _key368 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val360 = ( + _val369 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key359] = _val360 + self.success[_key368] = _val369 iprot.readMapEnd() else: iprot.skip(ftype) @@ -17535,12 +17535,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter361, viter362 in self.success.items(): + for kiter370, viter371 in self.success.items(): oprot.writeString( - kiter361.encode("utf-8") if sys.version_info[0] == 2 else kiter361 + kiter370.encode("utf-8") if sys.version_info[0] == 2 else kiter370 ) oprot.writeString( - viter362.encode("utf-8") if sys.version_info[0] == 2 else viter362 + viter371.encode("utf-8") if sys.version_info[0] == 2 else viter371 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -17611,14 +17611,14 @@ def read(self, iprot): if fid == 1: if ftype == TType.LIST: self.public_keys = [] - (_etype366, _size363) = iprot.readListBegin() - for _i367 in range(_size363): - _elem368 = ( + (_etype375, _size372) = iprot.readListBegin() + for _i376 in range(_size372): + _elem377 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.public_keys.append(_elem368) + self.public_keys.append(_elem377) iprot.readListEnd() else: iprot.skip(ftype) @@ -17631,11 +17631,11 @@ def read(self, iprot): elif fid == 3: if ftype == TType.LIST: self.worker_instances = [] - (_etype372, _size369) = iprot.readListBegin() - for _i373 in range(_size369): - _elem374 = ClusterInstance() - _elem374.read(iprot) - self.worker_instances.append(_elem374) + (_etype381, _size378) = iprot.readListBegin() + for _i382 in range(_size378): + _elem383 = ClusterInstance() + _elem383.read(iprot) + self.worker_instances.append(_elem383) iprot.readListEnd() else: iprot.skip(ftype) @@ -17663,9 +17663,9 @@ def write(self, oprot): if self.public_keys is not None: oprot.writeFieldBegin("public_keys", TType.LIST, 1) oprot.writeListBegin(TType.STRING, len(self.public_keys)) - for iter375 in self.public_keys: + for iter384 in self.public_keys: oprot.writeString( - iter375.encode("utf-8") if sys.version_info[0] == 2 else iter375 + iter384.encode("utf-8") if sys.version_info[0] == 2 else iter384 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -17676,8 +17676,8 @@ def write(self, oprot): if self.worker_instances is not None: oprot.writeFieldBegin("worker_instances", TType.LIST, 3) oprot.writeListBegin(TType.STRUCT, len(self.worker_instances)) - for iter376 in self.worker_instances: - iter376.write(oprot) + for iter385 in self.worker_instances: + iter385.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() if self.user is not None: @@ -17766,19 +17766,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype378, _vtype379, _size377) = iprot.readMapBegin() - for _i381 in range(_size377): - _key382 = ( + (_ktype387, _vtype388, _size386) = iprot.readMapBegin() + for _i390 in range(_size386): + _key391 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val383 = ( + _val392 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key382] = _val383 + self.success[_key391] = _val392 iprot.readMapEnd() else: iprot.skip(ftype) @@ -17797,12 +17797,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter384, viter385 in self.success.items(): + for kiter393, viter394 in self.success.items(): oprot.writeString( - kiter384.encode("utf-8") if sys.version_info[0] == 2 else kiter384 + kiter393.encode("utf-8") if sys.version_info[0] == 2 else kiter393 ) oprot.writeString( - viter385.encode("utf-8") if sys.version_info[0] == 2 else viter385 + viter394.encode("utf-8") if sys.version_info[0] == 2 else viter394 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -17952,19 +17952,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype387, _vtype388, _size386) = iprot.readMapBegin() - for _i390 in range(_size386): - _key391 = ( + (_ktype396, _vtype397, _size395) = iprot.readMapBegin() + for _i399 in range(_size395): + _key400 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val392 = ( + _val401 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key391] = _val392 + self.success[_key400] = _val401 iprot.readMapEnd() else: iprot.skip(ftype) @@ -17988,12 +17988,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter393, viter394 in self.success.items(): + for kiter402, viter403 in self.success.items(): oprot.writeString( - kiter393.encode("utf-8") if sys.version_info[0] == 2 else kiter393 + kiter402.encode("utf-8") if sys.version_info[0] == 2 else kiter402 ) oprot.writeString( - viter394.encode("utf-8") if sys.version_info[0] == 2 else viter394 + viter403.encode("utf-8") if sys.version_info[0] == 2 else viter403 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -18754,19 +18754,19 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype396, _vtype397, _size395) = iprot.readMapBegin() - for _i399 in range(_size395): - _key400 = ( + (_ktype405, _vtype406, _size404) = iprot.readMapBegin() + for _i408 in range(_size404): + _key409 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val401 = ( + _val410 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.success[_key400] = _val401 + self.success[_key409] = _val410 iprot.readMapEnd() else: iprot.skip(ftype) @@ -18795,12 +18795,12 @@ def write(self, oprot): if self.success is not None: oprot.writeFieldBegin("success", TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter402, viter403 in self.success.items(): + for kiter411, viter412 in self.success.items(): oprot.writeString( - kiter402.encode("utf-8") if sys.version_info[0] == 2 else kiter402 + kiter411.encode("utf-8") if sys.version_info[0] == 2 else kiter411 ) oprot.writeString( - viter403.encode("utf-8") if sys.version_info[0] == 2 else viter403 + viter412.encode("utf-8") if sys.version_info[0] == 2 else viter412 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -19085,19 +19085,19 @@ def read(self, iprot): elif fid == 3: if ftype == TType.MAP: self.metadata = {} - (_ktype405, _vtype406, _size404) = iprot.readMapBegin() - for _i408 in range(_size404): - _key409 = ( + (_ktype414, _vtype415, _size413) = iprot.readMapBegin() + for _i417 in range(_size413): + _key418 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val410 = ( + _val419 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.metadata[_key409] = _val410 + self.metadata[_key418] = _val419 iprot.readMapEnd() else: iprot.skip(ftype) @@ -19128,12 +19128,12 @@ def write(self, oprot): if self.metadata is not None: oprot.writeFieldBegin("metadata", TType.MAP, 3) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.metadata)) - for kiter411, viter412 in self.metadata.items(): + for kiter420, viter421 in self.metadata.items(): oprot.writeString( - kiter411.encode("utf-8") if sys.version_info[0] == 2 else kiter411 + kiter420.encode("utf-8") if sys.version_info[0] == 2 else kiter420 ) oprot.writeString( - viter412.encode("utf-8") if sys.version_info[0] == 2 else viter412 + viter421.encode("utf-8") if sys.version_info[0] == 2 else viter421 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -19340,19 +19340,19 @@ def read(self, iprot): elif fid == 2: if ftype == TType.MAP: self.metadata = {} - (_ktype414, _vtype415, _size413) = iprot.readMapBegin() - for _i417 in range(_size413): - _key418 = ( + (_ktype423, _vtype424, _size422) = iprot.readMapBegin() + for _i426 in range(_size422): + _key427 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val419 = ( + _val428 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.metadata[_key418] = _val419 + self.metadata[_key427] = _val428 iprot.readMapEnd() else: iprot.skip(ftype) @@ -19388,12 +19388,12 @@ def write(self, oprot): if self.metadata is not None: oprot.writeFieldBegin("metadata", TType.MAP, 2) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.metadata)) - for kiter420, viter421 in self.metadata.items(): + for kiter429, viter430 in self.metadata.items(): oprot.writeString( - kiter420.encode("utf-8") if sys.version_info[0] == 2 else kiter420 + kiter429.encode("utf-8") if sys.version_info[0] == 2 else kiter429 ) oprot.writeString( - viter421.encode("utf-8") if sys.version_info[0] == 2 else viter421 + viter430.encode("utf-8") if sys.version_info[0] == 2 else viter430 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -19608,19 +19608,19 @@ def read(self, iprot): elif fid == 2: if ftype == TType.MAP: self.metadata = {} - (_ktype423, _vtype424, _size422) = iprot.readMapBegin() - for _i426 in range(_size422): - _key427 = ( + (_ktype432, _vtype433, _size431) = iprot.readMapBegin() + for _i435 in range(_size431): + _key436 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val428 = ( + _val437 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.metadata[_key427] = _val428 + self.metadata[_key436] = _val437 iprot.readMapEnd() else: iprot.skip(ftype) @@ -19656,12 +19656,12 @@ def write(self, oprot): if self.metadata is not None: oprot.writeFieldBegin("metadata", TType.MAP, 2) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.metadata)) - for kiter429, viter430 in self.metadata.items(): + for kiter438, viter439 in self.metadata.items(): oprot.writeString( - kiter429.encode("utf-8") if sys.version_info[0] == 2 else kiter429 + kiter438.encode("utf-8") if sys.version_info[0] == 2 else kiter438 ) oprot.writeString( - viter430.encode("utf-8") if sys.version_info[0] == 2 else viter430 + viter439.encode("utf-8") if sys.version_info[0] == 2 else viter439 ) oprot.writeMapEnd() oprot.writeFieldEnd() diff --git a/simple_vm_client/openstack_connector/openstack_connector.py b/simple_vm_client/openstack_connector/openstack_connector.py index 1816307..f7c6cae 100644 --- a/simple_vm_client/openstack_connector/openstack_connector.py +++ b/simple_vm_client/openstack_connector/openstack_connector.py @@ -1430,6 +1430,7 @@ def start_server( volumes=volumes, userdata=init_script, security_groups=security_groups, + boot_from_volume=False, ) openstack_id: str = server["id"] diff --git a/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh b/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh index 2600646..da37f1c 100644 --- a/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh +++ b/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh @@ -4,45 +4,45 @@ TOKEN_ESCAPED='REPLACE_WITH_ACTUAL_TOKEN' ENDPOINT_ESCAPED='REPLACE_WITH_ACTUAL_ENDPOINT' -# Create a configuration file with the token in the ubuntu user's home directory -UBUNTU_HOME_DIR="/home/ubuntu" -CONFIG_FILE_PATH="$UBUNTU_HOME_DIR/.metadata_config.env" +# Create a configuration file with the token in /etc/simplevm directory +CONFIG_DIR="/etc/simplevm" +CONFIG_FILE_PATH="$CONFIG_DIR/.metadata_config.env" echo "METADATA_ACCESS_TOKEN='$TOKEN_ESCAPED'" > "$CONFIG_FILE_PATH" echo "METADATA_SERVER_ENDPOINT='$ENDPOINT_ESCAPED'" >> "$CONFIG_FILE_PATH" -# Secure the file permissions so only the ubuntu user can read it +# Secure the file permissions so only root can read it chmod 600 "$CONFIG_FILE_PATH" -chown ubuntu:ubuntu "$CONFIG_FILE_PATH" +chown root:root "$CONFIG_FILE_PATH" -# Create the ~/.get_metadata.sh script to fetch metadata using the saved token -SCRIPT_DIR="$UBUNTU_HOME_DIR" -SCRIPT_NAME=".get_metadata.sh" +# Create the /etc/simplevm/get_metadata.sh script to fetch metadata using the saved token +SCRIPT_DIR="$CONFIG_DIR" +SCRIPT_NAME="get_metadata.sh" SCRIPT_PATH="$SCRIPT_DIR/$SCRIPT_NAME" echo "#!/bin/bash" > "$SCRIPT_PATH" -echo "source ~/.metadata_config.env" >> "$SCRIPT_PATH" +echo "source $CONFIG_FILE_PATH" >> "$SCRIPT_PATH" echo "" >> "$SCRIPT_PATH" echo "# Define the metadata server endpoint and local machine IP" >> "$SCRIPT_PATH" -echo "SERVER_ENDPOINT=\\"$METADATA_SERVER_ENDPOINT\\"" >> "$SCRIPT_PATH" -echo "LOCAL_IP=\\$(ip route get 8.8.8.8 | awk '{print \\$7}' | tr -d '\\n')" >> "$SCRIPT_PATH" +echo "SERVER_ENDPOINT=\\\\"$METADATA_SERVER_ENDPOINT\\\\"" >> "$SCRIPT_PATH" +echo "LOCAL_IP=\\\\$(ip route get 8.8.8.8 | awk '{print \\\\$7}' | tr -d '\\\\n')" >> "$SCRIPT_PATH" echo "" >> "$SCRIPT_PATH" echo "# Construct the URL" >> "$SCRIPT_PATH" -echo "URL=\\"\\${SERVER_ENDPOINT}/\\${LOCAL_IP}\\"" >> "$SCRIPT_PATH" +echo "URL=\\\\"\\\\${SERVER_ENDPOINT}/\\\\${LOCAL_IP}\\\\"" >> "$SCRIPT_PATH" echo "" >> "$SCRIPT_PATH" echo "# Define the auth header with the token" >> "$SCRIPT_PATH" -echo "AUTH_HEADER=\\"auth_token: \\${METADATA_ACCESS_TOKEN}\\"" >> "$SCRIPT_PATH" +echo "AUTH_HEADER=\\\\"auth_token: \\\\${METADATA_ACCESS_TOKEN}\\\\"" >> "$SCRIPT_PATH" echo "" >> "$SCRIPT_PATH" echo "# Fetch the JSON response from the URL" >> "$SCRIPT_PATH" -echo "response=\\$(curl -s -X GET \\"\\$URL\\" -H \\"\\$AUTH_HEADER\\")" >> "$SCRIPT_PATH" +echo "response=\\\\$(curl -s -X GET \\\\"\\\\$URL\\\\" -H \\\\"\\\\$AUTH_HEADER\\\\")" >> "$SCRIPT_PATH" echo "" >> "$SCRIPT_PATH" -echo "echo \\"Response:\\"" >> "$SCRIPT_PATH" -echo "echo \\"\\$response\\"" >> "$SCRIPT_PATH" +echo "echo \\\\"Response:\\\\"" >> "$SCRIPT_PATH" +echo "echo \\\\"\\\\$response\\\\"" >> "$SCRIPT_PATH" # Make the script executable chmod 700 "$SCRIPT_PATH" -chown ubuntu:ubuntu "$SCRIPT_PATH" +chown root:root "$SCRIPT_PATH" # Print a message to indicate completion echo "Token has been set, configuration file created at $CONFIG_FILE_PATH with restricted access." -echo "~/.get_metadata.sh script created to fetch metadata using the saved token." +echo "/etc/simplevm/get_metadata.sh script created to fetch metadata using the saved token." diff --git a/simple_vm_client/ttypes.py b/simple_vm_client/ttypes.py index d06cc6d..c18982b 100644 --- a/simple_vm_client/ttypes.py +++ b/simple_vm_client/ttypes.py @@ -16,24 +16,24 @@ all_structs = [] -class VirtualMachineServerMetadata(object): +class User(object): """ Attributes: + - username + - user_id - public_keys - - hashed_auth_token - - ip """ def __init__( self, + username=None, + user_id=None, public_keys=None, - hashed_auth_token=None, - ip=None, ): + self.username = username + self.user_id = user_id self.public_keys = public_keys - self.hashed_auth_token = hashed_auth_token - self.ip = ip def read(self, iprot): if ( @@ -49,6 +49,24 @@ def read(self, iprot): if ftype == TType.STOP: break if fid == 1: + if ftype == TType.STRING: + self.username = ( + iprot.readString().decode("utf-8", errors="replace") + if sys.version_info[0] == 2 + else iprot.readString() + ) + else: + iprot.skip(ftype) + elif fid == 2: + if ftype == TType.STRING: + self.user_id = ( + iprot.readString().decode("utf-8", errors="replace") + if sys.version_info[0] == 2 + else iprot.readString() + ) + else: + iprot.skip(ftype) + elif fid == 3: if ftype == TType.LIST: self.public_keys = [] (_etype3, _size0) = iprot.readListBegin() @@ -62,24 +80,211 @@ def read(self, iprot): iprot.readListEnd() else: iprot.skip(ftype) - elif fid == 2: + else: + iprot.skip(ftype) + iprot.readFieldEnd() + iprot.readStructEnd() + + def write(self, oprot): + if oprot._fast_encode is not None and self.thrift_spec is not None: + oprot.trans.write( + oprot._fast_encode(self, [self.__class__, self.thrift_spec]) + ) + return + oprot.writeStructBegin("User") + if self.username is not None: + oprot.writeFieldBegin("username", TType.STRING, 1) + oprot.writeString( + self.username.encode("utf-8") + if sys.version_info[0] == 2 + else self.username + ) + oprot.writeFieldEnd() + if self.user_id is not None: + oprot.writeFieldBegin("user_id", TType.STRING, 2) + oprot.writeString( + self.user_id.encode("utf-8") + if sys.version_info[0] == 2 + else self.user_id + ) + oprot.writeFieldEnd() + if self.public_keys is not None: + oprot.writeFieldBegin("public_keys", TType.LIST, 3) + oprot.writeListBegin(TType.STRING, len(self.public_keys)) + for iter6 in self.public_keys: + oprot.writeString( + iter6.encode("utf-8") if sys.version_info[0] == 2 else iter6 + ) + oprot.writeListEnd() + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + + def validate(self): + if self.user_id is None: + raise TProtocolException(message="Required field user_id is unset!") + return + + def __repr__(self): + L = ["%s=%r" % (key, value) for key, value in self.__dict__.items()] + return "%s(%s)" % (self.__class__.__name__, ", ".join(L)) + + def __eq__(self, other): + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ + + def __ne__(self, other): + return not (self == other) + + +class UserData(object): + """ + Attributes: + - data + + """ + + def __init__( + self, + data={}, + ): + if data is self.thrift_spec[2][4]: + data = {} + self.data = data + + def read(self, iprot): + if ( + iprot._fast_decode is not None + and isinstance(iprot.trans, TTransport.CReadableTransport) + and self.thrift_spec is not None + ): + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) + return + iprot.readStructBegin() + while True: + (fname, ftype, fid) = iprot.readFieldBegin() + if ftype == TType.STOP: + break + if fid == 2: + if ftype == TType.MAP: + self.data = {} + (_ktype8, _vtype9, _size7) = iprot.readMapBegin() + for _i11 in range(_size7): + _key12 = ( + iprot.readString().decode("utf-8", errors="replace") + if sys.version_info[0] == 2 + else iprot.readString() + ) + _val13 = User() + _val13.read(iprot) + self.data[_key12] = _val13 + iprot.readMapEnd() + else: + iprot.skip(ftype) + else: + iprot.skip(ftype) + iprot.readFieldEnd() + iprot.readStructEnd() + + def write(self, oprot): + if oprot._fast_encode is not None and self.thrift_spec is not None: + oprot.trans.write( + oprot._fast_encode(self, [self.__class__, self.thrift_spec]) + ) + return + oprot.writeStructBegin("UserData") + if self.data is not None: + oprot.writeFieldBegin("data", TType.MAP, 2) + oprot.writeMapBegin(TType.STRING, TType.STRUCT, len(self.data)) + for kiter14, viter15 in self.data.items(): + oprot.writeString( + kiter14.encode("utf-8") if sys.version_info[0] == 2 else kiter14 + ) + viter15.write(oprot) + oprot.writeMapEnd() + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + + def validate(self): + if self.data is None: + raise TProtocolException(message="Required field data is unset!") + return + + def __repr__(self): + L = ["%s=%r" % (key, value) for key, value in self.__dict__.items()] + return "%s(%s)" % (self.__class__.__name__, ", ".join(L)) + + def __eq__(self, other): + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ + + def __ne__(self, other): + return not (self == other) + + +class VirtualMachineServerMetadata(object): + """ + Attributes: + - ip + - hashed_auth_token + - userdata + - last_time_updated + + """ + + def __init__( + self, + ip=None, + hashed_auth_token=None, + userdata=None, + last_time_updated=None, + ): + self.ip = ip + self.hashed_auth_token = hashed_auth_token + self.userdata = userdata + self.last_time_updated = last_time_updated + + def read(self, iprot): + if ( + iprot._fast_decode is not None + and isinstance(iprot.trans, TTransport.CReadableTransport) + and self.thrift_spec is not None + ): + iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) + return + iprot.readStructBegin() + while True: + (fname, ftype, fid) = iprot.readFieldBegin() + if ftype == TType.STOP: + break + if fid == 1: if ftype == TType.STRING: - self.hashed_auth_token = ( + self.ip = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) else: iprot.skip(ftype) - elif fid == 3: + elif fid == 2: if ftype == TType.STRING: - self.ip = ( + self.hashed_auth_token = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) else: iprot.skip(ftype) + elif fid == 3: + if ftype == TType.STRUCT: + self.userdata = UserData() + self.userdata.read(iprot) + else: + iprot.skip(ftype) + elif fid == 4: + if ftype == TType.I64: + self.last_time_updated = iprot.readI64() + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -92,14 +297,11 @@ def write(self, oprot): ) return oprot.writeStructBegin("VirtualMachineServerMetadata") - if self.public_keys is not None: - oprot.writeFieldBegin("public_keys", TType.LIST, 1) - oprot.writeListBegin(TType.STRING, len(self.public_keys)) - for iter6 in self.public_keys: - oprot.writeString( - iter6.encode("utf-8") if sys.version_info[0] == 2 else iter6 - ) - oprot.writeListEnd() + if self.ip is not None: + oprot.writeFieldBegin("ip", TType.STRING, 1) + oprot.writeString( + self.ip.encode("utf-8") if sys.version_info[0] == 2 else self.ip + ) oprot.writeFieldEnd() if self.hashed_auth_token is not None: oprot.writeFieldBegin("hashed_auth_token", TType.STRING, 2) @@ -109,16 +311,28 @@ def write(self, oprot): else self.hashed_auth_token ) oprot.writeFieldEnd() - if self.ip is not None: - oprot.writeFieldBegin("ip", TType.STRING, 3) - oprot.writeString( - self.ip.encode("utf-8") if sys.version_info[0] == 2 else self.ip - ) + if self.userdata is not None: + oprot.writeFieldBegin("userdata", TType.STRUCT, 3) + self.userdata.write(oprot) + oprot.writeFieldEnd() + if self.last_time_updated is not None: + oprot.writeFieldBegin("last_time_updated", TType.I64, 4) + oprot.writeI64(self.last_time_updated) oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() def validate(self): + if self.ip is None: + raise TProtocolException(message="Required field ip is unset!") + if self.hashed_auth_token is None: + raise TProtocolException( + message="Required field hashed_auth_token is unset!" + ) + if self.last_time_updated is None: + raise TProtocolException( + message="Required field last_time_updated is unset!" + ) return def __repr__(self): @@ -390,14 +604,14 @@ def read(self, iprot): elif fid == 7: if ftype == TType.LIST: self.incompatible_versions = [] - (_etype10, _size7) = iprot.readListBegin() - for _i11 in range(_size7): - _elem12 = ( + (_etype19, _size16) = iprot.readListBegin() + for _i20 in range(_size16): + _elem21 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.incompatible_versions.append(_elem12) + self.incompatible_versions.append(_elem21) iprot.readListEnd() else: iprot.skip(ftype) @@ -409,19 +623,19 @@ def read(self, iprot): elif fid == 9: if ftype == TType.MAP: self.information_for_display = {} - (_ktype14, _vtype15, _size13) = iprot.readMapBegin() - for _i17 in range(_size13): - _key18 = ( + (_ktype23, _vtype24, _size22) = iprot.readMapBegin() + for _i26 in range(_size22): + _key27 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val19 = ( + _val28 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.information_for_display[_key18] = _val19 + self.information_for_display[_key27] = _val28 iprot.readMapEnd() else: iprot.skip(ftype) @@ -501,9 +715,9 @@ def write(self, oprot): if self.incompatible_versions is not None: oprot.writeFieldBegin("incompatible_versions", TType.LIST, 7) oprot.writeListBegin(TType.STRING, len(self.incompatible_versions)) - for iter20 in self.incompatible_versions: + for iter29 in self.incompatible_versions: oprot.writeString( - iter20.encode("utf-8") if sys.version_info[0] == 2 else iter20 + iter29.encode("utf-8") if sys.version_info[0] == 2 else iter29 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -516,12 +730,12 @@ def write(self, oprot): oprot.writeMapBegin( TType.STRING, TType.STRING, len(self.information_for_display) ) - for kiter21, viter22 in self.information_for_display.items(): + for kiter30, viter31 in self.information_for_display.items(): oprot.writeString( - kiter21.encode("utf-8") if sys.version_info[0] == 2 else kiter21 + kiter30.encode("utf-8") if sys.version_info[0] == 2 else kiter30 ) oprot.writeString( - viter22.encode("utf-8") if sys.version_info[0] == 2 else viter22 + viter31.encode("utf-8") if sys.version_info[0] == 2 else viter31 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -1581,14 +1795,14 @@ def read(self, iprot): elif fid == 9: if ftype == TType.LIST: self.tags = [] - (_etype26, _size23) = iprot.readListBegin() - for _i27 in range(_size23): - _elem28 = ( + (_etype35, _size32) = iprot.readListBegin() + for _i36 in range(_size32): + _elem37 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.tags.append(_elem28) + self.tags.append(_elem37) iprot.readListEnd() else: iprot.skip(ftype) @@ -1691,9 +1905,9 @@ def write(self, oprot): if self.tags is not None: oprot.writeFieldBegin("tags", TType.LIST, 9) oprot.writeListBegin(TType.STRING, len(self.tags)) - for iter29 in self.tags: + for iter38 in self.tags: oprot.writeString( - iter29.encode("utf-8") if sys.version_info[0] == 2 else iter29 + iter38.encode("utf-8") if sys.version_info[0] == 2 else iter38 ) oprot.writeListEnd() oprot.writeFieldEnd() @@ -1828,19 +2042,19 @@ def read(self, iprot): elif fid == 3: if ftype == TType.MAP: self.metadata = {} - (_ktype31, _vtype32, _size30) = iprot.readMapBegin() - for _i34 in range(_size30): - _key35 = ( + (_ktype40, _vtype41, _size39) = iprot.readMapBegin() + for _i43 in range(_size39): + _key44 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - _val36 = ( + _val45 = ( iprot.readString().decode("utf-8", errors="replace") if sys.version_info[0] == 2 else iprot.readString() ) - self.metadata[_key35] = _val36 + self.metadata[_key44] = _val45 iprot.readMapEnd() else: iprot.skip(ftype) @@ -1948,12 +2162,12 @@ def write(self, oprot): if self.metadata is not None: oprot.writeFieldBegin("metadata", TType.MAP, 3) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.metadata)) - for kiter37, viter38 in self.metadata.items(): + for kiter46, viter47 in self.metadata.items(): oprot.writeString( - kiter37.encode("utf-8") if sys.version_info[0] == 2 else kiter37 + kiter46.encode("utf-8") if sys.version_info[0] == 2 else kiter46 ) oprot.writeString( - viter38.encode("utf-8") if sys.version_info[0] == 2 else viter38 + viter47.encode("utf-8") if sys.version_info[0] == 2 else viter47 ) oprot.writeMapEnd() oprot.writeFieldEnd() @@ -4115,15 +4329,52 @@ def __ne__(self, other): return not (self == other) -all_structs.append(VirtualMachineServerMetadata) -VirtualMachineServerMetadata.thrift_spec = ( +all_structs.append(User) +User.thrift_spec = ( None, # 0 ( 1, + TType.STRING, + "username", + "UTF8", + None, + ), # 1 + ( + 2, + TType.STRING, + "user_id", + "UTF8", + None, + ), # 2 + ( + 3, TType.LIST, "public_keys", (TType.STRING, "UTF8", False), None, + ), # 3 +) +all_structs.append(UserData) +UserData.thrift_spec = ( + None, # 0 + None, # 1 + ( + 2, + TType.MAP, + "data", + (TType.STRING, "UTF8", TType.STRUCT, [User, None], False), + {}, + ), # 2 +) +all_structs.append(VirtualMachineServerMetadata) +VirtualMachineServerMetadata.thrift_spec = ( + None, # 0 + ( + 1, + TType.STRING, + "ip", + "UTF8", + None, ), # 1 ( 2, @@ -4134,11 +4385,18 @@ def __ne__(self, other): ), # 2 ( 3, - TType.STRING, - "ip", - "UTF8", + TType.STRUCT, + "userdata", + [UserData, None], None, ), # 3 + ( + 4, + TType.I64, + "last_time_updated", + None, + None, + ), # 4 ) all_structs.append(Backend) Backend.thrift_spec = ( From 02f09100cfadffd6da5eabf111c34f77b2f81477 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Tue, 17 Sep 2024 14:02:33 +0200 Subject: [PATCH 3/8] feat(Metadata):updated metadata script --- .../openstack_connector.py | 24 ++-- .../scripts/bash/save_metadata_auth_token.sh | 106 +++++++++++++----- 2 files changed, 96 insertions(+), 34 deletions(-) diff --git a/simple_vm_client/openstack_connector/openstack_connector.py b/simple_vm_client/openstack_connector/openstack_connector.py index f7c6cae..3928d1f 100644 --- a/simple_vm_client/openstack_connector/openstack_connector.py +++ b/simple_vm_client/openstack_connector/openstack_connector.py @@ -499,9 +499,11 @@ def create_save_metadata_auth_token_script( # Use a unique placeholder in the script for replacement placeholder = "REPLACE_WITH_ACTUAL_TOKEN" + endpoint_placeholder = "REPLACE_WITH_ACTUAL_METADATA_INFO_ENDPOINT" # Replace the placeholder with the actual token text = text.replace(placeholder, token) + text = text.replace(endpoint_placeholder, metadata_endpoint) text = encodeutils.safe_encode(text.encode("utf-8")) @@ -1331,15 +1333,9 @@ def create_userdata( unlock_ubuntu_user_script.encode("utf-8") ) init_script = unlock_ubuntu_user_script_encoded - if metadata_token and metadata_endpoint: - save_metadata_token_script = self.create_save_metadata_auth_token_script( - token=metadata_token, metadata_endpoint=metadata_endpoint - ) - init_script = ( - init_script - + encodeutils.safe_encode("\n".encode("utf-8")) - + save_metadata_token_script - ) + logger.info( + f"Metadata token {metadata_token} | Metadata Endpoint {metadata_endpoint}" + ) if additional_keys: add_key_script = self.create_add_keys_script(keys=additional_keys) init_script = ( @@ -1357,6 +1353,16 @@ def create_userdata( + encodeutils.safe_encode("\n".encode("utf-8")) + mount_script ) + if metadata_token and metadata_endpoint: + save_metadata_token_script = self.create_save_metadata_auth_token_script( + token=metadata_token, metadata_endpoint=metadata_endpoint + ) + init_script = ( + init_script + + encodeutils.safe_encode("\n".encode("utf-8")) + + save_metadata_token_script + ) + return init_script def start_server( diff --git a/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh b/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh index da37f1c..04be6b4 100644 --- a/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh +++ b/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh @@ -2,44 +2,100 @@ # Use clear placeholders that will be replaced in the Python script TOKEN_ESCAPED='REPLACE_WITH_ACTUAL_TOKEN' -ENDPOINT_ESCAPED='REPLACE_WITH_ACTUAL_ENDPOINT' +METADATA_INFO_ENDPOINT_ESCAPED='REPLACE_WITH_ACTUAL_METADATA_INFO_ENDPOINT' # Create a configuration file with the token in /etc/simplevm directory CONFIG_DIR="/etc/simplevm" -CONFIG_FILE_PATH="$CONFIG_DIR/.metadata_config.env" +CONFIG_FILE_PATH="$CONFIG_DIR/metadata_config.env" -echo "METADATA_ACCESS_TOKEN='$TOKEN_ESCAPED'" > "$CONFIG_FILE_PATH" -echo "METADATA_SERVER_ENDPOINT='$ENDPOINT_ESCAPED'" >> "$CONFIG_FILE_PATH" +# Check if the config directory already exists +if [ -d "$CONFIG_DIR" ]; then + echo "Config directory $CONFIG_DIR already exists." +else + # Create the config directory with permissions that allow only root to read and write it + mkdir -p "$CONFIG_DIR" || { echo "Error creating directory $CONFIG_DIR"; exit 1; } + chmod 700 "$CONFIG_DIR" + chown root:root "$CONFIG_DIR" +fi -# Secure the file permissions so only root can read it +# Validate token value +if [ -z "${TOKEN_ESCAPED}" ]; then + echo "Error: Token cannot be empty" + exit 1 +fi + +# Create the config file with permissions that allow only root to read it +echo "METADATA_ACCESS_TOKEN=$TOKEN_ESCAPED" > "$CONFIG_FILE_PATH" || { echo "Error writing to file $CONFIG_FILE_PATH"; exit 1; } chmod 600 "$CONFIG_FILE_PATH" chown root:root "$CONFIG_FILE_PATH" +# Validate metadata info endpoint value +if [ -z "${METADATA_INFO_ENDPOINT_ESCAPED}" ]; then + echo "Error: Metadata info endpoint cannot be empty" + exit 1 +fi + +echo "METADATA_INFO_ENDPOINT=$METADATA_INFO_ENDPOINT_ESCAPED" >> "$CONFIG_FILE_PATH" || { echo "Error writing to file $CONFIG_FILE_PATH"; exit 1; } + +# Check if jq is installed +if ! command -v jq &> /dev/null; then + echo "jq is not installed. Installing..." + sudo apt-get update && sudo apt-get install -y jq || { echo "Error installing jq"; exit 1; } +fi + # Create the /etc/simplevm/get_metadata.sh script to fetch metadata using the saved token SCRIPT_DIR="$CONFIG_DIR" SCRIPT_NAME="get_metadata.sh" SCRIPT_PATH="$SCRIPT_DIR/$SCRIPT_NAME" -echo "#!/bin/bash" > "$SCRIPT_PATH" -echo "source $CONFIG_FILE_PATH" >> "$SCRIPT_PATH" -echo "" >> "$SCRIPT_PATH" -echo "# Define the metadata server endpoint and local machine IP" >> "$SCRIPT_PATH" -echo "SERVER_ENDPOINT=\\\\"$METADATA_SERVER_ENDPOINT\\\\"" >> "$SCRIPT_PATH" -echo "LOCAL_IP=\\\\$(ip route get 8.8.8.8 | awk '{print \\\\$7}' | tr -d '\\\\n')" >> "$SCRIPT_PATH" -echo "" >> "$SCRIPT_PATH" -echo "# Construct the URL" >> "$SCRIPT_PATH" -echo "URL=\\\\"\\\\${SERVER_ENDPOINT}/\\\\${LOCAL_IP}\\\\"" >> "$SCRIPT_PATH" -echo "" >> "$SCRIPT_PATH" -echo "# Define the auth header with the token" >> "$SCRIPT_PATH" -echo "AUTH_HEADER=\\\\"auth_token: \\\\${METADATA_ACCESS_TOKEN}\\\\"" >> "$SCRIPT_PATH" -echo "" >> "$SCRIPT_PATH" -echo "# Fetch the JSON response from the URL" >> "$SCRIPT_PATH" -echo "response=\\\\$(curl -s -X GET \\\\"\\\\$URL\\\\" -H \\\\"\\\\$AUTH_HEADER\\\\")" >> "$SCRIPT_PATH" -echo "" >> "$SCRIPT_PATH" -echo "echo \\\\"Response:\\\\"" >> "$SCRIPT_PATH" -echo "echo \\\\"\\\\$response\\\\"" >> "$SCRIPT_PATH" - -# Make the script executable +cat <<'EOF' > "$SCRIPT_PATH" +#!/bin/bash +source /etc/simplevm/metadata_config.env + +# Construct the URL with hostname query param +INFO_ENDPOINT_URL="${METADATA_INFO_ENDPOINT}?hostname=$(hostname)" + +# Define the auth header with the token +AUTH_HEADER="auth_token: ${METADATA_ACCESS_TOKEN}" + +# Get real metadata endpoint from config if available +REAL_METADATA_ENDPOINT=$(grep '^REAL_METADATA_ENDPOINT=' "/etc/simplevm/metadata_config.env" | cut -d '=' -f 2-) + +if [ -z "${REAL_METADATA_ENDPOINT}" ]; then + # Fetch the JSON response from the info endpoint to get real metadata endpoint + info_response=$(curl -s -X GET "${INFO_ENDPOINT_URL}" -H "${AUTH_HEADER}") + + if [ $? -ne 0 ]; then + echo "Error: Failed to fetch metadata endpoint" + exit 1 + fi + + # Validate the JSON response + if ! jq -e '.metadata_endpoint' <<< "${info_response}" &> /dev/null; then + echo "Error: Invalid JSON response from metadata endpoint" + exit 1 + fi + + # Extract the actual metadata endpoint from the response + REAL_METADATA_ENDPOINT=$(jq -r '.metadata_endpoint' <<< "${info_response}") + + # Save real metadata endpoint to config + echo "REAL_METADATA_ENDPOINT=${REAL_METADATA_ENDPOINT}" >> "/etc/simplevm/metadata_config.env" +fi + +# Fetch the actual metadata from the extracted endpoint +metadata_response=$(curl -s -X GET "${REAL_METADATA_ENDPOINT}" -H "${AUTH_HEADER}") + +if [ $? -ne 0 ]; then + echo "Error: Failed to fetch metadata" + exit 1 +fi + +echo "Response:" +echo "${metadata_response}" +EOF + +# Make the script executable and owned by root chmod 700 "$SCRIPT_PATH" chown root:root "$SCRIPT_PATH" From f3e7b37ea242820bc8acfe4d9a1243fdc547162b Mon Sep 17 00:00:00 2001 From: dweinholz Date: Tue, 17 Sep 2024 16:38:58 +0200 Subject: [PATCH 4/8] removed last time udpated form metadta --- portal_client.thrift | 3 +- simple_vm_client/VirtualMachineService-remote | 9 ++-- simple_vm_client/VirtualMachineService.py | 43 +++---------------- simple_vm_client/ttypes.py | 23 ---------- 4 files changed, 11 insertions(+), 67 deletions(-) diff --git a/portal_client.thrift b/portal_client.thrift index 69cf5e1..09a5a11 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -21,7 +21,6 @@ struct VirtualMachineServerMetadata { 1: required string ip, 2: required string hashed_auth_token, 3: optional UserData userdata, - 4: required i64 last_time_updated, } @@ -574,7 +573,7 @@ service VirtualMachineService { ) throws (1:BackendNotFoundException b,2:DefaultException d) - void set_metadata_server_data(1:string ip,2:string endpoint,3:VirtualMachineServerMetadata metadata) throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b) + void set_metadata_server_data(1:string ip,3:VirtualMachineServerMetadata metadata) throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b) void remove_metadata_server_data(1:string ip) throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b) void is_metadata_server_available() throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b) diff --git a/simple_vm_client/VirtualMachineService-remote b/simple_vm_client/VirtualMachineService-remote index bbf9029..0fb2e94 100755 --- a/simple_vm_client/VirtualMachineService-remote +++ b/simple_vm_client/VirtualMachineService-remote @@ -75,7 +75,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == "--help": print(" get_backends_by_template(string template)") print(" Backend get_backend_by_id(i64 id)") print( - " void set_metadata_server_data(string ip, string endpoint, VirtualMachineServerMetadata metadata)" + " void set_metadata_server_data(string ip, VirtualMachineServerMetadata metadata)" ) print(" void remove_metadata_server_data(string ip)") print(" void is_metadata_server_available()") @@ -551,14 +551,13 @@ elif cmd == "get_backend_by_id": ) elif cmd == "set_metadata_server_data": - if len(args) != 3: - print("set_metadata_server_data requires 3 args") + if len(args) != 2: + print("set_metadata_server_data requires 2 args") sys.exit(1) pp.pprint( client.set_metadata_server_data( args[0], - args[1], - eval(args[2]), + eval(args[1]), ) ) diff --git a/simple_vm_client/VirtualMachineService.py b/simple_vm_client/VirtualMachineService.py index 1818692..992f495 100644 --- a/simple_vm_client/VirtualMachineService.py +++ b/simple_vm_client/VirtualMachineService.py @@ -361,11 +361,10 @@ def get_backend_by_id(self, id): """ - def set_metadata_server_data(self, ip, endpoint, metadata): + def set_metadata_server_data(self, ip, metadata): """ Parameters: - ip - - endpoint - metadata """ @@ -2192,24 +2191,22 @@ def recv_get_backend_by_id(self): "get_backend_by_id failed: unknown result", ) - def set_metadata_server_data(self, ip, endpoint, metadata): + def set_metadata_server_data(self, ip, metadata): """ Parameters: - ip - - endpoint - metadata """ - self.send_set_metadata_server_data(ip, endpoint, metadata) + self.send_set_metadata_server_data(ip, metadata) self.recv_set_metadata_server_data() - def send_set_metadata_server_data(self, ip, endpoint, metadata): + def send_set_metadata_server_data(self, ip, metadata): self._oprot.writeMessageBegin( "set_metadata_server_data", TMessageType.CALL, self._seqid ) args = set_metadata_server_data_args() args.ip = ip - args.endpoint = endpoint args.metadata = metadata args.write(self._oprot) self._oprot.writeMessageEnd() @@ -4912,9 +4909,7 @@ def process_set_metadata_server_data(self, seqid, iprot, oprot): iprot.readMessageEnd() result = set_metadata_server_data_result() try: - self._handler.set_metadata_server_data( - args.ip, args.endpoint, args.metadata - ) + self._handler.set_metadata_server_data(args.ip, args.metadata) msg_type = TMessageType.REPLY except TTransport.TTransportException: raise @@ -13077,7 +13072,6 @@ class set_metadata_server_data_args(object): """ Attributes: - ip - - endpoint - metadata """ @@ -13085,11 +13079,9 @@ class set_metadata_server_data_args(object): def __init__( self, ip=None, - endpoint=None, metadata=None, ): self.ip = ip - self.endpoint = endpoint self.metadata = metadata def read(self, iprot): @@ -13114,15 +13106,6 @@ def read(self, iprot): ) else: iprot.skip(ftype) - elif fid == 2: - if ftype == TType.STRING: - self.endpoint = ( - iprot.readString().decode("utf-8", errors="replace") - if sys.version_info[0] == 2 - else iprot.readString() - ) - else: - iprot.skip(ftype) elif fid == 3: if ftype == TType.STRUCT: self.metadata = VirtualMachineServerMetadata() @@ -13147,14 +13130,6 @@ def write(self, oprot): self.ip.encode("utf-8") if sys.version_info[0] == 2 else self.ip ) oprot.writeFieldEnd() - if self.endpoint is not None: - oprot.writeFieldBegin("endpoint", TType.STRING, 2) - oprot.writeString( - self.endpoint.encode("utf-8") - if sys.version_info[0] == 2 - else self.endpoint - ) - oprot.writeFieldEnd() if self.metadata is not None: oprot.writeFieldBegin("metadata", TType.STRUCT, 3) self.metadata.write(oprot) @@ -13186,13 +13161,7 @@ def __ne__(self, other): "UTF8", None, ), # 1 - ( - 2, - TType.STRING, - "endpoint", - "UTF8", - None, - ), # 2 + None, # 2 ( 3, TType.STRUCT, diff --git a/simple_vm_client/ttypes.py b/simple_vm_client/ttypes.py index c18982b..f50af13 100644 --- a/simple_vm_client/ttypes.py +++ b/simple_vm_client/ttypes.py @@ -227,7 +227,6 @@ class VirtualMachineServerMetadata(object): - ip - hashed_auth_token - userdata - - last_time_updated """ @@ -236,12 +235,10 @@ def __init__( ip=None, hashed_auth_token=None, userdata=None, - last_time_updated=None, ): self.ip = ip self.hashed_auth_token = hashed_auth_token self.userdata = userdata - self.last_time_updated = last_time_updated def read(self, iprot): if ( @@ -280,11 +277,6 @@ def read(self, iprot): self.userdata.read(iprot) else: iprot.skip(ftype) - elif fid == 4: - if ftype == TType.I64: - self.last_time_updated = iprot.readI64() - else: - iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -315,10 +307,6 @@ def write(self, oprot): oprot.writeFieldBegin("userdata", TType.STRUCT, 3) self.userdata.write(oprot) oprot.writeFieldEnd() - if self.last_time_updated is not None: - oprot.writeFieldBegin("last_time_updated", TType.I64, 4) - oprot.writeI64(self.last_time_updated) - oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() @@ -329,10 +317,6 @@ def validate(self): raise TProtocolException( message="Required field hashed_auth_token is unset!" ) - if self.last_time_updated is None: - raise TProtocolException( - message="Required field last_time_updated is unset!" - ) return def __repr__(self): @@ -4390,13 +4374,6 @@ def __ne__(self, other): [UserData, None], None, ), # 3 - ( - 4, - TType.I64, - "last_time_updated", - None, - None, - ), # 4 ) all_structs.append(Backend) Backend.thrift_spec = ( From 449e759d1512275d00c06f87a8b7d0637399b5c5 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Tue, 17 Sep 2024 17:00:11 +0200 Subject: [PATCH 5/8] updated serializer for emtadata --- .../metadata_connector/metadata_connector.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/simple_vm_client/metadata_connector/metadata_connector.py b/simple_vm_client/metadata_connector/metadata_connector.py index 1b84e71..d589914 100644 --- a/simple_vm_client/metadata_connector/metadata_connector.py +++ b/simple_vm_client/metadata_connector/metadata_connector.py @@ -82,10 +82,21 @@ def remove_metadata(self, ip: str): logger.error(f"Failed to remove metadata for {ip}: {e}") def _serialize_metadata(self, metadata: VirtualMachineServerMetadata): + userdata_dict = None + if metadata.userdata is not None: + userdata_dict = { + user_id: { + "username": user.username, + "user_id": user.user_id, + "public_keys": user.public_keys, + } + for user_id, user in metadata.userdata.data.items() + } + return { - "public_keys": metadata.public_keys, - "hashed_auth_token": metadata.hashed_auth_token, "ip": metadata.ip, + "hashed_auth_token": metadata.hashed_auth_token, + "userdata": userdata_dict, } def set_metadata(self, ip: str, metadata: VirtualMachineServerMetadata): From e73002730f90b06e043492dcac55a512e757faf8 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Wed, 18 Sep 2024 08:17:26 +0200 Subject: [PATCH 6/8] updated serializer --- .../metadata_connector/metadata_connector.py | 26 ++++++------------- simple_vm_client/util/thrift_converter.py | 17 ++++++++++++ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/simple_vm_client/metadata_connector/metadata_connector.py b/simple_vm_client/metadata_connector/metadata_connector.py index d589914..f79b86a 100644 --- a/simple_vm_client/metadata_connector/metadata_connector.py +++ b/simple_vm_client/metadata_connector/metadata_connector.py @@ -1,3 +1,4 @@ +import json import os from urllib.parse import urljoin @@ -6,6 +7,7 @@ from simple_vm_client.ttypes import VirtualMachineServerMetadata from simple_vm_client.util.logger import setup_custom_logger +from simple_vm_client.util.thrift_converter import thrift_to_dict logger = setup_custom_logger(__name__) @@ -81,23 +83,9 @@ def remove_metadata(self, ip: str): except requests.exceptions.RequestException as e: logger.error(f"Failed to remove metadata for {ip}: {e}") - def _serialize_metadata(self, metadata: VirtualMachineServerMetadata): - userdata_dict = None - if metadata.userdata is not None: - userdata_dict = { - user_id: { - "username": user.username, - "user_id": user.user_id, - "public_keys": user.public_keys, - } - for user_id, user in metadata.userdata.data.items() - } - - return { - "ip": metadata.ip, - "hashed_auth_token": metadata.hashed_auth_token, - "userdata": userdata_dict, - } + def _serialize_metadata(self, metadata: VirtualMachineServerMetadata) -> str: + metadata_dict = thrift_to_dict(metadata) + return json.dumps(metadata_dict) def set_metadata(self, ip: str, metadata: VirtualMachineServerMetadata): if not ip: @@ -109,12 +97,14 @@ def set_metadata(self, ip: str, metadata: VirtualMachineServerMetadata): logger.info(f"Setting Metadata for {ip}") set_metadata_url = urljoin(self.METADATA_BASE_URL, f"metadata/{ip}") try: + serialized_data = self._serialize_metadata(metadata=metadata) response = requests.post( set_metadata_url, - json=self._serialize_metadata(metadata=metadata), + data=serialized_data, timeout=(30, 30), headers={ "X-Auth-Token": self.METADATA_SERVER_TOKEN, + "Content-Type": "application/json", }, verify=False, ) diff --git a/simple_vm_client/util/thrift_converter.py b/simple_vm_client/util/thrift_converter.py index 184fd96..46ab196 100644 --- a/simple_vm_client/util/thrift_converter.py +++ b/simple_vm_client/util/thrift_converter.py @@ -140,3 +140,20 @@ def os_to_thrift_servers(openstack_servers: list[OpenStack_Server]) -> list[VM]: os_to_thrift_server(openstack_server=openstack_server) for openstack_server in openstack_servers ] + + +def thrift_to_dict(obj): + if hasattr(obj, "thrift_spec"): + result = {} + for k in obj.thrift_spec: + if obj.thrift_spec[k] is not None: + field = obj.thrift_spec[k][2] + value = getattr(obj, field) + result[field] = thrift_to_dict(value) + return result + elif isinstance(obj, list): + return [thrift_to_dict(x) for x in obj] + elif isinstance(obj, dict): + return {thrift_to_dict(k): thrift_to_dict(v) for k, v in obj.items()} + else: + return obj From 8f5cf26d21dc10d1ecf73a58d3d27aceac6de52a Mon Sep 17 00:00:00 2001 From: dweinholz Date: Wed, 18 Sep 2024 08:35:03 +0200 Subject: [PATCH 7/8] updated serialization thrift to dict --- simple_vm_client/util/thrift_converter.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/simple_vm_client/util/thrift_converter.py b/simple_vm_client/util/thrift_converter.py index 46ab196..f067ee8 100644 --- a/simple_vm_client/util/thrift_converter.py +++ b/simple_vm_client/util/thrift_converter.py @@ -143,17 +143,19 @@ def os_to_thrift_servers(openstack_servers: list[OpenStack_Server]) -> list[VM]: def thrift_to_dict(obj): - if hasattr(obj, "thrift_spec"): + if hasattr(obj, "thrift_spec") and obj.thrift_spec is not None: result = {} - for k in obj.thrift_spec: - if obj.thrift_spec[k] is not None: - field = obj.thrift_spec[k][2] - value = getattr(obj, field) - result[field] = thrift_to_dict(value) + for field in obj.thrift_spec: + if field is not None: + field_id, field_type, field_name, *rest = field + value = getattr(obj, field_name, None) + result[field_name] = thrift_to_dict(value) return result elif isinstance(obj, list): - return [thrift_to_dict(x) for x in obj] + return [thrift_to_dict(item) for item in obj] elif isinstance(obj, dict): - return {thrift_to_dict(k): thrift_to_dict(v) for k, v in obj.items()} + return { + thrift_to_dict(key): thrift_to_dict(value) for key, value in obj.items() + } else: return obj From 3ef635d2b94266e725606bf4402e73d4df63ce8b Mon Sep 17 00:00:00 2001 From: dweinholz Date: Wed, 18 Sep 2024 09:43:17 +0200 Subject: [PATCH 8/8] updated script --- .../scripts/bash/save_metadata_auth_token.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh b/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh index 04be6b4..51ba670 100644 --- a/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh +++ b/simple_vm_client/openstack_connector/scripts/bash/save_metadata_auth_token.sh @@ -84,14 +84,14 @@ if [ -z "${REAL_METADATA_ENDPOINT}" ]; then fi # Fetch the actual metadata from the extracted endpoint -metadata_response=$(curl -s -X GET "${REAL_METADATA_ENDPOINT}" -H "${AUTH_HEADER}") +LOCAL_IP=$(hostname -I | awk '{print $1}') +metadata_response=$(curl -s -X GET "${REAL_METADATA_ENDPOINT}/metadata/${LOCAL_IP}" -H "${AUTH_HEADER}") if [ $? -ne 0 ]; then echo "Error: Failed to fetch metadata" exit 1 fi -echo "Response:" echo "${metadata_response}" EOF