Search in sources :

Example 1 with VirtualNetworkInner

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

the class AzureInstanceService method createNetwork.

private void createNetwork(AzureInstanceContext ctx, AzureInstanceStage nextStage, List<SubnetInner> subnetsToCreate) {
    // All NICs MUST be at the same vNet (no cross vNet VMs),
    // so we select the Primary vNet.
    final AzureNicContext primaryNic = ctx.getPrimaryNic();
    final VirtualNetworkInner vNetToCreate = newAzureVirtualNetwork(ctx, primaryNic, subnetsToCreate);
    final String vNetName = primaryNic.networkState.name;
    final String vNetRGName = primaryNic.networkRGState != null ? primaryNic.networkRGState.name : ctx.resourceGroup.name();
    VirtualNetworksInner azureClient = getNetworkManagementClientImpl(ctx).virtualNetworks();
    final String subnetNames = vNetToCreate.subnets().stream().map(SubnetInner::name).collect(Collectors.joining(","));
    final String msg = "Creating Azure vNet-Subnet [v=" + vNetName + "; s=" + subnetNames + "] for [" + ctx.vmName + "] VM";
    AzureProvisioningCallbackWithRetry<VirtualNetworkInner> handler = new AzureProvisioningCallbackWithRetry<VirtualNetworkInner>(this, msg) {

        @Override
        protected DeferredResult<VirtualNetworkInner> consumeProvisioningSuccess(VirtualNetworkInner vNet) {
            // Populate NICs with Azure Subnet
            for (AzureNicContext nicCtx : ctx.nics) {
                if (nicCtx.subnet == null) {
                    nicCtx.subnet = vNet.subnets().stream().filter(subnet -> subnet.name().equals(nicCtx.subnetState.name)).findFirst().get();
                }
            }
            return DeferredResult.completed(vNet);
        }

        @Override
        protected String getProvisioningState(VirtualNetworkInner vNet) {
            // or PROVISIONING_STATE_SUCCEEDED if all are Succeeded
            if (vNet.subnets().size() == 0) {
                return PROVISIONING_STATE_FAILED_NO_SUBNET;
            }
            String subnetPS = vNet.subnets().stream().map(SubnetInner::provisioningState).filter(ps -> !PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(ps)).findFirst().orElse(PROVISIONING_STATE_SUCCEEDED);
            if (PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(vNet.provisioningState()) && PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(subnetPS)) {
                return PROVISIONING_STATE_SUCCEEDED;
            }
            return vNet.provisioningState() + ":" + subnetPS;
        }

        @Override
        protected Runnable checkProvisioningStateCall(ServiceCallback<VirtualNetworkInner> checkProvisioningStateCallback) {
            return () -> azureClient.getByResourceGroupAsync(vNetRGName, vNetName, null, /* expand */
            checkProvisioningStateCallback);
        }

        @Override
        protected Runnable retryServiceCall(ServiceCallback<VirtualNetworkInner> retryCallback) {
            return () -> azureClient.createOrUpdateAsync(vNetRGName, vNetName, vNetToCreate, retryCallback);
        }
    };
    azureClient.createOrUpdateAsync(vNetRGName, vNetName, vNetToCreate, handler);
    handler.toDeferredResult().thenApply(ignore -> ctx).whenComplete(thenAllocation(ctx, nextStage, NETWORK_NAMESPACE));
}
Also used : AzureNicContext(com.vmware.photon.controller.model.adapters.azure.instance.AzureInstanceContext.AzureNicContext) AzureProvisioningCallbackWithRetry(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallbackWithRetry) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) PROVISIONING_STATE_SUCCEEDED(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.PROVISIONING_STATE_SUCCEEDED) ComputeManager(com.microsoft.azure.management.compute.implementation.ComputeManager) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) COMPUTE_NAMESPACE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.COMPUTE_NAMESPACE) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) StorageManagementClientImpl(com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl) AzureDiagnosticSettings(com.vmware.photon.controller.model.adapters.azure.model.diagnostics.AzureDiagnosticSettings) INVALID_RESOURCE_GROUP(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.INVALID_RESOURCE_GROUP) Utils(com.vmware.xenon.common.Utils) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) ProvisioningState(com.microsoft.azure.management.storage.ProvisioningState) OSDisk(com.microsoft.azure.management.compute.OSDisk) AZURE_STORAGE_ACCOUNT_KEY1(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_KEY1) ProviderInner(com.microsoft.azure.management.resources.implementation.ProviderInner) CachingTypes(com.microsoft.azure.management.compute.CachingTypes) Indexable(com.microsoft.azure.management.resources.fluentcore.model.Indexable) StorageAccountListKeysResultInner(com.microsoft.azure.management.storage.implementation.StorageAccountListKeysResultInner) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) AZURE_STORAGE_ACCOUNT_DEFAULT_RG_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_DEFAULT_RG_NAME) Disk(com.microsoft.azure.management.compute.Disk) AzureProvisioningCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback) CompletionStage(java.util.concurrent.CompletionStage) AzureSecurityGroupUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureSecurityGroupUtils) StorageAccountTypes(com.microsoft.azure.management.compute.StorageAccountTypes) SkuInner(com.microsoft.azure.management.storage.implementation.SkuInner) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) STATUS_CODE_UNAUTHORIZED(com.vmware.xenon.common.Operation.STATUS_CODE_UNAUTHORIZED) InvalidKeyException(java.security.InvalidKeyException) StorageAccountCreateParametersInner(com.microsoft.azure.management.storage.implementation.StorageAccountCreateParametersInner) DiskCreateOptionTypes(com.microsoft.azure.management.compute.DiskCreateOptionTypes) ResourceGroupsInner(com.microsoft.azure.management.resources.implementation.ResourceGroupsInner) AzureProvisioningCallbackWithRetry(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallbackWithRetry) AZURE_DATA_DISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DATA_DISK_CACHING) INVALID_PARAMETER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.INVALID_PARAMETER) STORAGE_ACCOUNT_ALREADY_EXIST(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_ACCOUNT_ALREADY_EXIST) VirtualNetworksInner(com.microsoft.azure.management.network.implementation.VirtualNetworksInner) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) OperationContext(com.vmware.xenon.common.OperationContext) PROVISIONING_STATE_FAILED_NO_SUBNET(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.PROVISIONING_STATE_FAILED_NO_SUBNET) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) OSProfile(com.microsoft.azure.management.compute.OSProfile) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) StorageException(com.microsoft.azure.storage.StorageException) AzureAsyncCallback(com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback) AzureImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureInstanceContext.AzureImageSource) MISSING_SUBSCRIPTION_CODE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.MISSING_SUBSCRIPTION_CODE) StorageProfile(com.microsoft.azure.management.compute.StorageProfile) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BiConsumer(java.util.function.BiConsumer) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) OperationStatusResponseInner(com.microsoft.azure.management.compute.implementation.OperationStatusResponseInner) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) DataDisk(com.microsoft.azure.management.compute.DataDisk) ServiceCallback(com.microsoft.rest.ServiceCallback) STORAGE_NAMESPACE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_NAMESPACE) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) ImageSource(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext.ImageSource) File(java.io.File) ManagedDiskParametersInner(com.microsoft.azure.management.compute.implementation.ManagedDiskParametersInner) NETWORK_NAMESPACE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.NETWORK_NAMESPACE) AzureUtils.getStorageAccountKeyName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getStorageAccountKeyName) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) IPAllocationMethod(com.microsoft.azure.management.network.IPAllocationMethod) CloudError(com.microsoft.azure.CloudError) HardwareProfile(com.microsoft.azure.management.compute.HardwareProfile) AzureNicContext(com.vmware.photon.controller.model.adapters.azure.instance.AzureInstanceContext.AzureNicContext) URISyntaxException(java.net.URISyntaxException) NetworkProfile(com.microsoft.azure.management.compute.NetworkProfile) VirtualMachineImageResourceInner(com.microsoft.azure.management.compute.implementation.VirtualMachineImageResourceInner) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) SubscriptionInner(com.microsoft.azure.management.resources.implementation.SubscriptionInner) AZURE_MANAGED_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) Creatable(com.microsoft.azure.management.resources.fluentcore.model.Creatable) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URI(java.net.URI) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AvailabilitySet(com.microsoft.azure.management.compute.AvailabilitySet) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) SkuName(com.microsoft.azure.management.storage.SkuName) AddressSpace(com.microsoft.azure.management.network.AddressSpace) COMPUTER_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.COMPUTER_NAME) Predicate(java.util.function.Predicate) Collection(java.util.Collection) DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) AvailabilitySetInner(com.microsoft.azure.management.compute.implementation.AvailabilitySetInner) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest.InstanceRequestType) Collectors(java.util.stream.Collectors) Base64(java.util.Base64) List(java.util.List) VirtualHardDisk(com.microsoft.azure.management.compute.VirtualHardDisk) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) NetworkSecurityGroupsInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) Optional(java.util.Optional) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) DiskService(com.vmware.photon.controller.model.resources.DiskService) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) SubResource(com.microsoft.azure.SubResource) AZURE_OSDISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_OSDISK_CACHING) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AzureDeferredResultServiceCallbackWithRetry(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallbackWithRetry) VirtualMachineSizeTypes(com.microsoft.azure.management.compute.VirtualMachineSizeTypes) SubscriptionClientImpl(com.microsoft.azure.management.resources.implementation.SubscriptionClientImpl) Kind(com.microsoft.azure.management.storage.Kind) Level(java.util.logging.Level) FileUtils(com.vmware.xenon.common.FileUtils) AZURE_STORAGE_ACCOUNT_RG_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_RG_NAME) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) PublicIPAddressesInner(com.microsoft.azure.management.network.implementation.PublicIPAddressesInner) STORAGE_CONNECTION_STRING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_CONNECTION_STRING) AzureDecommissionCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDecommissionCallback) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) EncryptionUtils(com.vmware.photon.controller.model.security.util.EncryptionUtils) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) Operation(com.vmware.xenon.common.Operation) AvailabilitySetSkuTypes(com.microsoft.azure.management.compute.AvailabilitySetSkuTypes) StorageAccountKey(com.microsoft.azure.management.storage.StorageAccountKey) BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) NetworkInterfaceReferenceInner(com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) AZURE_STORAGE_ACCOUNT_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_NAME) CloudException(com.microsoft.azure.CloudException) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) StorageAccountInner(com.microsoft.azure.management.storage.implementation.StorageAccountInner) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) CLOUD_CONFIG_DEFAULT_FILE_INDEX(com.vmware.photon.controller.model.constants.PhotonModelConstants.CLOUD_CONFIG_DEFAULT_FILE_INDEX) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) PROVIDER_REGISTRED_STATE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.PROVIDER_REGISTRED_STATE) VirtualNetworksInner(com.microsoft.azure.management.network.implementation.VirtualNetworksInner) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) ServiceCallback(com.microsoft.rest.ServiceCallback) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)

