Search in sources :

Example 1 with NetworkSecurityGroup

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

the class Utils method print.

/**
     * Print network info.
     * @param resource a network
     * @throws IOException IO errors
     * @throws CloudException Cloud errors
     */
public static void print(Network resource) {
    StringBuilder info = new StringBuilder();
    info.append("Network: ").append(resource.id()).append("Name: ").append(resource.name()).append("\n\tResource group: ").append(resource.resourceGroupName()).append("\n\tRegion: ").append(resource.region()).append("\n\tTags: ").append(resource.tags()).append("\n\tAddress spaces: ").append(resource.addressSpaces()).append("\n\tDNS server IPs: ").append(resource.dnsServerIPs());
    // Output subnets
    for (Subnet subnet : resource.subnets().values()) {
        info.append("\n\tSubnet: ").append(subnet.name()).append("\n\t\tAddress prefix: ").append(subnet.addressPrefix());
        NetworkSecurityGroup subnetNsg = subnet.getNetworkSecurityGroup();
        if (subnetNsg != null) {
            info.append("\n\t\tNetwork security group: ").append(subnetNsg.id());
        }
    }
    System.out.println(info.toString());
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) Subnet(com.microsoft.azure.management.network.Subnet)

Example 2 with NetworkSecurityGroup

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

the class AzureTests method testGenericResources.

/**
     * Tests basic generic resources retrieval.
     * @throws Exception
     */
@Test
public void testGenericResources() throws Exception {
    // Create some resources
    NetworkSecurityGroup nsg = azure.networkSecurityGroups().define(SdkContext.randomResourceName("nsg", 13)).withRegion(Region.US_EAST).withNewResourceGroup().create();
    azure.publicIPAddresses().define(SdkContext.randomResourceName("pip", 13)).withRegion(Region.US_EAST).withExistingResourceGroup(nsg.resourceGroupName()).create();
    PagedList<GenericResource> resources = azure.genericResources().listByResourceGroup(nsg.resourceGroupName());
    Assert.assertEquals(2, resources.size());
    GenericResource firstResource = resources.get(0);
    GenericResource resourceById = azure.genericResources().getById(firstResource.id());
    GenericResource resourceByDetails = azure.genericResources().get(firstResource.resourceGroupName(), firstResource.resourceProviderNamespace(), firstResource.resourceType(), firstResource.name());
    Assert.assertTrue(resourceById.id().equalsIgnoreCase(resourceByDetails.id()));
    azure.resourceGroups().beginDeleteByName(nsg.resourceGroupName());
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) GenericResource(com.microsoft.azure.management.resources.GenericResource) Test(org.junit.Test)

Example 3 with NetworkSecurityGroup

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

the class AzureUtils method validateSubnetRules.

