Search in sources :

Example 6 with VirtualMachineProfile

use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.

the class GloboDnsElementTest method testPrepareMethodCallGloboDnsToRegisterHostName.

@Test
public void testPrepareMethodCallGloboDnsToRegisterHostName() throws Exception {
    Network network = mock(Network.class);
    when(network.getDataCenterId()).thenReturn(zoneId);
    when(network.getId()).thenReturn(1l);
    NicProfile nic = new NicProfile();
    nic.setIPv4Address("10.11.12.13");
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    when(vm.getHostName()).thenReturn("vm-name");
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    DataCenterVO dataCenterVO = mock(DataCenterVO.class);
    when(dataCenterVO.getId()).thenReturn(zoneId);
    when(_datacenterDao.findById(zoneId)).thenReturn(dataCenterVO);
    DeployDestination dest = new DeployDestination();
    ReservationContext context = new ReservationContextImpl(null, null, user);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(globoDnsHostId);
    when(_hostDao.findByTypeNameAndZoneId(eq(zoneId), eq(Provider.GloboDns.getName()), eq(Type.L2Networking))).thenReturn(hostVO);
    when(_agentMgr.easySend(eq(globoDnsHostId), isA(CreateOrUpdateRecordAndReverseCommand.class))).then(new org.mockito.stubbing.Answer<Answer>() {

        @Override
        public Answer answer(InvocationOnMock invocation) throws Throwable {
            Command cmd = (Command) invocation.getArguments()[1];
            return new Answer(cmd);
        }
    });
    _globodnsElement.prepare(network, nic, vm, dest, context);
    verify(_agentMgr, times(1)).easySend(eq(globoDnsHostId), isA(CreateOrUpdateRecordAndReverseCommand.class));
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Answer(com.cloud.agent.api.Answer) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Command(com.cloud.agent.api.Command) DeployDestination(com.cloud.deploy.DeployDestination) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Network(com.cloud.network.Network) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Example 7 with VirtualMachineProfile

use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.

the class GloboDnsElementTest method testUpperCaseCharactersAreNotAllowed.

@Test(expected = InvalidParameterValueException.class)
public void testUpperCaseCharactersAreNotAllowed() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    Network network = mock(Network.class);
    when(network.getDataCenterId()).thenReturn(zoneId);
    when(network.getId()).thenReturn(1l);
    NicProfile nic = new NicProfile();
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    when(vm.getHostName()).thenReturn("UPPERCASENAME");
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    when(_datacenterDao.findById(zoneId)).thenReturn(mock(DataCenterVO.class));
    DeployDestination dest = new DeployDestination();
    ReservationContext context = new ReservationContextImpl(null, null, user);
    _globodnsElement.prepare(network, nic, vm, dest, context);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NicProfile(com.cloud.vm.NicProfile) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 8 with VirtualMachineProfile

use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.

the class VirtualRouterElement method addPasswordAndUserdata.

@Override
public boolean addPasswordAndUserdata(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    boolean result = true;
    if (canHandle(network, Service.UserData)) {
        if (vm.getType() != VirtualMachine.Type.User) {
            return false;
        }
        if (network.getIp6Gateway() != null) {
            s_logger.info("Skip password and userdata service setup for IPv6 VM");
            return true;
        }
        final VirtualMachineProfile uservm = vm;
        final List<DomainRouterVO> routers = getRouters(network, dest);
        if (routers == null || routers.size() == 0) {
            throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
        }
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        for (final DomainRouterVO domainRouterVO : routers) {
            result = result && networkTopology.applyUserData(network, nic, uservm, dest, domainRouterVO);
        }
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 9 with VirtualMachineProfile

use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.

the class VirtualRouterElement method configureDhcpSupport.

protected boolean configureDhcpSupport(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, Service service) throws ResourceUnavailableException {
    if (canHandle(network, service)) {
        if (vm.getType() != VirtualMachine.Type.User) {
            return false;
        }
        final VirtualMachineProfile uservm = vm;
        final List<DomainRouterVO> routers = getRouters(network, dest);
        if (routers == null || routers.size() == 0) {
            throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
        }
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        return networkTopology.configDhcpForSubnet(network, nic, uservm, dest, routers);
    }
    return false;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 10 with VirtualMachineProfile

use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.

the class VpcVirtualRouterElement 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 {
    final Long vpcId = network.getVpcId();
    if (vpcId == null) {
        s_logger.trace("Network " + network + " is not associated with any VPC");
        return false;
    }
    final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
    if (vpc == null) {
        s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
        return false;
    }
    if (vm.getType() == VirtualMachine.Type.User) {
        final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
        params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
        final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).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());
        }
        configureGuestNetwork(network, routers);
    }
    return true;
}
Also used : RouterDeploymentDefinition(org.cloud.network.router.deployment.RouterDeploymentDefinition) HashMap(java.util.HashMap) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)38 Test (org.junit.Test)23 DataCenterVO (com.cloud.dc.DataCenterVO)12 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)11 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)11 StoragePool (com.cloud.storage.StoragePool)11 DiskProfile (com.cloud.vm.DiskProfile)10 NicProfile (com.cloud.vm.NicProfile)10 StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)10 NetworkVO (com.cloud.network.dao.NetworkVO)9 NicVO (com.cloud.vm.NicVO)9 ReservationContext (com.cloud.vm.ReservationContext)9 DeploymentPlan (com.cloud.deploy.DeploymentPlan)8 HostVO (com.cloud.host.HostVO)8 Volume (com.cloud.storage.Volume)8 Commands (com.cloud.agent.manager.Commands)7 DomainRouterVO (com.cloud.vm.DomainRouterVO)7 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)6 ArrayList (java.util.ArrayList)6 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)6