Example 2 with VirtualNetworkInner

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

the class AzureInstanceService method newAzureVirtualNetwork.

/**
 * Converts Photon model constructs to underlying Azure VirtualNetwork model.
 */
private VirtualNetworkInner newAzureVirtualNetwork(AzureInstanceContext ctx, AzureNicContext nicCtx, List<SubnetInner> subnetsToCreate) {
    VirtualNetworkInner vNet = new VirtualNetworkInner();
    vNet.withLocation(ctx.resourceGroup.location());
    // Azure's custom serializers don't handle well collections constructed with
    // Collections.singletonList(), so initialize an ArrayList
    List<String> prefix = new ArrayList<>();
    prefix.add(nicCtx.networkState.subnetCIDR);
    AddressSpace addressSpace = new AddressSpace().withAddressPrefixes(prefix);
    vNet.withAddressSpace(addressSpace);
    vNet.withSubnets(subnetsToCreate);
    return vNet;
}
Also used : VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) AddressSpace(com.microsoft.azure.management.network.AddressSpace) ArrayList(java.util.ArrayList)

Example 3 with VirtualNetworkInner

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

the class TestAzureProvisionTask method assertVmNetworksConfiguration.

private void assertVmNetworksConfiguration(AzureNicSpecs azureNicSpec, String vmName) throws Throwable {
    // This assert is only suitable for real (non-mocking env).
    if (this.isMock) {
        return;
    }
    getHost().log(Level.INFO, "%s: Assert network configuration for [%s] VM", this.currentTestName.getMethodName(), this.vmState.name);
    ComputeState vm = getHost().getServiceState(null, ComputeState.class, UriUtils.buildUri(getHost(), this.vmState.documentSelfLink));
    NetworkInterfaceStateWithDescription primaryNicState = getHost().getServiceState(null, NetworkInterfaceStateWithDescription.class, NetworkInterfaceStateWithDescription.buildUri(UriUtils.buildUri(getHost(), vm.networkInterfaceLinks.get(0))));
    // In case that private ip is set explicitly.
    assertStaticPrivateIPAddress(azureNicSpec, primaryNicState.address);
    assertNotNull("Primary NIC private IP should be set.", primaryNicState.address);
    if (primaryNicState.description.assignPublicIpAddress == null || primaryNicState.description.assignPublicIpAddress == Boolean.TRUE) {
        assertNotNull("VM address should be set.", vm.address);
        assertNotEquals("VM address should not be the same as primary NIC private IP.", vm.address, primaryNicState.address);
    } else {
        assertNull("VM address should be empty.", vm.address);
    }
    assertNotNull("Primary NIC security group should be set.", primaryNicState.securityGroupLinks != null);
    for (int i = 1; i < vm.networkInterfaceLinks.size(); i++) {
        NetworkInterfaceState nonPrimaryNicState = getHost().getServiceState(null, NetworkInterfaceState.class, UriUtils.buildUri(getHost(), vm.networkInterfaceLinks.get(i)));
        assertNotNull("Non-primary NIC" + i + " IP should not be set to the privatese ip.", nonPrimaryNicState.address);
        assertNull("Non-primary NIC" + i + " security group should not be set.", nonPrimaryNicState.securityGroupLinks);
    }
    // Ensure that from the list of provided network resource groups,
    // and security group resource groups, the one with the correct type has been chosen.
    // Verifying the resources can be obtained from this RG, ensures they have been placed
    // correctly.
    NetworkManagementClientImpl networkClient = getAzureSdkClients().getNetworkManagementClientImpl();
    final String vmRGName = vm.customProperties.get(ComputeProperties.RESOURCE_GROUP_NAME);
    VirtualNetworkInner provisionedNetwork = AzureTestUtil.getAzureVirtualNetwork(networkClient, vmRGName, AzureTestUtil.AZURE_NETWORK_NAME);
    assertNotNull("Azure virtual network object '" + vmRGName + "/" + AzureTestUtil.AZURE_NETWORK_NAME + "' is not found.", provisionedNetwork);
    final String sgName = AzureTestUtil.AZURE_SECURITY_GROUP_NAME + "-" + vmName;
    NetworkSecurityGroupInner provisionedSG = AzureTestUtil.getAzureSecurityGroup(networkClient, vmRGName, sgName);
    assertNotNull("Azure security group object '" + vmRGName + "/" + sgName + "' is not found.", provisionedSG);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) NetworkInterfaceStateWithDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription)

