use of com.cloud.legacymodel.communication.answer.PlugNicAnswer in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method plugNic.
public boolean plugNic(final Network network, final NicTO nic, final VirtualMachineTO vm, final ReservationContext context, final DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
boolean result = true;
final VMInstanceVO router = _vmDao.findById(vm.getId());
if (router.getState() == State.Running) {
try {
final PlugNicCommand plugNicCmd = new PlugNicCommand(nic, vm.getName(), vm.getType(), vm.getDetails());
final Commands cmds = new Commands(Command.OnError.Stop);
cmds.addCommand("plugnic", plugNicCmd);
_agentMgr.send(dest.getHost().getId(), cmds);
final PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class);
if (!(plugNicAnswer != null && plugNicAnswer.getResult())) {
s_logger.warn("Unable to plug nic for vm " + vm.getName());
result = false;
}
} catch (final OperationTimedoutException e) {
throw new AgentUnavailableException("Unable to plug nic for router " + vm.getName() + " in network " + network, dest.getHost().getId(), e);
}
} else {
s_logger.warn("Unable to apply PlugNic, vm " + router + " is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply PlugNic on the backend," + " vm " + vm + " is not in the right state", DataCenter.class, router.getDataCenterId());
}
return result;
}
use of com.cloud.legacymodel.communication.answer.PlugNicAnswer in project cosmic by MissionCriticalCloud.
the class LibvirtPlugNicCommandWrapper method execute.
@Override
public Answer execute(final PlugNicCommand command, final LibvirtComputingResource libvirtComputingResource) {
final NicTO nic = command.getNic();
final String vmName = command.getVmName();
Domain vm = null;
try {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName);
vm = libvirtComputingResource.getDomain(conn, vmName);
final List<LibvirtVmDef.InterfaceDef> pluggedNics = libvirtComputingResource.getInterfaces(conn, vmName);
Integer nicnum = 0;
for (final LibvirtVmDef.InterfaceDef pluggedNic : pluggedNics) {
if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
s_logger.debug("found existing nic for mac " + pluggedNic.getMacAddress() + " at index " + nicnum);
return new PlugNicAnswer(command, true, "success");
}
nicnum++;
}
final VifDriver vifDriver = libvirtComputingResource.getVifDriver(nic.getType());
final LibvirtVmDef.InterfaceDef interfaceDef = vifDriver.plug(nic, "Default - VirtIO capable OS (64-bit)", "");
vm.attachDevice(interfaceDef.toString());
return new PlugNicAnswer(command, true, "success");
} catch (final LibvirtException e) {
final String msg = " Plug Nic failed due to " + e.toString();
s_logger.warn(msg, e);
return new PlugNicAnswer(command, false, msg);
} catch (final InternalErrorException e) {
final String msg = " Plug Nic failed due to " + e.toString();
s_logger.warn(msg, e);
return new PlugNicAnswer(command, false, msg);
} finally {
if (vm != null) {
try {
vm.free();
} catch (final LibvirtException l) {
s_logger.trace("Ignoring libvirt error.", l);
}
}
}
}
use of com.cloud.legacymodel.communication.answer.PlugNicAnswer in project cosmic by MissionCriticalCloud.
the class CitrixPlugNicCommandWrapper method execute.
@Override
public Answer execute(final PlugNicCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final String vmName = command.getVmName();
try {
final Set<VM> vms = VM.getByNameLabel(conn, vmName);
if (vms == null || vms.isEmpty()) {
return new PlugNicAnswer(command, false, "Can not find VM " + vmName);
}
final VM vm = vms.iterator().next();
final NicTO nic = command.getNic();
String mac = nic.getMac();
final Set<VIF> routerVIFs = vm.getVIFs(conn);
mac = mac.trim();
int counter = 0;
for (final VIF vif : routerVIFs) {
final String lmac = vif.getMAC(conn);
if (lmac.trim().equals(mac)) {
counter++;
}
}
// redundant.
if (counter > 2) {
final String msg = " Plug Nic failed due to a VIF with the same mac " + nic.getMac() + " exists in more than 2 routers.";
s_logger.error(msg);
return new PlugNicAnswer(command, false, msg);
}
// Wilder Rodrigues - replaced this code with the code above.
// VIF vif = getVifByMac(conn, vm, nic.getMac());
// if (vif != null) {
// final String msg = " Plug Nic failed due to a VIF with the same mac " + nic.getMac() + " exists";
// s_logger.warn(msg);
// return new PlugNicAnswer(cmd, false, msg);
// }
final VIF vif = citrixResourceBase.createVif(conn, vmName, vm, null, nic);
// vif = createVif(conn, vmName, vm, null, nic);
vif.plug(conn);
return new PlugNicAnswer(command, true, "success");
} catch (final Exception e) {
final String msg = " Plug Nic failed due to " + e.toString();
s_logger.error(msg, e);
return new PlugNicAnswer(command, false, msg);
}
}
Aggregations