private ExecutionResult prepNetBoth(String routerName, IpAddressTO[] ips, String type) { Xen xen = new Xen(c); try { Xen.Vm vm = xen.getVmConfig(routerName); for (IpAddressTO ip : ips) { Integer devId = vm.getVifIdByMac(ip.getVifMacAddress()); if (devId < 0 && "IpAssocVpcCommand".equals(type)) { String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress(); logger.error(msg); return new ExecutionResult(false, msg); } else if (devId < 0 && "IpAssocCommand".equals(type)) { // vm.get String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress() + " " + " Ignoring for now (routervm)"; logger.debug(msg); devId=2; } ip.setNicDevId(devId); } } catch (Exception e) { String msg = type + " failure on applying one ip due to exception: " + e; logger.error(msg); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); } }
protected ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) { final Connection conn = getConnection(); final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { final IpAddressTO[] ips = cmd.getIpAddresses(); for (final IpAddressTO ip : ips) { final VM router = getVM(conn, routerName); final VIF correctVif = getVifByMac(conn, router, ip.getVifMacAddress()); setNicDevIdIfCorrectVifIsNotNull(conn, ip, correctVif); } } catch (final Exception e) { s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.getMessage()); } return new ExecutionResult(true, null); }
protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) { if (s_logger.isInfoEnabled()) { s_logger.info("Executing resource SetSourceNatCommand " + s_gson.toJson(cmd)); } final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); final String routerIp = getRouterSshControlIp(cmd); final IpAddressTO pubIp = cmd.getIpAddress(); try { final int ethDeviceNum = findRouterEthDeviceIndex(routerName, routerIp, pubIp.getVifMacAddress()); String args = ""; args += " -A "; args += " -l "; args += pubIp.getPublicIp(); args += " -c "; args += "eth" + ethDeviceNum; final String command = String.format("%s%s %s", "/opt/cloud/bin/", VRScripts.VPC_SOURCE_NAT, args); final Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { final String msg = "SetupGuestNetworkCommand on domain router " + routerIp + " failed. message: " + result.second(); s_logger.error(msg); return new SetSourceNatAnswer(cmd, false, msg); } return new SetSourceNatAnswer(cmd, true, "success"); } catch (final Exception e) { final String msg = "Ip SNAT failure due to " + e.toString(); s_logger.error(msg, e); return new SetSourceNatAnswer(cmd, false, msg); } }
protected ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) { Connect conn; final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { conn = getLibvirtUtilitiesHelper().getConnectionByVmName(routerName); final IpAddressTO[] ips = cmd.getIpAddresses(); Integer devNum = 0; final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName); final Map<String, Integer> macAddressToNicNum = new HashMap<>(pluggedNics.size()); for (final InterfaceDef pluggedNic : pluggedNics) { final String pluggedVlan = pluggedNic.getBrName(); macAddressToNicNum.put(pluggedNic.getMacAddress(), devNum); devNum++; } for (final IpAddressTO ip : ips) { ip.setNicDevId(macAddressToNicNum.get(ip.getVifMacAddress())); } return new ExecutionResult(true, null); } catch (final LibvirtException e) { s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.getMessage()); } }
@Override public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) { final IpAssocCommand command = (IpAssocCommand) cmd; final List<IpAddress> ips = new LinkedList<IpAddress>(); for (final IpAddressTO ip : command.getIpAddresses()) { final IpAddress ipAddress = new IpAddress(ip.getPublicIp(), ip.isSourceNat(), ip.isAdd(), ip.isOneToOneNat(), ip.isFirstIP(), ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getNicDevId(), ip.isNewNic(), ip.getTrafficType().toString()); ips.add(ipAddress); } final IpAssociation ipAssociation = new IpAssociation(ips.toArray(new IpAddress[ips.size()])); return generateConfigItems(ipAssociation); }
VifHotPlug(conn, routerName, ip.getBroadcastUri(), ip.getVifMacAddress()); broadcastUriAllocatedToVM.put(ip.getBroadcastUri(), nicPos++); vifHotUnPlug(conn, routerName, ip.getVifMacAddress()); networkUsage(routerIp, "deleteVif", "eth" + nicNum);
if (!broadcastUriAllocatedToVM.containsKey(ip.getBroadcastUri())) { VifHotPlug(conn, routerName, ip.getBroadcastUri(), ip.getVifMacAddress()); broadcastUriAllocatedToVM.put(ip.getBroadcastUri(), nicPos++); newNic = true;
protected Answer execute(final IpAssocCommand cmd) { if (s_logger.isInfoEnabled()) { s_logger.info("Executing resource IPAssocCommand: " + s_gson.toJson(cmd)); } int i = 0; final String[] results = new String[cmd.getIpAddresses().length]; try { final IpAddressTO[] ips = cmd.getIpAddresses(); final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); final String controlIp = getRouterSshControlIp(cmd); for (final IpAddressTO ip : ips) { assignPublicIpAddress(routerName, controlIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getBroadcastUri(), ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress()); results[i++] = ip.getPublicIp() + " - success"; } for (; i < cmd.getIpAddresses().length; i++) { results[i++] = IpAssocAnswer.errorResult; } } catch (final Throwable e) { s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); for (; i < cmd.getIpAddresses().length; i++) { results[i++] = IpAssocAnswer.errorResult; } } return new IpAssocAnswer(cmd, results); }
nic.setMac(ip.getVifMacAddress()); nic.setType(ip.getTrafficType()); if (ip.getBroadcastUri() == null) {
nic.setMac(ip.getVifMacAddress()); nic.setType(ip.getTrafficType()); if (ip.getBroadcastUri() == null) {