From a74ac6ec8b405f839691a4a4532005f10a1252e1 Mon Sep 17 00:00:00 2001 From: DavidWein94 Date: Wed, 18 Jul 2018 17:17:05 +0200 Subject: [PATCH] Feature/volumes (#57) * feat(snapshot):added snapshot function * feat(handler):fixed response createsnapshot * feat(snapshot):added baseimtagetag * feat(volumes):added methods to delete volume anda ttach to server * fix(volumes):fixed a type bug * feat(volumes):added method to delete volume attachment * feat(volumes):changed delete volume a little bit * feat(snapshots):added delete method * feat(volumes):small changes * fix(merge):fixed merge errors --- .../VirtualMachineHandler.py | 129 ++-- .../VirtualMachineService-remote | 31 +- .../VirtualMachineService.py | 667 ++++++++++++++++-- portal_client.thrift | 14 +- 4 files changed, 734 insertions(+), 107 deletions(-) diff --git a/gen-py/VirtualMachineService/VirtualMachineHandler.py b/gen-py/VirtualMachineService/VirtualMachineHandler.py index a878ce11..ceaf90fb 100644 --- a/gen-py/VirtualMachineService/VirtualMachineHandler.py +++ b/gen-py/VirtualMachineService/VirtualMachineHandler.py @@ -127,7 +127,7 @@ def get_Images(self): 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=description,tag=tags + openstack_id=img['id'], description=description, tag=tags ) images.append(image) @@ -141,7 +141,7 @@ def get_Image_with_Tag(self, id): tags = img.get('tags') 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=description,tag=tags + openstack_id=img['id'], description=description, tag=tags ) return image @@ -209,7 +209,7 @@ def get_server(self, openstack_id): def start_server(self, flavor, image, public_key, servername, elixir_id, diskspace): - volumeId='' + volumeId = '' self.logger.info("Start Server {0}".format(servername)) try: metadata = {'elixir_id': elixir_id} @@ -226,7 +226,6 @@ def start_server(self, flavor, image, public_key, servername, elixir_id, diskspa self.logger.error('Network {0} not found!'.format(network)) raise networkNotFoundException(Reason='Network {0} not found!'.format(network)) - keyname = elixir_id[:-18] public_key = urllib.parse.unquote(public_key) keypair = self.import_keypair(keyname, public_key) @@ -240,10 +239,10 @@ def start_server(self, flavor, image, public_key, servername, elixir_id, diskspa 'Trying to create volume with {0} GB for vm {1} error : {2}'.format(diskspace, openstack_id, e), exc_info=True) raise ressourceException(Reason=str(e)) - volumeId =volume['id'] + volumeId = volume['id'] with open('../../mount.sh', 'r') as file: text = file.read() - text = text.replace('VOLUMEID', 'virtio-'+volumeId[0:20]) + text = text.replace('VOLUMEID', 'virtio-' + volumeId[0:20]) text = encodeutils.safe_encode(text.encode('utf-8')) init_script = base64.b64encode(text).decode('utf-8') @@ -255,12 +254,12 @@ def start_server(self, flavor, image, public_key, servername, elixir_id, diskspa name=servername, image_id=image.id, flavor_id=flavor.id, networks=[{"uuid": network.id}], key_name=keypair.name, metadata=metadata) - return {'openstackid':server.to_dict()['id'],'volumeId':volumeId} + return {'openstackid': server.to_dict()['id'], 'volumeId': volumeId} except Exception as e: self.logger.error(e) raise ressourceException(Reason=str(e)) - def attach_volume_to_server(self, openstack_id, diskspace,volume_id): + def attach_volume_to_server(self, openstack_id, volume_id): def checkStatusVolume(volume, conn): self.logger.info("Checking Status Volume {0}".format(volume_id)) done = False @@ -276,12 +275,11 @@ def checkStatusVolume(volume, conn): time.sleep(2) return volume - server = self.conn.compute.get_server(openstack_id) if server is None: self.logger.error("No Server {0} ".format(openstack_id)) raise serverNotFoundException(Reason='No Server {0}'.format(openstack_id)) - checkStatusVolume(volume_id,self.conn) + checkStatusVolume(volume_id, self.conn) self.logger.info('Attaching volume {0} to virtualmachine {1}'.format(volume_id, openstack_id)) try: @@ -296,7 +294,7 @@ def checkStatusVolume(volume, conn): return True - def check_server_status(self, openstack_id, diskspace,volume_id): + def check_server_status(self, openstack_id, diskspace, volume_id): self.logger.info('Check Status VM {0}'.format(openstack_id)) try: server = self.conn.compute.get_server(openstack_id) @@ -310,7 +308,8 @@ def check_server_status(self, openstack_id, diskspace,volume_id): if serv['status'] == 'ACTIVE': if diskspace > 0: - attached = self.attach_volume_to_server(openstack_id=openstack_id, diskspace=diskspace,volume_id=volume_id) + attached = self.attach_volume_to_server(openstack_id=openstack_id, + volume_id=volume_id) if attached is False: server = self.get_server(openstack_id) @@ -325,31 +324,45 @@ def check_server_status(self, openstack_id, diskspace,volume_id): return server def get_IP_PORT(self, openstack_id): - self.logger.info("Get IP and PORT for server {0}".format(openstack_id)) + self.logger.info("Get IP and PORT for server {0}".format(openstack_id)) - # check if jumphost is active + # check if jumphost is active - if 'True' == str(self.USE_JUMPHOST): - server = self.get_server(openstack_id) - server_base = server.fixed_ip.split(".")[-1] - port = int(self.JUMPHOST_BASE) + int(server_base) * 3 - return {'IP': str(self.JUMPHOST_IP),'PORT':str(port)} + if 'True' == str(self.USE_JUMPHOST): + server = self.get_server(openstack_id) + server_base = server.fixed_ip.split(".")[-1] + port = int(self.JUMPHOST_BASE) + int(server_base) * 3 + return {'IP': str(self.JUMPHOST_IP), 'PORT': str(port)} - else: - floating_ip = self.add_floating_ip_to_server(openstack_id, self.FLOATING_IP_NETWORK) + else: + floating_ip = self.add_floating_ip_to_server(openstack_id, self.FLOATING_IP_NETWORK) - return {'IP': str(floating_ip)} + return {'IP': str(floating_ip)} - def create_snapshot(self,openstack_id,name,elixir_id,base_tag): - self.logger.info('Create Snapshot from Instance {0} with name {1} for {2}'.format(openstack_id,name,elixir_id)) + def create_snapshot(self, openstack_id, name, elixir_id, base_tag): + self.logger.info( + 'Create Snapshot from Instance {0} with name {1} for {2}'.format(openstack_id, name, elixir_id)) - snapshot_munch= self.conn.create_image_snapshot(server=openstack_id,name=name) - snapshot_id=snapshot_munch['id'] - self.conn.image.add_tag(image=snapshot_id,tag=elixir_id) - self.conn.image.add_tag(image=snapshot_id,tag='snapshot_image:{0}'.format(base_tag)) + try: + snapshot_munch = self.conn.create_image_snapshot(server=openstack_id, name=name) + except Exception: + self.logger.error("Instance {0} not found".format(openstack_id)) + raise serverNotFoundException + snapshot_id = snapshot_munch['id'] + self.conn.image.add_tag(image=snapshot_id, tag=elixir_id) + self.conn.image.add_tag(image=snapshot_id, tag='snapshot_image:{0}'.format(base_tag)) + return snapshot_id + + def delete_image(self,image_id): + self.logger.info('Delete Image {0}'.format(image_id)) + + image = self.conn.compute.get_image(image_id) + if image is None: + self.logger.error('Image {0} not found!'.format(image)) + raise imageNotFoundException(Reason=('Image {0} not found'.format(image))) + self.conn.compute.delete_image(image) return True - def add_floating_ip_to_server(self, openstack_id, network): server = self.conn.compute.get_server(openstack_id) @@ -367,7 +380,7 @@ def add_floating_ip_to_server(self, openstack_id, network): if not floating_ip.fixed_ip_address: self.conn.compute.add_floating_ip_to_server(server, floating_ip.floating_ip_address) self.logger.info( - "Adding existing Floating IP {0} to {1}".format(str(floating_ip.floating_ip_address),openstack_id)) + "Adding existing Floating IP {0} to {1}".format(str(floating_ip.floating_ip_address), openstack_id)) return str(floating_ip.floating_ip_address) networkID = self.conn.network.find_network(network) @@ -394,46 +407,44 @@ def delete_server(self, openstack_id): while server.status != 'ACTIVE': server = self.conn.compute.get_server(server) time.sleep(3) + self.conn.compute.delete_server(server) - attachments = list() - volumeids = list() - - for volume in self.conn.compute.volume_attachments(server=server): - attachments.append(volume) - volumeids.append(volume.to_dict()['volume_id']) + return True - def deleteVolumeAttachmenServer(attachments, server, logger, conn): - for a in attachments: - logger.info("Delete VolumeAttachment {0}".format(a)) - conn.compute.delete_volume_attachment(volume_attachment=a, server=server) - deleteVolumeAttachmenServer(attachments=attachments, server=server, logger=self.logger, conn=self.conn) + def delete_volume_attachment(self, volume_id,server_id): + attachments=self.conn.block_storage.get_volume(volume_id).attachments + for attachment in attachments: + volume_attachment_id=attachment['id'] + instance_id=attachment['server_id'] + if instance_id == server_id: + self.logger.info("Delete Volume Attachment {0}".format(volume_attachment_id)) + self.conn.compute.delete_volume_attachment(volume_attachment=volume_attachment_id, server=server_id) + return True - def checkStatusVolumes(volumes, conn): + def delete_volume(self, volume_id): + def checkStatusVolume(volume, conn): + self.logger.info("Checking Status Volume {0}".format(volume_id)) done = False while done == False: - done = True - for a in volumes: - if conn.block_storage.get_volume(a).to_dict()['status'] != 'available': - conn.block_storage.get_volume(a).to_dict()['status'] - done = False - time.sleep(5) - break - return - - checkStatusVolumes(volumeids, self.conn) - - def deleteVolume(volume_id, conn, logger): - logger.info("Delete Volume {0}".format(volume_id)) - conn.block_storage.delete_volume(volume=volume_id) - for id in volumeids: - deleteVolume(id, self.conn, self.logger) - self.conn.compute.delete_server(server) + status = conn.block_storage.get_volume(volume).to_dict()['status'] + + if status != 'available': + time.sleep(3) + else: + done = True + return volume + checkStatusVolume(volume_id,self.conn) + self.logger.info("Delete Volume {0}".format(volume_id)) + self.conn.block_storage.delete_volume(volume=volume_id) return True + + + def stop_server(self, openstack_id): self.logger.info("Stop Server " + openstack_id) server = self.conn.compute.get_server(openstack_id) diff --git a/gen-py/VirtualMachineService/VirtualMachineService-remote b/gen-py/VirtualMachineService/VirtualMachineService-remote index 3d2960d1..16c1bc9e 100755 --- a/gen-py/VirtualMachineService/VirtualMachineService-remote +++ b/gen-py/VirtualMachineService/VirtualMachineService-remote @@ -37,8 +37,11 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help': print(' start_server(string flavor, string image, string public_key, string servername, string elixir_id, string diskspace)') print(' VM get_server(string openstack_id)') print(' bool stop_server(string openstack_id)') - print(' bool create_snapshot(string openstack_id, string name, string elixir_id, string base_tag)') - print(' bool attach_volume_to_server(string openstack_id, int diskspace, string volume_id)') + print(' string create_snapshot(string openstack_id, string name, string elixir_id, string base_tag)') + print(' bool delete_image(string image_id)') + print(' bool delete_volume_attachment(string volume_id, string server_id)') + print(' bool delete_volume(string volume_id)') + print(' bool attach_volume_to_server(string openstack_id, string volume_id)') print(' VM check_server_status(string openstack_id, int diskspace, string volume_id)') print(' string setUserPassword(string user, string password)') print(' bool resume_server(string openstack_id)') @@ -205,11 +208,29 @@ elif cmd == 'create_snapshot': sys.exit(1) pp.pprint(client.create_snapshot(args[0], args[1], args[2], args[3],)) +elif cmd == 'delete_image': + if len(args) != 1: + print('delete_image requires 1 args') + sys.exit(1) + pp.pprint(client.delete_image(args[0],)) + +elif cmd == 'delete_volume_attachment': + if len(args) != 2: + print('delete_volume_attachment requires 2 args') + sys.exit(1) + pp.pprint(client.delete_volume_attachment(args[0], args[1],)) + +elif cmd == 'delete_volume': + if len(args) != 1: + print('delete_volume requires 1 args') + sys.exit(1) + pp.pprint(client.delete_volume(args[0],)) + elif cmd == 'attach_volume_to_server': - if len(args) != 3: - print('attach_volume_to_server requires 3 args') + if len(args) != 2: + print('attach_volume_to_server requires 2 args') sys.exit(1) - pp.pprint(client.attach_volume_to_server(args[0], eval(args[1]), args[2],)) + pp.pprint(client.attach_volume_to_server(args[0], args[1],)) elif cmd == 'check_server_status': if len(args) != 3: diff --git a/gen-py/VirtualMachineService/VirtualMachineService.py b/gen-py/VirtualMachineService/VirtualMachineService.py index 31ca3f26..97bbe1d2 100755 --- a/gen-py/VirtualMachineService/VirtualMachineService.py +++ b/gen-py/VirtualMachineService/VirtualMachineService.py @@ -170,11 +170,32 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag): """ pass - def attach_volume_to_server(self, openstack_id, diskspace, volume_id): + def delete_image(self, image_id): + """ + Parameters: + - image_id + """ + pass + + def delete_volume_attachment(self, volume_id, server_id): + """ + Parameters: + - volume_id + - server_id + """ + pass + + def delete_volume(self, volume_id): + """ + Parameters: + - volume_id + """ + pass + + def attach_volume_to_server(self, openstack_id, volume_id): """ Parameters: - openstack_id - - diskspace - volume_id """ pass @@ -744,23 +765,122 @@ def recv_create_snapshot(self): iprot.readMessageEnd() if result.success is not None: return result.success + if result.e is not None: + raise result.e raise TApplicationException(TApplicationException.MISSING_RESULT, "create_snapshot failed: unknown result") - def attach_volume_to_server(self, openstack_id, diskspace, volume_id): + def delete_image(self, image_id): + """ + Parameters: + - image_id + """ + self.send_delete_image(image_id) + return self.recv_delete_image() + + def send_delete_image(self, image_id): + self._oprot.writeMessageBegin('delete_image', TMessageType.CALL, self._seqid) + args = delete_image_args() + args.image_id = image_id + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_delete_image(self): + iprot = self._iprot + (fname, mtype, rseqid) = iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(iprot) + iprot.readMessageEnd() + raise x + result = delete_image_result() + result.read(iprot) + iprot.readMessageEnd() + if result.success is not None: + return result.success + if result.e is not None: + raise result.e + raise TApplicationException(TApplicationException.MISSING_RESULT, "delete_image failed: unknown result") + + def delete_volume_attachment(self, volume_id, server_id): + """ + Parameters: + - volume_id + - server_id + """ + self.send_delete_volume_attachment(volume_id, server_id) + return self.recv_delete_volume_attachment() + + def send_delete_volume_attachment(self, volume_id, server_id): + self._oprot.writeMessageBegin('delete_volume_attachment', TMessageType.CALL, self._seqid) + args = delete_volume_attachment_args() + args.volume_id = volume_id + args.server_id = server_id + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_delete_volume_attachment(self): + iprot = self._iprot + (fname, mtype, rseqid) = iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(iprot) + iprot.readMessageEnd() + raise x + result = delete_volume_attachment_result() + result.read(iprot) + iprot.readMessageEnd() + if result.success is not None: + return result.success + if result.e is not None: + raise result.e + raise TApplicationException(TApplicationException.MISSING_RESULT, "delete_volume_attachment failed: unknown result") + + def delete_volume(self, volume_id): + """ + Parameters: + - volume_id + """ + self.send_delete_volume(volume_id) + return self.recv_delete_volume() + + def send_delete_volume(self, volume_id): + self._oprot.writeMessageBegin('delete_volume', TMessageType.CALL, self._seqid) + args = delete_volume_args() + args.volume_id = volume_id + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_delete_volume(self): + iprot = self._iprot + (fname, mtype, rseqid) = iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(iprot) + iprot.readMessageEnd() + raise x + result = delete_volume_result() + result.read(iprot) + iprot.readMessageEnd() + if result.success is not None: + return result.success + raise TApplicationException(TApplicationException.MISSING_RESULT, "delete_volume failed: unknown result") + + def attach_volume_to_server(self, openstack_id, volume_id): """ Parameters: - openstack_id - - diskspace - volume_id """ - self.send_attach_volume_to_server(openstack_id, diskspace, volume_id) + self.send_attach_volume_to_server(openstack_id, volume_id) return self.recv_attach_volume_to_server() - def send_attach_volume_to_server(self, openstack_id, diskspace, volume_id): + def send_attach_volume_to_server(self, openstack_id, volume_id): self._oprot.writeMessageBegin('attach_volume_to_server', TMessageType.CALL, self._seqid) args = attach_volume_to_server_args() args.openstack_id = openstack_id - args.diskspace = diskspace args.volume_id = volume_id args.write(self._oprot) self._oprot.writeMessageEnd() @@ -909,6 +1029,9 @@ def __init__(self, handler): self._processMap["get_server"] = Processor.process_get_server self._processMap["stop_server"] = Processor.process_stop_server self._processMap["create_snapshot"] = Processor.process_create_snapshot + self._processMap["delete_image"] = Processor.process_delete_image + self._processMap["delete_volume_attachment"] = Processor.process_delete_volume_attachment + self._processMap["delete_volume"] = Processor.process_delete_volume self._processMap["attach_volume_to_server"] = Processor.process_attach_volume_to_server self._processMap["check_server_status"] = Processor.process_check_server_status self._processMap["setUserPassword"] = Processor.process_setUserPassword @@ -1231,6 +1354,9 @@ def process_create_snapshot(self, seqid, iprot, oprot): msg_type = TMessageType.REPLY except (TTransport.TTransportException, KeyboardInterrupt, SystemExit): raise + except serverNotFoundException as e: + msg_type = TMessageType.REPLY + result.e = e except Exception as ex: msg_type = TMessageType.EXCEPTION logging.exception(ex) @@ -1240,13 +1366,76 @@ def process_create_snapshot(self, seqid, iprot, oprot): oprot.writeMessageEnd() oprot.trans.flush() + def process_delete_image(self, seqid, iprot, oprot): + args = delete_image_args() + args.read(iprot) + iprot.readMessageEnd() + result = delete_image_result() + try: + result.success = self._handler.delete_image(args.image_id) + msg_type = TMessageType.REPLY + except (TTransport.TTransportException, KeyboardInterrupt, SystemExit): + raise + except imageNotFoundException as e: + msg_type = TMessageType.REPLY + result.e = e + except Exception as ex: + msg_type = TMessageType.EXCEPTION + logging.exception(ex) + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') + oprot.writeMessageBegin("delete_image", msg_type, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + + def process_delete_volume_attachment(self, seqid, iprot, oprot): + args = delete_volume_attachment_args() + args.read(iprot) + iprot.readMessageEnd() + result = delete_volume_attachment_result() + try: + result.success = self._handler.delete_volume_attachment(args.volume_id, args.server_id) + msg_type = TMessageType.REPLY + except (TTransport.TTransportException, KeyboardInterrupt, SystemExit): + raise + except serverNotFoundException as e: + msg_type = TMessageType.REPLY + result.e = e + except Exception as ex: + msg_type = TMessageType.EXCEPTION + logging.exception(ex) + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') + oprot.writeMessageBegin("delete_volume_attachment", msg_type, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + + def process_delete_volume(self, seqid, iprot, oprot): + args = delete_volume_args() + args.read(iprot) + iprot.readMessageEnd() + result = delete_volume_result() + try: + result.success = self._handler.delete_volume(args.volume_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("delete_volume", msg_type, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + def process_attach_volume_to_server(self, seqid, iprot, oprot): args = attach_volume_to_server_args() args.read(iprot) iprot.readMessageEnd() result = attach_volume_to_server_result() try: - result.success = self._handler.attach_volume_to_server(args.openstack_id, args.diskspace, args.volume_id) + result.success = self._handler.attach_volume_to_server(args.openstack_id, args.volume_id) msg_type = TMessageType.REPLY except (TTransport.TTransportException, KeyboardInterrupt, SystemExit): raise @@ -3383,14 +3572,17 @@ class create_snapshot_result(object): """ Attributes: - success + - e """ thrift_spec = ( - (0, TType.BOOL, 'success', None, None, ), # 0 + (0, TType.STRING, 'success', 'UTF8', None, ), # 0 + (1, TType.STRUCT, 'e', (serverNotFoundException, serverNotFoundException.thrift_spec), None, ), # 1 ) - def __init__(self, success=None,): + def __init__(self, success=None, e=None,): self.success = success + self.e = e def read(self, iprot): if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: @@ -3402,8 +3594,14 @@ def read(self, iprot): if ftype == TType.STOP: break if fid == 0: - if ftype == TType.BOOL: - self.success = iprot.readBool() + if ftype == TType.STRING: + self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + elif fid == 1: + if ftype == TType.STRUCT: + self.e = serverNotFoundException() + self.e.read(iprot) else: iprot.skip(ftype) else: @@ -3417,8 +3615,12 @@ def write(self, oprot): return oprot.writeStructBegin('create_snapshot_result') if self.success is not None: - oprot.writeFieldBegin('success', TType.BOOL, 0) - oprot.writeBool(self.success) + oprot.writeFieldBegin('success', TType.STRING, 0) + oprot.writeString(self.success.encode('utf-8') if sys.version_info[0] == 2 else self.success) + oprot.writeFieldEnd() + if self.e is not None: + oprot.writeFieldBegin('e', TType.STRUCT, 1) + self.e.write(oprot) oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() @@ -3438,25 +3640,19 @@ def __ne__(self, other): return not (self == other) -class attach_volume_to_server_args(object): +class delete_image_args(object): """ Attributes: - - openstack_id - - diskspace - - volume_id + - image_id """ thrift_spec = ( None, # 0 - (1, TType.STRING, 'openstack_id', 'UTF8', None, ), # 1 - (2, TType.I32, 'diskspace', None, None, ), # 2 - (3, TType.STRING, 'volume_id', 'UTF8', None, ), # 3 + (1, TType.STRING, 'image_id', 'UTF8', None, ), # 1 ) - def __init__(self, openstack_id=None, diskspace=None, volume_id=None,): - self.openstack_id = openstack_id - self.diskspace = diskspace - self.volume_id = volume_id + def __init__(self, image_id=None,): + self.image_id = image_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: @@ -3469,17 +3665,75 @@ def read(self, iprot): 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() + self.image_id = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) - elif fid == 2: - if ftype == TType.I32: - self.diskspace = iprot.readI32() + 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('delete_image_args') + if self.image_id is not None: + oprot.writeFieldBegin('image_id', TType.STRING, 1) + oprot.writeString(self.image_id.encode('utf-8') if sys.version_info[0] == 2 else self.image_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 delete_image_result(object): + """ + Attributes: + - success + - e + """ + + thrift_spec = ( + (0, TType.BOOL, 'success', None, None, ), # 0 + (1, TType.STRUCT, 'e', (imageNotFoundException, imageNotFoundException.thrift_spec), None, ), # 1 + ) + + def __init__(self, success=None, e=None,): + self.success = success + self.e = e + + 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.BOOL: + self.success = iprot.readBool() else: iprot.skip(ftype) - elif fid == 3: - if ftype == TType.STRING: - self.volume_id = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + elif fid == 1: + if ftype == TType.STRUCT: + self.e = imageNotFoundException() + self.e.read(iprot) else: iprot.skip(ftype) else: @@ -3491,17 +3745,348 @@ 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('attach_volume_to_server_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.writeStructBegin('delete_image_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.BOOL, 0) + oprot.writeBool(self.success) oprot.writeFieldEnd() - if self.diskspace is not None: - oprot.writeFieldBegin('diskspace', TType.I32, 2) - oprot.writeI32(self.diskspace) + if self.e is not None: + oprot.writeFieldBegin('e', TType.STRUCT, 1) + self.e.write(oprot) oprot.writeFieldEnd() - if self.volume_id is not None: - oprot.writeFieldBegin('volume_id', TType.STRING, 3) + 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_volume_attachment_args(object): + """ + Attributes: + - volume_id + - server_id + """ + + thrift_spec = ( + None, # 0 + (1, TType.STRING, 'volume_id', 'UTF8', None, ), # 1 + (2, TType.STRING, 'server_id', 'UTF8', None, ), # 2 + ) + + def __init__(self, volume_id=None, server_id=None,): + self.volume_id = volume_id + self.server_id = server_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.volume_id = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + elif fid == 2: + if ftype == TType.STRING: + self.server_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('delete_volume_attachment_args') + if self.volume_id is not None: + oprot.writeFieldBegin('volume_id', TType.STRING, 1) + oprot.writeString(self.volume_id.encode('utf-8') if sys.version_info[0] == 2 else self.volume_id) + oprot.writeFieldEnd() + if self.server_id is not None: + oprot.writeFieldBegin('server_id', TType.STRING, 2) + oprot.writeString(self.server_id.encode('utf-8') if sys.version_info[0] == 2 else self.server_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 delete_volume_attachment_result(object): + """ + Attributes: + - success + - e + """ + + thrift_spec = ( + (0, TType.BOOL, 'success', None, None, ), # 0 + (1, TType.STRUCT, 'e', (serverNotFoundException, serverNotFoundException.thrift_spec), None, ), # 1 + ) + + def __init__(self, success=None, e=None,): + self.success = success + self.e = e + + 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.BOOL: + self.success = iprot.readBool() + else: + iprot.skip(ftype) + elif fid == 1: + if ftype == TType.STRUCT: + self.e = serverNotFoundException() + self.e.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('delete_volume_attachment_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.BOOL, 0) + oprot.writeBool(self.success) + oprot.writeFieldEnd() + if self.e is not None: + oprot.writeFieldBegin('e', TType.STRUCT, 1) + self.e.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_volume_args(object): + """ + Attributes: + - volume_id + """ + + thrift_spec = ( + None, # 0 + (1, TType.STRING, 'volume_id', 'UTF8', None, ), # 1 + ) + + def __init__(self, volume_id=None,): + self.volume_id = volume_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.volume_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('delete_volume_args') + if self.volume_id is not None: + oprot.writeFieldBegin('volume_id', TType.STRING, 1) + oprot.writeString(self.volume_id.encode('utf-8') if sys.version_info[0] == 2 else self.volume_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 delete_volume_result(object): + """ + Attributes: + - success + """ + + thrift_spec = ( + (0, TType.BOOL, 'success', None, 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.BOOL: + self.success = iprot.readBool() + 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('delete_volume_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.BOOL, 0) + oprot.writeBool(self.success) + 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 attach_volume_to_server_args(object): + """ + Attributes: + - openstack_id + - volume_id + """ + + thrift_spec = ( + None, # 0 + (1, TType.STRING, 'openstack_id', 'UTF8', None, ), # 1 + (2, TType.STRING, 'volume_id', 'UTF8', None, ), # 2 + ) + + def __init__(self, openstack_id=None, volume_id=None,): + self.openstack_id = openstack_id + self.volume_id = volume_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) + elif fid == 2: + if ftype == TType.STRING: + self.volume_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('attach_volume_to_server_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() + if self.volume_id is not None: + oprot.writeFieldBegin('volume_id', TType.STRING, 2) oprot.writeString(self.volume_id.encode('utf-8') if sys.version_info[0] == 2 else self.volume_id) oprot.writeFieldEnd() oprot.writeFieldStop() diff --git a/portal_client.thrift b/portal_client.thrift index e6eab747..b0f189c4 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -224,11 +224,21 @@ service VirtualMachineService { * This Method unpause a VirtualMachine with a specific Openstack-ID. */ - bool create_snapshot(1:string openstack_id, 2:string name,3: string elixir_id,4:string base_tag) + string create_snapshot(1:string openstack_id, 2:string name,3: string elixir_id,4:string base_tag) throws (1:serverNotFoundException e), - bool attach_volume_to_server(1:string openstack_id,2:int diskspace,3:string volume_id) throws (1:serverNotFoundException e), + + + + bool delete_image(1:string image_id) throws (1:imageNotFoundException e) + + bool delete_volume_attachment(1:string volume_id,2:string server_id) throws (1:serverNotFoundException e), + + bool delete_volume(1:string volume_id) + + + bool attach_volume_to_server(1:string openstack_id,2:string volume_id) throws (1:serverNotFoundException e), VM check_server_status(1:string openstack_id,2:int diskspace,3:string volume_id) throws (1:serverNotFoundException e,2:ressourceException r),