Search in sources :

Example 71 with DataCenterVO

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

the class CommandSetupHelper method createApplyVpnUsersCommand.

public void createApplyVpnUsersCommand(final List<? extends VpnUser> users, final VirtualRouter router, final Commands cmds) {
    final List<VpnUser> addUsers = new ArrayList<VpnUser>();
    final List<VpnUser> removeUsers = new ArrayList<VpnUser>();
    for (final VpnUser user : users) {
        if (user.getState() == VpnUser.State.Add || user.getState() == VpnUser.State.Active) {
            addUsers.add(user);
        } else if (user.getState() == VpnUser.State.Revoke) {
            removeUsers.add(user);
        }
    }
    final VpnUsersCfgCommand cmd = new VpnUsersCfgCommand(addUsers, removeUsers);
    cmd.setAccessDetail(NetworkElementCommand.ACCOUNT_ID, String.valueOf(router.getAccountId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand("users", cmd);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) VpnUsersCfgCommand(com.cloud.agent.api.routing.VpnUsersCfgCommand) VpnUser(com.cloud.network.VpnUser) ArrayList(java.util.ArrayList)

Example 72 with DataCenterVO

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

the class StorageManagerImpl method createLocalStorage.

@DB
@Override
public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws ConnectionException {
    DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    if (dc == null) {
        return null;
    }
    boolean useLocalStorageForSystemVM = false;
    Boolean isLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dc.getId());
    if (isLocal != null) {
        useLocalStorageForSystemVM = isLocal.booleanValue();
    }
    if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
        return null;
    }
    DataStore store;
    try {
        String hostAddress = pInfo.getHost();
        if (host.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
            hostAddress = "VMFS datastore: " + pInfo.getHostPath();
        }
        StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, pInfo.getHostPath(), pInfo.getUuid());
        if (pool == null && host.getHypervisorType() == HypervisorType.VMware) {
            // need to perform runtime upgrade here
            if (pInfo.getHostPath().length() > 0) {
                pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, "", pInfo.getUuid());
            }
        }
        if (pool == null) {
            //the path can be different, but if they have the same uuid, assume they are the same storage
            pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, null, pInfo.getUuid());
            if (pool != null) {
                s_logger.debug("Found a storage pool: " + pInfo.getUuid() + ", but with different hostpath " + pInfo.getHostPath() + ", still treat it as the same pool");
            }
        }
        DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
        DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
        if (pool == null) {
            Map<String, Object> params = new HashMap<String, Object>();
            String name = (host.getName() + " Local Storage");
            params.put("zoneId", host.getDataCenterId());
            params.put("clusterId", host.getClusterId());
            params.put("podId", host.getPodId());
            params.put("url", pInfo.getPoolType().toString() + "://" + pInfo.getHost() + "/" + pInfo.getHostPath());
            params.put("name", name);
            params.put("localStorage", true);
            params.put("details", pInfo.getDetails());
            params.put("uuid", pInfo.getUuid());
            params.put("providerName", provider.getName());
            store = lifeCycle.initialize(params);
        } else {
            store = _dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
        }
        pool = _storagePoolDao.findById(store.getId());
        if (pool.getStatus() != StoragePoolStatus.Maintenance && pool.getStatus() != StoragePoolStatus.Removed) {
            HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId());
            lifeCycle.attachHost(store, scope, pInfo);
        }
    } catch (Exception e) {
        s_logger.warn("Unable to setup the local storage pool for " + host, e);
        throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
    }
    return _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ConnectionException(com.cloud.exception.ConnectionException) DB(com.cloud.utils.db.DB)

Example 73 with DataCenterVO

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

