use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.
the class StartSystemVMCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Vm Id: " + getId());
VirtualMachine instance = _mgr.startSystemVM(getId());
if (instance != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to start system vm");
}
}
use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.
the class StopSystemVmCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
UserContext.current().setEventDetails("Vm Id: " + getId());
VirtualMachine result = _mgr.stopSystemVM(this);
if (result != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to stop system vm");
}
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class NuageVspGuestNetworkGuruTest method testDeallocate.
@Test
public void testDeallocate() throws Exception {
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getVpcId()).thenReturn(null);
when(network.getDomainId()).thenReturn(NETWORK_ID);
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
final NetworkOfferingVO offering = mock(NetworkOfferingVO.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(offering);
final DomainVO domain = mock(DomainVO.class);
when(domain.getUuid()).thenReturn("aaaaaa");
when(_domainDao.findById(NETWORK_ID)).thenReturn(domain);
final NicVO nic = mock(NicVO.class);
when(nic.getId()).thenReturn(NETWORK_ID);
when(nic.getIPv4Address()).thenReturn("10.10.10.10");
when(nic.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
when(_nicDao.findById(NETWORK_ID)).thenReturn(nic);
final NicProfile nicProfile = mock(NicProfile.class);
when(nicProfile.getId()).thenReturn(NETWORK_ID);
when(nicProfile.getIPv4Address()).thenReturn("10.10.10.10");
when(nicProfile.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
final VirtualMachine vm = mock(VirtualMachine.class);
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
when(vm.getState()).thenReturn(VirtualMachine.State.Expunging);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
when(vmProfile.getUuid()).thenReturn("aaaaaa");
when(vmProfile.getInstanceName()).thenReturn("Test-VM");
when(vmProfile.getVirtualMachine()).thenReturn(vm);
_nuageVspGuestNetworkGuru.deallocate(network, nicProfile, vmProfile);
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class BareMetalPlanner method plan.
@Override
public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
VirtualMachine vm = vmProfile.getVirtualMachine();
ServiceOffering offering = vmProfile.getServiceOffering();
String hostTag = null;
String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if (vm.getLastHostId() != null && haVmTag == null) {
HostVO h = _hostDao.findById(vm.getLastHostId());
DataCenter dc = _dcDao.findById(h.getDataCenterId());
Pod pod = _podDao.findById(h.getPodId());
Cluster c = _clusterDao.findById(h.getClusterId());
s_logger.debug("Start baremetal vm " + vm.getId() + " on last stayed host " + h.getId());
return new DeployDestination(dc, pod, c, h);
}
if (haVmTag != null) {
hostTag = haVmTag;
} else if (offering.getHostTag() != null) {
String[] tags = offering.getHostTag().split(",");
if (tags.length > 0) {
hostTag = tags[0];
}
}
List<ClusterVO> clusters = _clusterDao.listByDcHyType(vm.getDataCenterId(), HypervisorType.BareMetal.toString());
int cpu_requested;
long ram_requested;
HostVO target = null;
List<HostVO> hosts;
for (ClusterVO cluster : clusters) {
hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
if (hostTag != null) {
for (HostVO h : hosts) {
_hostDao.loadDetails(h);
if (h.getDetail("hostTag") != null && h.getDetail("hostTag").equalsIgnoreCase(hostTag)) {
target = h;
break;
}
}
}
}
if (target == null) {
s_logger.warn("Cannot find host with tag " + hostTag + " use capacity from service offering");
cpu_requested = offering.getCpu() * offering.getSpeed();
ram_requested = offering.getRamSize() * 1024L * 1024L;
} else {
cpu_requested = target.getCpus() * target.getSpeed().intValue();
ram_requested = target.getTotalMemory();
}
for (ClusterVO cluster : clusters) {
if (haVmTag == null) {
hosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
} else {
s_logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + cluster.getDataCenterId());
return null;
}
for (HostVO h : hosts) {
long cluster_id = h.getClusterId();
ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id, "cpuOvercommitRatio");
ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id, "memoryOvercommitRatio");
Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
if (_capacityMgr.checkIfHostHasCapacity(h.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true)) {
s_logger.debug("Find host " + h.getId() + " has enough capacity");
DataCenter dc = _dcDao.findById(h.getDataCenterId());
Pod pod = _podDao.findById(h.getPodId());
return new DeployDestination(dc, pod, cluster, h);
}
}
}
s_logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, ram_requested));
return null;
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class DeploymentPlanningManagerImpl method finalizeReservation.
@DB
@Override
public String finalizeReservation(final DeployDestination plannedDestination, final VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids, final DeploymentPlanner planner) throws InsufficientServerCapacityException, AffinityConflictException {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
return Transaction.execute(new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
boolean saveReservation = true;
if (vmGroupCount > 0) {
List<Long> groupIds = _affinityGroupVMMapDao.listAffinityGroupIdsByVmId(vm.getId());
SearchCriteria<AffinityGroupVO> criteria = _affinityGroupDao.createSearchCriteria();
criteria.addAnd("id", SearchCriteria.Op.IN, groupIds.toArray(new Object[groupIds.size()]));
_affinityGroupDao.lockRows(criteria, null, true);
for (AffinityGroupProcessor processor : _affinityProcessors) {
if (!processor.check(vmProfile, plannedDestination)) {
saveReservation = false;
break;
}
}
}
if (saveReservation) {
VMReservationVO vmReservation = new VMReservationVO(vm.getId(), plannedDestination.getDataCenter().getId(), plannedDestination.getPod().getId(), plannedDestination.getCluster().getId(), plannedDestination.getHost().getId());
if (planner != null) {
vmReservation.setDeploymentPlanner(planner.getName());
}
Map<Long, Long> volumeReservationMap = new HashMap<Long, Long>();
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
for (Volume vo : plannedDestination.getStorageForDisks().keySet()) {
volumeReservationMap.put(vo.getId(), plannedDestination.getStorageForDisks().get(vo).getId());
}
vmReservation.setVolumeReservation(volumeReservationMap);
}
_reservationDao.persist(vmReservation);
return vmReservation.getUuid();
}
return null;
}
});
}
Aggregations