Search in sources :

Example 1 with DataCenter

use of com.cloud.dc.DataCenter in project CloudStack-archive by CloudStack-extras.

the class ListZonesByCmd method execute.

@Override
public void execute() {
    List<? extends DataCenter> dataCenters = _mgr.listDataCenters(this);
    ListResponse<ZoneResponse> response = new ListResponse<ZoneResponse>();
    List<ZoneResponse> zoneResponses = new ArrayList<ZoneResponse>();
    for (DataCenter dataCenter : dataCenters) {
        ZoneResponse zoneResponse = _responseGenerator.createZoneResponse(dataCenter, showCapacities);
        zoneResponse.setObjectName("zone");
        zoneResponses.add(zoneResponse);
    }
    response.setResponses(zoneResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ZoneResponse(com.cloud.api.response.ZoneResponse) DataCenter(com.cloud.dc.DataCenter) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList)

Example 2 with DataCenter

use of com.cloud.dc.DataCenter in project CloudStack-archive by CloudStack-extras.

the class DeployVMCmd method create.

@Override
public void create() throws ResourceAllocationException {
    try {
        //Verify that all objects exist before passing them to the service
        Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
        DataCenter zone = _configService.getZone(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
        }
        ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
        }
        VirtualMachineTemplate template = _templateService.getTemplate(templateId);
        // Make sure a valid template ID was specified
        if (template == null) {
            throw new InvalidParameterValueException("Unable to use template " + templateId);
        }
        if (diskOfferingId != null) {
            DiskOffering diskOffering = _configService.getDiskOffering(diskOfferingId);
            if (diskOffering == null) {
                throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
            }
        }
        UserVm vm = null;
        if (getHypervisor() == HypervisorType.BareMetal) {
            vm = _bareMetalVmService.createVirtualMachine(this);
        } else {
            if (zone.getNetworkType() == NetworkType.Basic) {
                if (getNetworkIds() != null) {
                    throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
                } else {
                    vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                }
            } else {
                if (zone.isSecurityGroupEnabled()) {
                    vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                } else {
                    if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
                        throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
                    }
                    vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                }
            }
        }
        if (vm != null) {
            setEntityId(vm.getId());
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
        }
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 3 with DataCenter

use of com.cloud.dc.DataCenter in project CloudStack-archive by CloudStack-extras.

the class CreateZoneCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Zone Name: " + getZoneName());
    DataCenter result = _configService.createZone(this);
    if (result != null) {
        ZoneResponse response = _responseGenerator.createZoneResponse(result, false);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a zone");
    }
}
Also used : ZoneResponse(com.cloud.api.response.ZoneResponse) DataCenter(com.cloud.dc.DataCenter) ServerApiException(com.cloud.api.ServerApiException)

Example 4 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class CiscoVnmcElementTest method implementTest.

