Search in sources :

Example 1 with IllegalVirtualMachineException

use of com.cloud.legacymodel.exceptions.IllegalVirtualMachineException in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method prepareElement.

protected boolean prepareElement(final NetworkElement element, final Network network, final NicProfile profile, final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    try {
        element.prepare(network, profile, vmProfile, dest, context);
    } catch (final IllegalVirtualMachineException e) {
        s_logger.warn(e.getMessage());
    }
    if (vmProfile.getType() == VirtualMachineType.User && element.getProvider() != null) {
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && element instanceof DhcpServiceProvider) {
            final DhcpServiceProvider sp = (DhcpServiceProvider) element;
            final Map<Capability, String> dhcpCapabilities = element.getCapabilities().get(Service.Dhcp);
            final String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
            if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets) && profile.getIPv6Address() == null) {
                if (!sp.configDhcpSupportForSubnet(network, profile, vmProfile, dest, context)) {
                    return false;
                }
            }
            if (!sp.addDhcpEntry(network, profile, vmProfile, dest, context)) {
                return false;
            }
        }
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData, element.getProvider()) && element instanceof UserDataServiceProvider) {
            final UserDataServiceProvider sp = (UserDataServiceProvider) element;
            if (!sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context)) {
                return false;
            }
        }
    }
    return true;
}
Also used : Capability(com.cloud.legacymodel.network.Network.Capability) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider)

Example 2 with IllegalVirtualMachineException

use of com.cloud.legacymodel.exceptions.IllegalVirtualMachineException in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method prepare.

@Override
public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException, IllegalVirtualMachineException {
    if (vm.getType() != VirtualMachineType.User) {
        throw new IllegalVirtualMachineException("Illegal VM type informed. Expected USER VM, but got: " + vm.getType());
    }
    if (!canHandle(network, null)) {
        return false;
    }
    final NetworkOfferingVO offering = this._networkOfferingDao.findById(network.getNetworkOfferingId());
    if (offering.isSystemOnly()) {
        return false;
    }
    if (!this._networkMdl.isProviderEnabledInPhysicalNetwork(this._networkMdl.getPhysicalNetworkId(network), getProvider().getName())) {
        return false;
    }
    final RouterDeploymentDefinition routerDeploymentDefinition = this.routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setDeployDestination(dest).setAccountOwner(this._accountMgr.getAccount(network.getAccountId())).setParams(vm.getParameters()).build();
    final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
    if (routers == null || routers.size() == 0) {
        throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
    }
    return true;
}
Also used : RouterDeploymentDefinition(com.cloud.network.router.deployment.RouterDeploymentDefinition) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

IllegalVirtualMachineException (com.cloud.legacymodel.exceptions.IllegalVirtualMachineException)2 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)1 Capability (com.cloud.legacymodel.network.Network.Capability)1 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)1 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)1 RouterDeploymentDefinition (com.cloud.network.router.deployment.RouterDeploymentDefinition)1 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1