Skip to content

Commit

Permalink
Merge pull request #486 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Nov 9, 2017
2 parents 4f912e0 + b60ca22 commit 7e4bddf
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 267 deletions.
100 changes: 50 additions & 50 deletions IM/ConfManager.py

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions IM/InfrastructureInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,7 @@ def Contextualize(self, auth, vm_list=None):
break

if not ctxt:
InfrastructureInfo.logger.debug(
"Inf ID: " + str(self.id) + ": Contextualization disabled by the RADL.")
InfrastructureInfo.logger.info("Inf ID: " + str(self.id) + ": Contextualization disabled by the RADL.")
self.cont_out = "Contextualization disabled by the RADL."
self.configured = True
for vm in self.get_vm_list():
Expand Down
12 changes: 6 additions & 6 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c
requested_radl = radl.clone()
requested_radl.systems = [radl.get_system_by_name(concrete_system.name)]
try:
InfrastructureManager.logger.debug(
InfrastructureManager.logger.info(
"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)
Expand All @@ -198,7 +198,7 @@ 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.debug("VM successfully launched: " + str(launched_vm.id))
InfrastructureManager.logger.info("VM successfully launched: " + str(launched_vm.id))
deployed_vm.setdefault(deploy, []).append(launched_vm)
deploy.cloud_id = cloud_id
remain_vm -= 1
Expand Down Expand Up @@ -907,15 +907,15 @@ def GetInfrastructureState(inf_id, auth):
if state is None:
state = VirtualMachine.UNKNOWN

InfrastructureManager.logger.debug(
InfrastructureManager.logger.info(
"inf: " + str(inf_id) + " is in state: " + state)
return {'state': state, 'vm_states': vm_states}

@staticmethod
def _stop_vm(vm, auth, exceptions):
try:
success = False
InfrastructureManager.logger.debug("Stopping the VM id: " + vm.id)
InfrastructureManager.logger.info("Stopping the VM id: " + vm.id)
(success, msg) = vm.stop(auth)
except Exception as e:
msg = str(e)
Expand Down Expand Up @@ -968,7 +968,7 @@ def StopInfrastructure(inf_id, auth):
def _start_vm(vm, auth, exceptions):
try:
success = False
InfrastructureManager.logger.debug("Starting the VM id: " + vm.id)
InfrastructureManager.logger.info("Starting the VM id: " + vm.id)
(success, msg) = vm.start(auth)
except Exception as e:
msg = str(e)
Expand Down Expand Up @@ -1113,7 +1113,7 @@ def _delete_vm(vm, delete_list, auth, exceptions):
last = InfrastructureManager.is_last_in_cloud(vm, delete_list, remain_vms)
success = False
try:
InfrastructureManager.logger.debug("Finalizing the VM id: " + str(vm.id))
InfrastructureManager.logger.info("Finalizing the VM id: " + str(vm.id))
(success, msg) = vm.finalize(last, auth)
except Exception as e:
msg = str(e)
Expand Down
13 changes: 6 additions & 7 deletions IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def update_status(self, auth, force=False):
updated = True
self.last_update = now
elif self.creating:
self.log_debug("VM is in creation process, set pending state")
self.log_info("VM is in creation process, set pending state")
state = VirtualMachine.PENDING
else:
self.log_error("Error updating VM status: %s" % new_vm)
Expand Down Expand Up @@ -633,8 +633,7 @@ def kill_check_ctxt_process(self):
if self.ctxt_pid != self.WAIT_TO_PID:
ssh = self.get_ssh_ansible_master()
try:
self.log_debug(
"Killing ctxt process with pid: " + str(self.ctxt_pid))
self.log_info("Killing ctxt process with pid: " + str(self.ctxt_pid))

# Try to get PGID to kill all child processes
pgkill_success = False
Expand Down Expand Up @@ -691,7 +690,7 @@ def check_ctxt_process(self):
ssh = self.get_ssh_ansible_master()

try:
self.log_debug("Getting status of ctxt process with pid: " + str(ctxt_pid))
self.log_info("Getting status of ctxt process with pid: " + str(ctxt_pid))
(_, _, exit_status) = ssh.execute("ps " + str(ctxt_pid))
except:
self.log_warn("Error getting status of ctxt process with pid: " + str(ctxt_pid))
Expand All @@ -710,7 +709,7 @@ def check_ctxt_process(self):

if exit_status != 0:
# The process has finished, get the outputs
self.log_debug("The process %s has finished, get the outputs" % ctxt_pid)
self.log_info("The process %s has finished, get the outputs" % ctxt_pid)
ctxt_log = self.get_ctxt_log(remote_dir, True)
msg = self.get_ctxt_output(remote_dir, True)
if ctxt_log:
Expand All @@ -724,11 +723,11 @@ def check_ctxt_process(self):
# dynamically
if Config.UPDATE_CTXT_LOG_INTERVAL > 0 and wait > Config.UPDATE_CTXT_LOG_INTERVAL:
wait = 0
self.log_debug("Get the log of the ctxt process with pid: " + str(ctxt_pid))
self.log_info("Get the log of the ctxt process with pid: " + str(ctxt_pid))
ctxt_log = self.get_ctxt_log(remote_dir)
self.cont_out = initial_count_out + ctxt_log
# The process is still running, wait
self.log_debug("The process %s is still running. wait." % ctxt_pid)
self.log_info("The process %s is still running. wait." % ctxt_pid)
time.sleep(Config.CHECK_CTXT_PROCESS_INTERVAL)
wait += Config.CHECK_CTXT_PROCESS_INTERVAL
else:
Expand Down
2 changes: 1 addition & 1 deletion IM/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Config:
IM_PATH = os.path.dirname(os.path.realpath(__file__))
LOG_FILE = '/var/log/im/inf.log'
LOG_FILE_MAX_SIZE = 10485760
LOG_LEVEL = "DEBUG"
LOG_LEVEL = "INFO"
CONTEXTUALIZATION_DIR = '/usr/share/im/contextualization'
RECIPES_DIR = CONTEXTUALIZATION_DIR + '/AnsibleRecipes'
RECIPES_DB_FILE = CONTEXTUALIZATION_DIR + '/recipes_ansible.db'
Expand Down
44 changes: 22 additions & 22 deletions IM/connectors/Azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def get_azure_vm_create_json(self, storage_account, vm_name, nics, radl, instanc
data_disks = []
while system.getValue("disk." + str(cont) + ".size"):
disk_size = system.getFeature("disk." + str(cont) + ".size").getValue('G')
self.log_debug("Adding a %s GB disk." % disk_size)
self.log_info("Adding a %s GB disk." % disk_size)
data_disks.append({
'name': '%s_disk_%d' % (vm_name, cont),
'disk_size_gb': disk_size,
Expand Down Expand Up @@ -548,7 +548,7 @@ def create_vms(self, inf, radl, requested_radl, num_vm, location, storage_accoun
vm_name,
vm_parameters)

self.log_debug("VM ID: %s created." % vm.id)
self.log_info("VM ID: %s created." % vm.id)
inf.add_vm(vm)
vms.append((True, (vm, async_vm_creation)))
except Exception as ex:
Expand All @@ -557,7 +557,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_debug("Delete Resource group %s and everything in it." % 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:
Expand Down Expand Up @@ -587,15 +587,15 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
with inf._lock:
# Create resource group for the Infrastructure if it does not exists
if not self.get_rg("rg-%s" % inf.id, credentials, subscription_id):
self.log_debug("Creating Inf RG: %s" % "rg-%s" % inf.id)
self.log_info("Creating Inf RG: %s" % "rg-%s" % inf.id)
resource_client.resource_groups.create_or_update("rg-%s" % inf.id, {'location': location})

# Create an storage_account per Infrastructure
storage_account = self.get_storage_account("rg-%s" % inf.id, storage_account_name,
credentials, subscription_id)

if not storage_account:
self.log_debug("Creating storage account: %s" % storage_account_name)
self.log_info("Creating storage account: %s" % storage_account_name)
try:
storage_client = StorageManagementClient(credentials, subscription_id)
storage_client.storage_accounts.create("rg-%s" % inf.id,
Expand All @@ -606,7 +606,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_debug("Delete Inf RG group %s" % "rg-%s" % inf.id)
self.log_info("Delete Inf RG group %s" % "rg-%s" % inf.id)
try:
resource_client.resource_groups.delete("rg-%s" % inf.id)
except:
Expand All @@ -626,29 +626,29 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
if success:
vm, async_vm_creation = data
try:
self.log_debug("Waiting VM ID %s to be created." % vm.id)
self.log_info("Waiting VM ID %s to be created." % vm.id)
async_vm_creation.wait()
res.append((True, vm))
remaining_vms -= 1
except:
self.log_exception("Error waiting the VM %s." % vm.id)

self.log_debug("End of retry %d of %d" % (retries, Config.MAX_VM_FAILS))
self.log_info("End of retry %d of %d" % (retries, Config.MAX_VM_FAILS))

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

return res

def updateVMInfo(self, vm, auth_data):
self.log_debug("Get the VM info with the id: " + vm.id)
self.log_info("Get the VM info with the id: " + vm.id)
group_name = vm.id.split('/')[0]
vm_name = vm.id.split('/')[1]

Expand All @@ -661,9 +661,9 @@ def updateVMInfo(self, vm, auth_data):
self.log_exception("Error getting the VM info: " + vm.id)
return (False, "Error getting the VM info: " + vm.id + ". " + str(ex))

self.log_debug("VM info: " + vm.id + " obtained.")
self.log_info("VM info: " + vm.id + " obtained.")
vm.state = self.PROVISION_STATE_MAP.get(virtual_machine.provisioning_state, VirtualMachine.UNKNOWN)
self.log_debug("The VM state is: " + vm.state)
self.log_info("The VM state is: " + vm.state)

instance_type = self.get_instance_type_by_name(virtual_machine.hardware_profile.vm_size,
virtual_machine.location, credentials, subscription_id)
Expand Down Expand Up @@ -699,11 +699,11 @@ def add_dns_entries(self, vm, credentials, subscription_id):
except Exception:
pass
if not zone:
self.log_debug("Creating DNS zone %s" % domain)
self.log_info("Creating DNS zone %s" % domain)
zone = dns_client.zones.create_or_update(group_name, domain,
{'location': 'global'})
else:
self.log_debug("DNS zone %s exists. Do not create." % domain)
self.log_info("DNS zone %s exists. Do not create." % domain)

if zone:
record = None
Expand All @@ -712,11 +712,11 @@ def add_dns_entries(self, vm, credentials, subscription_id):
except Exception:
pass
if not record:
self.log_debug("Creating DNS record %s." % hostname)
self.log_info("Creating DNS record %s." % hostname)
record_data = {"ttl": 300, "arecords": [{"ipv4_address": ip}]}
dns_client.record_sets.create_or_update(group_name, domain, hostname, 'A', record_data)
else:
self.log_debug("DNS record %s exists. Do not create." % hostname)
self.log_info("DNS record %s exists. Do not create." % hostname)

return True
except Exception:
Expand Down Expand Up @@ -752,25 +752,25 @@ def setIPs(self, vm, network_profile, credentials, subscription_id):

def finalize(self, vm, last, auth_data):
try:
self.log_debug("Terminate VM: " + vm.id)
self.log_info("Terminate VM: " + vm.id)
group_name = vm.id.split('/')[0]
credentials, subscription_id = self.get_credentials(auth_data)
resource_client = ResourceManagementClient(credentials, subscription_id)

# Delete Resource group and everything in it
if self.get_rg(group_name, credentials, subscription_id):
self.log_debug("Removing RG: %s" % group_name)
self.log_info("Removing RG: %s" % group_name)
resource_client.resource_groups.delete(group_name).wait()
else:
self.log_debug("RG: %s does not exist. Do not remove." % group_name)
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_debug("Removing Inf. RG: %s" % "rg-%s" % vm.inf.id)
self.log_info("Removing Inf. RG: %s" % "rg-%s" % vm.inf.id)
resource_client.resource_groups.delete("rg-%s" % vm.inf.id)
else:
self.log_debug("RG: %s does not exist. Do not remove." % "rg-%s" % vm.inf.id)
self.log_info("RG: %s does not exist. Do not remove." % "rg-%s" % vm.inf.id)

except Exception as ex:
self.log_exception("Error terminating the VM")
Expand Down
23 changes: 11 additions & 12 deletions IM/connectors/AzureClassic.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def wait_operation_status(self, request_id, auth_data, delay=2, timeout=90):
output = Operation(resp.text)
status_str = output.Status
# InProgress|Succeeded|Failed
self.log_debug("Operation string state: " + status_str)
self.log_info("Operation string state: " + status_str)
else:
self.log_error(
"Error waiting operation to finish: Code %d. Msg: %s." % (resp.status_code, resp.text))
Expand Down Expand Up @@ -629,8 +629,7 @@ def get_storage_account(self, storage_account, auth_data):
storage_info = StorageService(resp.text)
return storage_info.StorageServiceProperties
elif resp.status_code == 404:
self.log_debug(
"Storage " + storage_account + " does not exist")
self.log_info("Storage " + storage_account + " does not exist")
return None
else:
self.log_warn(
Expand Down Expand Up @@ -682,7 +681,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
res.append((False, error_msg))
break

self.log_debug("Creating the VM with id: " + service_name)
self.log_info("Creating the VM with id: " + service_name)

# Create the VM to get the nodename
vm = VirtualMachine(inf, service_name, self.cloud, radl, requested_radl, self)
Expand Down Expand Up @@ -784,7 +783,7 @@ def get_instance_type(self, system, auth_data):
return res

def updateVMInfo(self, vm, auth_data):
self.log_debug("Get the VM info with the id: " + vm.id)
self.log_info("Get the VM info with the id: " + vm.id)
service_name = vm.id

try:
Expand All @@ -801,13 +800,13 @@ def updateVMInfo(self, vm, auth_data):
return (False, "Error getting the VM info: " + vm.id +
". Error Code: " + str(resp.status_code) + ". Msg: " + resp.text)
else:
self.log_debug("VM info: " + vm.id + " obtained.")
self.log_debug(resp.text)
self.log_info("VM info: " + vm.id + " obtained.")
self.log_info(resp.text)
vm_info = Deployment(resp.text)

vm.state = self.get_vm_state(vm_info)

self.log_debug("The VM state is: " + vm.state)
self.log_info("The VM state is: " + vm.state)

instance_type = self.get_instance_type_by_name(
vm_info.RoleInstanceList.RoleInstance[0].InstanceSize, auth_data)
Expand Down Expand Up @@ -857,7 +856,7 @@ def setIPs(self, vm, vm_info):
vm.setIps(public_ips, private_ips)

def finalize(self, vm, last, auth_data):
self.log_debug("Terminate VM: " + vm.id)
self.log_info("Terminate VM: " + vm.id)
service_name = vm.id

# Delete the service
Expand Down Expand Up @@ -900,7 +899,7 @@ def call_role_operation(self, op, vm, auth_data):
return (True, "")

def stop(self, vm, auth_data):
self.log_debug("Stop VM: " + vm.id)
self.log_info("Stop VM: " + vm.id)

op = """<ShutdownRoleOperation xmlns="http://schemas.microsoft.com/windowsazure"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
Expand All @@ -910,7 +909,7 @@ def stop(self, vm, auth_data):
return self.call_role_operation(op, vm, auth_data)

def start(self, vm, auth_data):
self.log_debug("Start VM: " + vm.id)
self.log_info("Start VM: " + vm.id)

op = """<StartRoleOperation xmlns="http://schemas.microsoft.com/windowsazure"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
Expand All @@ -935,7 +934,7 @@ def get_all_instance_types(self, auth_data):
"Error getting Role Sizes. Error Code: " + str(resp.status_code) + ". Msg: " + resp.text)
return []
else:
self.log_debug("Role List obtained.")
self.log_info("Role List obtained.")
role_sizes = RoleSizes(resp.text)
res = []
for role_size in role_sizes.RoleSize:
Expand Down
Loading

0 comments on commit 7e4bddf

Please sign in to comment.