Search in sources :

Example 1 with NicIPConfiguration

use of com.microsoft.azure.management.network.NicIPConfiguration in project azure-sdk-for-java by Azure.

the class SubnetImpl method getNetworkInterfaceIPConfigurations.

@Override
public Set<NicIPConfiguration> getNetworkInterfaceIPConfigurations() {
    Set<NicIPConfiguration> ipConfigs = new HashSet<>();
    Map<String, NetworkInterface> nics = new HashMap<>();
    List<IPConfigurationInner> ipConfigRefs = this.inner().ipConfigurations();
    if (ipConfigRefs == null) {
        return ipConfigs;
    }
    for (IPConfigurationInner ipConfigRef : ipConfigRefs) {
        String nicID = ResourceUtils.parentResourceIdFromResourceId(ipConfigRef.id());
        String ipConfigName = ResourceUtils.nameFromResourceId(ipConfigRef.id());
        // Check if NIC already cached
        NetworkInterface nic = nics.get(nicID.toLowerCase());
        if (nic == null) {
            //  NIC not previously found, so ask Azure for it
            nic = this.parent().manager().networkInterfaces().getById(nicID);
        }
        if (nic == null) {
            // NIC doesn't exist so ignore this bad reference
            continue;
        }
        // Cache the NIC
        nics.put(nic.id().toLowerCase(), nic);
        // Get the IP config
        NicIPConfiguration ipConfig = nic.ipConfigurations().get(ipConfigName);
        if (ipConfig == null) {
            // IP config not found, so ignore this bad reference
            continue;
        }
        ipConfigs.add(ipConfig);
    }
    return Collections.unmodifiableSet(ipConfigs);
}
Also used : HashMap(java.util.HashMap) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration) HashSet(java.util.HashSet)

Example 2 with NicIPConfiguration

use of com.microsoft.azure.management.network.NicIPConfiguration in project azure-sdk-for-java by Azure.

the class TestNetworkInterface method updateResource.

@Override
public NetworkInterface updateResource(NetworkInterface resource) throws Exception {
    resource = resource.update().withoutIPForwarding().withSubnet("subnet2").updateIPConfiguration(// Updating the primary ip configuration
    "primary").withPrivateIPAddressDynamic().withoutPublicIPAddress().parent().withTag("tag1", "value1").withTag("tag2", "value2").apply();
    // Verifications
    Assert.assertTrue(!resource.isIPForwardingEnabled());
    NicIPConfiguration primaryIpConfig = resource.primaryIPConfiguration();
    Assert.assertNotNull(primaryIpConfig);
    Assert.assertTrue(primaryIpConfig.isPrimary());
    Assert.assertTrue("subnet2".equalsIgnoreCase(primaryIpConfig.subnetName()));
    Assert.assertNull(primaryIpConfig.publicIPAddressId());
    Assert.assertTrue(resource.tags().containsKey("tag1"));
    return resource;
}
Also used : NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration)

Example 3 with NicIPConfiguration

use of com.microsoft.azure.management.network.NicIPConfiguration in project azure-sdk-for-java by Azure.

the class TestNetworkInterface method createResource.

@Override
public NetworkInterface createResource(NetworkInterfaces networkInterfaces) throws Exception {
    final String nicName = "nic" + this.testId;
    final String vnetName = "net" + this.testId;
    final String pipName = "pip" + this.testId;
    final Region region = Region.US_EAST;
    Network network = networkInterfaces.manager().networks().define(vnetName).withRegion(region).withNewResourceGroup().withAddressSpace("10.0.0.0/28").withSubnet("subnet1", "10.0.0.0/29").withSubnet("subnet2", "10.0.0.8/29").create();
    NetworkInterface nic = networkInterfaces.define(nicName).withRegion(region).withExistingResourceGroup(network.resourceGroupName()).withExistingPrimaryNetwork(network).withSubnet("subnet1").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(pipName).withIPForwarding().create();
    // Verifications
    NicIPConfiguration ipConfig = nic.primaryIPConfiguration();
    Assert.assertNotNull(ipConfig);
    network = ipConfig.getNetwork();
    Assert.assertNotNull(network);
    Subnet subnet = network.subnets().get(ipConfig.subnetName());
    Assert.assertNotNull(subnet);
    Assert.assertEquals(1, subnet.networkInterfaceIPConfigurationCount());
    Set<NicIPConfiguration> ipConfigs = subnet.getNetworkInterfaceIPConfigurations();
    Assert.assertNotNull(ipConfigs);
    Assert.assertEquals(1, ipConfigs.size());
    NicIPConfiguration ipConfig2 = ipConfigs.iterator().next();
    Assert.assertEquals(ipConfig.name().toLowerCase(), ipConfig2.name().toLowerCase());
    return nic;
}
Also used : Network(com.microsoft.azure.management.network.Network) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) Subnet(com.microsoft.azure.management.network.Subnet) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration)

Example 4 with NicIPConfiguration

use of com.microsoft.azure.management.network.NicIPConfiguration in project cloudbreak by hortonworks.

the class AzureResourceConnector method collectInstanceResourcesToRemove.

