use of com.cloud.legacymodel.to.NicTO in project cosmic by MissionCriticalCloud.
the class UserVmManagerImpl method finalizeStart.
@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
final UserVmVO vm = _vmDao.findById(profile.getId());
final Answer[] answersToCmds = cmds.getAnswers();
if (answersToCmds == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Returning from finalizeStart() since there are no answers to read");
}
return true;
}
final Answer startAnswer = cmds.getAnswer(StartAnswer.class);
String returnedIp = null;
String originalIp = null;
if (startAnswer != null) {
final StartAnswer startAns = (StartAnswer) startAnswer;
final VirtualMachineTO vmTO = startAns.getVirtualMachine();
for (final NicTO nicTO : vmTO.getNics()) {
if (nicTO.getType() == TrafficType.Guest) {
returnedIp = nicTO.getIp();
}
}
}
final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
NicVO guestNic = null;
NetworkVO guestNetwork = null;
for (final NicVO nic : nics) {
final NetworkVO network = _networkDao.findById(nic.getNetworkId());
final long isDefault = nic.isDefaultNic() ? 1 : 0;
if (network.getTrafficType() == TrafficType.Guest) {
originalIp = nic.getIPv4Address();
guestNic = nic;
guestNetwork = network;
if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, "pvlan-nic");
if (!setupVmForPvlan(true, hostId, nicProfile)) {
return false;
}
}
}
}
boolean ipChanged = false;
if (originalIp != null && !originalIp.equalsIgnoreCase(returnedIp)) {
if (returnedIp != null && guestNic != null) {
guestNic.setIPv4Address(returnedIp);
ipChanged = true;
}
}
if (returnedIp != null && !returnedIp.equalsIgnoreCase(originalIp)) {
if (guestNic != null) {
guestNic.setIPv4Address(returnedIp);
ipChanged = true;
}
}
// get system ip and create static nat rule for the vm
try {
_rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
} catch (final Exception ex) {
s_logger.warn("Failed to get system ip and enable static nat for the vm " + profile.getVirtualMachine() + " due to exception ", ex);
return false;
}
final Answer answer = cmds.getAnswer("restoreVMSnapshot");
if (answer != null && answer instanceof RestoreVMSnapshotAnswer) {
final RestoreVMSnapshotAnswer restoreVMSnapshotAnswer = (RestoreVMSnapshotAnswer) answer;
if (!restoreVMSnapshotAnswer.getResult()) {
s_logger.warn("Unable to restore the vm snapshot from image file to the VM: " + restoreVMSnapshotAnswer.getDetails());
}
}
return true;
}
use of com.cloud.legacymodel.to.NicTO in project cosmic by MissionCriticalCloud.
the class XenServer610WrapperTest method testMigrateWithStorageReceiveCommand.
@Test
public void testMigrateWithStorageReceiveCommand() {
final String vmName = "small";
final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO vol1 = Mockito.mock(VolumeTO.class);
final VolumeTO vol2 = Mockito.mock(VolumeTO.class);
final StorageFilerTO storage1 = Mockito.mock(StorageFilerTO.class);
final StorageFilerTO storage2 = Mockito.mock(StorageFilerTO.class);
final List<Pair<VolumeTO, StorageFilerTO>> volumeToFiler = new ArrayList<>();
volumeToFiler.add(new Pair<>(vol1, storage1));
volumeToFiler.add(new Pair<>(vol2, storage2));
final NicTO nicTO1 = Mockito.mock(NicTO.class);
final NicTO nicTO2 = Mockito.mock(NicTO.class);
final NicTO nicTO3 = Mockito.mock(NicTO.class);
final NicTO[] nicTOs = { nicTO1, nicTO2, nicTO3 };
final XsLocalNetwork nativeNetworkForTraffic = Mockito.mock(XsLocalNetwork.class);
final Network network = Mockito.mock(Network.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final Network nw1 = Mockito.mock(Network.class);
final Network nw2 = Mockito.mock(Network.class);
final Network nw3 = Mockito.mock(Network.class);
final SR sr1 = Mockito.mock(SR.class);
final SR sr2 = Mockito.mock(SR.class);
final MigrateWithStorageReceiveCommand migrateStorageCommand = new MigrateWithStorageReceiveCommand(vmSpec, volumeToFiler);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(vmSpec.getNics()).thenReturn(nicTOs);
when(storage1.getUuid()).thenReturn(uuid);
when(storage2.getUuid()).thenReturn(uuid);
when(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
try {
when(xenServer610Resource.getNetwork(conn, nicTO1)).thenReturn(nw1);
when(xenServer610Resource.getNetwork(conn, nicTO2)).thenReturn(nw2);
when(xenServer610Resource.getNetwork(conn, nicTO3)).thenReturn(nw3);
when(xenServer610Resource.getNativeNetworkForTraffic(conn, TrafficType.Storage, null)).thenReturn(nativeNetworkForTraffic);
when(nativeNetworkForTraffic.getNetwork()).thenReturn(network);
when(xenServer610Resource.getHost()).thenReturn(xsHost);
when(xsHost.getUuid()).thenReturn(uuid);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
try {
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO1);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO2);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO3);
verify(xenServer610Resource, times(1)).getNativeNetworkForTraffic(conn, TrafficType.Storage, null);
verify(nativeNetworkForTraffic, times(1)).getNetwork();
verify(xenServer610Resource, times(1)).getHost();
verify(xsHost, times(1)).getUuid();
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
assertFalse(answer.getResult());
}
use of com.cloud.legacymodel.to.NicTO in project cosmic by MissionCriticalCloud.
the class XenServer610WrapperTest method testMigrateWithStorageSendCommandNetException.
@Test
public void testMigrateWithStorageSendCommandNetException() {
final String vmName = "small";
final String path = "/";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO volume1 = Mockito.mock(VolumeTO.class);
final VolumeTO volume2 = Mockito.mock(VolumeTO.class);
final SR sr1 = Mockito.mock(SR.class);
final SR sr2 = Mockito.mock(SR.class);
final VDI vdi1 = Mockito.mock(VDI.class);
final VDI vdi2 = Mockito.mock(VDI.class);
final NicTO nic1 = Mockito.mock(NicTO.class);
final NicTO nic2 = Mockito.mock(NicTO.class);
final Gson gson = new Gson();
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
volumeToSr.add(new Pair<>(volume1, sr1));
volumeToSr.add(new Pair<>(volume2, sr2));
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<>();
nicToNetwork.add(new Pair<>(nic1, new String("a")));
nicToNetwork.add(new Pair<>(nic2, new String("b")));
final Map<String, String> token = new HashMap<>();
final MigrateWithStorageSendCommand migrateStorageCommand = new MigrateWithStorageSendCommand(vmSpec, volumeToSr, nicToNetwork, token);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(volume1.getPath()).thenReturn(path);
when(volume2.getPath()).thenReturn(path);
when(xenServer610Resource.getVDIbyUuid(conn, volume1.getPath())).thenReturn(vdi1);
when(xenServer610Resource.getVDIbyUuid(conn, volume2.getPath())).thenReturn(vdi2);
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.legacymodel.to.NicTO in project cosmic by MissionCriticalCloud.
the class XenServer610WrapperTest method testMigrateWithStorageSendCommand.
@Test
public void testMigrateWithStorageSendCommand() {
final String vmName = "small";
final String path = "/";
final String mac = "3c:15:c2:c4:4f:18";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO volume1 = Mockito.mock(VolumeTO.class);
final VolumeTO volume2 = Mockito.mock(VolumeTO.class);
final SR sr1 = Mockito.mock(SR.class);
final SR sr2 = Mockito.mock(SR.class);
final VDI vdi1 = Mockito.mock(VDI.class);
final VDI vdi2 = Mockito.mock(VDI.class);
final NicTO nic1 = Mockito.mock(NicTO.class);
final NicTO nic2 = Mockito.mock(NicTO.class);
final Network network1 = Mockito.mock(Network.class);
final Network network2 = Mockito.mock(Network.class);
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
volumeToSr.add(new Pair<>(volume1, sr1));
volumeToSr.add(new Pair<>(volume2, sr2));
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<>();
nicToNetwork.add(new Pair<>(nic1, network1));
nicToNetwork.add(new Pair<>(nic2, network2));
final Map<String, String> token = new HashMap<>();
final VIF vif1 = Mockito.mock(VIF.class);
final VIF vif2 = Mockito.mock(VIF.class);
final MigrateWithStorageSendCommand migrateStorageCommand = new MigrateWithStorageSendCommand(vmSpec, volumeToSr, nicToNetwork, token);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(volume1.getPath()).thenReturn(path);
when(volume2.getPath()).thenReturn(path);
when(nic1.getMac()).thenReturn(mac);
when(nic2.getMac()).thenReturn(mac);
when(xenServer610Resource.getVDIbyUuid(conn, volume1.getPath())).thenReturn(vdi1);
when(xenServer610Resource.getVDIbyUuid(conn, volume2.getPath())).thenReturn(vdi2);
try {
when(xenServer610Resource.getVifByMac(conn, null, nic1.getMac())).thenReturn(vif1);
when(xenServer610Resource.getVifByMac(conn, null, nic2.getMac())).thenReturn(vif2);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
try {
verify(xenServer610Resource, times(2)).getVDIbyUuid(conn, volume1.getPath());
verify(xenServer610Resource, times(2)).getVifByMac(conn, null, nic1.getMac());
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
assertFalse(answer.getResult());
}
use of com.cloud.legacymodel.to.NicTO in project cosmic by MissionCriticalCloud.
the class XenServer610WrapperTest method testMigrateWithStorageCommand.
@Test
public void testMigrateWithStorageCommand() {
final String vmName = "small";
final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
final String path = "/";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO vol1 = Mockito.mock(VolumeTO.class);
final VolumeTO vol2 = Mockito.mock(VolumeTO.class);
final StorageFilerTO storage1 = Mockito.mock(StorageFilerTO.class);
final StorageFilerTO storage2 = Mockito.mock(StorageFilerTO.class);
final Map<VolumeTO, StorageFilerTO> volumeToFiler = new HashMap<>();
volumeToFiler.put(vol1, storage1);
volumeToFiler.put(vol2, storage2);
final NicTO nicTO1 = Mockito.mock(NicTO.class);
final NicTO nicTO2 = Mockito.mock(NicTO.class);
final NicTO nicTO3 = Mockito.mock(NicTO.class);
final NicTO[] nicTOs = { nicTO1, nicTO2, nicTO3 };
final XsLocalNetwork nativeNetworkForTraffic = Mockito.mock(XsLocalNetwork.class);
final Network networkForSm = Mockito.mock(Network.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final SR sr1 = Mockito.mock(SR.class);
final SR sr2 = Mockito.mock(SR.class);
final VDI vdi1 = Mockito.mock(VDI.class);
final VDI vdi2 = Mockito.mock(VDI.class);
final MigrateWithStorageCommand migrateStorageCommand = new MigrateWithStorageCommand(vmSpec, volumeToFiler);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(vmSpec.getNics()).thenReturn(nicTOs);
when(storage1.getUuid()).thenReturn(uuid);
when(storage2.getUuid()).thenReturn(uuid);
when(vol1.getPath()).thenReturn(path);
when(vol2.getPath()).thenReturn(path);
when(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
when(xenServer610Resource.getVDIbyUuid(conn, storage1.getPath())).thenReturn(vdi1);
when(xenServer610Resource.getVDIbyUuid(conn, storage2.getPath())).thenReturn(vdi2);
try {
when(xenServer610Resource.getNativeNetworkForTraffic(conn, TrafficType.Storage, null)).thenReturn(nativeNetworkForTraffic);
when(nativeNetworkForTraffic.getNetwork()).thenReturn(networkForSm);
when(xenServer610Resource.getHost()).thenReturn(xsHost);
when(xsHost.getUuid()).thenReturn(uuid);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
try {
verify(xenServer610Resource, times(1)).prepareISO(conn, vmName, null, null);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO1);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO2);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO3);
verify(xenServer610Resource, times(1)).getNativeNetworkForTraffic(conn, TrafficType.Storage, null);
verify(nativeNetworkForTraffic, times(1)).getNetwork();
verify(xenServer610Resource, times(1)).getHost();
verify(xsHost, times(1)).getUuid();
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
assertFalse(answer.getResult());
}
Aggregations