Skip to content

Commit

Permalink
Merge branch 'master' into indigo3
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Dec 11, 2017
2 parents c574780 + 3d09401 commit 0cb9831
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 39 deletions.
2 changes: 1 addition & 1 deletion IM/CloudInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_cloud_list(auth_data):
res = []

for i, auth in enumerate(auth_data.auth_list):
if auth['type'] not in ['InfrastructureManager', 'VMRC']:
if 'type' in auth and auth['type'] not in ['InfrastructureManager', 'VMRC']:
cloud_item = CloudInfo()
cloud_item.type = auth['type']
if 'id' in auth.keys() and auth['id']:
Expand Down
49 changes: 29 additions & 20 deletions IM/connectors/Azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_instance_type(self, system, credentials, subscription_id):
disk_free_op = ">="
if system.getValue('disks.free_size'):
disk_free = system.getFeature('disks.free_size').getValue('M')
disk_free_op = system.getFeature('memory.size').getLogOperator()
disk_free_op = system.getFeature('disks.free_size').getLogOperator()

compute_client = ComputeManagementClient(credentials, subscription_id)
instace_types = list(compute_client.virtual_machine_sizes.list(location))
Expand Down Expand Up @@ -555,11 +555,7 @@ def create_vms(self, inf, radl, requested_radl, num_vm, location, storage_accoun

# Delete Resource group and everything in it
if group_name:
self.log_info("Delete Resource group %s and everything in it." % group_name)
try:
resource_client.resource_groups.delete(group_name).wait()
except:
self.log_exception("Error deleting Resource group %s." % group_name)
self.delete_resource_group(group_name, resource_client)

i += 1

Expand Down Expand Up @@ -604,11 +600,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
).wait()
except:
self.log_exception("Error creating storage account: %s" % storage_account)
self.log_info("Delete Inf RG group %s" % "rg-%s" % inf.id)
try:
resource_client.resource_groups.delete("rg-%s" % inf.id)
except:
pass
self.delete_resource_group("rg-%s" % inf.id, resource_client)

subnets = self.create_nets(radl, credentials, subscription_id, "rg-%s" % inf.id)

Expand All @@ -635,11 +627,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):

if remaining_vms > 0:
# Remove the general group
self.log_info("Delete Inf RG group %s" % "rg-%s" % inf.id)
try:
resource_client.resource_groups.delete("rg-%s" % inf.id)
except:
pass
self.delete_resource_group("rg-%s" % inf.id, resource_client)
else:
self.log_info("All VMs created successfully.")

Expand Down Expand Up @@ -757,16 +745,14 @@ def finalize(self, vm, last, auth_data):

# Delete Resource group and everything in it
if self.get_rg(group_name, credentials, subscription_id):
self.log_info("Removing RG: %s" % group_name)
resource_client.resource_groups.delete(group_name).wait()
self.delete_resource_group(group_name, resource_client)
else:
self.log_info("RG: %s does not exist. Do not remove." % group_name)

# if it is the last VM delete the RG of the Inf
if last:
if self.get_rg("rg-%s" % vm.inf.id, credentials, subscription_id):
self.log_info("Removing Inf. RG: %s" % "rg-%s" % vm.inf.id)
resource_client.resource_groups.delete("rg-%s" % vm.inf.id)
self.delete_resource_group("rg-%s" % vm.inf.id, resource_client)
else:
self.log_info("RG: %s does not exist. Do not remove." % "rg-%s" % vm.inf.id)

Expand Down Expand Up @@ -831,3 +817,26 @@ def alterVM(self, vm, radl, auth_data):
return False, "Error altering the VM: " + str(ex)

return (True, "")

def delete_resource_group(self, group_name, resource_client, max_retries=3):
"""
Delete a RG with retries
"""
cont = 0
deleted = False

self.log_info("Delete RG %s." % group_name)
while cont < max_retries and not deleted:
cont += 1
try:
resource_client.resource_groups.delete(group_name).wait()
deleted = True
except:
self.log_exception("Error deleting Resource group %s (%d/%d)." % (group_name, cont, max_retries))

if not deleted:
self.log_error("Resource group %s cannot be deleted!!!" % group_name)
else:
self.log_info("Resource group %s successfully deleted." % group_name)

return deleted
2 changes: 1 addition & 1 deletion IM/connectors/AzureClassic.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def get_instance_type(self, system, auth_data):
disk_free_op = ">="
if system.getValue('disks.free_size'):
disk_free = system.getFeature('disks.free_size').getValue('M')
disk_free_op = system.getFeature('memory.size').getLogOperator()
disk_free_op = system.getFeature('disks.free_size').getLogOperator()

instace_types = self.get_all_instance_types(auth_data)