Example 4 with VirtualNetworkInner

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

the class TestAzureLongRunningEnumeration method tagAzureResources.

/**
 * Add tags, that later should be discovered as part of first enumeration cycle.
 */
private void tagAzureResources() throws Exception {
    for (int i = 0; i < numOfVMsToTest; i++) {
        // tag v-Net
        VirtualNetworkInner vmNetwUpdate = getAzureVirtualNetwork(this.networkManagementClient, azureVMNames.get(i), nicSpecs.get(i).network.name);
        Map<String, String> vmNetwTags = new HashMap<>();
        vmNetwTags.put(NETWORK_TAG_KEY_PREFIX + azureVMNames.get(i), NETWORK_TAG_VALUE);
        vmNetwUpdate.withTags(vmNetwTags);
        updateAzureVirtualNetwork(this.networkManagementClient, azureVMNames.get(i), nicSpecs.get(i).network.name, vmNetwUpdate);
        // tag VM
        VirtualMachineInner vmUpdate = getAzureVirtualMachine(this.computeManagementClient, azureVMNames.get(i), azureVMNames.get(i));
        Map<String, String> vmTags = new HashMap<>();
        String timeStamp = String.valueOf(Utils.getNowMicrosUtc());
        vmTags.put(VM_TAG_KEY_PREFIX + azureVMNames.get(i), VM_TAG_VALUE);
        vmTags.put(TIME_STAMP_TAG_KEY, timeStamp);
        vmUpdate.withTags(vmTags);
        updateAzureVirtualMachine(this.computeManagementClient, azureVMNames.get(i), azureVMNames.get(i), vmUpdate);
        // tag Security Group
        NetworkSecurityGroupInner sgUpdate = getAzureSecurityGroup(this.networkManagementClient, azureVMNames.get(i), AZURE_SECURITY_GROUP_NAME + "-" + azureVMNames.get(i));
        Map<String, String> sgTags = new HashMap<>();
        sgTags.put(SG_TAG_KEY_PREFIX + azureVMNames.get(i), SG_TAG_VALUE);
        sgUpdate.withTags(sgTags);
        sgUpdate.withLocation(AzureTestUtil.AZURE_RESOURCE_GROUP_LOCATION);
        updateAzureSecurityGroup(this.networkManagementClient, azureVMNames.get(i), AZURE_SECURITY_GROUP_NAME, sgUpdate);
    }
}
Also used : VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AzureTestUtil.randomString(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString)

Example 5 with VirtualNetworkInner

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

Aggregations

VirtualNetworkInner (com.microsoft.azure.management.network.implementation.VirtualNetworkInner)7 AddressSpace (com.microsoft.azure.management.network.AddressSpace)5 ArrayList (java.util.ArrayList)4 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)3 NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)3 ResourceGroupInner (com.microsoft.azure.management.resources.implementation.ResourceGroupInner)3 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)3 CloudException (com.microsoft.azure.CloudException)2 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)2 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)2 VirtualNetworksInner (com.microsoft.azure.management.network.implementation.VirtualNetworksInner)2 ResourceManagementClientImpl (com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)2 AzureTestUtil.createDefaultResourceGroupState (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState)2 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)2 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)2 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)2 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2