Search in sources :

Example 6 with ResourceGroupInner

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

the class AzureTestUtil method createResourceGroup.

public static ResourceGroupInner createResourceGroup(ResourceManagementClientImpl resourceManagementClient, String name) {
    ResourceGroupInner rgParams = new ResourceGroupInner();
    rgParams.withName(name);
    rgParams.withLocation(AzureTestUtil.AZURE_RESOURCE_GROUP_LOCATION);
    ResourceGroupInner resourceGroup = resourceManagementClient.resourceGroups().createOrUpdate(rgParams.name(), rgParams);
    return resourceGroup;
}
Also used : ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner)

Example 7 with ResourceGroupInner

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

the class AzureInstanceService method createResourceGroup.

private void createResourceGroup(AzureInstanceContext ctx, AzureInstanceStage nextStage) {
    String resourceGroupName = AzureUtils.getResourceGroupName(ctx);
    ResourceGroupInner resourceGroup = new ResourceGroupInner();
    resourceGroup.withLocation(ctx.child.description.regionId);
    String msg = "Creating Azure Resource Group [" + resourceGroupName + "] for [" + ctx.vmName + "] VM";
    getResourceManagementClientImpl(ctx).resourceGroups().createOrUpdateAsync(resourceGroupName, resourceGroup, new TransitionToCallback<ResourceGroupInner>(ctx, nextStage, msg) {

        @Override
        CompletionStage<ResourceGroupInner> handleSuccess(ResourceGroupInner rg) {
            this.ctx.resourceGroup = rg;
            return CompletableFuture.completedFuture(rg);
        }
    });
}
Also used : ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) CompletionStage(java.util.concurrent.CompletionStage)

Example 8 with ResourceGroupInner

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

the class AzureInstanceService method createStorageAccountRG.

/**
 * Init storage account name and resource group, using the following approach:
 * <table border=1>
 * <tr>
 * <th>AZURE_STORAGE_ACCOUNT_NAME</th>
 * <th>AZURE_STORAGE_ACCOUNT_RG_NAME</th>
 * <th>Used Parameter</th>
 * </tr>
 * <tr>
 * <td>provided</td>
 * <td>provided</td>
 * <td>SA name = AZURE_STORAGE_ACCOUNT_NAME<br>
 * SA RG name = AZURE_STORAGE_ACCOUNT_RG_NAME</td>
 * </tr>
 * <tr>
 * <td>provided</td>
 * <td>not provided</td>
 * <td>SA name = AZURE_STORAGE_ACCOUNT_NAME<br>
 * SA RG name = AZURE_STORAGE_ACCOUNT_DEFAULT_RG_NAME</td>
 * </tr>
 * <tr>
 * <td>not provided</td>
 * <td>provided</td>
 * <td>SA name = generated name<br>
 * SA RG name = ctx.resourceGroup.getName()</td>
 * </tr>
 * <tr>
 * <td>not provided</td>
 * <td>not provided</td>
 * <td>SA name = generated name<br>
 * SA RG name = ctx.resourceGroup.getName()</td>
 * </tr>
 * </table>
 */
private DeferredResult<AzureInstanceContext> createStorageAccountRG(AzureInstanceContext ctx) {
    // Either we are reusing an existing storage account or using managed disks.
    if (ctx.reuseExistingStorageAccount() || ctx.useManagedDisks()) {
        return DeferredResult.completed(ctx);
    } else {
        ctx.storageAccountName = ctx.bootDiskState.customProperties.get(AZURE_STORAGE_ACCOUNT_NAME);
    }
    ctx.storageAccountRGName = ctx.bootDiskState.customProperties.getOrDefault(AZURE_STORAGE_ACCOUNT_RG_NAME, AZURE_STORAGE_ACCOUNT_DEFAULT_RG_NAME);
    if (ctx.storageAccountName == null) {
        // In case SA is not provided in the request, use request VA resource group
        ctx.storageAccountName = String.valueOf(System.currentTimeMillis()) + "st";
        ctx.storageAccountRGName = ctx.resourceGroup.name();
        return DeferredResult.completed(ctx);
    }
    String msg = "Create/Update SA Resource Group [" + ctx.storageAccountRGName + "] for [" + ctx.vmName + "] VM";
    AzureDeferredResultServiceCallback<ResourceGroupInner> handler = new Default<>(this, msg);
    // Use shared RG. In case not provided in the bootDisk properties, use the default one
    final ResourceGroupInner sharedSARG = new ResourceGroupInner();
    sharedSARG.withLocation(ctx.child.description.regionId);
    getResourceManagementClientImpl(ctx).resourceGroups().createOrUpdateAsync(ctx.storageAccountRGName, sharedSARG, handler);
    return handler.toDeferredResult().thenApply(ignore -> ctx);
}
Also used : ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default)

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