@Override public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) { final SetupGuestNetworkCommand command = (SetupGuestNetworkCommand) cmd; final NicTO nic = command.getNic(); final String routerGIP = command.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP); final String gateway = command.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY); final String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask())); final String netmask = nic.getNetmask(); final String domainName = command.getNetworkDomain(); String dns = command.getDefaultDns1(); if (dns == null || dns.isEmpty()) { dns = command.getDefaultDns2(); } else { final String dns2 = command.getDefaultDns2(); if (dns2 != null && !dns2.isEmpty()) { dns += "," + dns2; } } final GuestNetwork guestNetwork = new GuestNetwork(command.isAdd(), nic.getMac(), "eth" + nic.getDeviceId(), routerGIP, netmask, gateway, cidr, dns, domainName); return generateConfigItems(guestNetwork); }
final Connection conn = getConnection(); final NicTO nic = cmd.getNic(); final String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { final Set<VM> vms = VM.getByNameLabel(conn, domrName);
protected ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) { final NicTO nic = cmd.getNic(); final String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { final URI broadcastUri = nic.getBroadcastUri(); final String vlanId = BroadcastDomainType.getValue(broadcastUri); final int ethDeviceNum = getVmNics(domrName, vlanId); if (ethDeviceNum > 0) { nic.setDeviceId(ethDeviceNum); } else { return new ExecutionResult(false, "Prepare SetupGuestNetwork failed due to unable to find the nic"); } } catch (final Exception e) { final String msg = "Prepare SetupGuestNetwork failed due to " + e.toString(); s_logger.warn(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); }
private ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) { Connect conn; final NicTO nic = cmd.getNic(); final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { conn = LibvirtConnection.getConnectionByVmName(routerName); final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName); InterfaceDef routerNic = null; for (final InterfaceDef pluggedNic : pluggedNics) { if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) { routerNic = pluggedNic; break; } } if (routerNic == null) { return new ExecutionResult(false, "Can not find nic with mac " + nic.getMac() + " for VM " + routerName); } return new ExecutionResult(true, null); } catch (final LibvirtException e) { final String msg = "Creating guest network failed due to " + e.toString(); s_logger.warn(msg, e); return new ExecutionResult(false, msg); } }