Search in sources :

Example 1 with FindLogicalRouterPortAnswer

use of com.cloud.agent.api.FindLogicalRouterPortAnswer in project cloudstack by apache.

the class NiciraNvpGuestNetworkGuru method sharedNetworksCleanup.

private void sharedNetworksCleanup(NetworkVO networkObject, String logicalSwitchUuid, HostVO niciraNvpHost) {
    NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(networkObject.getId());
    if (routermapping == null) {
        // Case 1: Numerical Vlan Provided -> No lrouter used.
        s_logger.info("Shared Network " + networkObject.getDisplayText() + " didn't use Logical Router");
    } else {
        //Case 2: Logical Router's UUID provided as Vlan id -> Remove lrouter port but not lrouter.
        String lRouterUuid = routermapping.getLogicalRouterUuid();
        s_logger.debug("Finding Logical Router Port on Logical Router " + lRouterUuid + " with attachment_lswitch_uuid=" + logicalSwitchUuid + " to delete it");
        final FindLogicalRouterPortCommand cmd = new FindLogicalRouterPortCommand(lRouterUuid, logicalSwitchUuid);
        final FindLogicalRouterPortAnswer answer = (FindLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
        if (answer != null && answer.getResult()) {
            String logicalRouterPortUuid = answer.getLogicalRouterPortUuid();
            s_logger.debug("Found Logical Router Port " + logicalRouterPortUuid + ", deleting it");
            final DeleteLogicalRouterPortCommand cmdDeletePort = new DeleteLogicalRouterPortCommand(lRouterUuid, logicalRouterPortUuid);
            final DeleteLogicalRouterPortAnswer answerDelete = (DeleteLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmdDeletePort);
            if (answerDelete != null && answerDelete.getResult()) {
                s_logger.info("Successfully deleted Logical Router Port " + logicalRouterPortUuid);
            } else {
                s_logger.error("Could not delete Logical Router Port " + logicalRouterPortUuid);
            }
        } else {
            s_logger.error("Find Logical Router Port failed");
        }
    }
}
Also used : DeleteLogicalRouterPortAnswer(com.cloud.agent.api.DeleteLogicalRouterPortAnswer) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) FindLogicalRouterPortAnswer(com.cloud.agent.api.FindLogicalRouterPortAnswer) FindLogicalRouterPortCommand(com.cloud.agent.api.FindLogicalRouterPortCommand) DeleteLogicalRouterPortCommand(com.cloud.agent.api.DeleteLogicalRouterPortCommand)

Example 2 with FindLogicalRouterPortAnswer

use of com.cloud.agent.api.FindLogicalRouterPortAnswer in project cloudstack by apache.

the class NiciraNvpFindLogicalRouterPortCommandWrapper method execute.

@Override
public Answer execute(FindLogicalRouterPortCommand command, NiciraNvpResource niciraNvpResource) {
    final String logicalRouterUuid = command.getLogicalRouterUuid();
    final String attachmentLswitchUuid = command.getAttachmentLswitchUuid();
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    s_logger.debug("Finding Logical Router Port in Logical Router " + logicalRouterUuid + " and attachmentLSwitchUuid " + attachmentLswitchUuid);
    try {
        List<LogicalRouterPort> lRouterPorts = niciraNvpApi.findLogicalRouterPortByAttachmentLSwitchUuid(logicalRouterUuid, attachmentLswitchUuid);
        if (lRouterPorts.size() == 0) {
            return new FindLogicalRouterPortAnswer(command, false, "Logical Router Port not found", null);
        } else {
            return new FindLogicalRouterPortAnswer(command, true, "Logical Router Port found", lRouterPorts.get(0).getUuid());
        }
    } catch (NiciraNvpApiException e) {
        s_logger.error("Error finding Logical Router Port due to: " + e.getMessage());
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, FindLogicalRouterPortAnswer.class, e);
    }
}
Also used : LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) FindLogicalRouterPortAnswer(com.cloud.agent.api.FindLogicalRouterPortAnswer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Aggregations

FindLogicalRouterPortAnswer (com.cloud.agent.api.FindLogicalRouterPortAnswer)2 DeleteLogicalRouterPortAnswer (com.cloud.agent.api.DeleteLogicalRouterPortAnswer)1 DeleteLogicalRouterPortCommand (com.cloud.agent.api.DeleteLogicalRouterPortCommand)1 FindLogicalRouterPortCommand (com.cloud.agent.api.FindLogicalRouterPortCommand)1 NiciraNvpRouterMappingVO (com.cloud.network.NiciraNvpRouterMappingVO)1 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)1 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)1 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)1 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)1