diff --git a/package/cloudshell/cp/vcenter/commands/connect_orchestrator.py b/package/cloudshell/cp/vcenter/commands/connect_orchestrator.py index fce41817..5f083fa5 100644 --- a/package/cloudshell/cp/vcenter/commands/connect_orchestrator.py +++ b/package/cloudshell/cp/vcenter/commands/connect_orchestrator.py @@ -35,6 +35,7 @@ def __init__(self, connector, disconnector, resource_model_parser): self.dv_switch_name = '' self.port_group_path = '' self.default_network = '' + self.logger = None def connect_bulk(self, si, logger, vcenter_data_model, request): """ @@ -44,6 +45,11 @@ def connect_bulk(self, si, logger, vcenter_data_model, request): :param request: :return: """ + self.logger = logger + + self.logger.info('Apply connectivity changes has started') + self.logger.debug('Apply connectivity changes has started with the requet: {0}'.format(request)) + self.vcenter_data_model = vcenter_data_model if vcenter_data_model.reserved_networks: self.reserved_networks = [name.strip() for name in vcenter_data_model.reserved_networks.split(',')] @@ -58,20 +64,20 @@ def connect_bulk(self, si, logger, vcenter_data_model, request): holder = DeployDataHolder(jsonpickle.decode(request)) mappings = self._map_requsets(holder.driverRequest.actions) + self.logger.debug('Connectivity actions mappings: {0}'.format(jsonpickle.encode(mappings, unpicklable=False))) pool = ThreadPool() async_results = self._run_async_connection_actions(si, mappings, pool, logger) results = self._get_async_results(async_results, pool) - + self.logger.info('Apply connectivity changes done') + self.logger.debug('Apply connectivity has finished with the results: {0}'.format(jsonpickle.encode(results, + unpicklable=False))) return results def _map_requsets(self, actions): - vm_mapping = dict() - grouped_by_vm_by_requset_by_mode = self._group_action(actions) - self._create_mapping_from_groupings(grouped_by_vm_by_requset_by_mode, vm_mapping) - + vm_mapping = self._create_mapping_from_groupings(grouped_by_vm_by_requset_by_mode) return vm_mapping def _group_action(self, actions): @@ -107,7 +113,8 @@ def _group_action_by_vm(self, actions): self._add_safely_to_dict(dictionary=grouped_by_vm, key=vm_uuid, value=action) return grouped_by_vm - def _create_mapping_from_groupings(self, grouped_by_vm_by_requset_by_mode, vm_mapping): + def _create_mapping_from_groupings(self, grouped_by_vm_by_requset_by_mode): + vm_mapping = dict() for vm, req_to_modes in grouped_by_vm_by_requset_by_mode.items(): actions_mapping = self.ActionsMapping() @@ -120,6 +127,8 @@ def _create_mapping_from_groupings(self, grouped_by_vm_by_requset_by_mode, vm_ma actions_mapping.action_tree = req_to_modes vm_mapping[vm] = actions_mapping + return vm_mapping + def _get_remove_mappings(self, req_to_modes, vm): remove_mappings = [] if ACTION_TYPE_REMOVE_VLAN in req_to_modes: @@ -180,6 +189,10 @@ def _set_vlan(self, action_mappings, si, vm_uuid, logger): results = [] set_vlan_actions = action_mappings.action_tree[ACTION_TYPE_SET_VLAN] try: + self.logger.info('connecting vm({0})'.format(vm_uuid)) + self.logger.debug('connecting vm({0}) with the mappings'.format(vm_uuid, + jsonpickle.encode(action_mappings, + unpicklable=False))) connection_results = self.connector.connect_to_networks(si, logger, vm_uuid, @@ -193,6 +206,7 @@ def _set_vlan(self, action_mappings, si, vm_uuid, logger): results += self._get_set_vlan_result_suc(act_by_mode_by_vlan_by_nic, connection_res_map) except Exception as e: + self.logger.error('Exception raised while connecting vm({0}) with exception: {1}'.format(vm_uuid, e)) for mode, actions in set_vlan_actions.items(): for action in actions: error_result = self._create_error_action_res(action, e) @@ -259,9 +273,14 @@ def _group_action_by_vlan_id(self, set_vlan_actions): return set_actions_grouped_by_vlan_id def _remove_vlan(self, action_mappings, si, vm_uuid, logger): + results = [] mode_to_actions = action_mappings.action_tree[ACTION_TYPE_REMOVE_VLAN] try: + self.logger.info('disconnecting vm({0})'.format(vm_uuid)) + self.logger.debug('disconnecting vm({0}) with the mappings'.format(vm_uuid, + jsonpickle.encode(action_mappings, + unpicklable=False))) connection_results = self.disconnector.disconnect_from_networks(si, logger, self.vcenter_data_model, @@ -285,6 +304,7 @@ def _remove_vlan(self, action_mappings, si, vm_uuid, logger): action_result.updatedInterface = res.vnic_mac results.append(action_result) except Exception as e: + self.logger.error('Exception raised while disconnecting vm({0}) with exception: {1}'.format(vm_uuid, e)) for mode, actions in mode_to_actions.items(): for action in actions: error_result = self._create_error_action_res(action, e) diff --git a/package/cloudshell/cp/vcenter/vm/portgroup_configurer.py b/package/cloudshell/cp/vcenter/vm/portgroup_configurer.py index cae43721..f68394e2 100644 --- a/package/cloudshell/cp/vcenter/vm/portgroup_configurer.py +++ b/package/cloudshell/cp/vcenter/vm/portgroup_configurer.py @@ -61,10 +61,6 @@ def erase_network_by_mapping(self, networks, reserved_networks, logger): for net in networks: try: nets[net.name] = net - except vim.fault.ManagedObjectNotFound as e: - continue - - try: for network in nets.values(): if self.network_name_gen.is_generated_name(network.name) \ and (not reserved_networks or network.name not in reserved_networks) \ @@ -75,8 +71,9 @@ def erase_network_by_mapping(self, networks, reserved_networks, logger): self.synchronous_task_waiter.wait_for_task(task=task, logger=logger, action_name='Erase dv Port Group') - except vim.fault.ManagedObjectNotFound as e: - continue + except Exception as e: + a = e.msg + continue finally: self._lock.release() diff --git a/vCenterShellPackage/DataModel/datamodel.xml b/vCenterShellPackage/DataModel/datamodel.xml index 195f349a..fdccd95b 100644 --- a/vCenterShellPackage/DataModel/datamodel.xml +++ b/vCenterShellPackage/DataModel/datamodel.xml @@ -511,7 +511,7 @@ - + @@ -667,4 +667,4 @@ - + \ No newline at end of file