Expand Down
2 changes: 1 addition & 1 deletion IM/connectors/EC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def get_instance_type(self, radl, vpc=None):
disk_free_op = ">="
if radl.getValue('disks.free_size'):
disk_free = radl.getFeature('disks.free_size').getValue('G')
disk_free_op = radl.getFeature('memory.size').getLogOperator()
disk_free_op = radl.getFeature('disks.free_size').getLogOperator()

performance = 0
performance_op = ">="
Expand Down
11 changes: 4 additions & 7 deletions IM/connectors/OpenNebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,19 +941,16 @@ def get_networks_template(self, radl, sgs, auth_data):
for public in [True, False]:
i = 0
while system.getValue("net_interface." + str(i) + ".connection"):
network = system.getValue(
"net_interface." + str(i) + ".connection")
network = system.getValue("net_interface." + str(i) + ".connection")
fixed_ip = system.getValue("net_interface." + str(i) + ".ip")

# get the one network info
if nets[network]:
if network in nets and nets[network]:
(net_name, net_id, is_public) = nets[network]
radl.get_network_by_id(network).setValue('provider_id', str(net_name))
else:
self.log_error(
"No ONE network found for network: " + network)
raise Exception(
"No ONE network found for network: " + network)
self.log_error("No ONE network found for network: " + network)
raise Exception("No ONE network found for network: " + network)

if public == is_public:
if net_id is not None:
Expand Down
19 changes: 16 additions & 3 deletions IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ def __init__(self, cloud_info, inf):
self.add_public_ip_count = 0
LibCloudCloudConnector.__init__(self, cloud_info, inf)

def get_node_with_id(self, node_id, auth_data):
"""
Get the node with the specified ID
Arguments:
- node_id(str): ID of the node to get
- auth(Authentication): parsed authentication tokens.
Returns: a :py:class:`libcloud.compute.base.Node` with the node info
"""
driver = self.get_driver(auth_data)
node = driver.ex_get_node_details(node_id)
return node

def get_driver(self, auth_data):
"""
Get the driver from the auth data
Expand Down Expand Up @@ -171,9 +184,9 @@ def get_instance_type(self, sizes, radl):
memory_op = radl.getFeature('memory.size').getLogOperator()
disk_free = 0
disk_free_op = ">="
if radl.getValue('disk.0.free_size'):
disk_free = radl.getFeature('disk.0.free_size').getValue('G')
disk_free_op = radl.getFeature('memory.size').getLogOperator()
if radl.getValue('disks.free_size'):
disk_free = radl.getFeature('disks.free_size').getValue('G')
disk_free_op = radl.getFeature('disks.free_size').getLogOperator()

# get the node size with the lowest price, vcpus and memory
sizes.sort(key=lambda x: (x.price, x.vcpus, x.ram))
Expand Down
12 changes: 6 additions & 6 deletions test/unit/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_30_updateVMInfo(self, get_driver):
node.public_ips = []
node.private_ips = ['10.0.0.1']
node.driver = driver
driver.list_nodes.return_value = [node]
driver.ex_get_node_details.return_value = node

node_size = MagicMock()
node_size.ram = 512
Expand Down Expand Up @@ -308,7 +308,7 @@ def test_40_stop(self, get_driver):
node.public_ips = ['158.42.1.1']
node.private_ips = ['10.0.0.1']
node.driver = driver
driver.list_nodes.return_value = [node]
driver.ex_get_node_details.return_value = node

driver.ex_stop_node.return_value = True

Expand Down Expand Up @@ -336,7 +336,7 @@ def test_50_start(self, get_driver):
node.public_ips = ['158.42.1.1']
node.private_ips = ['10.0.0.1']
node.driver = driver
driver.list_nodes.return_value = [node]
driver.ex_get_node_details.return_value = node

driver.ex_start_node.return_value = True

Expand Down Expand Up @@ -386,7 +386,7 @@ def test_55_alter(self, get_driver):
node.public_ips = ['158.42.1.1']
node.private_ips = ['10.0.0.1']
node.driver = driver
driver.list_nodes.return_value = [node]
driver.ex_get_node_details.return_value = node

node_size = MagicMock()
node_size.ram = 2048
Expand Down Expand Up @@ -435,7 +435,7 @@ def test_60_finalize(self, sleep, get_driver):
node.private_ips = ['10.0.0.1']
node.driver = driver
node.destroy.return_value = True
driver.list_nodes.return_value = [node]
driver.ex_get_node_details.return_value = node

keypair = MagicMock()
driver.get_key_pair.return_value = keypair
Expand Down Expand Up @@ -468,7 +468,7 @@ def test_70_create_snapshot(self, get_driver):
node = MagicMock()
node.id = "1"
node.driver = driver
driver.list_nodes.return_value = [node]
driver.ex_get_node_details.return_value = node
image = MagicMock()
image.id = "newimage"
driver.create_image.return_value = image
Expand Down

0 comments on commit 0cb9831

Please sign in to comment.