Exemplo n.º 1
0
 def _create_error_action_res(action, e):
     error_result = ActionResult()
     error_result.actionId = action.actionId
     error_result.type = action.type
     error_result.errorMessage = get_error_message_from_exception(e)
     error_result.infoMessage = None
     error_result.success = False
     error_result.updatedInterface = ConnectionCommandOrchestrator._get_mac(action)
     return error_result
    def _remove_vlan(self, action_mappings, si, vm_uuid, logger):
        results = []
        mode_to_actions = action_mappings.action_tree[ACTION_TYPE_REMOVE_VLAN]
        try:
            connection_results = self.disconnector.disconnect_from_networks(si,
                                                                            logger,
                                                                            self.vcenter_data_model,
                                                                            vm_uuid,
                                                                            action_mappings.remove_mapping)

            interface_to_action = dict()
            for mode, actions in mode_to_actions.items():
                for action in actions:
                    name = self._get_mac(action)
                    interface_to_action[name] = action

            for res in connection_results:
                action = interface_to_action[res.vnic_mac]
                action_result = ActionResult()
                action_result.actionId = action.actionId
                action_result.success = True
                action_result.infoMessage = SUCCESSFULLY_REMOVED
                action_result.type = ACTION_TYPE_REMOVE_VLAN
                action_result.errorMessage = None
                action_result.updatedInterface = res.vnic_mac
                results.append(action_result)
        except Exception as e:
            for mode, actions in mode_to_actions.items():
                for action in actions:
                    error_result = self._create_error_action_res(action, e)
                    results.append(error_result)
        return results
 def _create_error_action_res(action, e):
     error_result = ActionResult()
     error_result.actionId = action.actionId
     error_result.type = action.type
     error_result.errorMessage = get_error_message_from_exception(e)
     error_result.infoMessage = None
     error_result.success = False
     error_result.updatedInterface = ConnectionCommandOrchestrator._get_mac(action)
     return error_result
 def _get_disconnect_excepted_results(self, request, error_msg=None):
     a = DeployDataHolder(request['driverRequest'])
     res = []
     for action in a.actions:
         r = ActionResult()
         r.actionId = action.actionId
         r.type = action.type
         r.errorMessage = error_msg
         r.infoMessage = 'VLAN Successfully removed' if not error_msg else None
         r.success = True if not error_msg else False
         r.updatedInterface = self._get_interface_name(action)
         res.append(r)
     return res
 def _get_disconnect_excepted_results(self, request, error_msg=None):
     a = DeployDataHolder(request['driverRequest'])
     res = []
     for action in a.actions:
         r = ActionResult()
         r.actionId = action.actionId
         r.type = action.type
         r.errorMessage = error_msg
         r.infoMessage = 'VLAN Successfully removed' if not error_msg else None
         r.success = True if not error_msg else False
         r.updatedInterface = self._get_interface_name(action)
         res.append(r)
     return res
Exemplo n.º 6
0
 def _get_set_vlan_result_suc(self, act_by_mode_by_vlan_by_nic, connection_res_map):
     results = []
     for mode, vlans_to_nics in act_by_mode_by_vlan_by_nic.items():
         for vlan_id, nics_to_actions in vlans_to_nics.items():
             for nic_name, actions in nics_to_actions.items():
                 nic_name = self._validate_vnic_name(nic_name)
                 for action in actions:
                     res = connection_res_map[mode][vlan_id][nic_name][0]
                     connection_res_map[mode][vlan_id][nic_name].remove(res)
                     result = ActionResult()
                     result.actionId = action.actionId
                     result.success = True
                     result.errorMessage = None
                     result.infoMessage = ACTION_SUCCESS_MSG
                     result.type = ACTION_TYPE_SET_VLAN
                     result.updatedInterface = res.mac_address
                     results.append(result)
     final_res = self._consolidate_duplicate_results(results)
     return final_res
    def test_set_command_result(self):
        action_result = ActionResult()
        action_result.actionId = 'A'
        action_result.errorMessage = ''
        action_result.infoMessage = ''
        action_result.success = True
        action_result.type = 'setVlan'
        action_result.updatedInterface = 'AA-BB'

        driver_response = DriverResponse()
        driver_response.actionResults = [action_result]

        driver_response_root = DriverResponseRoot()
        driver_response_root.driverResponse = driver_response

        result = set_command_result(driver_response_root)

        self.assertEqual(
            result,
            '{"driverResponse": {"actionResults": [{"success": true, "updatedInterface": "AA-BB", "errorMessage": "", "infoMessage": "", "actionId": "A", "type": "setVlan"}]}}'
        )
