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()); } }
final Set<VM> vms = VM.getByNameLabel(conn, vmName); if (vms == null || vms.isEmpty()) { return new PlugNicAnswer(command, false, "Can not find VM " + vmName); 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); 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);
/** * PlugNicAnswer: plug a network interface into a VM * @param cmd * @return */ public PlugNicAnswer execute(PlugNicCommand cmd) { Answer ans = plugNunplugNic(cmd.getNic(), cmd.getVmName(), true); return new PlugNicAnswer(cmd, ans.getResult(), ans.getDetails()); }
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"); 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) {