private InterfaceDef findPluggedNic(LibvirtComputingResource libvirtComputingResource, NicTO nic, String vmName, Connect conn) { InterfaceDef oldPluggedNic = null; final List<InterfaceDef> pluggedNics = libvirtComputingResource.getInterfaces(conn, vmName); for (final InterfaceDef pluggedNic : pluggedNics) { if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) { oldPluggedNic = pluggedNic; } } return oldPluggedNic; } }
protected OvmVif.Details createVif(NicTO nic) throws XmlRpcException { OvmVif.Details vif = new OvmVif.Details(); vif.mac = nic.getMac(); vif.bridge = getNetwork(nic); return vif; }
private Boolean deleteVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException { /* here we should use the housekeeping of VLANs/Networks etc.. * so we can clean after the last VM is gone */ try { String net = network.getNetwork(nic); if (net != null) { LOGGER.debug("Removing vif " + nic.getDeviceId() + " " + " " + nic.getMac() + " " + net + " from " + vm.getVmName()); vm.removeVif(net, nic.getMac()); } else { LOGGER.debug("Unable to remove vif " + nic.getDeviceId() + " no network for " + vm.getVmName()); return false; } } catch (Exception e) { String msg = "Unable to remove vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage(); LOGGER.debug(msg); throw new Ovm3ResourceException(msg); } return true; }
final NetworkACL networkACL = new NetworkACL(dev, nic.getMac(), privateGw != null, nic.getIp(), netmask, ingressRules.toArray(new AclRule[ingressRules.size()]), egressRules.toArray(new AclRule[egressRules.size()]));
private Boolean createVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException { try { String net = network.getNetwork(nic); if (net != null) { LOGGER.debug("Adding vif " + nic.getDeviceId() + " " + nic.getMac() + " " + net + " to " + vm.getVmName()); vm.addVif(nic.getDeviceId(), net, nic.getMac()); } else { LOGGER.debug("Unable to add vif " + nic.getDeviceId() + " no network for " + vm.getVmName()); return false; } } catch (Exception e) { String msg = "Unable to add vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage(); LOGGER.debug(msg); throw new Ovm3ResourceException(msg); } return true; } private Boolean deleteVif(Xen.Vm vm, NicTO nic)
protected ExecutionResult prepareNetworkElementCommand(final SetNetworkACLCommand cmd) { final Connection conn = getConnection(); final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { final VM router = getVM(conn, routerName); final NicTO nic = cmd.getNic(); if (nic != null) { final VIF vif = getVifByMac(conn, router, nic.getMac()); if (vif == null) { final String msg = "Prepare SetNetworkACL failed due to VIF is null for : " + nic.getMac() + " with routername: " + routerName; s_logger.error(msg); return new ExecutionResult(false, msg); } nic.setDeviceId(Integer.parseInt(vif.getDevice(conn))); } else { final String msg = "Prepare SetNetworkACL failed due to nic is null for : " + routerName; s_logger.error(msg); return new ExecutionResult(false, msg); } } catch (final Exception e) { final String msg = "Prepare SetNetworkACL failed due to " + e.toString(); s_logger.error(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); }
vifr.VM = vm; vifr.device = Integer.toString(nic.getDeviceId()); vifr.MAC = nic.getMac();
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); } }
final NicTO nic = command.getNic(); String mac = nic.getMac(); final Set<VIF> routerVIFs = vm.getVIFs(conn); mac = mac.trim(); 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);
final String mac = nic.getMac(); VIF domrVif = null; for (final VIF vif : vm.getVIFs(conn)) {
private void createVif(final LibvirtVMDef vm, final NicTO nic, final String nicAdapter, Map<String, String> extraConfig) throws InternalErrorException, LibvirtException { if (nic.getType().equals(TrafficType.Guest) && nic.getBroadcastType().equals(BroadcastDomainType.Vsp)) { String vrIp = nic.getBroadcastUri().getPath().substring(1); vm.getMetaData().getMetadataNode(LibvirtVMDef.NuageExtensionDef.class).addNuageExtension(nic.getMac(), vrIp); if (s_logger.isDebugEnabled()) { s_logger.debug("NIC with MAC " + nic.getMac() + " and BroadcastDomainType " + nic.getBroadcastType() + " in network(" + nic.getGateway() + "/" + nic.getNetmask() + ") is " + nic.getType() + " traffic type. So, vsp-vr-ip " + vrIp + " is set in the metadata"); } } if (vm.getDevices() == null) { s_logger.error("LibvirtVMDef object get devices with null result"); throw new InternalErrorException("LibvirtVMDef object get devices with null result"); } vm.getDevices().addDevice(getVifDriver(nic.getType(), nic.getName()).plug(nic, vm.getPlatformEmulator(), nicAdapter, extraConfig)); }
intf.defDpdkNet(_libvirtComputingResource.dpdkOvsPath, port, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), 0, getExtraDpdkProperties(extraConfig)); } else { s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.setVlanTag(Integer.parseInt(vlanId)); intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.setVlanTag(Integer.parseInt(vlanId)); intf.setVirtualPortInterfaceId(nic.getUuid()); String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private"); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vswitch) { String vnetId = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri()); String brName = "OVSTunnel" + vnetId; s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + brName); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vsp) { intf.setVirtualPortInterfaceId(nic.getUuid()); String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private"); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else { intf.defBridgeNet(_bridges.get("guest"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter)); } else if (nic.getType() == Networks.TrafficType.Public) { Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; if (trafficLabel != null && !trafficLabel.isEmpty()) {
final String mac = nic.getMac(); final VIF vif = citrixResourceBase.getVifByMac(conn, vm, mac); if (vif != null) {
/** * Experimental driver to configure direct networking in libvirt. This should only * be used on an LXC cluster that does not run any system VMs. * * @param nic * @param guestOsType * @param extraConfig * @return * @throws InternalErrorException * @throws LibvirtException */ @Override public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter, Map<String, String> extraConfig) throws InternalErrorException, LibvirtException { LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef(); if (nic.getType() == Networks.TrafficType.Guest) { Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; intf.defDirectNet(_libvirtComputingResource.getNetworkDirectDevice(), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), _libvirtComputingResource.getNetworkDirectSourceMode(), networkRateKBps); } else if (nic.getType() == Networks.TrafficType.Public) { Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; intf.defDirectNet(_libvirtComputingResource.getNetworkDirectDevice(), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), _libvirtComputingResource.getNetworkDirectSourceMode(), networkRateKBps); } return intf; }
@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); }
if (trafficLabel != null && !trafficLabel.isEmpty()) { s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); intf.defEthernet("ivsnet-" + nic.getUuid().substring(0, 5), nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), _ivsIfUpPath, networkRateKBps); } else { throw new InternalErrorException("no traffic label "); intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter)); } else if (nic.getType() == Networks.TrafficType.Public) { if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) || s_logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel); String brName = createVnetBr(vNetId, trafficLabel, protocol); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else { String brName = createVnetBr(vNetId, "public", protocol); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.defBridgeNet(_bridges.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.defBridgeNet(_bridges.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter)); } else if (nic.getType() == Networks.TrafficType.Storage) { String storageBrName = nic.getName() == null ? _bridges.get("private") : nic.getName(); intf.defBridgeNet(storageBrName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
protected boolean post_default_network_rules(final Connect conn, final String vmName, final NicTO nic, final Long vmId, final InetAddress dhcpServerIp, final String hostIp, final String hostMacAddr) { if (!_canBridgeFirewall) { return false; } final List<InterfaceDef> intfs = getInterfaces(conn, vmName); if (intfs.size() < nic.getDeviceId()) { return false; } final InterfaceDef intf = intfs.get(nic.getDeviceId()); final String brname = intf.getBrName(); final String vif = intf.getDevName(); final Script cmd = new Script(_securityGroupPath, _timeout, s_logger); cmd.add("post_default_network_rules"); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId.toString()); cmd.add("--vmip", nic.getIp()); cmd.add("--vmmac", nic.getMac()); cmd.add("--vif", vif); cmd.add("--brname", brname); if (dhcpServerIp != null) { cmd.add("--dhcpSvr", dhcpServerIp.getHostAddress()); } cmd.add("--hostIp", hostIp); cmd.add("--hostMacAddr", hostMacAddr); final String result = cmd.execute(); if (result != null) { return false; } return true; }
Integer nicnum = 0; for (final 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");
cmd.add("--vmip6", nic.getIp6Address()); cmd.add("--vmmac", nic.getMac()); cmd.add("--vif", vif); cmd.add("--brname", brname);
if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) { vm.detachDevice(pluggedNic.toString());