Search in sources :

Example 1 with ResourceGroupInner

use of com.microsoft.azure.management.resources.implementation.ResourceGroupInner in project photon-model by vmware.

the class AzureSecurityGroupService method createResourceGroup.

private DeferredResult<AzureSecurityGroupContext> createResourceGroup(AzureSecurityGroupContext context) {
    ResourceGroupInner resourceGroup = new ResourceGroupInner();
    resourceGroup.withLocation(context.securityGroupState.regionId);
    return AzureSecurityGroupUtils.createResourceGroupForSecurityGroup(this, context.azureSdkClients.getResourceManagementClientImpl().resourceGroups(), context.securityGroupState.name, resourceGroup).thenApply(rg -> {
        context.resourceGroup = rg;
        // add the resource group name to the SG custom properties
        if (context.securityGroupState.customProperties == null) {
            context.securityGroupState.customProperties = new HashMap<>(1);
        }
        context.securityGroupState.customProperties.put(RESOURCE_GROUP_NAME, context.resourceGroup.name());
        return context;
    });
}
Also used : ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner)

Example 2 with ResourceGroupInner

use of com.microsoft.azure.management.resources.implementation.ResourceGroupInner in project photon-model by vmware.

the class AzureTestUtil method createResourceGroupWithSharedNetwork.

/**
 * Create SHARED vNet-Subnets-Gateway in a separate RG.
 * <p>
 * NOTE1: The names of the vNet and Subnets MUST be equal to the ones set by
 * AzureTestUtil.createDefaultNicStates.
 * <p>
 * NOTE2: Since this is SHARED vNet it's not deleted after the test.
 */
public static ResourceGroupInner createResourceGroupWithSharedNetwork(ResourceManagementClientImpl resourceManagementClient, NetworkManagementClientImpl networkManagementClient, AzureNicSpecs nicSpecs) throws Throwable {
    // Create the shared RG itself
    ResourceGroupInner sharedNetworkRG = createResourceGroup(resourceManagementClient, AZURE_SHARED_NETWORK_RESOURCE_GROUP_NAME);
    // Create shared vNet-Subnet-Gateway under shared RG
    createAzureVirtualNetwork(sharedNetworkRG.name(), nicSpecs, networkManagementClient);
    // Create shared NSG under shared RG
    createAzureNetworkSecurityGroup(sharedNetworkRG.name(), networkManagementClient);
    return sharedNetworkRG;
}
Also used : ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner)

Example 3 with ResourceGroupInner

use of com.microsoft.azure.management.resources.implementation.ResourceGroupInner in project photon-model by vmware.

the class TestAzureProvisionTask method testProvisionVMUsingSharedNetwork.

/**
 * Creates Azure instance that uses shared/existing Network via a provision task.
 * <p>
 * It duplicates {@link #testProvision()} and just points to an external/shared Network.
 */
@Test
@Ignore("Since azure build timeouts due to the time consuming provision-decommission VM " + "executed by the tests. So far we sacrifice this test.")
public void testProvisionVMUsingSharedNetwork() throws Throwable {
    // The test is only suitable for real (non-mocking env).
    Assume.assumeFalse(this.isMock);
    /*
         * Create SHARED vNet-Subnets in a separate RG.
         *
         * VERY IMPORTANT NOTE1: The names of the vNet and Subnets MUST be equal to the ones set by
         * AzureTestUtil.createDefaultNicStates.
         *
         * NOTE2: Since this is SHARED vNet it's not deleted after the test.
         *
         * The idea here is that we are provisioning a VM and linking it to an already existing
         * subnet/network. That's why the network is with a !!!FIXED!!! name, and that SAME name is
         * being used by standard provisioning!
         */
    final ResourceGroupInner sharedNetworkRG = AzureTestUtil.createResourceGroupWithSharedNetwork(getAzureSdkClients().getResourceManagementClientImpl(), getAzureSdkClients().getNetworkManagementClientImpl(), SHARED_NETWORK_NIC_SPEC);
    // Create corresponding ResourceGroupState
    ResourceGroupState sharedNetworkRGState = createDefaultResourceGroupState(getHost(), sharedNetworkRG.name(), this.computeHost, this.endpointState, ResourceGroupStateType.AzureResourceGroup);
    // END of prepare phase.
    // In this scenario mark the VM name (and its corresponding RG) with "-withSharedNW"
    String vmName = azureVMName + "-SharedNW";
    // create a Azure VM compute resource
    this.vmState = createDefaultVMResource(getHost(), vmName, this.computeHost, this.endpointState, DEFAULT_NIC_SPEC, // In addition to standard provisioning pass the RG of the shared network
    sharedNetworkRGState.documentSelfLink);
    kickOffProvisionTask();
    assertVmNetworksConfiguration(DEFAULT_NIC_SPEC, vmName);
}
Also used : ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) Ignore(org.junit.Ignore) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 4 with ResourceGroupInner

use of com.microsoft.azure.management.resources.implementation.ResourceGroupInner in project photon-model by vmware.

the class AzureLoadBalancerServiceTest method setUpTests.

