use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.
the class DestroySystemVmCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Vm Id: " + getId());
VirtualMachine instance = _mgr.destroySystemVM(this);
if (instance != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to destroy system vm");
}
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class ExplicitDedicationProcessor method process.
/**
* This method will process the affinity group of type 'Explicit Dedication' for a deployment of a VM that demands dedicated resources.
* For ExplicitDedicationProcessor we need to add dedicated resources into the IncludeList based on the level we have dedicated resources available.
* For eg. if admin dedicates a pod to a domain, then all the user in that domain can use the resources of that pod.
* We need to take care of the situation when dedicated resources further have resources dedicated to sub-domain/account.
* This IncludeList is then used to update the avoid list for a given data center.
*/
@Override
public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException {
VirtualMachine vm = vmProfile.getVirtualMachine();
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
DataCenter dc = _dcDao.findById(vm.getDataCenterId());
List<DedicatedResourceVO> resourceList = new ArrayList<DedicatedResourceVO>();
if (vmGroupMappings != null && !vmGroupMappings.isEmpty()) {
for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
if (vmGroupMapping != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + "of type 'ExplicitDedication' for VM Id: " + vm.getId());
}
long affinityGroupId = vmGroupMapping.getAffinityGroupId();
List<DedicatedResourceVO> dr = _dedicatedDao.listByAffinityGroupId(affinityGroupId);
resourceList.addAll(dr);
}
}
boolean canUse = false;
if (plan.getHostId() != null) {
HostVO host = _hostDao.findById(plan.getHostId());
ClusterVO clusterofHost = _clusterDao.findById(host.getClusterId());
HostPodVO podOfHost = _podDao.findById(host.getPodId());
DataCenterVO zoneOfHost = _dcDao.findById(host.getDataCenterId());
if (resourceList != null && resourceList.size() != 0) {
for (DedicatedResourceVO resource : resourceList) {
if ((resource.getHostId() != null && resource.getHostId().longValue() == plan.getHostId().longValue()) || (resource.getClusterId() != null && resource.getClusterId().longValue() == clusterofHost.getId()) || (resource.getPodId() != null && resource.getPodId().longValue() == podOfHost.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId().longValue() == zoneOfHost.getId())) {
canUse = true;
}
}
}
if (!canUse) {
throw new CloudRuntimeException("Cannot use this host " + host.getName() + " for explicit dedication");
}
} else if (plan.getClusterId() != null) {
ClusterVO cluster = _clusterDao.findById(plan.getClusterId());
HostPodVO podOfCluster = _podDao.findById(cluster.getPodId());
DataCenterVO zoneOfCluster = _dcDao.findById(cluster.getDataCenterId());
List<HostVO> hostToUse = new ArrayList<HostVO>();
// check whether this cluster or its pod is dedicated
if (resourceList != null && resourceList.size() != 0) {
for (DedicatedResourceVO resource : resourceList) {
if ((resource.getClusterId() != null && resource.getClusterId() == cluster.getId()) || (resource.getPodId() != null && resource.getPodId() == podOfCluster.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfCluster.getId())) {
canUse = true;
}
// cluster
if (!canUse) {
if (resource.getHostId() != null) {
HostVO dHost = _hostDao.findById(resource.getHostId());
if (dHost.getClusterId() == cluster.getId()) {
hostToUse.add(dHost);
}
}
}
}
}
if (hostToUse.isEmpty() && !canUse) {
throw new CloudRuntimeException("Cannot use this cluster " + cluster.getName() + " for explicit dedication");
}
if (hostToUse != null && hostToUse.size() != 0) {
// add other non-dedicated hosts to avoid list
List<HostVO> hostList = _hostDao.findByClusterId(cluster.getId());
for (HostVO host : hostList) {
if (!hostToUse.contains(host)) {
avoid.addHost(host.getId());
}
}
}
} else if (plan.getPodId() != null) {
HostPodVO pod = _podDao.findById(plan.getPodId());
DataCenterVO zoneOfPod = _dcDao.findById(pod.getDataCenterId());
List<ClusterVO> clustersToUse = new ArrayList<ClusterVO>();
List<HostVO> hostsToUse = new ArrayList<HostVO>();
// check whether this cluster or its pod is dedicated
if (resourceList != null && resourceList.size() != 0) {
for (DedicatedResourceVO resource : resourceList) {
if ((resource.getPodId() != null && resource.getPodId() == pod.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfPod.getId())) {
canUse = true;
}
// this pod
if (!canUse) {
if (resource.getClusterId() != null) {
ClusterVO dCluster = _clusterDao.findById(resource.getClusterId());
if (dCluster.getPodId() == pod.getId()) {
clustersToUse.add(dCluster);
}
}
if (resource.getHostId() != null) {
HostVO dHost = _hostDao.findById(resource.getHostId());
if (dHost.getPodId() == pod.getId()) {
hostsToUse.add(dHost);
}
}
}
}
}
if (hostsToUse.isEmpty() && clustersToUse.isEmpty() && !canUse) {
throw new CloudRuntimeException("Cannot use this pod " + pod.getName() + " for explicit dedication");
}
if (clustersToUse != null && clustersToUse.size() != 0) {
// add other non-dedicated clusters to avoid list
List<ClusterVO> clusterList = _clusterDao.listByPodId(pod.getId());
for (ClusterVO cluster : clusterList) {
if (!clustersToUse.contains(cluster)) {
avoid.addCluster(cluster.getId());
}
}
}
if (hostsToUse != null && hostsToUse.size() != 0) {
// add other non-dedicated hosts to avoid list
List<HostVO> hostList = _hostDao.findByPodId(pod.getId());
for (HostVO host : hostList) {
if (!hostsToUse.contains(host)) {
avoid.addHost(host.getId());
}
}
}
} else {
// check all resources under this zone
if (resourceList != null && resourceList.size() != 0) {
avoid = updateAvoidList(resourceList, avoid, dc);
} else {
avoid.addDataCenter(dc.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("No dedicated resources available for this domain or account under this group");
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " + avoid.getPodsToAvoid() + ", clusters: " + avoid.getClustersToAvoid() + ", hosts: " + avoid.getHostsToAvoid());
}
}
}
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class HostAntiAffinityProcessor method check.
@Override
public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedDestination) throws AffinityConflictException {
if (plannedDestination.getHost() == null) {
return true;
}
long plannedHostId = plannedDestination.getHost().getId();
VirtualMachine vm = vmProfile.getVirtualMachine();
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
// if more than 1 VM's are present in the group then check for
// conflict due to parallel deployment
List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(vmGroupMapping.getAffinityGroupId());
groupVMIds.remove(vm.getId());
for (Long groupVMId : groupVMIds) {
VMReservationVO vmReservation = _reservationDao.findByVmId(groupVMId);
if (vmReservation != null && vmReservation.getHostId() != null && vmReservation.getHostId().equals(plannedHostId)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + " reserved on the same host " + plannedHostId);
}
return false;
}
}
}
return true;
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class LibvirtComputingResourceTest method testFenceCommand.
@Test
public void testFenceCommand() {
final VirtualMachine vm = Mockito.mock(VirtualMachine.class);
;
final com.cloud.host.Host host = Mockito.mock(com.cloud.host.Host.class);
final FenceCommand command = new FenceCommand(vm, host);
final KVMHAMonitor monitor = Mockito.mock(KVMHAMonitor.class);
final NfsStoragePool storagePool = Mockito.mock(NfsStoragePool.class);
final List<NfsStoragePool> pools = new ArrayList<NfsStoragePool>();
pools.add(storagePool);
when(libvirtComputingResource.getMonitor()).thenReturn(monitor);
when(monitor.getStoragePools()).thenReturn(pools);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getMonitor();
verify(monitor, times(1)).getStoragePools();
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class NuageVspGuestNetworkGuruTest method testReserve.
@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, URISyntaxException {
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getDomainId()).thenReturn(NETWORK_ID);
when(network.getAccountId()).thenReturn(NETWORK_ID);
when(network.getVpcId()).thenReturn(null);
when(network.getBroadcastUri()).thenReturn(new URI("vsp://aaaaaa-aavvv/10.1.1.1"));
final DataCenterVO dataCenter = mock(DataCenterVO.class);
when(_dataCenterDao.findById(NETWORK_ID)).thenReturn(dataCenter);
final AccountVO networksAccount = mock(AccountVO.class);
when(networksAccount.getId()).thenReturn(NETWORK_ID);
when(networksAccount.getUuid()).thenReturn("aaaa-abbbb");
when(networksAccount.getType()).thenReturn(Account.ACCOUNT_TYPE_NORMAL);
when(_accountDao.findById(NETWORK_ID)).thenReturn(networksAccount);
final DomainVO networksDomain = mock(DomainVO.class);
when(networksDomain.getId()).thenReturn(NETWORK_ID);
when(networksDomain.getUuid()).thenReturn("aaaaa-bbbbb");
when(_domainDao.findById(NETWORK_ID)).thenReturn(networksDomain);
final NicVO nicvo = mock(NicVO.class);
when(nicvo.getId()).thenReturn(NETWORK_ID);
when(nicvo.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
when(nicvo.getUuid()).thenReturn("aaaa-fffff");
when(nicvo.getNetworkId()).thenReturn(NETWORK_ID);
when(nicvo.getInstanceId()).thenReturn(NETWORK_ID);
when(_nicDao.findById(NETWORK_ID)).thenReturn(nicvo);
when(_nicDao.findDefaultNicForVM(NETWORK_ID)).thenReturn(nicvo);
final VirtualMachine vm = mock(VirtualMachine.class);
when(vm.getId()).thenReturn(NETWORK_ID);
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
when(vmProfile.getType()).thenReturn(VirtualMachine.Type.User);
when(vmProfile.getInstanceName()).thenReturn("");
when(vmProfile.getUuid()).thenReturn("aaaa-bbbbb");
when(vmProfile.getVirtualMachine()).thenReturn(vm);
NicProfile nicProfile = mock(NicProfile.class);
when(nicProfile.getUuid()).thenReturn("aaa-bbbb");
when(nicProfile.getId()).thenReturn(NETWORK_ID);
when(nicProfile.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
final NetworkOfferingVO ntwkoffering = mock(NetworkOfferingVO.class);
when(ntwkoffering.getId()).thenReturn(NETWORK_ID);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffering);
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(_ipAddressDao.findByVmIdAndNetworkId(NETWORK_ID, NETWORK_ID)).thenReturn(null);
when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
final ReservationContext reservationContext = mock(ReservationContext.class);
when(reservationContext.getAccount()).thenReturn(networksAccount);
when(reservationContext.getDomain()).thenReturn(networksDomain);
_nuageVspGuestNetworkGuru.reserve(nicProfile, network, vmProfile, mock(DeployDestination.class), reservationContext);
}
Aggregations