@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); }
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); }
public SetupGuestNetworkCommand createSetupGuestNetworkCommand(final DomainRouterVO router, final boolean add, final NicProfile guestNic) { final Network network = _networkModel.getNetwork(guestNic.getNetworkId()); String defaultDns1 = null; String defaultDns2 = null; final boolean dnsProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VPCVirtualRouter); final boolean dhcpProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, Provider.VPCVirtualRouter); final boolean setupDns = dnsProvided || dhcpProvided; if (setupDns) { defaultDns1 = guestNic.getIPv4Dns1(); defaultDns2 = guestNic.getIPv4Dns2(); } final Nic nic = _nicDao.findByNtwkIdAndInstanceId(network.getId(), router.getId()); final String networkDomain = network.getNetworkDomain(); final String dhcpRange = getGuestDhcpRange(guestNic, network, _entityMgr.findById(DataCenter.class, network.getDataCenterId())); final NicProfile nicProfile = _networkModel.getNicProfile(router, nic.getNetworkId(), null); final SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, router.getIsRedundantRouter(), defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType())); final String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIPv4Address()) | ~NetUtils.ip2Long(guestNic.getIPv4Netmask())); setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(network.getId(), router.getId())); setupCmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, network.getGateway()); setupCmd.setAccessDetail(NetworkElementCommand.GUEST_BRIDGE, brd); setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); if (network.getBroadcastDomainType() == BroadcastDomainType.Vlan) { final long guestVlanTag = Long.parseLong(BroadcastDomainType.Vlan.getValueFrom(network.getBroadcastUri())); setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag)); } return setupCmd; }
final NicTO nic = cmd.getNic(); final String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { final Set<VM> vms = VM.getByNameLabel(conn, domrName);
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); } }