diff --git a/IM/InfrastructureManager.py b/IM/InfrastructureManager.py index 4f75883fa..7591ed60f 100644 --- a/IM/InfrastructureManager.py +++ b/IM/InfrastructureManager.py @@ -153,7 +153,7 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c """Launch a group of deploys together.""" if not deploy_group: - InfrastructureManager.logger.warning("No VMs to deploy!") + InfrastructureManager.logger.warning("Inf ID: %s: No VMs to deploy!" % sel_inf.id) return if not deploys_group_cloud_list: cancel_deployment.append(Exception("No cloud provider available")) @@ -169,6 +169,7 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c concrete_system = concrete_systems[cloud_id][deploy.id][0] if not concrete_system: InfrastructureManager.logger.error( + "Inf ID: " + sel_inf.id + ": " + "Error, no concrete system to deploy: " + deploy.id + " in cloud: " + cloud_id + ". Check if a correct image is being used") exceptions.append("Error, no concrete system to deploy: " + deploy.id + @@ -177,8 +178,7 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c (username, _, _, _) = concrete_system.getCredentialValues() if not username: - raise IncorrectVMCrecentialsException( - "No username for deploy: " + deploy.id) + raise IncorrectVMCrecentialsException("No username for deploy: " + deploy.id) launch_radl = radl.clone() launch_radl.systems = [concrete_system.clone()] @@ -186,11 +186,13 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c requested_radl.systems = [radl.get_system_by_name(concrete_system.name)] try: InfrastructureManager.logger.info( + "Inf ID: " + sel_inf.id + ": " + "Launching %d VMs of type %s" % (remain_vm, concrete_system.name)) launched_vms = cloud.cloud.getCloudConnector(sel_inf).launch( sel_inf, launch_radl, requested_radl, remain_vm, auth) except Exception as e: - InfrastructureManager.logger.exception("Error launching some of the VMs: %s" % e) + InfrastructureManager.logger.exception("Inf ID: " + sel_inf.id + ": " + + "Error launching some of the VMs: %s" % e) exceptions.append("Error launching the VMs of type %s to cloud ID %s" " of type %s. Cloud Provider Error: %s" % (concrete_system.name, cloud.cloud.id, @@ -198,12 +200,14 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c launched_vms = [] for success, launched_vm in launched_vms: if success: - InfrastructureManager.logger.info("VM successfully launched: " + str(launched_vm.id)) + InfrastructureManager.logger.info("Inf ID: " + sel_inf.id + ": " + + "VM successfully launched: " + str(launched_vm.id)) deployed_vm.setdefault(deploy, []).append(launched_vm) deploy.cloud_id = cloud_id remain_vm -= 1 else: InfrastructureManager.logger.warn( + "Inf ID: " + sel_inf.id + ": " + "Error launching some of the VMs: " + str(launched_vm)) exceptions.append("Error launching the VMs of type %s to cloud ID %s of type %s. %s" % ( concrete_system.name, cloud.cloud.id, cloud.cloud.type, str(launched_vm))) @@ -266,8 +270,7 @@ def Reconfigure(inf_id, radl_data, auth, vm_list=None): """ auth = InfrastructureManager.check_auth_data(auth) - InfrastructureManager.logger.info( - "Reconfiguring the inf: " + str(inf_id)) + InfrastructureManager.logger.info("Reconfiguring the inf: " + str(inf_id)) if isinstance(radl_data, RADL): radl = radl_data else: @@ -281,6 +284,7 @@ def Reconfigure(inf_id, radl_data, auth, vm_list=None): for s in radl.configures: sel_inf.radl.add(s.clone(), "replace") InfrastructureManager.logger.info( + "Inf ID: " + sel_inf.id + ": " + "(Re)definition of %s %s" % (type(s), s.getId())) # and update contextualize @@ -301,7 +305,7 @@ def Reconfigure(inf_id, radl_data, auth, vm_list=None): password=password, public_key=public_key, private_key=private_key, new=True) # Stick all virtual machines to be reconfigured - InfrastructureManager.logger.info("Contextualize the inf.") + InfrastructureManager.logger.info("Contextualize the inf: " + sel_inf.id) # reset ansible_configured to force the re-installation of galaxy roles sel_inf.ansible_configured = None sel_inf.Contextualize(auth, vm_list) @@ -373,8 +377,7 @@ def AddResource(inf_id, radl_data, auth, context=True, failed_clouds=None): failed_clouds = [] auth = InfrastructureManager.check_auth_data(auth) - InfrastructureManager.logger.info( - "Adding resources to inf: " + str(inf_id)) + InfrastructureManager.logger.info("Adding resources to inf: " + str(inf_id)) if isinstance(radl_data, RADL): radl = radl_data @@ -392,8 +395,7 @@ def AddResource(inf_id, radl_data, auth, context=True, failed_clouds=None): # If any deploy is defined, only update definitions. if not radl.deploys: sel_inf.update_radl(radl, []) - InfrastructureManager.logger.warn( - "Infrastructure without any deploy. Exiting.") + InfrastructureManager.logger.warn("Inf ID: " + sel_inf.id + ": without any deploy. Exiting.") return [] for system in radl.systems: @@ -411,6 +413,7 @@ def AddResource(inf_id, radl_data, auth, context=True, failed_clouds=None): requirements_radl, conflict="other", missing="other") except Exception: InfrastructureManager.logger.exception( + "Inf ID: " + sel_inf.id + ": " + "Error in the requirements of the app: " + app_to_install.getValue("name") + ". Ignore them.") @@ -476,7 +479,7 @@ def AddResource(inf_id, radl_data, auth, context=True, failed_clouds=None): # Group virtual machines to deploy by network dependencies deploy_groups = InfrastructureManager._compute_deploy_groups(radl) - InfrastructureManager.logger.debug("Groups of VMs with dependencies") + InfrastructureManager.logger.debug("Inf ID: " + sel_inf.id + ": Groups of VMs with dependencies") InfrastructureManager.logger.debug(deploy_groups) # Sort by score the cloud providers @@ -494,7 +497,7 @@ def AddResource(inf_id, radl_data, auth, context=True, failed_clouds=None): "are asked to be deployed in different cloud providers: %s" % deploy_group) elif len(suggested_cloud_ids) == 1: if suggested_cloud_ids[0] not in cloud_list: - InfrastructureManager.logger.debug("Cloud Provider list:") + InfrastructureManager.logger.debug("Inf ID: " + sel_inf.id + ": Cloud Provider list:") InfrastructureManager.logger.debug(cloud_list) raise Exception("No auth data for cloud with ID: %s" % suggested_cloud_ids[0]) else: @@ -581,8 +584,7 @@ def AddResource(inf_id, radl_data, auth, context=True, failed_clouds=None): # Add the new virtual machines to the infrastructure sel_inf.update_radl(radl, [(d, deployed_vm[d], concrete_systems[d.cloud_id][d.id][0]) for d in deployed_vm]) - InfrastructureManager.logger.info( - "VMs %s successfully added to Inf id %s" % (new_vms, sel_inf.id)) + InfrastructureManager.logger.info("VMs %s successfully added to Inf id %s" % (new_vms, sel_inf.id)) # Let's contextualize! if context and new_vms: @@ -608,8 +610,7 @@ def RemoveResource(inf_id, vm_list, auth, context=True): """ auth = InfrastructureManager.check_auth_data(auth) - InfrastructureManager.logger.info( - "Removing the VMs: " + str(vm_list) + " from inf ID: '" + str(inf_id) + "'") + InfrastructureManager.logger.info("Removing the VMs: " + str(vm_list) + " from inf ID: '" + str(inf_id) + "'") sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth) @@ -630,7 +631,7 @@ def RemoveResource(inf_id, vm_list, auth, context=True): if InfrastructureManager._delete_vm(vm, delete_list, auth, exceptions): cont += 1 - InfrastructureManager.logger.info("%d VMs successfully removed" % cont) + InfrastructureManager.logger.info("Inf ID: " + sel_inf.id + ": %d VMs successfully removed" % cont) if context and cont > 0: # Now test again if the infrastructure is contextualizing @@ -639,7 +640,7 @@ def RemoveResource(inf_id, vm_list, auth, context=True): IM.InfrastructureList.InfrastructureList.save_data(inf_id) if exceptions: - InfrastructureManager.logger.exception("Error removing resources") + InfrastructureManager.logger.exception("Inf ID: " + sel_inf.id + ": Error removing resources") raise Exception("Error removing resources: %s" % exceptions) return cont @@ -690,7 +691,8 @@ def GetVMInfo(inf_id, vm_id, auth, json_res=False): success = vm.update_status(auth) if not success: - InfrastructureManager.logger.warn( + InfrastructureManager.logger.debug( + "Inf ID: " + str(inf_id) + ": " + "Information not updated. Using last information retrieved") if json_res: @@ -744,6 +746,7 @@ def AlterVM(inf_id, vm_id, radl_data, auth): vm = InfrastructureManager.get_vm_from_inf(inf_id, vm_id, auth) if not vm: InfrastructureManager.logger.info( + "Inf ID: " + str(inf_id) + ": " + "VM does not exist or Access Error") raise Exception("VM does not exist or Access Error") @@ -762,9 +765,8 @@ def AlterVM(inf_id, vm_id, radl_data, auth): raise exception if not success: InfrastructureManager.logger.warn( - "Error getting the information about the VM " + str(vm_id) + ": " + str(alter_res)) - InfrastructureManager.logger.warn( - "Using last information retrieved") + "Inf ID: " + str(inf_id) + ": " + + "Error modifying the information about the VM " + str(vm_id) + ": " + str(alter_res)) vm.update_status(auth) IM.InfrastructureList.InfrastructureList.save_data(inf_id) @@ -785,8 +787,7 @@ def GetInfrastructureRADL(inf_id, auth): """ auth = InfrastructureManager.check_auth_data(auth) - InfrastructureManager.logger.info( - "Getting RADL of the inf: " + str(inf_id)) + InfrastructureManager.logger.info("Getting RADL of the inf: " + str(inf_id)) sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth) @@ -808,15 +809,11 @@ def GetInfrastructureInfo(inf_id, auth): """ auth = InfrastructureManager.check_auth_data(auth) - InfrastructureManager.logger.info( - "Getting information about the inf: " + str(inf_id)) + InfrastructureManager.logger.info("Getting information about the inf: " + str(inf_id)) sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth) - # : .. todo:: - # : Return int instead res = [str(vm.im_id) for vm in sel_inf.get_vm_list()] - InfrastructureManager.logger.info("Information obtained successfully") InfrastructureManager.logger.debug(res) return res @@ -960,8 +957,7 @@ def StopInfrastructure(inf_id, auth): msg += str(e) + "\n" raise Exception("Error stopping the infrastructure: %s" % msg) - InfrastructureManager.logger.info( - "Infrastructure successfully stopped") + InfrastructureManager.logger.info("Inf ID: " + sel_inf.id + ": Successfully stopped") return "" @staticmethod @@ -1013,8 +1009,7 @@ def StartInfrastructure(inf_id, auth): msg += str(e) + "\n" raise Exception("Error starting the infrastructure: %s" % msg) - InfrastructureManager.logger.info( - "Infrastructure successfully restarted") + InfrastructureManager.logger.info("Inf ID: " + sel_inf.id + ": Successfully restarted") return "" @staticmethod @@ -1044,10 +1039,12 @@ def StartVM(inf_id, vm_id, auth): if not success: InfrastructureManager.logger.info( + "Inf ID: " + str(inf_id) + ": " + "The VM %s cannot be restarted: %s" % (vm_id, msg)) raise Exception("Error starting the VM: %s" % msg) else: InfrastructureManager.logger.info( + "Inf ID: " + str(inf_id) + ": " + "The VM %s successfully restarted" % vm_id) return "" @@ -1079,10 +1076,12 @@ def StopVM(inf_id, vm_id, auth): if not success: InfrastructureManager.logger.info( + "Inf ID: " + str(inf_id) + ": " + "The VM %s cannot be stopped: %s" % (vm_id, msg)) raise Exception("Error stopping the VM: %s" % msg) else: InfrastructureManager.logger.info( + "Inf ID: " + str(inf_id) + ": " + "The VM %s successfully stopped" % vm_id) return "" @@ -1137,8 +1136,7 @@ def DestroyInfrastructure(inf_id, auth): # First check the auth data auth = InfrastructureManager.check_auth_data(auth) - InfrastructureManager.logger.info( - "Destroying the infrastructure id: " + str(inf_id)) + InfrastructureManager.logger.info("Destroying the infrastructure id: " + str(inf_id)) sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth) exceptions = [] @@ -1167,8 +1165,7 @@ def DestroyInfrastructure(inf_id, auth): sel_inf.delete() IM.InfrastructureList.InfrastructureList.save_data(inf_id) IM.InfrastructureList.InfrastructureList.remove_inf(sel_inf) - InfrastructureManager.logger.info( - "Infrastructure %s successfully destroyed" % inf_id) + InfrastructureManager.logger.info("Infrastructure %s successfully destroyed" % inf_id) return "" @staticmethod @@ -1335,6 +1332,7 @@ def CreateDiskSnapshot(inf_id, vm_id, disk_num, image_name, auto_delete, auth): Return: a str with url of the saved snapshot. """ auth = InfrastructureManager.check_auth_data(auth) + InfrastructureManager.logger.info("Creating a snapshot of VM id: %s Inf id: %s" % (vm_id, inf_id)) vm = InfrastructureManager.get_vm_from_inf(inf_id, vm_id, auth)