@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({ "name", "id", "etag", "properties" }) public static IpConfiguration create(final String name, final String id, final String etag, final IpConfigurationProperties properties) { return builder() .name(name) .id(id) .etag(etag) .properties(properties) .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 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); }
@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); }
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); }
@Override public IdReference apply(NetworkInterfaceCard input) { return IdReference.create(input.properties().ipConfigurations().get(0).id()); } };
@SerializedNames({"name", "id", "etag", "primary", "properties"}) public static IpConfiguration create(final String name, final String id, final String etag, final Boolean primary, final IpConfigurationProperties properties) { return builder() .name(name) .id(id) .etag(etag) .primary(primary) .properties(properties) .build(); }
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"); }
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 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); }
@Override public IdReference apply(IpConfiguration input) { return input.properties().publicIPAddress(); } }), notNull());
final String nicName = namingConvention.uniqueNameForGroup(subnetName); IpConfiguration config = IpConfiguration.builder().name(ipName).properties(ipProperties.build()).build();
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"); }
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; }
final String nicName = namingConvention.uniqueNameForGroup(subnetName); IpConfiguration config = IpConfiguration.builder().name(ipName).properties(ipProperties.build()).build();
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 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 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; }