use of com.cloud.vm.UserVmVO in project cloudstack by apache.
the class OvsNetworkTopologyGuruImpl method getActiveVmsInNetworkOnHost.
/**
* get the list of all Vm id's in the network that are running on the host
*/
@Override
public List<Long> getActiveVmsInNetworkOnHost(long networkId, long hostId, boolean includeVr) {
List<Long> vmIds = new ArrayList<>();
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Running, VirtualMachine.State.Migrating);
// Find routers for the network
List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
if (vms != null) {
for (UserVmVO vm : vms) {
if (vm.getHostId() == hostId)
vmIds.add(vm.getId());
}
}
if (routers.size() != 0 && includeVr) {
for (DomainRouterVO router : routers) {
if (router.getHostId() == hostId)
vmIds.add(router.getId());
}
}
return vmIds;
}
use of com.cloud.vm.UserVmVO in project cloudstack by apache.
the class OvsNetworkTopologyGuruImpl method getAllActiveVmsInNetwork.
/**
* get the list of all active Vm id's in a network
*/
@Override
public List<Long> getAllActiveVmsInNetwork(long networkId) {
List<Long> vmIds = new ArrayList<>();
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Running, VirtualMachine.State.Starting, VirtualMachine.State.Stopping, VirtualMachine.State.Unknown, VirtualMachine.State.Migrating);
// Find routers for the network
List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
if (vms != null) {
for (UserVmVO vm : vms) {
vmIds.add(vm.getId());
}
}
if (routers.size() != 0) {
for (DomainRouterVO router : routers) {
vmIds.add(router.getId());
}
}
return vmIds;
}
use of com.cloud.vm.UserVmVO in project cloudstack by apache.
the class OvsNetworkTopologyGuruImpl method getNetworkSpanedHosts.
/**
* get the list of hypervisor hosts on which VM's belonging to a network currently spans
*/
public List<Long> getNetworkSpanedHosts(long networkId) {
List<Long> hostIds = new ArrayList<Long>();
// Find active VMs with a NIC on the target network
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Running, VirtualMachine.State.Starting, VirtualMachine.State.Stopping, VirtualMachine.State.Unknown, VirtualMachine.State.Migrating);
// Find routers for the network
List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
List<VMInstanceVO> ins = new ArrayList<VMInstanceVO>();
if (vms != null) {
ins.addAll(vms);
}
if (routers.size() != 0) {
ins.addAll(routers);
}
for (VMInstanceVO v : ins) {
Long rh = v.getHostId();
if (rh == null) {
continue;
}
if (!hostIds.contains(rh)) {
hostIds.add(rh);
}
}
return hostIds;
}
use of com.cloud.vm.UserVmVO in project cloudstack by apache.
the class CloudZonesNetworkElement method addPasswordAndUserdata.
@Override
public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(dest, network.getTrafficType())) {
if (vm.getType() != VirtualMachine.Type.User) {
return false;
}
@SuppressWarnings("unchecked") UserVmVO uservm = _userVmDao.findById(vm.getId());
_userVmDao.loadDetails(uservm);
String password = (String) vm.getParameter(VirtualMachineProfile.Param.VmPassword);
String userData = uservm.getUserData();
String sshPublicKey = uservm.getDetail("SSH.PublicKey");
Commands cmds = new Commands(Command.OnError.Continue);
if (password != null && nic.isDefaultNic()) {
SavePasswordCommand cmd = new SavePasswordCommand(password, nic.getIPv4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd());
cmds.addCommand("password", cmd);
}
String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(uservm.getServiceOfferingId()).getDisplayText();
String zoneName = _dcDao.findById(network.getDataCenterId()).getName();
cmds.addCommand("vmdata", generateVmDataCommand(nic.getIPv4Address(), userData, serviceOffering, zoneName, nic.getIPv4Address(), uservm.getHostName(), uservm.getInstanceName(), uservm.getId(), uservm.getUuid(), sshPublicKey));
try {
_agentManager.send(dest.getHost().getId(), cmds);
} catch (OperationTimedoutException e) {
s_logger.debug("Unable to send vm data command to host " + dest.getHost());
return false;
}
Answer dataAnswer = cmds.getAnswer("vmdata");
if (dataAnswer != null && dataAnswer.getResult()) {
s_logger.info("Sent vm data successfully to vm " + uservm.getInstanceName());
return true;
}
s_logger.info("Failed to send vm data to vm " + uservm.getInstanceName());
return false;
}
return false;
}
use of com.cloud.vm.UserVmVO in project cloudstack by apache.
the class VMSnapshotStrategyTest method testRevertSnapshot.
@Test
public void testRevertSnapshot() throws AgentUnavailableException, OperationTimedoutException {
Long hostId = 1L;
Long vmId = 1L;
Long guestOsId = 1L;
HypervisorType hypervisorType = HypervisorType.Any;
String hypervisorVersion = "default";
String guestOsName = "Other";
List<VolumeObjectTO> volumeObjectTOs = new ArrayList<VolumeObjectTO>();
VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
UserVmVO userVmVO = Mockito.mock(UserVmVO.class);
Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId);
Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId);
Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId);
Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs);
Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO);
GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class);
Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName);
Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO);
Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO);
VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class);
Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO);
Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot);
Mockito.when(vmSnapshot.getId()).thenReturn(1L);
Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date());
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
HostVO hostVO = Mockito.mock(HostVO.class);
Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO);
Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType);
Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion);
Exception e = null;
try {
vmSnapshotStrategy.revertVMSnapshot(vmSnapshot);
} catch (CloudRuntimeException e1) {
e = e1;
}
assertNotNull(e);
RevertToVMSnapshotAnswer answer = Mockito.mock(RevertToVMSnapshotAnswer.class);
Mockito.when(answer.getResult()).thenReturn(Boolean.TRUE);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer);
boolean result = vmSnapshotStrategy.revertVMSnapshot(vmSnapshot);
assertTrue(result);
}
Aggregations