use of com.cloud.model.enumeration.VirtualMachineType in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPlugNicCommandMatchMack.
@Test
public void testPlugNicCommandMatchMack() {
final NicTO nic = Mockito.mock(NicTO.class);
final String instanceName = "Test";
final VirtualMachineType vmtype = VirtualMachineType.DomainRouter;
final PlugNicCommand command = new PlugNicCommand(nic, instanceName, vmtype);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final Domain vm = Mockito.mock(Domain.class);
final List<InterfaceDef> nics = new ArrayList<>();
final InterfaceDef intDef = Mockito.mock(InterfaceDef.class);
nics.add(intDef);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(this.libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
when(intDef.getDevName()).thenReturn("eth0");
when(intDef.getBrName()).thenReturn("br0");
when(intDef.getMacAddress()).thenReturn("00:00:00:00");
when(nic.getMac()).thenReturn("00:00:00:00");
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
when(this.libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
verify(this.libvirtComputingResource, times(1)).getDomain(conn, instanceName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.model.enumeration.VirtualMachineType in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPlugNicCommandInternalError.
@Test
public void testPlugNicCommandInternalError() {
final NicTO nic = Mockito.mock(NicTO.class);
final String instanceName = "Test";
final VirtualMachineType vmtype = VirtualMachineType.DomainRouter;
final PlugNicCommand command = new PlugNicCommand(nic, instanceName, vmtype);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final Domain vm = Mockito.mock(Domain.class);
final VifDriver vifDriver = Mockito.mock(VifDriver.class);
final List<InterfaceDef> nics = new ArrayList<>();
final InterfaceDef intDef = Mockito.mock(InterfaceDef.class);
nics.add(intDef);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(this.libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
when(intDef.getDevName()).thenReturn("eth0");
when(intDef.getBrName()).thenReturn("br0");
when(intDef.getMacAddress()).thenReturn("00:00:00:00");
when(nic.getMac()).thenReturn("00:00:00:01");
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
when(this.libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
when(this.libvirtComputingResource.getVifDriver(nic.getType())).thenReturn(vifDriver);
when(vifDriver.plug(nic, "Default - VirtIO capable OS (64-bit)", "")).thenThrow(InternalErrorException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
verify(this.libvirtComputingResource, times(1)).getDomain(conn, instanceName);
verify(this.libvirtComputingResource, times(1)).getVifDriver(nic.getType());
verify(vifDriver, times(1)).plug(nic, "Default - VirtIO capable OS (64-bit)", "");
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
fail(e.getMessage());
}
}
use of com.cloud.model.enumeration.VirtualMachineType in project cosmic by MissionCriticalCloud.
the class GuestNetworkGuru method allocate.
@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
assert network.getTrafficType() == TrafficType.Guest : "Look at my name! Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
if (nic == null) {
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
}
final Zone zone = zoneRepository.findById(network.getDataCenterId()).orElse(null);
if (nic.getIPv4Address() == null && !GuestType.Sync.equals(network.getGuestType())) {
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
nic.setIPv4Gateway(network.getGateway());
String guestIp;
if (network.getSpecifyIpRanges()) {
_ipAddrMgr.allocateDirectIp(nic, zone, vm, network, nic.getRequestedIPv4(), null);
} else {
final VirtualMachineType vmtype = vm.getVirtualMachine().getType();
switch(vmtype) {
case User:
guestIp = assignGuestOrGatewayIp(network, nic, vm, zone);
break;
case DomainRouter:
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Gateway, Provider.VPCVirtualRouter)) {
// Networks that support the Gateway service acquire the gateway ip on their nic
guestIp = network.getGateway();
} else {
// In other cases, acquire an ip address from the DHCP range (take lowest possible)
guestIp = _ipAddrMgr.acquireGuestIpAddressForRouter(network, nic.getRequestedIPv4());
}
break;
default:
// Backwards compatibility
guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
break;
}
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP" + " address for network " + network, DataCenter.class, zone.getId());
}
nic.setIPv4Address(guestIp);
nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
if (network.getDns1() != null && network.getDns1().equals("")) {
nic.setIPv4Dns1(null);
} else {
nic.setIPv4Dns1(network.getDns1());
}
if (network.getDns2() != null && network.getDns2().equals("")) {
nic.setIPv4Dns2(null);
} else {
nic.setIPv4Dns2(network.getDns2());
}
nic.setFormat(IpAddressFormat.Ip4);
}
}
nic.setReservationStrategy(ReservationStrategy.Start);
if (nic.getMacAddress() == null) {
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
if (nic.getMacAddress() == null) {
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
}
}
return nic;
}
use of com.cloud.model.enumeration.VirtualMachineType in project cosmic by MissionCriticalCloud.
the class UserVmDaoImpl method getVmsDetailByNames.
@Override
public List<Pair<Pair<String, VirtualMachineType>, Pair<Long, String>>> getVmsDetailByNames(final Set<String> vmNames, final String detail) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
final List<Pair<Pair<String, VirtualMachineType>, Pair<Long, String>>> vmsDetailByNames = new ArrayList<>();
try (PreparedStatement pstmt = txn.prepareStatement(VMS_DETAIL_BY_NAME + getQueryBatchAppender(vmNames.size()))) {
pstmt.setString(1, detail);
int i = 2;
for (final String name : vmNames) {
pstmt.setString(i, name);
i++;
}
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
vmsDetailByNames.add(new Pair<>(new Pair<>(rs.getString("vm_instance.instance_name"), VirtualMachineType.valueOf(rs.getString("vm_type"))), new Pair<>(rs.getLong("vm_instance.id"), rs.getString("user_vm_details.value"))));
}
}
} catch (final SQLException e) {
s_logger.error("GetVmsDetailsByNames: Exception in sql: " + e.getMessage());
throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage());
}
return vmsDetailByNames;
}
use of com.cloud.model.enumeration.VirtualMachineType in project cosmic by MissionCriticalCloud.
the class RecreatableFencer method fenceOff.
@Override
public Boolean fenceOff(final VirtualMachine vm, final Host host) {
final VirtualMachineType type = vm.getType();
if (type != VirtualMachineType.ConsoleProxy && type != VirtualMachineType.DomainRouter && type != VirtualMachineType.SecondaryStorageVm) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Don't know how to fence off " + type);
}
return null;
}
final List<VolumeVO> vols = _volsDao.findByInstance(vm.getId());
for (final VolumeVO vol : vols) {
if (!vol.isRecreatable()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to fence off volumes that are not recreatable: " + vol);
}
return null;
}
if (vol.getPoolType().isShared()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to fence off volumes that are shared: " + vol);
}
return null;
}
}
return true;
}
Aggregations