Search in sources :

Example 1 with UpdateDhcpOptionVspCommand

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

the class NuageVspGuestNetworkGuru method updateDhcpOptionsForExistingVms.

private void updateDhcpOptionsForExistingVms(Network network, HostVO nuageVspHost, VspNetwork vspNetwork, boolean networkHasDns, Map<Long, Boolean> networkHasDnsCache) throws InsufficientVirtualNetworkCapacityException {
    // Update dhcp options if a VR is added when we are not initiating the network
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(String.format("DomainRouter is added to an existing network: %s in state: %s", network.getName(), network.getState()));
    }
    List<NicVO> userNics = _nicDao.listByNetworkId(network.getId());
    LinkedListMultimap<Long, VspDhcpVMOption> dhcpOptionsPerDomain = LinkedListMultimap.create();
    for (NicVO userNic : userNics) {
        if (userNic.getVmType() == VirtualMachine.Type.DomainRouter) {
            continue;
        }
        VMInstanceVO userVm = _vmInstanceDao.findById(userNic.getInstanceId());
        boolean defaultHasDns = getDefaultHasDns(networkHasDnsCache, userNic);
        VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder.buildVmDhcpOption(userNic, defaultHasDns, networkHasDns);
        dhcpOptionsPerDomain.put(userVm.getDomainId(), dhcpOption);
    }
    for (Long domainId : dhcpOptionsPerDomain.keySet()) {
        VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(_domainDao.findById(domainId));
        VspNetwork vspNetworkForDomain = new VspNetwork.Builder().fromObject(vspNetwork).domain(vspDomain).build();
        List<VspDhcpVMOption> dhcpOptions = dhcpOptionsPerDomain.get(domainId);
        UpdateDhcpOptionVspCommand cmd = new UpdateDhcpOptionVspCommand(dhcpOptions, vspNetworkForDomain);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("UpdateDhcpOptionVspCommand failed at \"reserve\" for network " + vspNetwork.getName() + " under domain " + vspNetwork.getVspDomain().getName());
            if ((null != answer) && (null != answer.getDetails())) {
                s_logger.error(answer.getDetails());
            }
            throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
        }
    }
}
Also used : VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) VMInstanceVO(com.cloud.vm.VMInstanceVO) UpdateDhcpOptionVspCommand(com.cloud.agent.api.guru.UpdateDhcpOptionVspCommand) Answer(com.cloud.agent.api.Answer) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) NicVO(com.cloud.vm.NicVO) VspDhcpVMOption(net.nuage.vsp.acs.client.api.model.VspDhcpVMOption)

Aggregations

Answer (com.cloud.agent.api.Answer)1 UpdateDhcpOptionVspCommand (com.cloud.agent.api.guru.UpdateDhcpOptionVspCommand)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 NicVO (com.cloud.vm.NicVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VspDhcpVMOption (net.nuage.vsp.acs.client.api.model.VspDhcpVMOption)1 VspDomain (net.nuage.vsp.acs.client.api.model.VspDomain)1 VspNetwork (net.nuage.vsp.acs.client.api.model.VspNetwork)1