the class VolumeApiServiceImplTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    _svc._volsDao = _volumeDao;
    _svc._accountMgr = _accountMgr;
    _svc._userVmDao = _userVmDao;
    _svc._storagePoolDao = _storagePoolDao;
    _svc._vmSnapshotDao = _vmSnapshotDao;
    _svc._vmInstanceDao = _vmInstanceDao;
    _svc._jobMgr = _jobMgr;
    _svc.volFactory = _volFactory;
    _svc.volService = volService;
    _svc._userVmMgr = _userVmMgr;
    _svc._dcDao = _dcDao;
    _svc._resourceLimitMgr = _resourceLimitMgr;
    _svc._accountDao = _accountDao;
    _svc._hostDao = _hostDao;
    _svc._gson = GsonHelper.getGsonLogger();
    // mock caller context
    AccountVO account = new AccountVO("admin", 1L, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
    AccountVO account2 = new AccountVO("Account2", 2L, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    // mock async context
    AsyncJobExecutionContext context = new AsyncJobExecutionContext();
    AsyncJobExecutionContext.init(_svc._jobMgr, _joinMapDao);
    AsyncJobVO job = new AsyncJobVO();
    context.setJob(job);
    AsyncJobExecutionContext.setCurrentExecutionContext(context);
    TransactionLegacy txn = TransactionLegacy.open("runVolumeDaoImplTest");
    try {
        // volume of running vm id=1
        VolumeVO volumeOfRunningVm = new VolumeVO("root", 1L, 1L, 1L, 1L, 1L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        when(_svc._volsDao.findById(1L)).thenReturn(volumeOfRunningVm);
        UserVmVO runningVm = new UserVmVO(1L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false, false, 1L, 1L, 1, 1L, null, "vm", null);
        runningVm.setState(State.Running);
        runningVm.setDataCenterId(1L);
        when(_svc._userVmDao.findById(1L)).thenReturn(runningVm);
        // volume of stopped vm id=2
        VolumeVO volumeOfStoppedVm = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        volumeOfStoppedVm.setPoolId(1L);
        when(_svc._volsDao.findById(2L)).thenReturn(volumeOfStoppedVm);
        UserVmVO stoppedVm = new UserVmVO(2L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false, false, 1L, 1L, 1, 1L, null, "vm", null);
        stoppedVm.setState(State.Stopped);
        stoppedVm.setDataCenterId(1L);
        when(_svc._userVmDao.findById(2L)).thenReturn(stoppedVm);
        // volume of hyperV vm id=3
        UserVmVO hyperVVm = new UserVmVO(3L, "vm", "vm", 1, HypervisorType.Hyperv, 1L, false, false, 1L, 1L, 1, 1L, null, "vm", null);
        hyperVVm.setState(State.Stopped);
        hyperVVm.setDataCenterId(1L);
        when(_svc._userVmDao.findById(3L)).thenReturn(hyperVVm);
        VolumeVO volumeOfStoppeHyperVVm = new VolumeVO("root", 1L, 1L, 1L, 1L, 3L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        volumeOfStoppeHyperVVm.setPoolId(1L);
        when(_svc._volsDao.findById(3L)).thenReturn(volumeOfStoppeHyperVVm);
        StoragePoolVO unmanagedPool = new StoragePoolVO();
        when(_svc._storagePoolDao.findById(1L)).thenReturn(unmanagedPool);
        // volume of managed pool id=4
        StoragePoolVO managedPool = new StoragePoolVO();
        managedPool.setManaged(true);
        when(_svc._storagePoolDao.findById(2L)).thenReturn(managedPool);
        VolumeVO managedPoolVolume = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        managedPoolVolume.setPoolId(2L);
        when(_svc._volsDao.findById(4L)).thenReturn(managedPoolVolume);
        // non-root non-datadisk volume
        VolumeInfo volumeWithIncorrectVolumeType = Mockito.mock(VolumeInfo.class);
        when(volumeWithIncorrectVolumeType.getId()).thenReturn(5L);
        when(volumeWithIncorrectVolumeType.getVolumeType()).thenReturn(Volume.Type.ISO);
        when(_svc.volFactory.getVolume(5L)).thenReturn(volumeWithIncorrectVolumeType);
        // correct root volume
        VolumeInfo correctRootVolume = Mockito.mock(VolumeInfo.class);
        when(correctRootVolume.getId()).thenReturn(6L);
        when(correctRootVolume.getDataCenterId()).thenReturn(1L);
        when(correctRootVolume.getVolumeType()).thenReturn(Volume.Type.ROOT);
        when(correctRootVolume.getInstanceId()).thenReturn(null);
        when(correctRootVolume.getState()).thenReturn(Volume.State.Ready);
        when(correctRootVolume.getTemplateId()).thenReturn(null);
        when(correctRootVolume.getPoolId()).thenReturn(1L);
        when(_svc.volFactory.getVolume(6L)).thenReturn(correctRootVolume);
        VolumeVO correctRootVolumeVO = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        when(_svc._volsDao.findById(6L)).thenReturn(correctRootVolumeVO);
        // managed root volume
        VolumeInfo managedVolume = Mockito.mock(VolumeInfo.class);
        when(managedVolume.getId()).thenReturn(7L);
        when(managedVolume.getDataCenterId()).thenReturn(1L);
        when(managedVolume.getVolumeType()).thenReturn(Volume.Type.ROOT);
        when(managedVolume.getInstanceId()).thenReturn(null);
        when(managedVolume.getPoolId()).thenReturn(2L);
        when(_svc.volFactory.getVolume(7L)).thenReturn(managedVolume);
        VolumeVO managedVolume1 = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        managedVolume1.setPoolId(2L);
        managedVolume1.setDataCenterId(1L);
        when(_svc._volsDao.findById(7L)).thenReturn(managedVolume1);
        // vm having root volume
        UserVmVO vmHavingRootVolume = new UserVmVO(4L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false, false, 1L, 1L, 1, 1L, null, "vm", null);
        vmHavingRootVolume.setState(State.Stopped);
        vmHavingRootVolume.setDataCenterId(1L);
        when(_svc._userVmDao.findById(4L)).thenReturn(vmHavingRootVolume);
        List<VolumeVO> vols = new ArrayList<VolumeVO>();
        vols.add(new VolumeVO());
        when(_svc._volsDao.findByInstanceAndDeviceId(4L, 0L)).thenReturn(vols);
        // volume in uploaded state
        VolumeInfo uploadedVolume = Mockito.mock(VolumeInfo.class);
        when(uploadedVolume.getId()).thenReturn(8L);
        when(uploadedVolume.getDataCenterId()).thenReturn(1L);
        when(uploadedVolume.getVolumeType()).thenReturn(Volume.Type.ROOT);
        when(uploadedVolume.getInstanceId()).thenReturn(null);
        when(uploadedVolume.getPoolId()).thenReturn(1L);
        when(uploadedVolume.getState()).thenReturn(Volume.State.Uploaded);
        when(_svc.volFactory.getVolume(8L)).thenReturn(uploadedVolume);
        VolumeVO upVolume = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        upVolume.setPoolId(1L);
        upVolume.setDataCenterId(1L);
        upVolume.setState(Volume.State.Uploaded);
        when(_svc._volsDao.findById(8L)).thenReturn(upVolume);
        // helper dao methods mock
        when(_svc._vmSnapshotDao.findByVm(any(Long.class))).thenReturn(new ArrayList<VMSnapshotVO>());
        when(_svc._vmInstanceDao.findById(any(Long.class))).thenReturn(stoppedVm);
        DataCenterVO enabledZone = Mockito.mock(DataCenterVO.class);
        when(enabledZone.getAllocationState()).thenReturn(Grouping.AllocationState.Enabled);
        when(_svc._dcDao.findById(anyLong())).thenReturn(enabledZone);
    } finally {
        txn.close("runVolumeDaoImplTest");
    }
    // helper methods mock
    doNothing().when(_svc._accountMgr).checkAccess(any(Account.class), any(AccessType.class), any(Boolean.class), any(ControlledEntity.class));
    doNothing().when(_svc._jobMgr).updateAsyncJobAttachment(any(Long.class), any(String.class), any(Long.class));
    when(_svc._jobMgr.submitAsyncJob(any(AsyncJobVO.class), any(String.class), any(Long.class))).thenReturn(1L);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) UserVmVO(com.cloud.vm.UserVmVO) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Matchers.anyString(org.mockito.Matchers.anyString) AccountVO(com.cloud.user.AccountVO) AsyncJobVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) UserVO(com.cloud.user.UserVO) ControlledEntity(org.apache.cloudstack.acl.ControlledEntity) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) Matchers.anyLong(org.mockito.Matchers.anyLong) AccessType(org.apache.cloudstack.acl.SecurityChecker.AccessType) Before(org.junit.Before)

Example 74 with DataCenterVO

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

the class UserVmManagerImpl method updateDefaultNicForVirtualMachine.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NIC_UPDATE, eventDescription = "Creating Nic", async = true)
public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) throws InvalidParameterValueException, CloudRuntimeException {
    Long vmId = cmd.getVmId();
    Long nicId = cmd.getNicId();
    Account caller = CallContext.current().getCallingAccount();
    UserVmVO vmInstance = _vmDao.findById(vmId);
    if (vmInstance == null) {
        throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
    }
    // Check that Vm does not have VM Snapshots
    if (_vmSnapshotDao.findByVm(vmId).size() > 0) {
        throw new InvalidParameterValueException("NIC cannot be updated for VM with VM Snapshots");
    }
    NicVO nic = _nicDao.findById(nicId);
    if (nic == null) {
        throw new InvalidParameterValueException("unable to find a nic with id " + nicId);
    }
    NetworkVO network = _networkDao.findById(nic.getNetworkId());
    if (network == null) {
        throw new InvalidParameterValueException("unable to find a network with id " + nic.getNetworkId());
    }
    // Perform permission check on VM
    _accountMgr.checkAccess(caller, null, true, vmInstance);
    // Verify that zone is not Basic
    DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterId());
    if (dc.getNetworkType() == DataCenter.NetworkType.Basic) {
        throw new CloudRuntimeException("Zone " + vmInstance.getDataCenterId() + ", has a NetworkType of Basic. Can't change default NIC on a Basic Network");
    }
    // no need to check permissions for network, we'll enumerate the ones they already have access to
    Network existingdefaultnet = _networkModel.getDefaultNetworkForVm(vmId);
    //check to see if nic is attached to VM
    if (nic.getInstanceId() != vmId) {
        throw new InvalidParameterValueException(nic + " is not a nic on  " + vmInstance);
    }
    // if current default equals chosen new default, Throw an exception
    if (nic.isDefaultNic()) {
        throw new CloudRuntimeException("refusing to set default nic because chosen nic is already the default");
    }
    //make sure the VM is Running or Stopped
    if ((vmInstance.getState() != State.Running) && (vmInstance.getState() != State.Stopped)) {
        throw new CloudRuntimeException("refusing to set default " + vmInstance + " is not Running or Stopped");
    }
    NicProfile existing = null;
    List<NicProfile> nicProfiles = _networkMgr.getNicProfiles(vmInstance);
    for (NicProfile nicProfile : nicProfiles) {
        if (nicProfile.isDefaultNic() && existingdefaultnet != null && nicProfile.getNetworkId() == existingdefaultnet.getId()) {
            existing = nicProfile;
        }
    }
    if (existing == null) {
        s_logger.warn("Failed to update default nic, no nic profile found for existing default network");
        throw new CloudRuntimeException("Failed to find a nic profile for the existing default network. This is bad and probably means some sort of configuration corruption");
    }
    Network oldDefaultNetwork = null;
    oldDefaultNetwork = _networkModel.getDefaultNetworkForVm(vmId);
    String oldNicIdString = Long.toString(_networkModel.getDefaultNic(vmId).getId());
    long oldNetworkOfferingId = -1L;
    if (oldDefaultNetwork != null) {
        oldNetworkOfferingId = oldDefaultNetwork.getNetworkOfferingId();
    }
    NicVO existingVO = _nicDao.findById(existing.id);
    Integer chosenID = nic.getDeviceId();
    Integer existingID = existing.getDeviceId();
    nic.setDefaultNic(true);
    nic.setDeviceId(existingID);
    existingVO.setDefaultNic(false);
    existingVO.setDeviceId(chosenID);
    nic = _nicDao.persist(nic);
    existingVO = _nicDao.persist(existingVO);
    Network newdefault = null;
    newdefault = _networkModel.getDefaultNetworkForVm(vmId);
    if (newdefault == null) {
        nic.setDefaultNic(false);
        nic.setDeviceId(chosenID);
        existingVO.setDefaultNic(true);
        existingVO.setDeviceId(existingID);
        nic = _nicDao.persist(nic);
        _nicDao.persist(existingVO);
        newdefault = _networkModel.getDefaultNetworkForVm(vmId);
        if (newdefault.getId() == existingdefaultnet.getId()) {
            throw new CloudRuntimeException("Setting a default nic failed, and we had no default nic, but we were able to set it back to the original");
        }
        throw new CloudRuntimeException("Failed to change default nic to " + nic + " and now we have no default");
    } else if (newdefault.getId() == nic.getNetworkId()) {
        s_logger.debug("successfully set default network to " + network + " for " + vmInstance);
        String nicIdString = Long.toString(nic.getId());
        long newNetworkOfferingId = network.getNetworkOfferingId();
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(), oldNicIdString, oldNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(), nicIdString, newNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(), nicIdString, newNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(), oldNicIdString, oldNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
        return _vmDao.findById(vmInstance.getId());
    }
    throw new CloudRuntimeException("something strange happened, new default network(" + newdefault.getId() + ") is not null, and is not equal to the network(" + nic.getNetworkId() + ") of the chosen nic");
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ActionEvent(com.cloud.event.ActionEvent)

