Search in sources :

Example 11 with NetworkSecurityGroupInner

use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method testCreateSecurityGroupNoRules.

@Test
public void testCreateSecurityGroupNoRules() throws Throwable {
    SecurityGroupState securityGroupState = provisionSecurityGroup(new ArrayList<>(), new ArrayList<>(), TaskStage.FINISHED);
    assertNotNull(securityGroupState.id);
    assertNotEquals(securityGroupState.id, this.securityGroupName);
    if (!this.isMock) {
        // Verify that the security group was created.
        NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
        assertEquals(this.securityGroupName, sgResponse.name());
        assertEquals(securityGroupState.id, sgResponse.id());
        assertEquals(sgResponse.securityRules().size(), 0);
        // delete the security group
        startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
    }
}
Also used : NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 12 with NetworkSecurityGroupInner

use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.

the class AzureTestUtil method createAzureNetworkSecurityGroup.

private static void createAzureNetworkSecurityGroup(String resourceGroupName, NetworkManagementClientImpl networkManagementClient) throws Exception {
    final NetworkSecurityGroupInner sharedNSG = new NetworkSecurityGroupInner();
    sharedNSG.withLocation(AzureTestUtil.AZURE_RESOURCE_GROUP_LOCATION);
    SecurityRuleInner sr = new SecurityRuleInner();
    sr.withPriority(AzureConstants.AZURE_SECURITY_GROUP_PRIORITY);
    sr.withAccess(SecurityRuleAccess.ALLOW);
    sr.withDirection(SecurityRuleDirection.INBOUND);
    sr.withSourceAddressPrefix(AzureConstants.AZURE_SECURITY_GROUP_SOURCE_ADDRESS_PREFIX);
    sr.withDestinationAddressPrefix(AzureConstants.AZURE_SECURITY_GROUP_DESTINATION_ADDRESS_PREFIX);
    sr.withSourcePortRange(AzureConstants.AZURE_SECURITY_GROUP_SOURCE_PORT_RANGE);
    sr.withDestinationPortRange(AzureConstants.AZURE_LINUX_SECURITY_GROUP_DESTINATION_PORT_RANGE);
    sr.withName(AzureConstants.AZURE_LINUX_SECURITY_GROUP_NAME);
    sr.withProtocol(SecurityRuleProtocol.TCP);
    // Azure's custom serializers don't handle well collections constructed with
    // Collections.singletonList(), so initialize an ArrayList
    ArrayList<SecurityRuleInner> rules = new ArrayList<>();
    rules.add(sr);
    sharedNSG.withSecurityRules(rules);
    networkManagementClient.networkSecurityGroups().createOrUpdate(resourceGroupName, AzureTestUtil.AZURE_SECURITY_GROUP_NAME, sharedNSG);
}
Also used : SecurityRuleInner(com.microsoft.azure.management.network.implementation.SecurityRuleInner) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) ArrayList(java.util.ArrayList)

Example 13 with NetworkSecurityGroupInner

use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.

the class AzureInstanceContext method getSecurityGroups.

/**
 * For every NIC lookup associated Azure Security Groups as specified by
 * {@code AzureNicContext.securityGroupState.name}. If any of the security groups is not found
 * leave the {@code AzureNicContext.securityGroup} as null and proceed without an exception.
 */
private DeferredResult<AzureInstanceContext> getSecurityGroups(AzureInstanceContext context) {
    if (context.nics.isEmpty()) {
        return DeferredResult.completed(context);
    }
    NetworkSecurityGroupsInner azureClient = context.azureSdkClients.getNetworkManagementClientImpl().networkSecurityGroups();
    List<DeferredResult<NetworkSecurityGroupInner>> getSecurityGroupDRs = context.nics.stream().filter(nicCtx -> nicCtx.securityGroupState() != null && nicCtx.securityGroupRGState != null).map(nicCtx -> {
        String sgName = nicCtx.securityGroupState().name;
        String msg = "Getting Azure Security Group [" + nicCtx.securityGroupRGState.name + "/" + sgName + "] for [" + nicCtx.nicStateWithDesc.name + "] NIC for [" + context.vmName + "] VM";
        return AzureSecurityGroupUtils.getSecurityGroup(service(), azureClient, nicCtx.securityGroupRGState.name, sgName, msg).thenApply(sg -> {
            nicCtx.securityGroup = sg;
            return sg;
        });
    }).collect(Collectors.toList());
    return DeferredResult.allOf(getSecurityGroupDRs).handle((all, exc) -> {
        if (exc != null) {
            String msg = String.format("Error getting Security Group from Azure for [%s] VM.", context.child.name);
            throw new IllegalStateException(msg, exc);
        }
        return context;
    });
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Level(java.util.logging.Level) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AvailabilitySet(com.microsoft.azure.management.compute.AvailabilitySet) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) AvailabilitySetInner(com.microsoft.azure.management.compute.implementation.AvailabilitySetInner) Collectors(java.util.stream.Collectors) Disk(com.microsoft.azure.management.compute.Disk) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) BaseComputeInstanceContext(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext) AzureSecurityGroupUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureSecurityGroupUtils) SubnetsInner(com.microsoft.azure.management.network.implementation.SubnetsInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkSecurityGroupsInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner) DeferredResult(com.vmware.xenon.common.DeferredResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) StorageAccountInner(com.microsoft.azure.management.storage.implementation.StorageAccountInner) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) DiskService(com.vmware.photon.controller.model.resources.DiskService) NetworkSecurityGroupsInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)13 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)9 NetworkInterfaceInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)4 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)4 NetworkSecurityGroupsInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner)4 PublicIPAddressInner (com.microsoft.azure.management.network.implementation.PublicIPAddressInner)4 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)4 AzureTestUtil.getSecurityGroupState (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState)4 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)4 AzureSecurityGroupUtils (com.vmware.photon.controller.model.adapters.azure.utils.AzureSecurityGroupUtils)4 AzureUtils (com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils)4 DeferredResult (com.vmware.xenon.common.DeferredResult)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 SubResource (com.microsoft.azure.SubResource)3 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)3 IPAllocationMethod (com.microsoft.azure.management.network.IPAllocationMethod)3 NetworkInterfaceIPConfigurationInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner)3