@Before
public void setUpTests() throws Throwable {
    if (computeHost == null) {
        ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
        endpointState = this.createEndpointState();
        // create a compute host for the Azure
        computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
    }
    AuthCredentialsServiceState azureVMAuth = new AuthCredentialsServiceState();
    azureVMAuth.userEmail = AZURE_ADMIN_USERNAME;
    azureVMAuth.privateKey = AZURE_ADMIN_PASSWORD;
    azureVMAuth = TestUtils.doPost(host, azureVMAuth, AuthCredentialsServiceState.class, UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK));
    ComputeDescription compDesc = buildComputeDescription(host, computeHost, endpointState, azureVMAuth);
    this.rgName = AzureUtils.DEFAULT_GROUP_PREFIX + compDesc.documentCreationTimeMicros / 1000;
    ResourceGroupState rgState = createDefaultResourceGroupState(this.host, this.rgName, computeHost, endpointState, ResourceGroupStateType.AzureResourceGroup);
    networkState = createNetworkState(rgState.documentSelfLink);
    vmStates = new ArrayList<>();
    for (int i = 0; i < poolSize; i++) {
        ComputeState vmState = createDefaultVMResource(getHost(), this.rgName + "VM" + i, computeHost, endpointState, NO_PUBLIC_IP_NIC_SPEC, null, 0, compDesc, this.rgName);
        vmStates.add(vmState);
    }
    subnetState = createSubnetState(this.subnetName);
    if (!this.isMock) {
        this.loadBalancerClient = getAzureSdkClients().getNetworkManagementClientImpl().loadBalancers();
        this.rgOpsClient = getAzureSdkClients().getResourceManagementClientImpl().resourceGroups();
        ResourceGroupInner rg = new ResourceGroupInner();
        rg.withName(this.rgName);
        rg.withLocation(this.regionId);
        this.rgOpsClient.createOrUpdate(this.rgName, rg);
        VirtualNetworkInner vNet = new VirtualNetworkInner();
        AddressSpace addressSpace = new AddressSpace();
        addressSpace.withAddressPrefixes(Collections.singletonList(AZURE_DEFAULT_VPC_CIDR));
        vNet.withAddressSpace(addressSpace);
        vNet.withLocation(this.regionId);
        VirtualNetworksInner vNetClient = getAzureSdkClients().getNetworkManagementClientImpl().virtualNetworks();
        vNetClient.createOrUpdate(this.rgName, this.vNetName, vNet);
        kickOffComputeProvision();
        kickOffSubnetProvision(InstanceRequestType.CREATE, subnetState, TaskStage.FINISHED);
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VirtualNetworksInner(com.microsoft.azure.management.network.implementation.VirtualNetworksInner) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) AddressSpace(com.microsoft.azure.management.network.AddressSpace) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) AzureTestUtil.buildComputeDescription(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.buildComputeDescription) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) Before(org.junit.Before)

Example 5 with ResourceGroupInner

use of com.microsoft.azure.management.resources.implementation.ResourceGroupInner in project photon-model by vmware.

the class AzureSubnetTaskServiceTest method setUp.

@Override
@Before
public void setUp() throws Throwable {
    CommandLineArgumentParser.parseFromProperties(this);
    if (computeHost == null) {
        PhotonModelServices.startServices(this.host);
        PhotonModelTaskServices.startServices(this.host);
        PhotonModelAdaptersRegistryAdapters.startServices(this.host);
        AzureAdaptersTestUtils.startServicesSynchronouslyAzure(this.host);
        this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
        // TODO: VSYM-992 - improve test/fix arbitrary timeout
        this.host.setTimeoutSeconds(600);
        ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
        AuthCredentialsServiceState authCredentials = createDefaultAuthCredentials(this.host, this.clientID, this.clientKey, this.subscriptionId, this.tenantId);
        endpointState = createDefaultEndpointState(this.host, authCredentials.documentSelfLink);
        // create a compute host for the Azure
        computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
    }
    if (!this.isMock) {
        ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
        NetworkManagementClientImpl networkManagementClient = new NetworkManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
        ResourceManagementClientImpl resourceManagementClient = new ResourceManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
        this.vNetClient = networkManagementClient.virtualNetworks();
        this.rgOpsClient = resourceManagementClient.resourceGroups();
        this.subnetsClient = networkManagementClient.subnets();
        ResourceGroupInner rg = new ResourceGroupInner();
        rg.withName(this.rgName);
        rg.withLocation(this.regionId);
        this.rgOpsClient.createOrUpdate(this.rgName, rg);
        VirtualNetworkInner vNet = new VirtualNetworkInner();
        // Azure's custom serializers don't handle well collections constructed with
        // Collections.singletonList(), so initialize an ArrayList
        AddressSpace addressSpace = new AddressSpace();
        List<String> cidrs = new ArrayList<>();
        cidrs.add(AZURE_DEFAULT_VPC_CIDR);
        addressSpace.withAddressPrefixes(cidrs);
        vNet.withAddressSpace(addressSpace);
        vNet.withLocation(this.regionId);
        this.vNetClient.createOrUpdate(this.rgName, this.vNetName, vNet);
    }
    ResourceGroupState rgState = createDefaultResourceGroupState(this.host, this.rgName, computeHost, endpointState, ResourceGroupStateType.AzureResourceGroup);
    this.networkState = createNetworkState(rgState.documentSelfLink);
}
Also used : NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) AddressSpace(com.microsoft.azure.management.network.AddressSpace) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) ArrayList(java.util.ArrayList) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) Before(org.junit.Before)

Aggregations

ResourceGroupInner (com.microsoft.azure.management.resources.implementation.ResourceGroupInner)8 AzureTestUtil.createDefaultResourceGroupState (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState)3 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)3 AddressSpace (com.microsoft.azure.management.network.AddressSpace)2 VirtualNetworkInner (com.microsoft.azure.management.network.implementation.VirtualNetworkInner)2 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)2 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)2 Before (org.junit.Before)2 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)1 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)1 VirtualNetworksInner (com.microsoft.azure.management.network.implementation.VirtualNetworksInner)1 ResourceManagementClientImpl (com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)1 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)1 AzureTestUtil.buildComputeDescription (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.buildComputeDescription)1 Default (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default)1 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 ArrayList (java.util.ArrayList)1 CompletionStage (java.util.concurrent.CompletionStage)1 Ignore (org.junit.Ignore)1