private Iterable<IdReference> getPublicIps(NetworkInterfaceCard nic) { return filter(transform(nic.properties().ipConfigurations(), new Function<IpConfiguration, IdReference>() { @Override public IdReference apply(IpConfiguration input) { return input.properties().publicIPAddress(); } }), notNull()); }
private Iterable<IdReference> getPublicIps(NetworkInterfaceCard nic) { return filter(transform(nic.properties().ipConfigurations(), new Function<IpConfiguration, IdReference>() { @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; }
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"); }
@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); }
@Override public IdReference apply(NetworkInterfaceCard input) { return IdReference.create(input.properties().ipConfigurations().get(0).id()); } };
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 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; }
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 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; }
@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"); }
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); }
@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 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); }