From 1dbefe5e9b05350996e18491d12f1b02f7ee6c18 Mon Sep 17 00:00:00 2001 From: DavidWein94 Date: Fri, 18 Jan 2019 12:29:31 +0100 Subject: [PATCH] feat(Snapshot):check status (#97) * feat(Snapshot):check status * updated changelog --- CHANGELOG.md | 6 + .../VirtualMachineHandler.py | 2 + .../VirtualMachineService-remote | 7 + .../VirtualMachineService.py | 196 +++++++++++++++++- VirtualMachineService/config/config.yml | 2 +- VirtualMachineService/constants.py | 5 +- portal_client.thrift | 6 + requirements.txt | 2 +- 8 files changed, 212 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3856935a..0af62998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +#### Features + +* **Snapshot:** check status + + + ### Features * **PR_TEMPLATE:** diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 0903bf60..cbb8f792 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -212,6 +212,7 @@ def get_client_version(self): self.logger.info("Get Version of Client: {}".format(VERSION)) return str(VERSION) + def get_Images(self): """ Get Images. @@ -649,6 +650,7 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag): :param base_tag: Tag with which the servers image is also tagged :return: Id of the new Snapshot """ + self.logger.info(base_tag) self.logger.info( 'Create Snapshot from Instance {0} with name {1} for {2}'.format( openstack_id, name, elixir_id)) diff --git a/VirtualMachineService/VirtualMachineService-remote b/VirtualMachineService/VirtualMachineService-remote index 39cad337..f6db22f5 100755 --- a/VirtualMachineService/VirtualMachineService-remote +++ b/VirtualMachineService/VirtualMachineService-remote @@ -30,6 +30,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help': print(' get_IP_PORT(string openstack_id)') print(' get_Flavors()') print(' get_Images()') + print(' Image get_Image_with_Tag(string openstack_id)') print(' bool delete_server(string openstack_id)') print(' add_metadata_to_server(string servername, metadata)') print(' delete_metadata_from_server(string servername, keys)') @@ -164,6 +165,12 @@ elif cmd == 'get_Images': sys.exit(1) pp.pprint(client.get_Images()) +elif cmd == 'get_Image_with_Tag': + if len(args) != 1: + print('get_Image_with_Tag requires 1 args') + sys.exit(1) + pp.pprint(client.get_Image_with_Tag(args[0],)) + elif cmd == 'delete_server': if len(args) != 1: print('delete_server requires 1 args') diff --git a/VirtualMachineService/VirtualMachineService.py b/VirtualMachineService/VirtualMachineService.py index 11d5fc5f..4111e88e 100644 --- a/VirtualMachineService/VirtualMachineService.py +++ b/VirtualMachineService/VirtualMachineService.py @@ -10,11 +10,7 @@ from thrift.protocol.TProtocol import TProtocolException import sys import logging -try: - from ttypes import * -except Exception: - from .ttypes import * - +from ttypes import * from thrift.Thrift import TProcessor from thrift.transport import TTransport @@ -72,6 +68,16 @@ def get_Images(self): """ pass + def get_Image_with_Tag(self, openstack_id): + """ + Get an image with tag. + Returns: Image with tag. + + Parameters: + - openstack_id + """ + pass + def delete_server(self, openstack_id): """ Delete server. @@ -171,7 +177,7 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag): - openstack_id: Id of the server - name: Name of new Snapshot - elixir_id: Elixir-Id of the user who requested creation of Snapshot - - base_tag: Tag with which the servers image is also taged ( for connection information at the webapp) + - base_tag: Tag with which the servers image is also tagged ( for connection information at the webapp) """ pass @@ -483,6 +489,40 @@ def recv_get_Images(self): return result.success raise TApplicationException(TApplicationException.MISSING_RESULT, "get_Images failed: unknown result") + def get_Image_with_Tag(self, openstack_id): + """ + Get an image with tag. + Returns: Image with tag. + + Parameters: + - openstack_id + """ + self.send_get_Image_with_Tag(openstack_id) + return self.recv_get_Image_with_Tag() + + def send_get_Image_with_Tag(self, openstack_id): + self._oprot.writeMessageBegin('get_Image_with_Tag', TMessageType.CALL, self._seqid) + args = get_Image_with_Tag_args() + args.openstack_id = openstack_id + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_get_Image_with_Tag(self): + iprot = self._iprot + (fname, mtype, rseqid) = iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(iprot) + iprot.readMessageEnd() + raise x + result = get_Image_with_Tag_result() + result.read(iprot) + iprot.readMessageEnd() + if result.success is not None: + return result.success + raise TApplicationException(TApplicationException.MISSING_RESULT, "get_Image_with_Tag failed: unknown result") + def delete_server(self, openstack_id): """ Delete server. @@ -817,7 +857,7 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag): - openstack_id: Id of the server - name: Name of new Snapshot - elixir_id: Elixir-Id of the user who requested creation of Snapshot - - base_tag: Tag with which the servers image is also taged ( for connection information at the webapp) + - base_tag: Tag with which the servers image is also tagged ( for connection information at the webapp) """ self.send_create_snapshot(openstack_id, name, elixir_id, base_tag) return self.recv_create_snapshot() @@ -1231,6 +1271,7 @@ def __init__(self, handler): self._processMap["get_IP_PORT"] = Processor.process_get_IP_PORT self._processMap["get_Flavors"] = Processor.process_get_Flavors self._processMap["get_Images"] = Processor.process_get_Images + self._processMap["get_Image_with_Tag"] = Processor.process_get_Image_with_Tag self._processMap["delete_server"] = Processor.process_delete_server self._processMap["add_metadata_to_server"] = Processor.process_add_metadata_to_server self._processMap["delete_metadata_from_server"] = Processor.process_delete_metadata_from_server @@ -1380,6 +1421,25 @@ def process_get_Images(self, seqid, iprot, oprot): oprot.writeMessageEnd() oprot.trans.flush() + def process_get_Image_with_Tag(self, seqid, iprot, oprot): + args = get_Image_with_Tag_args() + args.read(iprot) + iprot.readMessageEnd() + result = get_Image_with_Tag_result() + try: + result.success = self._handler.get_Image_with_Tag(args.openstack_id) + msg_type = TMessageType.REPLY + except (TTransport.TTransportException, KeyboardInterrupt, SystemExit): + raise + except Exception as ex: + msg_type = TMessageType.EXCEPTION + logging.exception(ex) + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') + oprot.writeMessageBegin("get_Image_with_Tag", msg_type, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + def process_delete_server(self, seqid, iprot, oprot): args = delete_server_args() args.read(iprot) @@ -2519,6 +2579,126 @@ def __ne__(self, other): return not (self == other) +class get_Image_with_Tag_args(object): + """ + Attributes: + - openstack_id + """ + + thrift_spec = ( + None, # 0 + (1, TType.STRING, 'openstack_id', 'UTF8', None, ), # 1 + ) + + def __init__(self, openstack_id=None,): + self.openstack_id = openstack_id + + 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.openstack_id = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + 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('get_Image_with_Tag_args') + if self.openstack_id is not None: + oprot.writeFieldBegin('openstack_id', TType.STRING, 1) + oprot.writeString(self.openstack_id.encode('utf-8') if sys.version_info[0] == 2 else self.openstack_id) + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + + def validate(self): + 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 get_Image_with_Tag_result(object): + """ + Attributes: + - success + """ + + thrift_spec = ( + (0, TType.STRUCT, 'success', (Image, Image.thrift_spec), None, ), # 0 + ) + + def __init__(self, success=None,): + self.success = success + + 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 == 0: + if ftype == TType.STRUCT: + self.success = Image() + self.success.read(iprot) + 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('get_Image_with_Tag_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.STRUCT, 0) + self.success.write(oprot) + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + + def validate(self): + 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 delete_server_args(object): """ Attributes: @@ -3879,7 +4059,7 @@ class create_snapshot_args(object): - openstack_id: Id of the server - name: Name of new Snapshot - elixir_id: Elixir-Id of the user who requested creation of Snapshot - - base_tag: Tag with which the servers image is also taged ( for connection information at the webapp) + - base_tag: Tag with which the servers image is also tagged ( for connection information at the webapp) """ thrift_spec = ( diff --git a/VirtualMachineService/config/config.yml b/VirtualMachineService/config/config.yml index 154df7a3..dcafef2b 100644 --- a/VirtualMachineService/config/config.yml +++ b/VirtualMachineService/config/config.yml @@ -4,7 +4,7 @@ openstack_connection: port: 9090 # Gateway Port and IP gateway_base: 30000 - gateway_ip: 172.21.40.14 + gateway_ip: 172.21.40.78 # If set to True the client will use a Gateway instead of providing floating IPs for each instance. use_gateway: True set_password: False diff --git a/VirtualMachineService/constants.py b/VirtualMachineService/constants.py index 4669e069..b31e6be4 100644 --- a/VirtualMachineService/constants.py +++ b/VirtualMachineService/constants.py @@ -9,8 +9,5 @@ from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException from thrift.protocol.TProtocol import TProtocolException import sys -try: - from ttypes import * -except Exception: - from .ttypes import * +from ttypes import * VERSION = "1.0.0" diff --git a/portal_client.thrift b/portal_client.thrift index 201c4683..0cd492c4 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -209,6 +209,12 @@ service VirtualMachineService { */ list get_Images() + /** + * Get an image with tag. + * Returns: Image with tag. + */ + Image get_Image_with_Tag(1:string openstack_id) + /** * Delete server. diff --git a/requirements.txt b/requirements.txt index f2bfea0d..fae916a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ setuptools==40.4.3 thrift >= 0.10.0,<0.20.0 python-keystoneclient -openstacksdk >= 0.9.19, < 1.0.0 +openstacksdk ==0.20.0 deprecated == 1.2.4 Click==7.0 flake8