From 326307b5b754d33680d4b30360706a0853bcbea3 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Wed, 3 Nov 2021 17:34:35 +0000 Subject: [PATCH 1/3] fix(Linting):blacked code --- .../VirtualMachineHandler.py | 198 +++++++++--------- VirtualMachineService/VirtualMachineServer.py | 4 +- 2 files changed, 102 insertions(+), 100 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index b5047538..eeeee244 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -225,9 +225,9 @@ def __init__(self, config): self.FORC_REMOTE_ID = cfg["forc"]["forc_remote_id"] self.GITHUB_PLAYBOOKS_REPO = cfg["forc"]["github_playbooks_repo"] if ( - not self.RE_BACKEND_URL - or not self.FORC_API_KEY - or not self.GITHUB_PLAYBOOKS_REPO + not self.RE_BACKEND_URL + or not self.FORC_API_KEY + or not self.GITHUB_PLAYBOOKS_REPO ): raise ValueError LOG.info(msg="Forc-Backend url loaded: {0}".format(self.RE_BACKEND_URL)) @@ -370,10 +370,10 @@ def get_Images(self): images = list() try: for img in filter( - lambda x: "tags" in x - and len(x["tags"]) > 0 - and x["status"] == "active", - self.conn.list_images(), + lambda x: "tags" in x + and len(x["tags"]) > 0 + and x["status"] == "active", + self.conn.list_images(), ): metadata = img["metadata"] @@ -381,7 +381,7 @@ def get_Images(self): tags = img.get("tags") LOG.info(set(self.ALL_TEMPLATES).intersection(tags)) if len( - set(self.ALL_TEMPLATES).intersection(tags) + set(self.ALL_TEMPLATES).intersection(tags) ) > 0 and not self.cross_check_forc_image(tags): LOG.info("Resenv check: Skipping {0}.".format(img["name"])) continue @@ -417,7 +417,7 @@ def prepare_image(self, img): tags = img.get("tags") LOG.info(set(self.ALL_TEMPLATES).intersection(tags)) if len( - set(self.ALL_TEMPLATES).intersection(tags) + set(self.ALL_TEMPLATES).intersection(tags) ) > 0 and not self.cross_check_forc_image(tags): LOG.info("Resenv check: Skipping {0}.".format(img["name"])) return None @@ -453,11 +453,11 @@ def get_public_Images(self): images = list() try: for img in filter( - lambda x: "tags" in x - and len(x["tags"]) > 0 - and x["status"] == "active" - and x["visibility"] == "public", - self.conn.list_images(), + lambda x: "tags" in x + and len(x["tags"]) > 0 + and x["status"] == "active" + and x["visibility"] == "public", + self.conn.list_images(), ): image = self.prepare_image(img) if image is None: @@ -479,11 +479,11 @@ def get_private_Images(self): images = list() try: for img in filter( - lambda x: "tags" in x - and len(x["tags"]) > 0 - and x["status"] == "active" - and x["visibility"] == "private", - self.conn.list_images(), + lambda x: "tags" in x + and len(x["tags"]) > 0 + and x["status"] == "active" + and x["visibility"] == "private", + self.conn.list_images(), ): image = self.prepare_image(img) if image is None: @@ -536,10 +536,10 @@ def get_Images_by_filter(self, filter_list): images = list() try: for img in filter( - lambda x: "tags" in x - and len(x["tags"]) > 0 - and x["status"] == "active", - self.conn.list_images(), + lambda x: "tags" in x + and len(x["tags"]) > 0 + and x["status"] == "active", + self.conn.list_images(), ): tags = img.get("tags") if "resenv" in filter_list: @@ -791,7 +791,7 @@ def create_add_keys_script(self, keys): return key_script def create_mount_init_script( - self, volume_ids_path_new=None, volume_ids_path_attach=None + self, volume_ids_path_new=None, volume_ids_path_attach=None ): LOG.info("create init script for volume ids:{}".format(volume_ids_path_new)) if not volume_ids_path_new and not volume_ids_path_attach: @@ -940,17 +940,17 @@ def create_volume(self, volume_name, volume_storage, metadata): raise ressourceException(Reason=str(e)) def volume_ids( - self, - flavor, - image, - public_key, - servername, - metadata, - https, - http, - resenv, - volume_ids_path_new, - volume_ids_path_attach, + self, + flavor, + image, + public_key, + servername, + metadata, + https, + http, + resenv, + volume_ids_path_new, + volume_ids_path_attach, ): image = self.get_image(image=image) flavor = self.get_flavor(flavor=flavor) @@ -1023,18 +1023,18 @@ def prepare_security_groups_new_server(self, resenv, servername, http, https): return custom_security_groups def start_server_without_playbook( - self, - flavor, - image, - public_key, - servername, - metadata, - https, - http, - resenv, - volume_ids_path_new=None, - volume_ids_path_attach=None, - additional_keys=None, + self, + flavor, + image, + public_key, + servername, + metadata, + https, + http, + resenv, + volume_ids_path_new=None, + volume_ids_path_attach=None, + additional_keys=None, ): """ Start a new Server. @@ -1083,9 +1083,9 @@ def start_server_without_playbook( if init_script: add_key_script = self.create_add_keys_script(keys=additional_keys) init_script = ( - add_key_script - + encodeutils.safe_encode("\n".encode("utf-8")) - + init_script + add_key_script + + encodeutils.safe_encode("\n".encode("utf-8")) + + init_script ) else: @@ -1118,17 +1118,17 @@ def start_server_without_playbook( return {} def start_server( - self, - flavor, - image, - public_key, - servername, - metadata, - diskspace, - volumename, - https, - http, - resenv, + self, + flavor, + image, + public_key, + servername, + metadata, + diskspace, + volumename, + https, + http, + resenv, ): """ Start a new Server. @@ -1182,16 +1182,16 @@ def start_server( return {} def start_server_with_custom_key( - self, - flavor, - image, - servername, - metadata, - http, - https, - resenv, - volume_ids_path_new=None, - volume_ids_path_attach=None, + self, + flavor, + image, + servername, + metadata, + http, + https, + resenv, + volume_ids_path_new=None, + volume_ids_path_attach=None, ): """ @@ -1267,7 +1267,7 @@ def start_server_with_custom_key( return {} def create_and_deploy_playbook( - self, public_key, playbooks_information, openstack_id + self, public_key, playbooks_information, openstack_id ): global active_playbooks LOG.info(msg="Starting Playbook for (openstack_id): {0}".format(openstack_id)) @@ -1316,8 +1316,8 @@ def cross_check_forc_image(self, tags): cross_tags = list(set(self.ALL_TEMPLATES).intersection(tags)) for template_dict in templates: if ( - template_dict["name"] in self.FORC_ALLOWED - and template_dict["name"] in cross_tags + template_dict["name"] in self.FORC_ALLOWED + and template_dict["name"] in cross_tags ): if template_dict["version"] in self.FORC_ALLOWED[template_dict["name"]]: return True @@ -1950,8 +1950,8 @@ def add_udp_security_group(self, server_id): ip_base = ( list(self.conn.compute.server_ips(server=server_id))[0] - .to_dict()["address"] - .split(".")[-1] + .to_dict()["address"] + .split(".")[-1] ) x = int(ip_base) udp_port_start = eval(self.UDP_PORT_CALCULATION) @@ -2074,7 +2074,7 @@ def get_clusters_info(self): return infos def scale_up_cluster( - self, cluster_id, image, flavor, count, names, start_idx, batch_index + self, cluster_id, image, flavor, count, names, start_idx, batch_index ): cluster_info = self.get_cluster_info(cluster_id=cluster_id) image = self.get_image(image=image) @@ -2350,9 +2350,9 @@ def delete_server(self, openstack_id): return False task_state = self.check_server_task_state(openstack_id) if ( - task_state == "image_snapshot" - or task_state == "image_pending_upload" - or task_state == "image_uploading" + task_state == "image_snapshot" + or task_state == "image_pending_upload" + or task_state == "image_uploading" ): raise ConflictException("task_state in image creating") security_groups = self.conn.list_server_security_groups(server=server) @@ -2361,7 +2361,7 @@ def delete_server(self, openstack_id): sec for sec in security_groups if sec.name != self.DEFAULT_SECURITY_GROUP_NAME - and not "bibigrid" in sec.name + and not "bibigrid" in sec.name ] if security_groups is not None: for sg in security_groups: @@ -2514,15 +2514,15 @@ def resume_server(self, openstack_id): return False def create_security_group( - self, - name, - udp_port_start=None, - ssh=True, - http=False, - https=False, - udp=False, - description=None, - resenv=[], + self, + name, + udp_port_start=None, + ssh=True, + http=False, + https=False, + udp=False, + description=None, + resenv=[], ): LOG.info("Create new security group {}".format(name)) sec = self.conn.get_security_group(name_or_id=name) @@ -2756,15 +2756,15 @@ def update_forc_allowed(self, template_metadata): class ResenvMetadata: def __init__( - self, - name, - port, - security_group_name, - security_group_description, - security_group_ssh, - direction, - protocol, - information_for_display, + self, + name, + port, + security_group_name, + security_group_description, + security_group_ssh, + direction, + protocol, + information_for_display, ): self.name = name self.port = port diff --git a/VirtualMachineService/VirtualMachineServer.py b/VirtualMachineService/VirtualMachineServer.py index f03f4cff..fe8c4369 100644 --- a/VirtualMachineService/VirtualMachineServer.py +++ b/VirtualMachineService/VirtualMachineServer.py @@ -72,7 +72,9 @@ def catch_shutdown(signal, frame): processor = Processor(handler) if USE_SSL: click.echo("Use SSL") - transport = TSSLSocket.TSSLServerSocket(host=HOST, port=PORT, certfile=CERTFILE,ssl_version=ssl.PROTOCOL_TLS_SERVER) + transport = TSSLSocket.TSSLServerSocket( + host=HOST, port=PORT, certfile=CERTFILE, ssl_version=ssl.PROTOCOL_TLS_SERVER + ) else: click.echo("Does not use SSL") transport = TSocket.TServerSocket(host=HOST, port=PORT) From 70d060f820cae1bddc246182903e8cba2f4055e5 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Wed, 3 Nov 2021 17:39:26 +0000 Subject: [PATCH 2/3] fix(Linting):blacked code --- VirtualMachineService/VirtualMachineServer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/VirtualMachineService/VirtualMachineServer.py b/VirtualMachineService/VirtualMachineServer.py index f03f4cff..fe8c4369 100644 --- a/VirtualMachineService/VirtualMachineServer.py +++ b/VirtualMachineService/VirtualMachineServer.py @@ -72,7 +72,9 @@ def catch_shutdown(signal, frame): processor = Processor(handler) if USE_SSL: click.echo("Use SSL") - transport = TSSLSocket.TSSLServerSocket(host=HOST, port=PORT, certfile=CERTFILE,ssl_version=ssl.PROTOCOL_TLS_SERVER) + transport = TSSLSocket.TSSLServerSocket( + host=HOST, port=PORT, certfile=CERTFILE, ssl_version=ssl.PROTOCOL_TLS_SERVER + ) else: click.echo("Does not use SSL") transport = TSocket.TServerSocket(host=HOST, port=PORT) From 965552ad318a0f80ce1e7969408e195bc7d4da5a Mon Sep 17 00:00:00 2001 From: dweinholz Date: Wed, 10 Nov 2021 15:43:19 +0100 Subject: [PATCH 3/3] fix(image) --- VirtualMachineService/VirtualMachineHandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index eeeee244..2a78dfc1 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -506,7 +506,7 @@ def get_Image_with_Tag(self, id): try: img = self.conn.get_image(name_or_id=id) if not img: - return None + return Image() metadata = img["metadata"] description = metadata.get("description") tags = img.get("tags")