protected void setNicDevIdIfCorrectVifIsNotNull(final Connection conn, final IpAddressTO ip, final VIF correctVif) throws InternalErrorException, BadServerResponse, XenAPIException, XmlRpcException { if (correctVif == null) { if (ip.isAdd()) { throw new InternalErrorException("Failed to find DomR VIF to associate IP with."); } else { s_logger.debug("VIF to deassociate IP with does not exist, return success"); } } else { ip.setNicDevId(Integer.valueOf(correctVif.getDevice(conn))); } }
@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); }
if (org.apache.commons.lang.StringUtils.equalsIgnoreCase(lastIp, "true") && !ip.isAdd()) {
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); }
private ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) { final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { final IpAddressTO[] ips = cmd.getIpAddresses(); for (final IpAddressTO ip : ips) { final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri()); if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) { throw new InternalErrorException("Invalid Broadcast URI " + ip.getBroadcastUri()); } final String vlanId = BroadcastDomainType.getValue(broadcastUri); int publicNicInfo = -1; publicNicInfo = getVmNics(routerName, vlanId); if (publicNicInfo < 0) { if (ip.isAdd()) { throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with."); } else { s_logger.debug("VIF to deassociate IP with does not exist, return success"); continue; } } ip.setNicDevId(publicNicInfo); } } catch (final Exception e) { s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.toString()); } return new ExecutionResult(true, null); }
if (ip.isAdd()) {
if (ip.isAdd() && publicNicInfo == -1) { if (s_logger.isDebugEnabled()) { s_logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp());
if (org.apache.commons.lang.StringUtils.equalsIgnoreCase(lastIp, "true") && !ip.isAdd()) { final VIF correctVif = getCorrectVif(conn, router, network);