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; }
final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO, publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()), domainRouterVO.getInstanceName(), domainRouterVO.getType(), details); cmds.addCommand(plugNicCmd); final Nic guestNic = nicNtwk.first(); final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO, guestNic.getNetworkId(), null), domainRouterVO.getInstanceName(), domainRouterVO.getType(), details); cmds.addCommand(plugNicCmd); if (!_networkModel.isPrivateGateway(guestNic.getNetworkId())) {
private PlugNicAnswer execute(final PlugNicCommand cmd) { if (s_logger.isInfoEnabled()) { s_logger.info("Executing resource PlugNicCommand " + s_gson.toJson(cmd)); } try { final String vmName = cmd.getVmName(); final NicTO nic = cmd.getNic(); final URI broadcastUri = nic.getBroadcastUri(); if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) { throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + nic.getBroadcastUri()); } final String vlanId = BroadcastDomainType.getValue(broadcastUri); int publicNicInfo = -1; publicNicInfo = getVmFreeNicIndex(vmName); if (publicNicInfo > 0) { modifyNicVlan(vmName, vlanId, publicNicInfo, true, cmd.getNic().getName()); return new PlugNicAnswer(cmd, true, "success"); } final String msg = " Plug Nic failed for the vm as it has reached max limit of NICs to be added"; s_logger.warn(msg); return new PlugNicAnswer(cmd, false, msg); } catch (final Exception e) { s_logger.error("Unexpected exception: ", e); return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString()); } }
@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); final NicTO nic = command.getNic();