Exemplo n.º 8
0
    def _remove_vlan(self, action_mappings, si, vm_uuid, logger):
        final_res = []
        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, vm_uuid,
                action_mappings.remove_mapping)

            interface_to_action = dict()
            for mode, actions in mode_to_actions.items():
                for action in actions:
                    names = self._get_macs_from_action(action)
                    for name in names:
                        interface_to_action[name] = action
            results = []
            for res in connection_results:
                action = interface_to_action[res.vnic_mac]
                action_result = ActionResult()
                action_result.actionId = action.actionId
                action_result.success = True
                action_result.infoMessage = SUCCESSFULLY_REMOVED
                action_result.type = ACTION_TYPE_REMOVE_VLAN
                action_result.errorMessage = None
                action_result.updatedInterface = res.vnic_mac
                results.append(action_result)
            final_res = self._consolidate_duplicate_results(results)
        except Exception as e:
            self.logger.error(
                'Exception raised while disconnecting vm({0}) with exception: {1}'
                .format(vm_uuid, traceback.format_exc()))
            for mode, actions in mode_to_actions.items():
                for action in actions:
                    error_result = self._create_error_action_res(action, e)
                    final_res.append(error_result)
            final_res = self._consolidate_duplicate_results(final_res)
        return final_res
    def test_set_command_result(self):
        action_result = ActionResult()
        action_result.actionId = 'A'
        action_result.errorMessage = ''
        action_result.infoMessage = ''
        action_result.success = True
        action_result.type = 'setVlan'
        action_result.updatedInterface = 'AA-BB'

        driver_response = DriverResponse()
        driver_response.actionResults = [action_result]

        driver_response_root = DriverResponseRoot()
        driver_response_root.driverResponse = driver_response

        result = set_command_result(driver_response_root)

        self.assertEqual(result, '{"driverResponse": {"actionResults": [{"success": true, "updatedInterface": "AA-BB", "errorMessage": "", "infoMessage": "", "actionId": "A", "type": "setVlan"}]}}')
 def _get_set_vlan_result_suc(self, act_by_mode_by_vlan_by_nic, connection_res_map):
     results = []
     for mode, vlans_to_nics in act_by_mode_by_vlan_by_nic.items():
         for vlan_id, nics_to_actions in vlans_to_nics.items():
             for nic_name, actions in nics_to_actions.items():
                 nic_name = self._validate_vnic_name(nic_name)
                 for action in actions:
                     res = connection_res_map[mode][vlan_id][nic_name][0]
                     connection_res_map[mode][vlan_id][nic_name].remove(res)
                     result = ActionResult()
                     result.actionId = action.actionId
                     result.success = True
                     result.errorMessage = None
                     result.infoMessage = ACTION_SUCCESS_MSG
                     result.type = ACTION_TYPE_SET_VLAN
                     result.updatedInterface = res.mac_address
                     results.append(result)
     return results
    def _remove_vlan(self, action_mappings, si, vm_uuid, logger):
        final_res = []
        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,
                                                                            vm_uuid,
                                                                            action_mappings.remove_mapping)

            interface_to_action = dict()
            for mode, actions in mode_to_actions.items():
                for action in actions:
                    names = self._get_macs_from_action(action)
                    for name in names:
                        interface_to_action[name] = action
            results = []
            for res in connection_results:
                action = interface_to_action[res.vnic_mac]
                action_result = ActionResult()
                action_result.actionId = action.actionId
                action_result.success = True
                action_result.infoMessage = SUCCESSFULLY_REMOVED
                action_result.type = ACTION_TYPE_REMOVE_VLAN
                action_result.errorMessage = None
                action_result.updatedInterface = res.vnic_mac
                results.append(action_result)
            final_res = self._consolidate_duplicate_results(results)
        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)
                    final_res.append(error_result)
            final_res = self._consolidate_duplicate_results(final_res)
        return final_res