public void validateSubnetRules(AzureClient client, Network network) {
    if (isExistingNetwork(network)) {
        String resourceGroupName = getCustomResourceGroupName(network);
        String networkId = getCustomNetworkId(network);
        Collection<String> subnetIds = getCustomSubnetIds(network);
        for (String subnetId : subnetIds) {
            try {
                Subnet subnet = client.getSubnetProperties(resourceGroupName, networkId, subnetId);
                if (subnet == null) {
                    throw new CloudConnectorException(String.format("Subnet [%s] does not found with resourceGroupName [%s] and network [%s]", subnetId, resourceGroupName, networkId));
                }
                NetworkSecurityGroup networkSecurityGroup = subnet.getNetworkSecurityGroup();
                if (networkSecurityGroup != null) {
                    validateSecurityGroup(client, networkSecurityGroup);
                }
            } catch (RuntimeException e) {
                throw new CloudConnectorException("Subnet validation failed, cause: " + e.getMessage(), e);
            }
        }
    }
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Subnet(com.microsoft.azure.management.network.Subnet)

Example 4 with NetworkSecurityGroup

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

the class AzureUtils method validateSecurityGroup.

private void validateSecurityGroup(AzureClient client, HasId networkSecurityGroup) {
    String securityGroupId = networkSecurityGroup.id();
    String[] parts = securityGroupId.split("/");
    if (parts.length != ID_SEGMENTS) {
        LOGGER.info("Cannot get the security group's properties, id: {}", securityGroupId);
        return;
    }
    try {
        NetworkSecurityGroup securityGroup = client.getSecurityGroupProperties(parts[RG_PART], parts[SEC_GROUP_PART]);
        LOGGER.info("Retrieved security group properties: {}", securityGroup);
        Map<String, NetworkSecurityRule> securityRules = securityGroup.securityRules();
        boolean port22Found = false;
        boolean port443Found = false;
        for (NetworkSecurityRule securityRule : securityRules.values()) {
            if (isValidInboundRule(securityRule)) {
                String destinationPortRange = securityRule.destinationPortRange();
                if ("*".equals(destinationPortRange)) {
                    return;
                }
                String[] range = destinationPortRange.split("-");
                port443Found = port443Found || isPortFound(PORT_443, range);
                port22Found = port22Found || isPortFound(PORT_22, range);
                if (port22Found && port443Found) {
                    return;
                }
            }
        }
    } catch (RuntimeException e) {
        throw new CloudConnectorException("Validating security group failed.", e);
    }
    throw new CloudConnectorException("The specified subnet's security group does not allow traffic for port 22 and/or 443");
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) NetworkSecurityRule(com.microsoft.azure.management.network.NetworkSecurityRule)

Example 5 with NetworkSecurityGroup

use of com.microsoft.azure.management.network.NetworkSecurityGroup in project azure-tools-for-java by Microsoft.

the class SettingsStep method retrieveNetworkSecurityGroups.

private void retrieveNetworkSecurityGroups() {
    AzureTaskManager.getInstance().runInBackground("Loading network security groups...", new Runnable() {

        @Override
        public void run() {
            if (networkSecurityGroups == null) {
                networkSecurityGroups = wizard.getAzure().networkSecurityGroups().list();
            }
            DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                @Override
                public void run() {
                    nsgCombo.removeAll();
                    nsgCombo.add(NONE);
                    for (NetworkSecurityGroup nsg : networkSecurityGroups) {
                        nsgCombo.add(nsg.name());
                        nsgCombo.setData(nsg.name(), nsg);
                    }
                    nsgCombo.select(0);
                }
            });
        }
    });
    nsgCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (NONE.equals(nsgCombo.getText())) {
                wizard.setNetworkSecurityGroup(null);
            } else if (nsgCombo.getData(nsgCombo.getText()) instanceof NetworkSecurityGroup) {
                wizard.setNetworkSecurityGroup((NetworkSecurityGroup) nsgCombo.getData(nsgCombo.getText()));
            }
        }
    });
    if (networkSecurityGroups == null) {
        DefaultLoader.getIdeHelper().invokeAndWait(new Runnable() {

            @Override
            public void run() {
                nsgCombo.setItems(new String[] { NONE, LOADING });
                nsgCombo.select(0);
            }
        });
    }
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

NetworkSecurityGroup (com.microsoft.azure.management.network.NetworkSecurityGroup)13 Network (com.microsoft.azure.management.network.Network)5 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)4 Subnet (com.microsoft.azure.management.network.Subnet)4 Date (java.util.Date)3 NetworkInterface (com.microsoft.azure.management.network.NetworkInterface)2 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)2 Indexable (com.microsoft.azure.management.resources.fluentcore.model.Indexable)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 ArrayList (java.util.ArrayList)2 Strings (com.google.common.base.Strings)1 SubResource (com.microsoft.azure.SubResource)1 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)1 NetworkSecurityRule (com.microsoft.azure.management.network.NetworkSecurityRule)1 RouteTable (com.microsoft.azure.management.network.RouteTable)1 GenericResource (com.microsoft.azure.management.resources.GenericResource)1 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)1 Creatable (com.microsoft.azure.management.resources.fluentcore.model.Creatable)1 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)1 PlatformResources (com.sequenceiq.cloudbreak.cloud.PlatformResources)1