private NetworkInterfaceCard attachNicToBackendPool(final String nicName, BackendAddressPool pool) { List<IdReference> poolRefs = ImmutableList.of(IdReference.create(pool.id())); // Assume we are attaching the first IP to the Load Balancer NetworkInterfaceCard nic = nicApi.get(nicName); IpConfigurationProperties ipProps = nic.properties().ipConfigurations().get(0).properties().toBuilder() .loadBalancerBackendAddressPools(poolRefs).build(); List<IpConfiguration> ips = ImmutableList.of(nic.properties().ipConfigurations().get(0).toBuilder() .properties(ipProps).build()); NetworkInterfaceCardProperties nicProps = nic.properties().toBuilder().ipConfigurations(ips).build(); nicApi.createOrUpdate(nicName, location, nicProps, null); resourceAvailable.apply(new Supplier<Provisionable>() { @Override public Provisionable get() { NetworkInterfaceCard updated = nicApi.get(nicName); return updated == null ? null : updated.properties(); } }); return nicApi.get(nicName); }
private NetworkInterfaceCard attachNicToNatRule(final String nicName, InboundNatRule rule) { List<IdReference> natRuleRefs = ImmutableList.of(IdReference.create(rule.id())); // Assume we are attaching the first IP to the NAT rule NetworkInterfaceCard nic = nicApi.get(nicName); IpConfigurationProperties ipProps = nic.properties().ipConfigurations().get(0).properties().toBuilder() .loadBalancerInboundNatRules(natRuleRefs).build(); List<IpConfiguration> ips = ImmutableList.of(nic.properties().ipConfigurations().get(0).toBuilder() .properties(ipProps).build()); NetworkInterfaceCardProperties nicProps = nic.properties().toBuilder().ipConfigurations(ips).build(); nicApi.createOrUpdate(nicName, location, nicProps, null); resourceAvailable.apply(new Supplier<Provisionable>() { @Override public Provisionable get() { NetworkInterfaceCard updated = nicApi.get(nicName); return updated == null ? null : updated.properties(); } }); return nicApi.get(nicName); }