@Override public int compare(NicTO arg0, NicTO arg1) { if (arg0.getDeviceId() < arg1.getDeviceId()) { return -1; } else if (arg0.getDeviceId() == arg1.getDeviceId()) { return 0; } return 1; } });
protected void createVifs(OvmVm.Details vm, VirtualMachineTO spec) throws CloudRuntimeException, XmlRpcException { NicTO[] nics = spec.getNics(); List<OvmVif.Details> vifs = new ArrayList<OvmVif.Details>(nics.length); for (NicTO nic : nics) { OvmVif.Details vif = createVif(nic); vifs.add(nic.getDeviceId(), vif); } vm.vifs.addAll(vifs); }
protected boolean defaultNetworkRulesForUserVm(String vmName, Long vmId, NicTO nic) throws XmlRpcException { if (!_canBridgeFirewall) { return false; } OvmVif.Details vif = getVifFromVm(vmName, nic.getDeviceId()); String ipAddress = nic.getIp(); String macAddress = vif.mac; String vifName = vif.name; String bridgeName = vif.bridge; return OvmSecurityGroup.defaultNetworkRulesForUserVm(_conn, vmName, String.valueOf(vmId), ipAddress, macAddress, vifName, bridgeName); }
public void createVifs(final VirtualMachineTO vmSpec, final LibvirtVMDef vm) throws InternalErrorException, LibvirtException { final NicTO[] nics = vmSpec.getNics(); final Map <String, String> params = vmSpec.getDetails(); String nicAdapter = ""; if (params != null && params.get("nicAdapter") != null && !params.get("nicAdapter").isEmpty()) { nicAdapter = params.get("nicAdapter"); } Map<String, String> extraConfig = vmSpec.getExtraConfig(); for (int i = 0; i < nics.length; i++) { for (final NicTO nic : vmSpec.getNics()) { if (nic.getDeviceId() == i) { createVif(vm, nic, nicAdapter, extraConfig); } } } }
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)
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 String[] aclRules = rules[0]; final NicTO nic = command.getNic(); final String dev = "eth" + nic.getDeviceId(); final String netmask = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
vifr.device = Integer.toString(nic.getDeviceId()); vifr.MAC = nic.getMac(); vifr = vif.getRecord(conn); if (vifr != null) { s_logger.debug("Created a vif " + vifr.uuid + " on " + nic.getDeviceId());
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; }
if (intfs.size() == 0 || intfs.size() < nic.getDeviceId()) { return false; final InterfaceDef intf = intfs.get(nic.getDeviceId()); final String brname = intf.getBrName(); final String vif = intf.getDevName();
@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); }
for(i = 0; i < nics.length; i++) { expandedNics[i] = nics[i]; if(nics[i].getDeviceId() > deviceId) deviceId = nics[i].getDeviceId();