Example 75 with DataCenterVO

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

the class VmwareDatacenterApiUnitTest method testSetUp.

@Before
public void testSetUp() {
    Mockito.when(_configDao.isPremium()).thenReturn(true);
    ComponentContext.initComponentsLifeCycle();
    MockitoAnnotations.initMocks(this);
    DataCenterVO zone = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
    zoneId = 1L;
    HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), zoneId, "192.168.56.1", "192.168.56.0/24", 8, "test");
    podId = 1L;
    AccountVO acct = new AccountVO(200L);
    acct.setType(Account.ACCOUNT_TYPE_ADMIN);
    acct.setAccountName("admin");
    acct.setDomainId(domainId);
    UserVO user1 = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user1, acct);
    when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
    dc = new VmwareDatacenterVO(guid, vmwareDcName, vCenterHost, user, password);
    vmwareDcs = new ArrayList<VmwareDatacenterVO>();
    vmwareDcs.add(dc);
    vmwareDcId = dc.getId();
    cluster = new ClusterVO(zone.getId(), pod.getId(), "vmwarecluster");
    cluster.setHypervisorType(HypervisorType.VMware.toString());
    cluster.setClusterType(ClusterType.ExternalManaged);
    cluster.setManagedState(ManagedState.Managed);
    clusterId = 1L;
    clusterList = new ArrayList<ClusterVO>();
    clusterList.add(cluster);
    clusterDetails = new ClusterDetailsVO(clusterId, "url", url);
    dcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDcId);
    Mockito.when(_dcDao.persist(Matchers.any(DataCenterVO.class))).thenReturn(zone);
    Mockito.when(_dcDao.findById(1L)).thenReturn(zone);
    Mockito.when(_podDao.persist(Matchers.any(HostPodVO.class))).thenReturn(pod);
    Mockito.when(_podDao.findById(1L)).thenReturn(pod);
    Mockito.when(_clusterDao.persist(Matchers.any(ClusterVO.class))).thenReturn(cluster);
    Mockito.when(_clusterDao.findById(1L)).thenReturn(cluster);
    Mockito.when(_clusterDao.listByZoneId(1L)).thenReturn(null);
    Mockito.when(_clusterDao.expunge(1L)).thenReturn(true);
    Mockito.when(_clusterDetailsDao.persist(Matchers.any(ClusterDetailsVO.class))).thenReturn(clusterDetails);
    Mockito.when(_clusterDetailsDao.expunge(1L)).thenReturn(true);
    Mockito.when(_vmwareDcDao.persist(Matchers.any(VmwareDatacenterVO.class))).thenReturn(dc);
    Mockito.when(_vmwareDcDao.findById(1L)).thenReturn(null);
    Mockito.when(_vmwareDcDao.expunge(1L)).thenReturn(true);
    Mockito.when(_vmwareDcDao.getVmwareDatacenterByNameAndVcenter(vmwareDcName, vCenterHost)).thenReturn(null);
    Mockito.when(_vmwareDcZoneMapDao.persist(Matchers.any(VmwareDatacenterZoneMapVO.class))).thenReturn(dcZoneMap);
    Mockito.when(_vmwareDcZoneMapDao.findByZoneId(1L)).thenReturn(null);
    Mockito.when(_vmwareDcZoneMapDao.expunge(1L)).thenReturn(true);
    Mockito.when(addCmd.getZoneId()).thenReturn(1L);
    Mockito.when(addCmd.getVcenter()).thenReturn(vCenterHost);
    Mockito.when(addCmd.getUsername()).thenReturn(user);
    Mockito.when(addCmd.getPassword()).thenReturn(password);
    Mockito.when(addCmd.getName()).thenReturn(vmwareDcName);
    Mockito.when(removeCmd.getZoneId()).thenReturn(1L);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) UserVO(com.cloud.user.UserVO) HostPodVO(com.cloud.dc.HostPodVO) AccountVO(com.cloud.user.AccountVO) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) Before(org.junit.Before)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)214 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)53 HostVO (com.cloud.host.HostVO)42 Account (com.cloud.user.Account)37 NetworkVO (com.cloud.network.dao.NetworkVO)35 DomainRouterVO (com.cloud.vm.DomainRouterVO)33 HostPodVO (com.cloud.dc.HostPodVO)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 ClusterVO (com.cloud.dc.ClusterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 DB (com.cloud.utils.db.DB)26 Network (com.cloud.network.Network)25 HashMap (java.util.HashMap)25 ConfigurationException (javax.naming.ConfigurationException)25 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)20 Test (org.junit.Test)20 NicProfile (com.cloud.vm.NicProfile)19 ActionEvent (com.cloud.event.ActionEvent)18