From 7fdc0ea55e50253756a980a77668ce7b5a9d853b Mon Sep 17 00:00:00 2001 From: konsthol Date: Wed, 15 Mar 2023 23:17:26 +0200 Subject: [PATCH] I cannot believe that it took this long to write a test for this. --- secdep.py | 72 +++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/secdep.py b/secdep.py index e944f0a..cbfd73f 100755 --- a/secdep.py +++ b/secdep.py @@ -963,17 +963,17 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi if provider == "gce": node = driver.create_node(name=name, image=image, size=size, location=location, ex_service_accounts=sa_scopes, ex_metadata=metadata) elif provider == "azure": - # sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP) - # for sec_group in sec_groups: - # if sec_group.name == name+"-sec_group": - # print("A security group with that name already exists, please try a different virtual machine name to differentiate the security group name") - # exit(0) + sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP) + for sec_group in sec_groups: + if sec_group.name == name+"-sec_group": + print("A security group with that name already exists, please try a different virtual machine name to differentiate the security group name") + exit(0) # ips = driver.ex_list_public_ips(SECDEP_AZURE_RESOURCE_GROUP) # for ip in ips: # if ip.name == name+"-ip": # print("An ip with that name already exists, please try a different virtual machine name to differentiate the ip name") # exit(0) - # driver.ex_create_network_security_group(name=name+"-sec_group", resource_group=SECDEP_AZURE_RESOURCE_GROUP, location=location) + driver.ex_create_network_security_group(name=name+"-sec_group", resource_group=SECDEP_AZURE_RESOURCE_GROUP, location=location) networks = driver.ex_list_networks() for network in networks: if network.name == SECDEP_AZURE_VIRTUAL_NETWORK: @@ -988,7 +988,7 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi exit(0) subnet = driver.ex_list_subnets(network=ex_network)[0] # public_ip = driver.ex_create_public_ip(name=name+"-ip", resource_group=SECDEP_AZURE_RESOURCE_GROUP, location=location, public_ip_allocation_method="Static") - print(public_ip = driver.ex_list_public_ips(SECDEP_AZURE_RESOURCE_GROUP)) + public_ip = driver.ex_list_public_ips(SECDEP_AZURE_RESOURCE_GROUP)[0] network_interface = driver.ex_create_network_interface(name=name+"-nic", subnet=subnet, resource_group=SECDEP_AZURE_RESOURCE_GROUP, location=location, public_ip=public_ip) node = driver.create_node(name=name, size=size, image=image, location=location, auth=auth, ex_user_name="secdep", ex_resource_group=SECDEP_AZURE_RESOURCE_GROUP, ex_use_managed_disks=True, ex_nic=network_interface, ex_os_disk_delete=True) else: @@ -1024,11 +1024,11 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi if provider == "gce": node = driver.create_node(name=name, image=image, size=size, location=location, ex_service_accounts=sa_scopes, ex_metadata=metadata) elif provider == "azure": - # sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP) - # for sec_group in sec_groups: - # if sec_group.name == name+"-sec_group": - # print("A security group with that name already exists, please try a different virtual machine name to differentiate the security group name") - # exit(0) + sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP) + for sec_group in sec_groups: + if sec_group.name == name+"-sec_group": + print("A security group with that name already exists, please try a different virtual machine name to differentiate the security group name") + exit(0) # ips = driver.ex_list_public_ips(SECDEP_AZURE_RESOURCE_GROUP) # for ip in ips: # if ip.name == name+"-ip": @@ -1149,18 +1149,18 @@ def delete_node(): print("%s node deleted successfully" % (providerName.upper())) else: print("%s node could not be deleted" % (providerName.upper())) - # if providerName == "azure": - # driver = get_corresponding_driver("azure") - # node_location = node.extra['location'] - # locations = driver.list_locations() - # for loc in locations: - # if loc.id == node_location: - # location = loc - # break - # sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP) - # for sec_group in sec_groups: - # if sec_group.name == node.name+"-sec_group": - # driver.ex_delete_network_security_group(name=sec_group.name, resource_group=SECDEP_AZURE_RESOURCE_GROUP, location=location) + if providerName == "azure": + driver = get_corresponding_driver("azure") + node_location = node.extra['location'] + locations = driver.list_locations() + for loc in locations: + if loc.id == node_location: + location = loc + break + sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP) + for sec_group in sec_groups: + if sec_group.name == node.name+"-sec_group": + driver.ex_delete_network_security_group(name=sec_group.name, resource_group=SECDEP_AZURE_RESOURCE_GROUP, location=location) # ips = driver.ex_list_public_ips(SECDEP_AZURE_RESOURCE_GROUP) # for ip in ips: # if ip.name == node.name+"-ip": @@ -1184,18 +1184,18 @@ def delete_all_nodes(): print("%s node deleted successfully" % (node.name)) else: print("%s node could not be deleted" % (node.name)) - # if providerName == "azure": - # driver = get_corresponding_driver("azure") - # node_location = node.extra['location'] - # locations = driver.list_locations() - # for loc in locations: - # if loc.id == node_location: - # location = loc - # break - # sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP) - # for sec_group in sec_groups: - # if sec_group.name == node.name+"-sec_group": - # driver.ex_delete_network_security_group(name=sec_group.name, resource_group=SECDEP_AZURE_RESOURCE_GROUP, location=location) + if providerName == "azure": + driver = get_corresponding_driver("azure") + node_location = node.extra['location'] + locations = driver.list_locations() + for loc in locations: + if loc.id == node_location: + location = loc + break + sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP) + for sec_group in sec_groups: + if sec_group.name == node.name+"-sec_group": + driver.ex_delete_network_security_group(name=sec_group.name, resource_group=SECDEP_AZURE_RESOURCE_GROUP, location=location) # ips = driver.ex_list_public_ips(SECDEP_AZURE_RESOURCE_GROUP) # for ip in ips: # if ip.name == node.name+"-ip":