diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index f80e3acf..6fa129e3 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -674,6 +674,12 @@ def create_and_deploy_playbook(self, public_key, playbooks_information, openstac active_playbooks[openstack_id] = playbook return 0 + def exist_server(self, name): + if self.conn.compute.find_server(name) is not None: + return True + else: + return False + def get_playbook_logs(self, openstack_id): global active_playbooks if self.redis.exists(openstack_id) == 1 and openstack_id in active_playbooks: diff --git a/VirtualMachineService/VirtualMachineService-remote b/VirtualMachineService/VirtualMachineService-remote index 1a02a76f..85b7ddd1 100755 --- a/VirtualMachineService/VirtualMachineService-remote +++ b/VirtualMachineService/VirtualMachineService-remote @@ -38,6 +38,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help': print(' bool create_connection(string username, string password, string auth_url, string user_domain_name, string project_domain_name)') print(' start_server(string flavor, string image, string public_key, string servername, metadata, string diskspace, string volumename)') print(' start_server_with_custom_key(string flavor, string image, string servername, metadata, string diskspace, string volumename)') + print(' bool exist_server(string name)') print(' int create_and_deploy_playbook(string public_key, playbooks_information, string openstack_id)') print(' PlaybookResult get_playbook_logs(string openstack_id)') print(' bool add_security_group_to_server(bool http, bool https, bool udp, string server_id)') @@ -217,6 +218,12 @@ elif cmd == 'start_server_with_custom_key': sys.exit(1) pp.pprint(client.start_server_with_custom_key(args[0], args[1], args[2], eval(args[3]), args[4], args[5],)) +elif cmd == 'exist_server': + if len(args) != 1: + print('exist_server requires 1 args') + sys.exit(1) + pp.pprint(client.exist_server(args[0],)) + elif cmd == 'create_and_deploy_playbook': if len(args) != 3: print('create_and_deploy_playbook requires 3 args') diff --git a/VirtualMachineService/VirtualMachineService.py b/VirtualMachineService/VirtualMachineService.py index 3a8c64aa..21c8d39d 100644 --- a/VirtualMachineService/VirtualMachineService.py +++ b/VirtualMachineService/VirtualMachineService.py @@ -179,6 +179,16 @@ def start_server_with_custom_key(self, flavor, image, servername, metadata, disk """ pass + def exist_server(self, name): + """ + Check if there is an instance with name + + Parameters: + - name + + """ + pass + def create_and_deploy_playbook(self, public_key, playbooks_information, openstack_id): """ Create and deploy an anaconda ansible playbook @@ -929,6 +939,40 @@ def recv_start_server_with_custom_key(self): raise result.o raise TApplicationException(TApplicationException.MISSING_RESULT, "start_server_with_custom_key failed: unknown result") + def exist_server(self, name): + """ + Check if there is an instance with name + + Parameters: + - name + + """ + self.send_exist_server(name) + return self.recv_exist_server() + + def send_exist_server(self, name): + self._oprot.writeMessageBegin('exist_server', TMessageType.CALL, self._seqid) + args = exist_server_args() + args.name = name + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_exist_server(self): + iprot = self._iprot + (fname, mtype, rseqid) = iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(iprot) + iprot.readMessageEnd() + raise x + result = exist_server_result() + result.read(iprot) + iprot.readMessageEnd() + if result.success is not None: + return result.success + raise TApplicationException(TApplicationException.MISSING_RESULT, "exist_server failed: unknown result") + def create_and_deploy_playbook(self, public_key, playbooks_information, openstack_id): """ Create and deploy an anaconda ansible playbook @@ -1566,6 +1610,7 @@ def __init__(self, handler): self._processMap["create_connection"] = Processor.process_create_connection self._processMap["start_server"] = Processor.process_start_server self._processMap["start_server_with_custom_key"] = Processor.process_start_server_with_custom_key + self._processMap["exist_server"] = Processor.process_exist_server self._processMap["create_and_deploy_playbook"] = Processor.process_create_and_deploy_playbook self._processMap["get_playbook_logs"] = Processor.process_get_playbook_logs self._processMap["add_security_group_to_server"] = Processor.process_add_security_group_to_server @@ -1980,6 +2025,29 @@ def process_start_server_with_custom_key(self, seqid, iprot, oprot): oprot.writeMessageEnd() oprot.trans.flush() + def process_exist_server(self, seqid, iprot, oprot): + args = exist_server_args() + args.read(iprot) + iprot.readMessageEnd() + result = exist_server_result() + try: + result.success = self._handler.exist_server(args.name) + msg_type = TMessageType.REPLY + except TTransport.TTransportException: + raise + except TApplicationException as ex: + logging.exception('TApplication exception in handler') + msg_type = TMessageType.EXCEPTION + result = ex + except Exception: + logging.exception('Unexpected exception in handler') + msg_type = TMessageType.EXCEPTION + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') + oprot.writeMessageBegin("exist_server", msg_type, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + def process_create_and_deploy_playbook(self, seqid, iprot, oprot): args = create_and_deploy_playbook_args() args.read(iprot) @@ -4655,6 +4723,129 @@ def __ne__(self, other): ) +class exist_server_args(object): + """ + Attributes: + - name + + """ + + + def __init__(self, name=None,): + self.name = name + + 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.name = 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('exist_server_args') + if self.name is not None: + oprot.writeFieldBegin('name', TType.STRING, 1) + oprot.writeString(self.name.encode('utf-8') if sys.version_info[0] == 2 else self.name) + 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) +all_structs.append(exist_server_args) +exist_server_args.thrift_spec = ( + None, # 0 + (1, TType.STRING, 'name', 'UTF8', None, ), # 1 +) + + +class exist_server_result(object): + """ + Attributes: + - success + + """ + + + 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('exist_server_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) +all_structs.append(exist_server_result) +exist_server_result.thrift_spec = ( + (0, TType.BOOL, 'success', None, None, ), # 0 +) + + class create_and_deploy_playbook_args(object): """ Attributes: diff --git a/portal_client.thrift b/portal_client.thrift index c4768595..ec0a3b4f 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -33,14 +33,14 @@ const string VERSION= '1.0.0' /** List of tags from flavor */ 7: required list tags - - + + } /** * This Struct defines an Image. */ -struct Image{ - +struct Image{ + /** The name of the image*/ 1:required string name @@ -75,7 +75,7 @@ struct Image{ * This Struct defines a VirtualMachine. */ struct VM { - + /** The flavor of the VM*/ 1: required Flavor flav, @@ -346,6 +346,11 @@ service VirtualMachineService { throws (1:nameException e,2:ressourceException r,3:serverNotFoundException s,4: networkNotFoundException n,5:imageNotFoundException i,6:flavorNotFoundException f,7:otherException o) + /** Check if there is an instance with name */ + bool exist_server( + 1:string name + ) + /** Create and deploy an anaconda ansible playbook*/ int create_and_deploy_playbook( 1:string public_key,