Search in sources :

Example 1 with NetworkSecurityRule

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

the class Utils method print.

/**
     * Print network security group.
     * @param resource a network security group
     */
public static void print(NetworkSecurityGroup resource) {
    StringBuilder info = new StringBuilder();
    info.append("NSG: ").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());
    // Output security rules
    for (NetworkSecurityRule rule : resource.securityRules().values()) {
        info.append("\n\tRule: ").append(rule.name()).append("\n\t\tAccess: ").append(rule.access()).append("\n\t\tDirection: ").append(rule.direction()).append("\n\t\tFrom address: ").append(rule.sourceAddressPrefix()).append("\n\t\tFrom port range: ").append(rule.sourcePortRange()).append("\n\t\tTo address: ").append(rule.destinationAddressPrefix()).append("\n\t\tTo port: ").append(rule.destinationPortRange()).append("\n\t\tProtocol: ").append(rule.protocol()).append("\n\t\tPriority: ").append(rule.priority());
    }
    System.out.println(info.toString());
}
Also used : NetworkSecurityRule(com.microsoft.azure.management.network.NetworkSecurityRule)

Example 2 with NetworkSecurityRule

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

the class TestNSG method printNSG.

public static void printNSG(NetworkSecurityGroup resource) {
    StringBuilder info = new StringBuilder();
    info.append("NSG: ").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());
    // Output security rules
    info.append("\n\tCustom security rules:");
    for (NetworkSecurityRule rule : resource.securityRules().values()) {
        info = printRule(rule, info);
    }
    // Output default security rules
    info.append("\n\tDefault security rules:");
    for (NetworkSecurityRule rule : resource.defaultSecurityRules().values()) {
        info = printRule(rule, info);
    }
    // Output associated NIC IDs
    info.append("\n\tNICs: ").append(resource.networkInterfaceIds());
    // Output associated subnets
    info.append("\n\tAssociated subnets: ");
    List<Subnet> subnets = resource.listAssociatedSubnets();
    if (subnets == null || subnets.size() == 0) {
        info.append("(None)");
    } else {
        for (Subnet subnet : subnets) {
            info.append("\n\t\tNetwork ID: ").append(subnet.parent().id()).append("\n\t\tSubnet name: ").append(subnet.name());
        }
    }
    System.out.println(info.toString());
}
Also used : NetworkSecurityRule(com.microsoft.azure.management.network.NetworkSecurityRule) Subnet(com.microsoft.azure.management.network.Subnet)

Example 3 with NetworkSecurityRule

use of com.microsoft.azure.management.network.NetworkSecurityRule 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)

Aggregations

NetworkSecurityRule (com.microsoft.azure.management.network.NetworkSecurityRule)3 NetworkSecurityGroup (com.microsoft.azure.management.network.NetworkSecurityGroup)1 Subnet (com.microsoft.azure.management.network.Subnet)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1