diff --git a/CHANGELOG.md b/CHANGELOG.md index 064e1178..8a5b3fb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## (2019-07-10) + + +#### Features + +* **Snapshot:** addeed description ([e7570b12](e7570b12)) + +#### Bug Fixes + +* **ansible:** fix string.strip error ([dafd8045](dafd8045)) + + ## (2019-06-18) #### Refactor diff --git a/Dockerfile b/Dockerfile index 16bc6c91..5974be72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,5 @@ FROM python:3.6.6-slim ADD . /code WORKDIR /code RUN pip install -r requirements.txt +COPY ansible.cfg /etc/ansible/ WORKDIR /code/VirtualMachineService diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 9500a196..33b28ab2 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -15,6 +15,8 @@ from ttypes import ressourceException from ttypes import Flavor, Image, VM from constants import VERSION + from ancon.BiocondaPlaybook import BiocondaPlaybook + except Exception: from .VirtualMachineService import Iface from .ttypes import serverNotFoundException @@ -26,6 +28,8 @@ from .ttypes import ressourceException from .ttypes import Flavor, Image, VM from .constants import VERSION + from .ancon.BiocondaPlaybook import BiocondaPlaybook + from openstack import connection from deprecated import deprecated from keystoneauth1.identity import v3 @@ -42,10 +46,18 @@ import base64 from oslo_utils import encodeutils +osi_key_dict = dict() + class VirtualMachineHandler(Iface): """Handler which the PortalClient uses.""" + global osi_key_dict + BUILD = "BUILD" + ACTIVE = "ACTIVE" + PREPARE_BIOCONDA_BUILD = "PREPARE_BIOCONDA_BUILD" + BUILD_BIOCONDA = "BUILD_BIOCONDA" + def create_connection(self): """ Create connection to OpenStack. @@ -297,6 +309,11 @@ def get_Image_with_Tag(self, id): self.logger.exception("Get Image {0} with Tag Error: {1}".format(id, e)) return + def delete_keypair(self, key_name): + key_pair = self.conn.compute.find_keypair(key_name) + if key_pair: + self.conn.compute.delete_keypair(key_pair) + def import_keypair(self, keyname, public_key): """ Import Keypair to OpenStack. @@ -420,6 +437,60 @@ def get_server(self, openstack_id): ) return server + def get_image(self, image): + image = self.conn.compute.find_image(image) + if image is None: + self.logger.exception("Image {0} not found!".format(image)) + raise imageNotFoundException( + Reason=("Image {0} not found".format(image)) + ) + return image + + def get_flavor(self, flavor): + flavor = self.conn.compute.find_flavor(flavor) + if flavor is None: + self.logger.exception("Flavor {0} not found!".format(flavor)) + raise flavorNotFoundException( + Reason="Flavor {0} not found!".format(flavor) + ) + return flavor + + def get_network(self): + network = self.conn.network.find_network(self.NETWORK) + if network is None: + self.logger.exception("Network {0} not found!".format(network)) + raise networkNotFoundException( + Reason="Network {0} not found!".format(network) + ) + return network + + def create_volume_by_start(self, volume_storage, volume_name, server_name): + self.logger.info( + "Creating volume with {0} GB diskspace".format(volume_storage) + ) + try: + volume = self.conn.block_storage.create_volume( + name=volume_name, size=int(volume_storage) + ).to_dict() + except Exception as e: + self.logger.exception( + "Trying to create volume with {0}" + " GB for vm {1} error : {2}".format(volume_storage, server_name, e), + exc_info=True, + ) + raise ressourceException(Reason=str(e)) + return volume["id"] + + def create_mount_init_script(self, volume_id): + fileDir = os.path.dirname(os.path.abspath(__file__)) + mount_script = os.path.join(fileDir, "scripts/bash/mount.sh") + with open(mount_script, "r") as file: + text = file.read() + text = text.replace("VOLUMEID", "virtio-" + volume_id[0:20]) + text = encodeutils.safe_encode(text.encode("utf-8")) + init_script = base64.b64encode(text).decode("utf-8") + return init_script + def start_server( self, flavor, @@ -442,64 +513,29 @@ def start_server( :param volumename: Name of the volume :return: {'openstackid': serverId, 'volumeId': volumeId} """ - volumeId = "" + volume_id = '' self.logger.info("Start Server {0}".format(servername)) try: metadata = {"elixir_id": elixir_id} - image = self.conn.compute.find_image(image) - if image is None: - self.logger.exception("Image {0} not found!".format(image)) - raise imageNotFoundException( - Reason=("Image {0} not fournd".format(image)) - ) - flavor = self.conn.compute.find_flavor(flavor) - if flavor is None: - self.logger.exception("Flavor {0} not found!".format(flavor)) - raise flavorNotFoundException( - Reason="Flavor {0} not found!".format(flavor) - ) - network = self.conn.network.find_network(self.NETWORK) - if network is None: - self.logger.exception("Network {0} not found!".format(network)) - raise networkNotFoundException( - Reason="Network {0} not found!".format(network) - ) - - keyname = elixir_id[:-18] + image = self.get_image(image=image) + flavor = self.get_flavor(flavor=flavor) + network = self.get_network() + key_name = elixir_id[:-18] public_key = urllib.parse.unquote(public_key) - keypair = self.import_keypair(keyname, public_key) + key_pair = self.import_keypair(key_name, public_key) if diskspace > "0": - self.logger.info( - "Creating volume with {0} GB diskspace".format(diskspace) - ) - try: - volume = self.conn.block_storage.create_volume( - name=volumename, size=int(diskspace) - ).to_dict() - except Exception as e: - self.logger.exception( - "Trying to create volume with {0}" - " GB for vm {1} error : {2}".format(diskspace, servername, e), - exc_info=True, - ) - raise ressourceException(Reason=str(e)) - volumeId = volume["id"] - - fileDir = os.path.dirname(os.path.abspath(__file__)) - mount_script = os.path.join(fileDir, "scripts/bash/mount.sh") - with open(mount_script, "r") as file: - text = file.read() - text = text.replace("VOLUMEID", "virtio-" + volumeId[0:20]) - text = encodeutils.safe_encode(text.encode("utf-8")) - init_script = base64.b64encode(text).decode("utf-8") + volume_id = self.create_volume_by_start(volume_storage=diskspace, + volume_name=volumename, + server_name=servername) + init_script = self.create_mount_init_script(volume_id=volume_id) server = self.conn.compute.create_server( name=servername, image_id=image.id, flavor_id=flavor.id, networks=[{"uuid": network.id}], - key_name=keypair.name, + key_name=key_pair.name, metadata=metadata, user_data=init_script, availability_zone=self.AVAIALABILITY_ZONE, @@ -510,38 +546,88 @@ def start_server( image_id=image.id, flavor_id=flavor.id, networks=[{"uuid": network.id}], - key_name=keypair.name, + key_name=key_pair.name, metadata=metadata, ) openstack_id = server.to_dict()["id"] - return {"openstackid": openstack_id, "volumeId": volumeId} + return {"openstackid": openstack_id, "volumeId": volume_id} except Exception as e: self.logger.exception("Start Server {1} error:{0}".format(e, servername)) return {} - def create_volume(self, volume_name, diskspace): + def start_server_with_custom_key(self, flavor, image, servername, elixir_id, diskspace, + volumename): + """ - Create volume. + Start a new Server. - :param volume_name: Name of volume - :param diskspace: Diskspace in GB for new volume - :return: Id of new volume + :param flavor: Name of flavor which should be used. + :param image: Name of image which should be used + :param public_key: Publickey which should be used + :param servername: Name of the new server + :param elixir_id: Elixir_id of the user who started a new server + :param diskspace: Diskspace in GB for volume which should be created + :param volumename: Name of the volume + :return: {'openstackid': serverId, 'volumeId': volumeId} """ - self.logger.info("Creating volume with {0} GB diskspace".format(diskspace)) + self.logger.info("Start Server {} with custom key".format(servername)) + volume_id = '' try: - volume = self.conn.block_storage.create_volume( - name=volume_name, size=int(diskspace) - ).to_dict() - volumeId = volume["id"] - return volumeId + metadata = {"elixir_id": elixir_id} + image = self.get_image(image=image) + flavor = self.get_flavor(flavor=flavor) + network = self.get_network() + private_key = self.conn.create_keypair(name=servername).__dict__['private_key'] + if int(diskspace) > 0: + volume_id = self.create_volume_by_start(volume_storage=diskspace, + volume_name=volumename, + server_name=servername) + init_script = self.create_mount_init_script(volume_id=volume_id) + + server = self.conn.compute.create_server( + name=servername, + image_id=image.id, + flavor_id=flavor.id, + networks=[{"uuid": network.id}], + key_name=servername, + metadata=metadata, + user_data=init_script, + availability_zone=self.AVAIALABILITY_ZONE, + ) + else: + server = self.conn.compute.create_server( + name=servername, + image_id=image.id, + flavor_id=flavor.id, + networks=[{"uuid": network.id}], + key_name=servername, + metadata=metadata, + ) + + openstack_id = server.to_dict()["id"] + global osi_key_dict + osi_key_dict[openstack_id] = dict(key=private_key, name=servername, + status=self.PREPARE_BIOCONDA_BUILD) + return {"openstackid": openstack_id, "volumeId": volume_id, 'private_key': private_key} except Exception as e: - self.logger.exception( - "Trying to create volume with {0} GB error : {1}".format(diskspace, e), - exc_info=True, - ) - raise ressourceException(Reason=str(e)) + self.delete_keypair(key_name=servername) + self.logger.exception("Start Server {1} error:{0}".format(e, servername)) + return {} + + def create_and_deploy_playbook(self, private_key, play_source, openstack_id): + # get ip and port for inventory + fields = self.get_ip_ports(openstack_id=openstack_id) + global osi_key_dict + key_name = osi_key_dict[openstack_id]['name'] + playbook = BiocondaPlaybook(fields["IP"], fields["PORT"], play_source, + osi_key_dict[openstack_id]["key"], private_key) + osi_key_dict[openstack_id]["status"] = self.BUILD_BIOCONDA + playbook.run_it() + osi_key_dict[openstack_id]["status"] = self.ACTIVE + self.delete_keypair(key_name=key_name) + return 0 def attach_volume_to_server(self, openstack_id, volume_id): """ @@ -623,7 +709,8 @@ def check_server_status(self, openstack_id, diskspace, volume_id): serv = server.to_dict() try: - if serv["status"] == "ACTIVE": + global osi_key_dict + if serv["status"] == self.ACTIVE: host = self.get_server(openstack_id).floating_ip port = self.SSH_PORT @@ -637,17 +724,29 @@ def check_server_status(self, openstack_id, diskspace, volume_id): openstack_id, self.FLOATING_IP_NETWORK ) if self.netcat(host, port): + server = self.get_server(openstack_id) + if diskspace > 0: attached = self.attach_volume_to_server( openstack_id=openstack_id, volume_id=volume_id ) if attached is False: - server = self.get_server(openstack_id) self.delete_server(openstack_id=openstack_id) server.status = "DESTROYED" return server - return self.get_server(openstack_id) + + if openstack_id in osi_key_dict: + if osi_key_dict[openstack_id][ + "status"] == self.PREPARE_BIOCONDA_BUILD: + server.status = self.PREPARE_BIOCONDA_BUILD + return server + elif osi_key_dict[openstack_id][ + "status"] == self.BUILD_BIOCONDA: + server.status = self.BUILD_BIOCONDA + return server + else: + return server return self.get_server(openstack_id) else: server = self.get_server(openstack_id) @@ -655,7 +754,7 @@ def check_server_status(self, openstack_id, diskspace, volume_id): return server else: server = self.get_server(openstack_id) - server.status = "BUILD" + server.status = self.BUILD return server except Exception as e: self.logger.exception("Check Status VM {0} error: {1}".format(openstack_id, e)) @@ -744,7 +843,7 @@ def get_ip_ports(self, openstack_id): ) return {} - def create_snapshot(self, openstack_id, name, elixir_id, base_tag): + def create_snapshot(self, openstack_id, name, elixir_id, base_tag, description): """ Create an Snapshot from an server. @@ -770,17 +869,21 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag): try: snapshot = self.conn.get_image_by_id(snapshot_munch["id"]) snapshot_id = snapshot["id"] - #todo check again + # todo check again try: + image = self.conn.get_image(name_or_id=snapshot_id) + if description: + self.conn.update_image_properties( + image=image, + meta={'description': description}) + self.conn.image.add_tag( image=snapshot_id, tag="snapshot_image:{0}".format(base_tag) ) except Exception: self.logger.exception("Tag error catched") pass - try : - self.logger.exception("Tag error catched") - + try: self.conn.image.add_tag(image=snapshot_id, tag=elixir_id) except Exception: pass diff --git a/VirtualMachineService/VirtualMachineServer.py b/VirtualMachineService/VirtualMachineServer.py index e7cff268..0b6737c4 100644 --- a/VirtualMachineService/VirtualMachineServer.py +++ b/VirtualMachineService/VirtualMachineServer.py @@ -4,12 +4,12 @@ try: from VirtualMachineService import Client, Processor except Exception: - from .VirtualMachineService import Client, Processor + from VirtualMachineService import Client, Processor try: from VirtualMachineHandler import VirtualMachineHandler except Exception: - from .VirtualMachineHandler import VirtualMachineHandler + from VirtualMachineHandler import VirtualMachineHandler from thrift.transport import TSSLSocket from thrift.transport import TTransport diff --git a/VirtualMachineService/VirtualMachineService-remote b/VirtualMachineService/VirtualMachineService-remote index 1376ab87..25a95af0 100755 --- a/VirtualMachineService/VirtualMachineService-remote +++ b/VirtualMachineService/VirtualMachineService-remote @@ -37,10 +37,12 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help': print(' string add_floating_ip_to_server(string openstack_id, string network)') 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, string elixir_id, string diskspace, string volumename)') + print(' start_server_with_custom_key(string flavor, string image, string servername, string elixir_id, string diskspace, string volumename)') + print(' int create_and_deploy_playbook(string private_key, string play_source, string openstack_id)') print(' bool add_security_group_to_server(bool http, bool https, bool udp, string server_id)') print(' VM get_server(string openstack_id)') print(' bool stop_server(string openstack_id)') - print(' string create_snapshot(string openstack_id, string name, string elixir_id, string base_tag)') + print(' string create_snapshot(string openstack_id, string name, string elixir_id, string base_tag, string description)') print(' get_limits()') print(' bool delete_image(string image_id)') print(' bool delete_volume_attachment(string volume_id, string server_id)') @@ -208,6 +210,18 @@ elif cmd == 'start_server': sys.exit(1) pp.pprint(client.start_server(args[0], args[1], args[2], args[3], args[4], args[5], args[6],)) +elif cmd == 'start_server_with_custom_key': + if len(args) != 6: + print('start_server_with_custom_key requires 6 args') + sys.exit(1) + pp.pprint(client.start_server_with_custom_key(args[0], args[1], args[2], args[3], args[4], args[5],)) + +elif cmd == 'create_and_deploy_playbook': + if len(args) != 3: + print('create_and_deploy_playbook requires 3 args') + sys.exit(1) + pp.pprint(client.create_and_deploy_playbook(args[0], args[1], args[2],)) + elif cmd == 'add_security_group_to_server': if len(args) != 4: print('add_security_group_to_server requires 4 args') @@ -227,10 +241,10 @@ elif cmd == 'stop_server': pp.pprint(client.stop_server(args[0],)) elif cmd == 'create_snapshot': - if len(args) != 4: - print('create_snapshot requires 4 args') + if len(args) != 5: + print('create_snapshot requires 5 args') sys.exit(1) - pp.pprint(client.create_snapshot(args[0], args[1], args[2], args[3],)) + pp.pprint(client.create_snapshot(args[0], args[1], args[2], args[3], args[4],)) elif cmd == 'get_limits': if len(args) != 0: diff --git a/VirtualMachineService/VirtualMachineService.py b/VirtualMachineService/VirtualMachineService.py index 58c6f81e..9aa7fd20 100644 --- a/VirtualMachineService/VirtualMachineService.py +++ b/VirtualMachineService/VirtualMachineService.py @@ -164,6 +164,33 @@ def start_server(self, flavor, image, public_key, servername, elixir_id, diskspa """ pass + def start_server_with_custom_key(self, flavor, image, servername, elixir_id, diskspace, volumename): + """ + Start a new server. + + Parameters: + - flavor: Name of the Flavor to use. + - image: Name of the image to use. + - servername: Name for the new server + - elixir_id: Elixir-Id of the user who requested to start a new server + - diskspace: Diskspace in GB for additional volume. + - volumename: Name of additional Volume + + """ + pass + + def create_and_deploy_playbook(self, private_key, play_source, openstack_id): + """ + Create and deploy an anaconda ansible playbook + + Parameters: + - private_key + - play_source + - openstack_id + + """ + pass + def add_security_group_to_server(self, http, https, udp, server_id): """ Adds a security group to a server @@ -199,7 +226,7 @@ def stop_server(self, openstack_id): """ pass - def create_snapshot(self, openstack_id, name, elixir_id, base_tag): + def create_snapshot(self, openstack_id, name, elixir_id, base_tag, description): """ Create Snapshot. Returns: Id of new Snapshot @@ -210,6 +237,7 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag): - 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 tagged ( for connection information at the webapp) + - description: Description of the new snapshot """ pass @@ -832,6 +860,102 @@ def recv_start_server(self): raise result.o raise TApplicationException(TApplicationException.MISSING_RESULT, "start_server failed: unknown result") + def start_server_with_custom_key(self, flavor, image, servername, elixir_id, diskspace, volumename): + """ + Start a new server. + + Parameters: + - flavor: Name of the Flavor to use. + - image: Name of the image to use. + - servername: Name for the new server + - elixir_id: Elixir-Id of the user who requested to start a new server + - diskspace: Diskspace in GB for additional volume. + - volumename: Name of additional Volume + + """ + self.send_start_server_with_custom_key(flavor, image, servername, elixir_id, diskspace, volumename) + return self.recv_start_server_with_custom_key() + + def send_start_server_with_custom_key(self, flavor, image, servername, elixir_id, diskspace, volumename): + self._oprot.writeMessageBegin('start_server_with_custom_key', TMessageType.CALL, self._seqid) + args = start_server_with_custom_key_args() + args.flavor = flavor + args.image = image + args.servername = servername + args.elixir_id = elixir_id + args.diskspace = diskspace + args.volumename = volumename + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_start_server_with_custom_key(self): + iprot = self._iprot + (fname, mtype, rseqid) = iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(iprot) + iprot.readMessageEnd() + raise x + result = start_server_with_custom_key_result() + result.read(iprot) + iprot.readMessageEnd() + if result.success is not None: + return result.success + if result.e is not None: + raise result.e + if result.r is not None: + raise result.r + if result.s is not None: + raise result.s + if result.n is not None: + raise result.n + if result.i is not None: + raise result.i + if result.f is not None: + raise result.f + if result.o is not None: + raise result.o + raise TApplicationException(TApplicationException.MISSING_RESULT, "start_server_with_custom_key failed: unknown result") + + def create_and_deploy_playbook(self, private_key, play_source, openstack_id): + """ + Create and deploy an anaconda ansible playbook + + Parameters: + - private_key + - play_source + - openstack_id + + """ + self.send_create_and_deploy_playbook(private_key, play_source, openstack_id) + return self.recv_create_and_deploy_playbook() + + def send_create_and_deploy_playbook(self, private_key, play_source, openstack_id): + self._oprot.writeMessageBegin('create_and_deploy_playbook', TMessageType.CALL, self._seqid) + args = create_and_deploy_playbook_args() + args.private_key = private_key + args.play_source = play_source + args.openstack_id = openstack_id + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_create_and_deploy_playbook(self): + iprot = self._iprot + (fname, mtype, rseqid) = iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(iprot) + iprot.readMessageEnd() + raise x + result = create_and_deploy_playbook_result() + result.read(iprot) + iprot.readMessageEnd() + if result.success is not None: + return result.success + raise TApplicationException(TApplicationException.MISSING_RESULT, "create_and_deploy_playbook failed: unknown result") + def add_security_group_to_server(self, http, https, udp, server_id): """ Adds a security group to a server @@ -950,7 +1074,7 @@ def recv_stop_server(self): raise result.e raise TApplicationException(TApplicationException.MISSING_RESULT, "stop_server failed: unknown result") - def create_snapshot(self, openstack_id, name, elixir_id, base_tag): + def create_snapshot(self, openstack_id, name, elixir_id, base_tag, description): """ Create Snapshot. Returns: Id of new Snapshot @@ -961,18 +1085,20 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag): - 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 tagged ( for connection information at the webapp) + - description: Description of the new snapshot """ - self.send_create_snapshot(openstack_id, name, elixir_id, base_tag) + self.send_create_snapshot(openstack_id, name, elixir_id, base_tag, description) return self.recv_create_snapshot() - def send_create_snapshot(self, openstack_id, name, elixir_id, base_tag): + def send_create_snapshot(self, openstack_id, name, elixir_id, base_tag, description): self._oprot.writeMessageBegin('create_snapshot', TMessageType.CALL, self._seqid) args = create_snapshot_args() args.openstack_id = openstack_id args.name = name args.elixir_id = elixir_id args.base_tag = base_tag + args.description = description args.write(self._oprot) self._oprot.writeMessageEnd() self._oprot.trans.flush() @@ -1392,6 +1518,8 @@ def __init__(self, handler): self._processMap["add_floating_ip_to_server"] = Processor.process_add_floating_ip_to_server 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["create_and_deploy_playbook"] = Processor.process_create_and_deploy_playbook self._processMap["add_security_group_to_server"] = Processor.process_add_security_group_to_server self._processMap["get_server"] = Processor.process_get_server self._processMap["stop_server"] = Processor.process_stop_server @@ -1760,6 +1888,73 @@ def process_start_server(self, seqid, iprot, oprot): oprot.writeMessageEnd() oprot.trans.flush() + def process_start_server_with_custom_key(self, seqid, iprot, oprot): + args = start_server_with_custom_key_args() + args.read(iprot) + iprot.readMessageEnd() + result = start_server_with_custom_key_result() + try: + result.success = self._handler.start_server_with_custom_key(args.flavor, args.image, args.servername, args.elixir_id, args.diskspace, args.volumename) + msg_type = TMessageType.REPLY + except TTransport.TTransportException: + raise + except nameException as e: + msg_type = TMessageType.REPLY + result.e = e + except ressourceException as r: + msg_type = TMessageType.REPLY + result.r = r + except serverNotFoundException as s: + msg_type = TMessageType.REPLY + result.s = s + except networkNotFoundException as n: + msg_type = TMessageType.REPLY + result.n = n + except imageNotFoundException as i: + msg_type = TMessageType.REPLY + result.i = i + except flavorNotFoundException as f: + msg_type = TMessageType.REPLY + result.f = f + except otherException as o: + msg_type = TMessageType.REPLY + result.o = o + 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("start_server_with_custom_key", 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) + iprot.readMessageEnd() + result = create_and_deploy_playbook_result() + try: + result.success = self._handler.create_and_deploy_playbook(args.private_key, args.play_source, args.openstack_id) + 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("create_and_deploy_playbook", msg_type, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + def process_add_security_group_to_server(self, seqid, iprot, oprot): args = add_security_group_to_server_args() args.read(iprot) @@ -1847,7 +2042,7 @@ def process_create_snapshot(self, seqid, iprot, oprot): iprot.readMessageEnd() result = create_snapshot_result() try: - result.success = self._handler.create_snapshot(args.openstack_id, args.name, args.elixir_id, args.base_tag) + result.success = self._handler.create_snapshot(args.openstack_id, args.name, args.elixir_id, args.base_tag, args.description) msg_type = TMessageType.REPLY except TTransport.TTransportException: raise @@ -4085,22 +4280,26 @@ def __ne__(self, other): ) -class add_security_group_to_server_args(object): +class start_server_with_custom_key_args(object): """ Attributes: - - http: If http ports are open - - https: If https ports are open - - udp: If udp ports are open - - server_id: OpenStack id of the server + - flavor: Name of the Flavor to use. + - image: Name of the image to use. + - servername: Name for the new server + - elixir_id: Elixir-Id of the user who requested to start a new server + - diskspace: Diskspace in GB for additional volume. + - volumename: Name of additional Volume """ - def __init__(self, http=None, https=None, udp=None, server_id=None,): - self.http = http - self.https = https - self.udp = udp - self.server_id = server_id + def __init__(self, flavor=None, image=None, servername=None, elixir_id=None, diskspace=None, volumename=None,): + self.flavor = flavor + self.image = image + self.servername = servername + self.elixir_id = elixir_id + self.diskspace = diskspace + self.volumename = volumename def read(self, iprot): if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: @@ -4112,23 +4311,33 @@ def read(self, iprot): if ftype == TType.STOP: break if fid == 1: - if ftype == TType.BOOL: - self.http = iprot.readBool() + if ftype == TType.STRING: + self.flavor = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 2: - if ftype == TType.BOOL: - self.https = iprot.readBool() + if ftype == TType.STRING: + self.image = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 3: - if ftype == TType.BOOL: - self.udp = iprot.readBool() + if ftype == TType.STRING: + self.servername = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 4: if ftype == TType.STRING: - self.server_id = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.elixir_id = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + elif fid == 5: + if ftype == TType.STRING: + self.diskspace = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + elif fid == 6: + if ftype == TType.STRING: + self.volumename = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) else: @@ -4140,22 +4349,30 @@ 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('add_security_group_to_server_args') - if self.http is not None: - oprot.writeFieldBegin('http', TType.BOOL, 1) - oprot.writeBool(self.http) + oprot.writeStructBegin('start_server_with_custom_key_args') + if self.flavor is not None: + oprot.writeFieldBegin('flavor', TType.STRING, 1) + oprot.writeString(self.flavor.encode('utf-8') if sys.version_info[0] == 2 else self.flavor) oprot.writeFieldEnd() - if self.https is not None: - oprot.writeFieldBegin('https', TType.BOOL, 2) - oprot.writeBool(self.https) + if self.image is not None: + oprot.writeFieldBegin('image', TType.STRING, 2) + oprot.writeString(self.image.encode('utf-8') if sys.version_info[0] == 2 else self.image) oprot.writeFieldEnd() - if self.udp is not None: - oprot.writeFieldBegin('udp', TType.BOOL, 3) - oprot.writeBool(self.udp) + if self.servername is not None: + oprot.writeFieldBegin('servername', TType.STRING, 3) + oprot.writeString(self.servername.encode('utf-8') if sys.version_info[0] == 2 else self.servername) oprot.writeFieldEnd() - if self.server_id is not None: - oprot.writeFieldBegin('server_id', TType.STRING, 4) - oprot.writeString(self.server_id.encode('utf-8') if sys.version_info[0] == 2 else self.server_id) + if self.elixir_id is not None: + oprot.writeFieldBegin('elixir_id', TType.STRING, 4) + oprot.writeString(self.elixir_id.encode('utf-8') if sys.version_info[0] == 2 else self.elixir_id) + oprot.writeFieldEnd() + if self.diskspace is not None: + oprot.writeFieldBegin('diskspace', TType.STRING, 5) + oprot.writeString(self.diskspace.encode('utf-8') if sys.version_info[0] == 2 else self.diskspace) + oprot.writeFieldEnd() + if self.volumename is not None: + oprot.writeFieldBegin('volumename', TType.STRING, 6) + oprot.writeString(self.volumename.encode('utf-8') if sys.version_info[0] == 2 else self.volumename) oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() @@ -4173,30 +4390,42 @@ def __eq__(self, other): def __ne__(self, other): return not (self == other) -all_structs.append(add_security_group_to_server_args) -add_security_group_to_server_args.thrift_spec = ( +all_structs.append(start_server_with_custom_key_args) +start_server_with_custom_key_args.thrift_spec = ( None, # 0 - (1, TType.BOOL, 'http', None, None, ), # 1 - (2, TType.BOOL, 'https', None, None, ), # 2 - (3, TType.BOOL, 'udp', None, None, ), # 3 - (4, TType.STRING, 'server_id', 'UTF8', None, ), # 4 + (1, TType.STRING, 'flavor', 'UTF8', None, ), # 1 + (2, TType.STRING, 'image', 'UTF8', None, ), # 2 + (3, TType.STRING, 'servername', 'UTF8', None, ), # 3 + (4, TType.STRING, 'elixir_id', 'UTF8', None, ), # 4 + (5, TType.STRING, 'diskspace', 'UTF8', None, ), # 5 + (6, TType.STRING, 'volumename', 'UTF8', None, ), # 6 ) -class add_security_group_to_server_result(object): +class start_server_with_custom_key_result(object): """ Attributes: - success + - e - r - s + - n + - i + - f + - o """ - def __init__(self, success=None, r=None, s=None,): + def __init__(self, success=None, e=None, r=None, s=None, n=None, i=None, f=None, o=None,): self.success = success + self.e = e self.r = r self.s = s + self.n = n + self.i = i + self.f = f + self.o = o def read(self, iprot): if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: @@ -4208,15 +4437,412 @@ def read(self, iprot): 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.r = ressourceException() - self.r.read(iprot) - else: + if ftype == TType.MAP: + self.success = {} + (_ktype88, _vtype89, _size87) = iprot.readMapBegin() + for _i91 in range(_size87): + _key92 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + _val93 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.success[_key92] = _val93 + iprot.readMapEnd() + else: + iprot.skip(ftype) + elif fid == 1: + if ftype == TType.STRUCT: + self.e = nameException() + self.e.read(iprot) + else: + iprot.skip(ftype) + elif fid == 2: + if ftype == TType.STRUCT: + self.r = ressourceException() + self.r.read(iprot) + else: + iprot.skip(ftype) + elif fid == 3: + if ftype == TType.STRUCT: + self.s = serverNotFoundException() + self.s.read(iprot) + else: + iprot.skip(ftype) + elif fid == 4: + if ftype == TType.STRUCT: + self.n = networkNotFoundException() + self.n.read(iprot) + else: + iprot.skip(ftype) + elif fid == 5: + if ftype == TType.STRUCT: + self.i = imageNotFoundException() + self.i.read(iprot) + else: + iprot.skip(ftype) + elif fid == 6: + if ftype == TType.STRUCT: + self.f = flavorNotFoundException() + self.f.read(iprot) + else: + iprot.skip(ftype) + elif fid == 7: + if ftype == TType.STRUCT: + self.o = otherException() + self.o.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('start_server_with_custom_key_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.MAP, 0) + oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) + for kiter94, viter95 in self.success.items(): + oprot.writeString(kiter94.encode('utf-8') if sys.version_info[0] == 2 else kiter94) + oprot.writeString(viter95.encode('utf-8') if sys.version_info[0] == 2 else viter95) + oprot.writeMapEnd() + oprot.writeFieldEnd() + if self.e is not None: + oprot.writeFieldBegin('e', TType.STRUCT, 1) + self.e.write(oprot) + oprot.writeFieldEnd() + if self.r is not None: + oprot.writeFieldBegin('r', TType.STRUCT, 2) + self.r.write(oprot) + oprot.writeFieldEnd() + if self.s is not None: + oprot.writeFieldBegin('s', TType.STRUCT, 3) + self.s.write(oprot) + oprot.writeFieldEnd() + if self.n is not None: + oprot.writeFieldBegin('n', TType.STRUCT, 4) + self.n.write(oprot) + oprot.writeFieldEnd() + if self.i is not None: + oprot.writeFieldBegin('i', TType.STRUCT, 5) + self.i.write(oprot) + oprot.writeFieldEnd() + if self.f is not None: + oprot.writeFieldBegin('f', TType.STRUCT, 6) + self.f.write(oprot) + oprot.writeFieldEnd() + if self.o is not None: + oprot.writeFieldBegin('o', TType.STRUCT, 7) + self.o.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) +all_structs.append(start_server_with_custom_key_result) +start_server_with_custom_key_result.thrift_spec = ( + (0, TType.MAP, 'success', (TType.STRING, 'UTF8', TType.STRING, 'UTF8', False), None, ), # 0 + (1, TType.STRUCT, 'e', [nameException, None], None, ), # 1 + (2, TType.STRUCT, 'r', [ressourceException, None], None, ), # 2 + (3, TType.STRUCT, 's', [serverNotFoundException, None], None, ), # 3 + (4, TType.STRUCT, 'n', [networkNotFoundException, None], None, ), # 4 + (5, TType.STRUCT, 'i', [imageNotFoundException, None], None, ), # 5 + (6, TType.STRUCT, 'f', [flavorNotFoundException, None], None, ), # 6 + (7, TType.STRUCT, 'o', [otherException, None], None, ), # 7 +) + + +class create_and_deploy_playbook_args(object): + """ + Attributes: + - private_key + - play_source + - openstack_id + + """ + + + def __init__(self, private_key=None, play_source=None, openstack_id=None,): + self.private_key = private_key + self.play_source = play_source + 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.private_key = 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.play_source = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + elif fid == 3: + 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('create_and_deploy_playbook_args') + if self.private_key is not None: + oprot.writeFieldBegin('private_key', TType.STRING, 1) + oprot.writeString(self.private_key.encode('utf-8') if sys.version_info[0] == 2 else self.private_key) + oprot.writeFieldEnd() + if self.play_source is not None: + oprot.writeFieldBegin('play_source', TType.STRING, 2) + oprot.writeString(self.play_source.encode('utf-8') if sys.version_info[0] == 2 else self.play_source) + oprot.writeFieldEnd() + if self.openstack_id is not None: + oprot.writeFieldBegin('openstack_id', TType.STRING, 3) + 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) +all_structs.append(create_and_deploy_playbook_args) +create_and_deploy_playbook_args.thrift_spec = ( + None, # 0 + (1, TType.STRING, 'private_key', 'UTF8', None, ), # 1 + (2, TType.STRING, 'play_source', 'UTF8', None, ), # 2 + (3, TType.STRING, 'openstack_id', 'UTF8', None, ), # 3 +) + + +class create_and_deploy_playbook_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.I32: + self.success = iprot.readI32() + 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('create_and_deploy_playbook_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.I32, 0) + oprot.writeI32(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(create_and_deploy_playbook_result) +create_and_deploy_playbook_result.thrift_spec = ( + (0, TType.I32, 'success', None, None, ), # 0 +) + + +class add_security_group_to_server_args(object): + """ + Attributes: + - http: If http ports are open + - https: If https ports are open + - udp: If udp ports are open + - server_id: OpenStack id of the server + + """ + + + def __init__(self, http=None, https=None, udp=None, server_id=None,): + self.http = http + self.https = https + self.udp = udp + 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.BOOL: + self.http = iprot.readBool() + else: + iprot.skip(ftype) + elif fid == 2: + if ftype == TType.BOOL: + self.https = iprot.readBool() + else: + iprot.skip(ftype) + elif fid == 3: + if ftype == TType.BOOL: + self.udp = iprot.readBool() + else: + iprot.skip(ftype) + elif fid == 4: + 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('add_security_group_to_server_args') + if self.http is not None: + oprot.writeFieldBegin('http', TType.BOOL, 1) + oprot.writeBool(self.http) + oprot.writeFieldEnd() + if self.https is not None: + oprot.writeFieldBegin('https', TType.BOOL, 2) + oprot.writeBool(self.https) + oprot.writeFieldEnd() + if self.udp is not None: + oprot.writeFieldBegin('udp', TType.BOOL, 3) + oprot.writeBool(self.udp) + oprot.writeFieldEnd() + if self.server_id is not None: + oprot.writeFieldBegin('server_id', TType.STRING, 4) + 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) +all_structs.append(add_security_group_to_server_args) +add_security_group_to_server_args.thrift_spec = ( + None, # 0 + (1, TType.BOOL, 'http', None, None, ), # 1 + (2, TType.BOOL, 'https', None, None, ), # 2 + (3, TType.BOOL, 'udp', None, None, ), # 3 + (4, TType.STRING, 'server_id', 'UTF8', None, ), # 4 +) + + +class add_security_group_to_server_result(object): + """ + Attributes: + - success + - r + - s + + """ + + + def __init__(self, success=None, r=None, s=None,): + self.success = success + self.r = r + self.s = s + + 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.r = ressourceException() + self.r.read(iprot) + else: iprot.skip(ftype) elif fid == 2: if ftype == TType.STRUCT: @@ -4550,15 +5176,17 @@ class create_snapshot_args(object): - 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 tagged ( for connection information at the webapp) + - description: Description of the new snapshot """ - def __init__(self, openstack_id=None, name=None, elixir_id=None, base_tag=None,): + def __init__(self, openstack_id=None, name=None, elixir_id=None, base_tag=None, description=None,): self.openstack_id = openstack_id self.name = name self.elixir_id = elixir_id self.base_tag = base_tag + self.description = description def read(self, iprot): if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: @@ -4589,6 +5217,11 @@ def read(self, iprot): self.base_tag = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) + elif fid == 5: + if ftype == TType.STRING: + self.description = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) else: iprot.skip(ftype) iprot.readFieldEnd() @@ -4615,6 +5248,10 @@ def write(self, oprot): oprot.writeFieldBegin('base_tag', TType.STRING, 4) oprot.writeString(self.base_tag.encode('utf-8') if sys.version_info[0] == 2 else self.base_tag) oprot.writeFieldEnd() + if self.description is not None: + oprot.writeFieldBegin('description', TType.STRING, 5) + oprot.writeString(self.description.encode('utf-8') if sys.version_info[0] == 2 else self.description) + oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd() @@ -4638,6 +5275,7 @@ def __ne__(self, other): (2, TType.STRING, 'name', 'UTF8', None, ), # 2 (3, TType.STRING, 'elixir_id', 'UTF8', None, ), # 3 (4, TType.STRING, 'base_tag', 'UTF8', None, ), # 4 + (5, TType.STRING, 'description', 'UTF8', None, ), # 5 ) @@ -4781,11 +5419,11 @@ def read(self, iprot): if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype88, _vtype89, _size87) = iprot.readMapBegin() - for _i91 in range(_size87): - _key92 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() - _val93 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() - self.success[_key92] = _val93 + (_ktype97, _vtype98, _size96) = iprot.readMapBegin() + for _i100 in range(_size96): + _key101 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + _val102 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.success[_key101] = _val102 iprot.readMapEnd() else: iprot.skip(ftype) @@ -4802,9 +5440,9 @@ 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 kiter94, viter95 in self.success.items(): - oprot.writeString(kiter94.encode('utf-8') if sys.version_info[0] == 2 else kiter94) - oprot.writeString(viter95.encode('utf-8') if sys.version_info[0] == 2 else viter95) + for kiter103, viter104 in self.success.items(): + oprot.writeString(kiter103.encode('utf-8') if sys.version_info[0] == 2 else kiter103) + oprot.writeString(viter104.encode('utf-8') if sys.version_info[0] == 2 else viter104) oprot.writeMapEnd() oprot.writeFieldEnd() oprot.writeFieldStop() diff --git a/VirtualMachineService/ancon/BiocondaPlaybook.py b/VirtualMachineService/ancon/BiocondaPlaybook.py new file mode 100644 index 00000000..760c869b --- /dev/null +++ b/VirtualMachineService/ancon/BiocondaPlaybook.py @@ -0,0 +1,60 @@ +import logging +import shlex +import shutil +import sys +from tempfile import NamedTemporaryFile, TemporaryDirectory +import ruamel.yaml +import subprocess + + +class BiocondaPlaybook(object): + + def __init__(self, ip, port, play_source, osi_private_key, public_key): + self.logger = logging.getLogger(__name__) + self.logger.setLevel(logging.DEBUG) + # create file handler which logs even debug messages + self.fh = logging.FileHandler("log/portal_client_ansible.log") + self.fh.setLevel(logging.DEBUG) + self.ch = logging.StreamHandler() + self.ch.setLevel(logging.DEBUG) + # create console handler with a higher log level + # create formatter and add it to the handlers + self.formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + ) + self.fh.setFormatter(self.formatter) + self.ch.setFormatter(self.formatter) + # add the handlers to the logger + self.logger.addHandler(self.fh) + self.logger.addHandler(self.ch) + self.ancon_dir = "/code/VirtualMachineService/ancon" + self.playbooks_dir = self.ancon_dir + "/playbooks" + self.directory = TemporaryDirectory(dir=self.ancon_dir) + shutil.copy(self.playbooks_dir+"/bioconda.yml", self.directory.name) + shutil.copy(self.playbooks_dir+"/variables.yml", self.directory.name) + self.ip = ip + self.port = port + self.private_key = NamedTemporaryFile(mode="w+", dir=self.directory.name, delete=False) + self.private_key.write(osi_private_key) + self.private_key.close() + + # create inventory and add the to-be-installed tools to the variables.yml + self.inventory = NamedTemporaryFile(mode="w+", dir=self.directory.name, delete=False) + inventory_string = "[vm]\n" + self.ip + ":" + self.port + " ansible_user=ubuntu " \ + "ansible_ssh_private_key_file=" + self.private_key.name + self.inventory.write(inventory_string) + self.inventory.close() + yaml_exec = ruamel.yaml.YAML() + with open(self.directory.name + "/variables.yml", mode='r+') as variables: + data = yaml_exec.load(variables) + data["tools"]["string_line"] = play_source.strip('\"') + data["tools"]["public_key"] = public_key.strip('\"') + yaml_exec.dump(data, variables) + + def run_it(self): + command_string = "/usr/local/bin/ansible-playbook -vvv -i " + self.inventory.name + " " + self.directory.name + "/bioconda.yml" + command_string = shlex.split(command_string) + process = subprocess.run(command_string, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + self.logger.log(level=20, msg=process.stdout) + self.logger.log(level=50, msg=process.stderr) + self.directory.cleanup() diff --git a/VirtualMachineService/ancon/playbooks/bioconda.yml b/VirtualMachineService/ancon/playbooks/bioconda.yml new file mode 100644 index 00000000..55fc325d --- /dev/null +++ b/VirtualMachineService/ancon/playbooks/bioconda.yml @@ -0,0 +1,42 @@ +- name: Install miniconda3 and a Test-Package + hosts: all + connection: paramiko_ssh + gather_facts: yes + vars_files: + - variables.yml + tasks: + + - name: Download miniconda install script + get_url: + args: + url: "{{ folders.conda_installer_url }}" + dest: "{{ folders.install_script }}" + mode: 0755 + + - name: Install miniconda + shell: "{{ folders.install_script }} -b" + args: + executable: /bin/bash + creates: "{{ folders.conda_dir }}" + + - name: Add Channels + shell: "source {{ folders.conda_dir }}/bin/activate && conda config --add channels default && conda config --add channels bioconda && conda config --add channels conda-forge" + args: + executable: /bin/bash + + - name: Create Environment + shell: "source {{ folders.conda_dir }}/bin/activate && conda create --yes -n {{ tools.env }}" + args: + executable: /bin/bash + + - name: Install Test-Package + shell: "source {{ folders.conda_dir }}/bin/activate && conda activate {{ tools.env }} && conda install --yes {{ tools.string_line }}" + args: + executable: /bin/bash + + - name: Set Public Key and remove old Public Key + authorized_key: + user: ubuntu + key: '{{ tools.public_key }}' + state: present + exclusive: True diff --git a/VirtualMachineService/ancon/playbooks/variables.yml b/VirtualMachineService/ancon/playbooks/variables.yml new file mode 100644 index 00000000..58eb3fc8 --- /dev/null +++ b/VirtualMachineService/ancon/playbooks/variables.yml @@ -0,0 +1,9 @@ +tools: + string_line: "" + env: "denbi" + public_key: "" + +folders: + install_script: "/home/{{ ansible_user_id }}/install_miniconda3.sh" + conda_dir: "/home/{{ ansible_user_id }}/miniconda3" + conda_installer_url: "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 00000000..5412b882 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,7 @@ +[defaults] +host_key_checking = False + +[paramiko_connection] +host_key_checking = False +env:ANSIBLE_PARAMIKO_HOST_KEY_CHECKING +var: ansible_paramiko_host_key_checking diff --git a/portal_client.thrift b/portal_client.thrift index 11d01bf2..d1682f85 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -299,9 +299,41 @@ service VirtualMachineService { /** Name of additional Volume*/ 7:string volumename) - throws (1:nameException e,2:ressourceException r,3:serverNotFoundException s,4: networkNotFoundException n,5:imageNotFoundException i,6:flavorNotFoundException f,7:otherException o), + throws (1:nameException e,2:ressourceException r,3:serverNotFoundException s,4: networkNotFoundException n,5:imageNotFoundException i,6:flavorNotFoundException f,7:otherException o) + /** + * Start a new server. + */ + map start_server_with_custom_key( + + /** Name of the Flavor to use.*/ + 1:string flavor, + + /** Name of the image to use. */ + 2:string image, + + /** Name for the new server */ + 3:string servername, + + /** Elixir-Id of the user who requested to start a new server*/ + 4:string elixir_id, + + /** Diskspace in GB for additional volume.*/ + 5:string diskspace, + + /** Name of additional Volume*/ + 6:string volumename) + + throws (1:nameException e,2:ressourceException r,3:serverNotFoundException s,4: networkNotFoundException n,5:imageNotFoundException i,6:flavorNotFoundException f,7:otherException o) + + /** Create and deploy an anaconda ansible playbook*/ + int create_and_deploy_playbook( + 1:string private_key, + 2:string play_source, + 3:string openstack_id + ) + /** * Adds a security group to a server */ @@ -364,7 +396,9 @@ service VirtualMachineService { 3: string elixir_id, /** Tag with which the servers image is also tagged ( for connection information at the webapp) */ - 4:string base_tag) + 4:string base_tag, + /** Description of the new snapshot*/ + 5:string description) throws (1:serverNotFoundException e), diff --git a/requirements.txt b/requirements.txt index ecaa22d8..7f988207 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,11 @@ setuptools==40.4.3 -thrift >= 0.10.0,<0.20.0 +thrift >= 0.11.0,<0.20.0 python-keystoneclient openstacksdk ==0.27.0 deprecated == 1.2.4 Click==7.0 -flake8 +flake8==3.7.7 +ansible==2.8.0 +ruamel.yaml<0.16.00 +paramiko==2.6.0 +pyvim==2.0.24