diff --git a/config.yml b/config.yml index 48c3194c..56c46e79 100644 --- a/config.yml +++ b/config.yml @@ -1,6 +1,6 @@ openstack_connection: host: 0.0.0.0 - port: 9091 + port: 9090 jumphost_base: 30000 jumphost_ip: 172.21.40.14 use_jumphost: True diff --git a/gen-py/VirtualMachineService/VirtualMachineHandler.py b/gen-py/VirtualMachineService/VirtualMachineHandler.py index a32b52da..8df37747 100644 --- a/gen-py/VirtualMachineService/VirtualMachineHandler.py +++ b/gen-py/VirtualMachineService/VirtualMachineHandler.py @@ -98,19 +98,34 @@ def get_Images(self): img = img.to_dict() img.pop('links', None) + metadata=img['metadata'] - - try: + if 'description' in metadata and 'default_user' in metadata: image = Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'], status=img['status'], created_at=img['created_at'], updated_at=img['updated_at'], - openstack_id=img['id'], description=img['metadata']['description']) + openstack_id=img['id'], description=metadata['description'],default_user=metadata['default_user']) - except KeyError: + elif 'description' in metadata: + self.logger.warning("No default_user for " + img['name']) + image = Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'], + status=img['status'], created_at=img['created_at'], updated_at=img['updated_at'], + openstack_id=img['id'], description=metadata['description'], + ) + elif 'default_user' in metadata: self.logger.warning("No Description for " + img['name']) image = Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'], status=img['status'], created_at=img['created_at'], updated_at=img['updated_at'], - openstack_id=img['id']) + openstack_id=img['id'], + default_user=metadata['default_user']) + else: + self.logger.warning("No Description and default_user for " + img['name']) + image = Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'], + status=img['status'], created_at=img['created_at'], updated_at=img['updated_at'], + openstack_id=img['id'], + ) + + images.append(image) return images @@ -146,6 +161,11 @@ def get_server(self, servername): flav = self.conn.compute.get_flavor(serv['flavor']['id']).to_dict() img = self.conn.compute.get_image(serv['image']['id']).to_dict() + default_user='default' + try: + default_user=img['metadata']['default_user'] + except Exception: + pass for values in server.addresses.values(): for address in values: @@ -158,7 +178,7 @@ def get_server(self, servername): server = VM(flav=Flavor(vcpus=flav['vcpus'], ram=flav['ram'], disk=flav['disk'], name=flav['name'], openstack_id=flav['id']), img=Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'], status=img['status'], - created_at=img['created_at'], updated_at=img['updated_at'], openstack_id=img['id']), + created_at=img['created_at'], updated_at=img['updated_at'], openstack_id=img['id'],default_user=default_user), status=serv['status'], metadata=serv['metadata'], project_id=serv['project_id'], keyname=serv['key_name'], openstack_id=serv['id'], name=serv['name'], created_at=str(timestamp), floating_ip=floating_ip, fixed_ip=fixed_ip) @@ -166,7 +186,7 @@ def get_server(self, servername): server = VM(flav=Flavor(vcpus=flav['vcpus'], ram=flav['ram'], disk=flav['disk'], name=flav['name'], openstack_id=flav['id']), img=Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'], - status=img['status'], + status=img['status'],default_user=default_user, created_at=img['created_at'], updated_at=img['updated_at'], openstack_id=img['id']), status=serv['status'], metadata=serv['metadata'], project_id=serv['project_id'], keyname=serv['key_name'], openstack_id=serv['id'], name=serv['name'], created_at=str(timestamp), @@ -212,16 +232,25 @@ def start_server(self, flavor, image, public_key, servername, elixir_id): def generate_SSH_Login_String(self,servername): #check if jumphost is active + if 'True' == str(self.USE_JUMPHOST): - server_base = self.get_server(servername=servername).fixed_ip.split(".")[-1] + server = self.get_server(servername=servername) + img=server.img + default_user=img.default_user + server_base = server.fixed_ip.split(".")[-1] port=int(self.JUMPHOST_BASE) + int (server_base)*3 - ssh_command="ssh -i private_key_file ubuntu@" + str(self.JUMPHOST_IP) + " -p " + str(port) + ssh_command="ssh -i private_key_file " + str(default_user)+"@" + str(self.JUMPHOST_IP) + " -p " + str(port) return ssh_command else: floating_ip=self.add_floating_ip_to_server(servername, self.FLOATING_IP_NETWORK) - return "ssh -i private_key_file ubuntu@" + str(floating_ip) + server = self.get_server(servername=servername) + img = server.img + + default_user=img.default_user + + return "ssh -i private_key_file " + str(default_user)+"@" + str(floating_ip) def add_floating_ip_to_server(self, servername, network): server = self.conn.compute.find_server(servername) diff --git a/gen-py/VirtualMachineService/ttypes.py b/gen-py/VirtualMachineService/ttypes.py index c869fa51..21f428fe 100755 --- a/gen-py/VirtualMachineService/ttypes.py +++ b/gen-py/VirtualMachineService/ttypes.py @@ -158,6 +158,7 @@ class Image(object): - updated_at - openstack_id - description + - default_user """ thrift_spec = ( @@ -170,9 +171,10 @@ class Image(object): (6, TType.STRING, 'updated_at', 'UTF8', None, ), # 6 (7, TType.STRING, 'openstack_id', 'UTF8', None, ), # 7 (8, TType.STRING, 'description', 'UTF8', None, ), # 8 + (9, TType.STRING, 'default_user', 'UTF8', None, ), # 9 ) - def __init__(self, name=None, min_disk=None, min_ram=None, status=None, created_at=None, updated_at=None, openstack_id=None, description=None,): + def __init__(self, name=None, min_disk=None, min_ram=None, status=None, created_at=None, updated_at=None, openstack_id=None, description=None, default_user=None,): self.name = name self.min_disk = min_disk self.min_ram = min_ram @@ -181,6 +183,7 @@ def __init__(self, name=None, min_disk=None, min_ram=None, status=None, created_ self.updated_at = updated_at self.openstack_id = openstack_id self.description = description + self.default_user = default_user def read(self, iprot): if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: @@ -231,6 +234,11 @@ def read(self, iprot): self.description = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) + elif fid == 9: + if ftype == TType.STRING: + self.default_user = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -273,6 +281,10 @@ def write(self, oprot): oprot.writeFieldBegin('description', TType.STRING, 8) oprot.writeString(self.description.encode('utf-8') if sys.version_info[0] == 2 else self.description) oprot.writeFieldEnd() + if self.default_user is not None: + oprot.writeFieldBegin('default_user', TType.STRING, 9) + oprot.writeString(self.default_user.encode('utf-8') if sys.version_info[0] == 2 else self.default_user) + oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() diff --git a/portal_client.thrift b/portal_client.thrift index 5927f85b..7c6f0263 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -34,6 +34,7 @@ struct Image{ 6:optional string updated_at 7:required string openstack_id 8:optional string description + 9:optional string default_user } /** * This Struct defines a VirtualMachine. @@ -52,6 +53,7 @@ struct VM { 9: required string created_at 10: optional string floating_ip 11: required string fixed_ip + }