private Iterable<String> getPrivateIpAddresses(List<NetworkInterface> networkInterfaces) { List<String> privateIpAddresses = Lists.newArrayList(); for (NetworkInterface networkInterfaceCardIdReference : networkInterfaces) { NetworkInterfaceCard networkInterfaceCard = getNetworkInterfaceCard(networkInterfaceCardIdReference); if (networkInterfaceCard != null && networkInterfaceCard.properties() != null && networkInterfaceCard.properties().ipConfigurations() != null) { for (IpConfiguration ipConfiguration : networkInterfaceCard.properties().ipConfigurations()) { if (ipConfiguration.properties().privateIPAddress() != null) { privateIpAddresses.add(ipConfiguration.properties().privateIPAddress()); } } } } return privateIpAddresses; }
@Override public IdReference apply(IpConfiguration input) { return input.properties().publicIPAddress(); } }), notNull());
@Test public void createNetworkInterfaceCard() { //Create properties object final NetworkInterfaceCardProperties networkInterfaceCardProperties = NetworkInterfaceCardProperties.builder() .ipConfigurations(Arrays.asList(IpConfiguration.builder().name("myipconfig") .properties(IpConfigurationProperties.builder().privateIPAllocationMethod("Dynamic").primary (TRUE) .subnet(IdReference.create(subnetId)).build() ).build() )).build(); final Map<String, String> tags = ImmutableMap.of("jclouds", "livetest"); NetworkInterfaceCard nic = api().createOrUpdate(nicName, LOCATION, networkInterfaceCardProperties, tags); assertEquals(nic.name(), nicName); assertEquals(nic.location(), LOCATION); assertTrue(nic.properties().ipConfigurations().size() > 0); assertEquals(nic.properties().ipConfigurations().get(0).name(), "myipconfig"); assertEquals(nic.properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic"); assertTrue(nic.properties().ipConfigurations().get(0).properties().primary()); assertEquals(nic.properties().ipConfigurations().get(0).properties().subnet().id(), subnetId); assertEquals(nic.tags().get("jclouds"), "livetest"); }
@SerializedNames({ "provisioningState", "privateIPAddress", "privateIPAllocationMethod", "subnet", "publicIPAddress", "loadBalancerBackendAddressPools", "loadBalancerInboundNatRules" }) public static IpConfigurationProperties create(final String provisioningState, final String privateIPAddress, final String privateIPAllocationMethod, final IdReference subnet, final IdReference publicIPAddress, List<IdReference> loadBalancerBackendAddressPools, List<IdReference> loadBalancerInboundNatRules) { return builder() .provisioningState(provisioningState) .privateIPAddress(privateIPAddress) .privateIPAllocationMethod(privateIPAllocationMethod) .subnet(subnet) .publicIPAddress(publicIPAddress) .loadBalancerBackendAddressPools(loadBalancerBackendAddressPools) .loadBalancerInboundNatRules(loadBalancerInboundNatRules) .build(); }
@Test(dependsOnMethods = "createNetworkInterfaceCard") public void getNetworkInterfaceCard() { NetworkInterfaceCard nic = api().get(nicName); assertEquals(nic.name(), nicName); assertEquals(nic.location(), LOCATION); assertTrue(nic.properties().ipConfigurations().size() > 0); assertEquals(nic.properties().ipConfigurations().get(0).name(), "myipconfig"); assertEquals(nic.properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic"); assertEquals(nic.properties().ipConfigurations().get(0).properties().subnet().id(), subnetId); }
private NetworkInterfaceCard createNetworkInterfaceCard(final String resourceGroupName, String networkInterfaceCardName, String locationName, String ipConfigurationName) { //Create properties object final NetworkInterfaceCardProperties networkInterfaceCardProperties = NetworkInterfaceCardProperties .builder().ipConfigurations(Arrays.asList(IpConfiguration.create(ipConfigurationName, null, null, IpConfigurationProperties .create(null, null, "Dynamic", IdReference.create(subnetId), null, null, null, Boolean.TRUE)))) .build(); final Map<String, String> tags = ImmutableMap.of("jclouds", "livetest"); return api.getNetworkInterfaceCardApi(resourceGroupName).createOrUpdate(networkInterfaceCardName, locationName, networkInterfaceCardProperties, tags); }
public void listNetworkInterfaceCards() throws InterruptedException { server.enqueue(jsonResponse("/listnetworkinterfaces.json")); final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); List<NetworkInterfaceCard> nicList = nicApi.list(); String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, resourcegroup, apiVersion); assertSent(server, "GET", path); assertTrue(nicList.size() == 2); assertTrue(nicList.get(0).properties().ipConfigurations().size() > 0); assertEquals(nicList.get(0).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic"); assertTrue(nicList.get(1).properties().ipConfigurations().size() > 0); assertEquals(nicList.get(1).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Static"); }
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); }
public void getNetworkInterfaceCard() throws InterruptedException { server.enqueue(jsonResponse("/getnetworkinterfacecard.json")); final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); NetworkInterfaceCard nic = nicApi.get(nicName); String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion); assertSent(server, "GET", path); assertNotNull(nic); assertEquals(nic.name(), nicName); assertTrue(nic.properties().primary()); assertEquals(nic.properties().ipConfigurations().get(0).name(), "myip1"); assertTrue(nic.properties().ipConfigurations().get(0).properties().primary()); assertEquals(nic.tags().get("mycustomtag"), "foobar"); }
@Test(dependsOnMethods = "testAttachNodesToBackendPool") public void testAddInboundNatRule() { IdReference frontendIp = IdReference.create(lb.properties().frontendIPConfigurations().get(0).id()); InboundNatRuleProperties natProps = InboundNatRuleProperties.builder().frontendIPConfiguration(frontendIp) .frontendPort(5679).backendPort(56710).protocol(Tcp).build(); InboundNatRule natRule = InboundNatRule.create("inboundnat", null, natProps, null); LoadBalancerProperties props = lb.properties().toBuilder().inboundNatRules(ImmutableList.of(natRule)).build(); lb = updateLoadBalancer(lbName, props); assertEquals(lb.properties().inboundNatRules().size(), 1); assertEquals(lb.properties().inboundNatRules().get(0).name(), natRule.name()); InboundNatRule createdRule = lb.properties().inboundNatRules().get(0); NetworkInterfaceCard updatedNic = attachNicToNatRule(nicNames.get(0), createdRule); List<IdReference> natRulesInNic = updatedNic.properties().ipConfigurations().get(0).properties() .loadBalancerInboundNatRules(); assertEquals(natRulesInNic.size(), 1); assertEquals(natRulesInNic.get(0), IdReference.create(createdRule.id())); // Refresh the LB after having attached NICs to the pool lb = lbApi.get(lbName); IdReference backendIpRef = IdReference.create(updatedNic.properties().ipConfigurations().get(0).id()); assertEquals(lb.properties().inboundNatRules().size(), 1); assertEquals(lb.properties().inboundNatRules().get(0).properties().backendIPConfiguration(), backendIpRef); }
@SerializedNames({ "provisioningState", "privateIPAddress", "privateIPAllocationMethod", "subnet", "publicIPAddress", "loadBalancerBackendAddressPools", "loadBalancerInboundNatRules", "primary" }) public static IpConfigurationProperties create(final String provisioningState, final String privateIPAddress, final String privateIPAllocationMethod, final IdReference subnet, final IdReference publicIPAddress, List<IdReference> loadBalancerBackendAddressPools, List<IdReference> loadBalancerInboundNatRules, final Boolean primary) { return builder() .provisioningState(provisioningState) .privateIPAddress(privateIPAddress) .privateIPAllocationMethod(privateIPAllocationMethod) .subnet(subnet) .publicIPAddress(publicIPAddress) .loadBalancerBackendAddressPools(loadBalancerBackendAddressPools) .loadBalancerInboundNatRules(loadBalancerInboundNatRules).primary(primary) .build(); }
private NetworkInterfaceCard createNetworkInterfaceCard(final String resourceGroupName, String networkInterfaceCardName, String locationName, String ipConfigurationName) { //Create properties object final NetworkInterfaceCardProperties networkInterfaceCardProperties = NetworkInterfaceCardProperties .builder().ipConfigurations(Arrays.asList(IpConfiguration.create(ipConfigurationName, null, null, IpConfigurationProperties .create(null, null, "Dynamic", IdReference.create(subnetId), null, null, null, null)))).build(); final Map<String, String> tags = ImmutableMap.of("jclouds", "livetest"); return api.getNetworkInterfaceCardApi(resourceGroupName).createOrUpdate(networkInterfaceCardName, locationName, networkInterfaceCardProperties, tags); }
public void listAllNetworkInterfaceCardsInSubscription() throws InterruptedException { server.enqueue(jsonResponse("/listallnetworkinterfaces.json")); final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(null); List<NetworkInterfaceCard> nicList = nicApi.listAllInSubscription(); String path = String .format("/subscriptions/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, apiVersion); assertSent(server, "GET", path); assertTrue(nicList.size() == 3); assertTrue(nicList.get(0).properties().ipConfigurations().size() > 0); assertEquals(nicList.get(0).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic"); assertTrue(nicList.get(1).properties().ipConfigurations().size() > 0); assertEquals(nicList.get(1).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Static"); assertTrue(nicList.get(2).properties().ipConfigurations().size() > 0); assertNotEquals(IdReference.extractResourceGroup(nicList.get(2).id()), resourcegroup); assertEquals(nicList.get(2).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Static"); }
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); }
String subnetName = extractName(ipConfig.subnet()); IpConfigurationProperties.Builder ipProperties = IpConfigurationProperties.builder() .subnet(IdReference.create(ipConfig.subnet())) .privateIPAllocationMethod(ipConfig.address().isPresent() ? "Static" : "Dynamic")
@Override public IdReference apply(IpConfiguration input) { return input.properties().publicIPAddress(); } }), notNull());
private Iterable<String> getPrivateIpAddresses(List<NetworkInterface> networkInterfaces) { List<String> privateIpAddresses = Lists.newArrayList(); for (NetworkInterface networkInterfaceCardIdReference : networkInterfaces) { NetworkInterfaceCard networkInterfaceCard = getNetworkInterfaceCard(networkInterfaceCardIdReference); if (networkInterfaceCard != null && networkInterfaceCard.properties() != null && networkInterfaceCard.properties().ipConfigurations() != null) { for (IpConfiguration ipConfiguration : networkInterfaceCard.properties().ipConfigurations()) { if (ipConfiguration.properties().privateIPAddress() != null) { privateIpAddresses.add(ipConfiguration.properties().privateIPAddress()); } } } } return privateIpAddresses; }
public void createNetworkInterfaceCard() throws InterruptedException { server.enqueue(jsonResponse("/createnetworkinterfacecard.json").setStatus("HTTP/1.1 201 Created")); final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); final String SubnetID = "/subscriptions/" + subscriptionid + "/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/myvirtualnetwork/subnets/mysubnet"; //Create properties object final NetworkInterfaceCardProperties networkInterfaceCardProperties = NetworkInterfaceCardProperties .create(null, null, null, Arrays.asList(IpConfiguration.create("myipconfig", null, null, IpConfigurationProperties .create(null, null, "Dynamic", IdReference.create(SubnetID), null, null, null, Boolean.TRUE))), null, null, Boolean.TRUE); final Map<String, String> tags = ImmutableMap.of("mycustomtag", "foobar"); NetworkInterfaceCard nic = nicApi.createOrUpdate(nicName, location, networkInterfaceCardProperties, tags); String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion); String json = String.format( "{\"location\":\"northeurope\",\"properties\":{\"ipConfigurations\":[{\"name\":\"myipconfig\"," + "\"properties\":{\"privateIPAllocationMethod\":\"Dynamic\"," + "\"subnet\":{\"id\":\"/subscriptions/SUBSCRIPTIONID/resourceGroups/azurearmtesting/providers" + "/Microsoft" + ".Network/virtualNetworks/myvirtualnetwork/subnets/mysubnet\"},\"primary\":true}}]," + "\"primary\":true}," + "\"tags\":{\"mycustomtag\":\"foobar\"}}"); assertSent(server, "PUT", path, json); assertEquals(nic.tags().get("mycustomtag"), "foobar"); }
String subnetName = extractName(ipConfig.subnet()); IpConfigurationProperties.Builder ipProperties = IpConfigurationProperties.builder() .subnet(IdReference.create(ipConfig.subnet())) .privateIPAllocationMethod(ipConfig.address().isPresent() ? "Static" : "Dynamic")
private Iterable<String> getPublicIpAddresses(List<NetworkInterface> networkInterfaces) { List<String> publicIpAddresses = Lists.newArrayList(); for (NetworkInterface networkInterfaceCardIdReference : networkInterfaces) { NetworkInterfaceCard networkInterfaceCard = getNetworkInterfaceCard(networkInterfaceCardIdReference); if (networkInterfaceCard != null && networkInterfaceCard.properties() != null && networkInterfaceCard.properties().ipConfigurations() != null) { for (IpConfiguration ipConfiguration : networkInterfaceCard.properties().ipConfigurations()) { if (ipConfiguration.properties().publicIPAddress() != null) { IdReference publicIpId = ipConfiguration.properties().publicIPAddress(); PublicIPAddress publicIp = api.getPublicIPAddressApi(publicIpId.resourceGroup()).get( publicIpId.name()); if (publicIp != null && publicIp.properties().ipAddress() != null) { publicIpAddresses.add(publicIp.properties().ipAddress()); } } } } } return publicIpAddresses; }