private Map<String, Object> collectInstanceResourcesToRemove(AuthenticatedContext ac, CloudStack stack, AzureClient client, AzureCredentialView azureCredentialView, String stackName, CloudInstance instance) {
    String instanceId = instance.getInstanceId();
    Long privateId = instance.getTemplate().getPrivateId();
    AzureDiskType azureDiskType = AzureDiskType.getByValue(instance.getTemplate().getVolumeType());
    String attachedDiskStorageName = azureStorage.getAttachedDiskStorageName(azureStorage.getArmAttachedStorageOption(stack.getParameters()), azureCredentialView, privateId, ac.getCloudContext(), azureDiskType);
    Map<String, Object> resourcesToRemove = new HashMap<>();
    resourcesToRemove.put(ATTACHED_DISK_STORAGE_NAME, attachedDiskStorageName);
    try {
        VirtualMachine virtualMachine = client.getVirtualMachine(stackName, instanceId);
        List<String> networkInterfaceIds = virtualMachine.networkInterfaceIds();
        Collection<String> networkInterfacesNames = new ArrayList<>();
        Collection<String> publicIpAddressNames = new ArrayList<>();
        for (String interfaceId : networkInterfaceIds) {
            NetworkInterface networkInterface = client.getNetworkInterfaceById(interfaceId);
            String interfaceName = networkInterface.name();
            networkInterfacesNames.add(interfaceName);
            Collection<String> ipNames = new HashSet<>();
            for (NicIPConfiguration ipConfiguration : networkInterface.ipConfigurations().values()) {
                if (ipConfiguration.publicIPAddressId() != null && ipConfiguration.getPublicIPAddress().name() != null) {
                    ipNames.add(ipConfiguration.getPublicIPAddress().name());
                }
            }
            publicIpAddressNames.addAll(ipNames);
        }
        resourcesToRemove.put(NETWORK_INTERFACES_NAMES, networkInterfacesNames);
        resourcesToRemove.put(PUBLIC_ADDRESS_NAME, publicIpAddressNames);
        collectRemovableDisks(resourcesToRemove, virtualMachine);
    } catch (CloudException e) {
        if (e.response().code() != AzureConstants.NOT_FOUND) {
            throw new CloudConnectorException(e.body().message(), e);
        }
    } catch (RuntimeException e) {
        throw new CloudConnectorException("can't collect instance resources", e);
    }
    return resourcesToRemove;
}
Also used : HashMap(java.util.HashMap) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) CloudException(com.microsoft.azure.CloudException) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) HashSet(java.util.HashSet)

Example 5 with NicIPConfiguration

use of com.microsoft.azure.management.network.NicIPConfiguration in project azure-sdk-for-java by Azure.

the class TestPublicIPAddress method printPIP.

public static void printPIP(PublicIPAddress resource) {
    StringBuilder info = new StringBuilder().append("Public IP Address: ").append(resource.id()).append("\n\tName: ").append(resource.name()).append("\n\tResource group: ").append(resource.resourceGroupName()).append("\n\tRegion: ").append(resource.region()).append("\n\tTags: ").append(resource.tags()).append("\n\tIP Address: ").append(resource.ipAddress()).append("\n\tLeaf domain label: ").append(resource.leafDomainLabel()).append("\n\tFQDN: ").append(resource.fqdn()).append("\n\tReverse FQDN: ").append(resource.reverseFqdn()).append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes()).append("\n\tIP allocation method: ").append(resource.ipAllocationMethod().toString()).append("\n\tIP version: ").append(resource.version().toString());
    // Show the associated load balancer if any
    info.append("\n\tLoad balancer association: ");
    if (resource.hasAssignedLoadBalancer()) {
        final LoadBalancerPublicFrontend frontend = resource.getAssignedLoadBalancerFrontend();
        final LoadBalancer lb = frontend.parent();
        info.append("\n\t\tLoad balancer ID: ").append(lb.id()).append("\n\t\tFrontend name: ").append(frontend.name());
    } else {
        info.append("(None)");
    }
    // Show the associated NIC if any
    info.append("\n\tNetwork interface association: ");
    if (resource.hasAssignedNetworkInterface()) {
        final NicIPConfiguration nicIp = resource.getAssignedNetworkInterfaceIPConfiguration();
        final NetworkInterface nic = nicIp.parent();
        info.append("\n\t\tNetwork interface ID: ").append(nic.id()).append("\n\t\tIP config name: ").append(nicIp.name());
    } else {
        info.append("(None)");
    }
    System.out.println(info.toString());
}
Also used : LoadBalancerPublicFrontend(com.microsoft.azure.management.network.LoadBalancerPublicFrontend) LoadBalancer(com.microsoft.azure.management.network.LoadBalancer) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration)

Aggregations

NicIPConfiguration (com.microsoft.azure.management.network.NicIPConfiguration)8 NetworkInterface (com.microsoft.azure.management.network.NetworkInterface)5 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 CloudException (com.microsoft.azure.CloudException)1 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1 LoadBalancer (com.microsoft.azure.management.network.LoadBalancer)1 LoadBalancerBackend (com.microsoft.azure.management.network.LoadBalancerBackend)1 LoadBalancerInboundNatRule (com.microsoft.azure.management.network.LoadBalancerInboundNatRule)1 LoadBalancerPublicFrontend (com.microsoft.azure.management.network.LoadBalancerPublicFrontend)1 Network (com.microsoft.azure.management.network.Network)1 Subnet (com.microsoft.azure.management.network.Subnet)1 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CompositeException (rx.exceptions.CompositeException)1