From 630db2b261e7710e44f24d769ba948fdd03a9205 Mon Sep 17 00:00:00 2001 From: Wayne Gemmell Date: Fri, 17 Feb 2023 11:42:01 +0200 Subject: [PATCH] Clean up and linting issues --- salt/cloud/clouds/digitalocean.py | 94 ++++++++++++++----------------- 1 file changed, 41 insertions(+), 53 deletions(-) diff --git a/salt/cloud/clouds/digitalocean.py b/salt/cloud/clouds/digitalocean.py index c14a328fc42..7ecfffc09a0 100644 --- a/salt/cloud/clouds/digitalocean.py +++ b/salt/cloud/clouds/digitalocean.py @@ -180,16 +180,6 @@ def list_nodes(call=None): ) return _list_nodes() -def list_vpcs(call=None): - """ - Return a list of the VMs that are on the provider - """ - if call == "action": - raise SaltCloudSystemExit( - "The list_nodes function must be called with -f or --function." - ) - return _list_vpcs() - def list_nodes_full(call=None, for_output=True): """ Return a list of the VMs that are on the provider @@ -373,35 +363,33 @@ def create(vm_): ) if vpc_name is not None: - vpc = _get_vpc_by_name(vpc_name) - if vpc is None: - raise SaltCloudConfigError( - "Invalid VPC name provided" - ) - else: - kwargs["vpc_uuid"] = vpc[vpc_name]['id'] + vpc = _get_vpc_by_name(vpc_name) + if vpc is None: + raise SaltCloudConfigError( + "Invalid VPC name provided" + ) + else: + kwargs["vpc_uuid"] = vpc[vpc_name]['id'] else: - private_networking = config.get_cloud_config_value( - "private_networking", - vm_, - __opts__, - search_global=False, - default=None, - ) - - if private_networking is not None: - if not isinstance(private_networking, bool): - raise SaltCloudConfigError( - "'private_networking' should be a boolean value." - ) - kwargs["private_networking"] = private_networking - - if not private_networking and ssh_interface == "private": - raise SaltCloudConfigError( - "The DigitalOcean driver requires ssh_interface if defined as 'private' " - "then private_networking should be set as 'True'." - ) - + private_networking = config.get_cloud_config_value( + "private_networking", + vm_, + __opts__, + search_global=False, + default=None, + ) + if private_networking is not None: + if not isinstance(private_networking, bool): + raise SaltCloudConfigError( + "'private_networking' should be a boolean value." + ) + kwargs["private_networking"] = private_networking + + if not private_networking and ssh_interface == "private": + raise SaltCloudConfigError( + "The DigitalOcean driver requires ssh_interface if defined as 'private' " + "then private_networking should be set as 'True'." + ) backups_enabled = config.get_cloud_config_value( "backups_enabled", vm_, @@ -636,11 +624,11 @@ def query( default="https://api.digitalocean.com/v2", ) ) - # vpcs method doesn't like the / at the end. + # vpcs method doesn't like the / at the end. if method == 'vpcs': - path = "{}/{}".format(base_path, method) + path = "{}/{}".format(base_path, method) else: - path = "{}/{}/".format(base_path, method) + path = "{}/{}/".format(base_path, method) if droplet_id: path += "{}/".format(droplet_id) @@ -1293,18 +1281,18 @@ def _get_vpc_by_name(name): items = query(method="vpcs", command="?page=" + str(page) + "&per_page=200") for node in items["vpcs"]: log.debug("Node returned : %s", node["name"]) - if(name == node["name"]): - log.debug("Matched VPC node") - ret[name] = { - "id": node["id"], - "urn": node["urn"], - "name": name, - "description": node["description"], - "region": node["region"], - "ip_range": node["ip_range"], - "default": node["default"], - } - return ret + if name == node["name"]: + log.debug("Matched VPC node") + ret[name] = { + "id": node["id"], + "urn": node["urn"], + "name": name, + "description": node["description"], + "region": node["region"], + "ip_range": node["ip_range"], + "default": node["default"], + } + return ret page += 1 try: fetch = "next" in items["links"]["pages"]