@Test
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    URI uri = URI.create("vlan://123");
    Network network = mock(Network.class);
    when(network.getId()).thenReturn(1L);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
    when(network.getDataCenterId()).thenReturn(1L);
    when(network.getGateway()).thenReturn("1.1.1.1");
    when(network.getBroadcastUri()).thenReturn(uri);
    when(network.getCidr()).thenReturn("1.1.1.0/24");
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(1L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeployDestination dest = mock(DeployDestination.class);
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("d1");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("a1");
    ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    DataCenter dc = mock(DataCenter.class);
    when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_entityMgr.findById(DataCenter.class, network.getDataCenterId())).thenReturn(dc);
    List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
    devices.add(mock(CiscoVnmcControllerVO.class));
    when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
    CiscoAsa1000vDeviceVO asaVO = mock(CiscoAsa1000vDeviceVO.class);
    when(asaVO.getInPortProfile()).thenReturn("foo");
    when(asaVO.getManagementIp()).thenReturn("1.2.3.4");
    List<CiscoAsa1000vDeviceVO> asaList = new ArrayList<CiscoAsa1000vDeviceVO>();
    asaList.add(asaVO);
    when(_ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(asaList);
    when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
    when(_networkAsa1000vMapDao.findByAsa1000vId(anyLong())).thenReturn(null);
    when(_networkAsa1000vMapDao.persist(any(NetworkAsa1000vMapVO.class))).thenReturn(mock(NetworkAsa1000vMapVO.class));
    when(_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.CiscoVnmc)).thenReturn(true);
    ClusterVSMMapVO clusterVsmMap = mock(ClusterVSMMapVO.class);
    when(_clusterVsmMapDao.findByClusterId(anyLong())).thenReturn(clusterVsmMap);
    CiscoNexusVSMDeviceVO vsmDevice = mock(CiscoNexusVSMDeviceVO.class);
    when(vsmDevice.getUserName()).thenReturn("foo");
    when(vsmDevice.getPassword()).thenReturn("bar");
    when(vsmDevice.getipaddr()).thenReturn("1.2.3.4");
    when(_vsmDeviceDao.findById(anyLong())).thenReturn(vsmDevice);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(1L);
    when(_hostDao.findById(anyLong())).thenReturn(hostVO);
    Ip ip = mock(Ip.class);
    when(ip.addr()).thenReturn("1.2.3.4");
    PublicIp publicIp = mock(PublicIp.class);
    when(publicIp.getAddress()).thenReturn(ip);
    when(publicIp.getState()).thenReturn(IpAddress.State.Releasing);
    when(publicIp.getAccountId()).thenReturn(1L);
    when(publicIp.isSourceNat()).thenReturn(true);
    when(publicIp.getVlanTag()).thenReturn("123");
    when(publicIp.getGateway()).thenReturn("1.1.1.1");
    when(publicIp.getNetmask()).thenReturn("1.1.1.1");
    when(publicIp.getMacAddress()).thenReturn(null);
    when(publicIp.isOneToOneNat()).thenReturn(true);
    when(_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(acc, network)).thenReturn(publicIp);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanGateway()).thenReturn("1.1.1.1");
    List<VlanVO> vlanVOList = new ArrayList<VlanVO>();
    when(_vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId())).thenReturn(vlanVOList);
    Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentMgr.easySend(anyLong(), any(CreateLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(ConfigureNexusVsmForAsaCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(SetSourceNatCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(AssociateAsaWithLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    assertTrue(_element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) AssociateAsaWithLogicalEdgeFirewallCommand(com.cloud.agent.api.AssociateAsaWithLogicalEdgeFirewallCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) URI(java.net.URI) ReservationContext(com.cloud.vm.ReservationContext) Network(com.cloud.network.Network) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) VlanVO(com.cloud.dc.VlanVO) CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) NetworkOffering(com.cloud.offering.NetworkOffering) PublicIp(com.cloud.network.addr.PublicIp) ConfigureNexusVsmForAsaCommand(com.cloud.agent.api.ConfigureNexusVsmForAsaCommand) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) DataCenter(com.cloud.dc.DataCenter) CreateLogicalEdgeFirewallCommand(com.cloud.agent.api.CreateLogicalEdgeFirewallCommand) DeployDestination(com.cloud.deploy.DeployDestination) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 5 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class LoadBalanceRuleHandler method deployLoadBalancerVM.

private DomainRouterVO deployLoadBalancerVM(final Long networkId, final IPAddressVO ipAddr) {
    final NetworkVO network = _networkDao.findById(networkId);
    final DataCenter dc = _dcDao.findById(network.getDataCenterId());
    final Long podId = getPodIdForDirectIp(ipAddr);
    final Pod pod = podId == null ? null : _podDao.findById(podId);
    final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
    params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
    final Account owner = _accountService.getActiveAccountByName("system", new Long(1));
    final DeployDestination dest = new DeployDestination(dc, pod, null, null);
    s_logger.debug("About to deploy ELB vm ");
    try {
        final DomainRouterVO elbVm = deployELBVm(network, dest, owner, params);
        if (elbVm == null) {
            throw new InvalidParameterValueException("Could not deploy or find existing ELB VM");
        }
        s_logger.debug("Deployed ELB  vm = " + elbVm);
        return elbVm;
    } catch (final Throwable t) {
        s_logger.warn("Error while deploying ELB VM:  ", t);
        return null;
    }
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) Pod(com.cloud.dc.Pod) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) Param(com.cloud.vm.VirtualMachineProfile.Param) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

DataCenter (com.cloud.dc.DataCenter)144 Account (com.cloud.user.Account)50 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)37 NetworkVO (com.cloud.network.dao.NetworkVO)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 Network (com.cloud.network.Network)30 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)27 ArrayList (java.util.ArrayList)27 DeployDestination (com.cloud.deploy.DeployDestination)25 NetworkOffering (com.cloud.offering.NetworkOffering)23 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)17 IPAddressVO (com.cloud.network.dao.IPAddressVO)17 DB (com.cloud.utils.db.DB)17 Domain (com.cloud.domain.Domain)16 ReservationContext (com.cloud.vm.ReservationContext)16 HostVO (com.cloud.host.HostVO)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)13 PhysicalNetwork (com.cloud.network.PhysicalNetwork)11 ServiceOffering (com.cloud.offering.ServiceOffering)11