Search in sources :

Example 1 with NetworkManagementClientImpl

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

the class AzureInstanceService method getPublicIPAddress.

private DeferredResult<AzureInstanceContext> getPublicIPAddress(AzureInstanceContext ctx) {
    if (ctx.getPrimaryNic().publicIP == null) {
        // No public IP address created -> do nothing.
        return DeferredResult.completed(ctx);
    }
    NetworkManagementClientImpl client = getNetworkManagementClientImpl(ctx);
    String msg = "Get public IP address for resource group [" + ctx.resourceGroup.name() + "] and name [" + ctx.getPrimaryNic().publicIP.name() + "].";
    AzureDeferredResultServiceCallback<PublicIPAddressInner> callback = new AzureDeferredResultServiceCallback<PublicIPAddressInner>(ctx.service, msg) {

        @Override
        protected DeferredResult<PublicIPAddressInner> consumeSuccess(PublicIPAddressInner result) {
            ctx.getPrimaryNic().publicIP = result;
            return DeferredResult.completed(result);
        }
    };
    client.publicIPAddresses().getByResourceGroupAsync(ctx.resourceGroup.name(), ctx.getPrimaryNic().publicIP.name(), null, /* expand */
    callback);
    return callback.toDeferredResult().thenApply(ignored -> ctx);
}
Also used : NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner)

Example 2 with NetworkManagementClientImpl

use of com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl 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 3 with NetworkManagementClientImpl

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

the class TestAzureEnumerationTask method setUp.

@Override
@Before
public void setUp() throws Exception {
    try {
        /*
             * Init Class-specific (shared between test runs) vars.
             *
             * NOTE: Ultimately this should go to @BeforeClass, BUT BasicReusableHostTestCase.HOST
             * is not accessible.
             */
        if (computeHost == null) {
            PhotonModelServices.startServices(this.host);
            PhotonModelMetricServices.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);
            // Create a resource pool where the VMs will be housed
            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);
            endpointState.computeHostLink = computeHost.documentSelfLink;
            this.host.waitForResponse(Operation.createPatch(this.host, endpointState.documentSelfLink).setBody(endpointState));
        }
        azureVMName = azureVMName == null ? generateName(azureVMNamePrefix) : azureVMName;
        this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
        AzureUtils.setAzureClientMock(this.isAzureClientMock);
        AzureUtils.setAzureMockHost(this.azureMockEndpointReference);
        if (!this.isMock) {
            if (AzureUtils.isAzureClientMock()) {
                AzureEnvironment azureEnv = AzureEnvironment.AZURE;
                azureEnv.endpoints().put(AzureEnvironment.Endpoint.ACTIVE_DIRECTORY.toString(), AzureUtils.getAzureBaseUri());
                ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, azureEnv);
                this.computeManagementClient = new ComputeManagementClientImpl(AzureUtils.getAzureBaseUri(), credentials).withSubscriptionId(this.subscriptionId);
                this.resourceManagementClient = new ResourceManagementClientImpl(AzureUtils.getAzureBaseUri(), credentials).withSubscriptionId(this.subscriptionId);
                this.networkManagementClient = new NetworkManagementClientImpl(AzureUtils.getAzureBaseUri(), credentials).withSubscriptionId(this.subscriptionId);
            } else {
                ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
                this.computeManagementClient = new ComputeManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
                ;
                this.resourceManagementClient = new ResourceManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
                ;
                this.networkManagementClient = new NetworkManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
                ;
            }
        }
    } catch (Throwable e) {
        throw new Exception(e);
    }
}
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) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) AzureEnvironment(com.microsoft.azure.AzureEnvironment) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) Before(org.junit.Before)

Example 4 with NetworkManagementClientImpl

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

Example 5 with NetworkManagementClientImpl

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

the class AzureLoadBalancerService method getPublicIPAddress.

/**
 * Fetch public IP address after an address has been assigned
 */
private DeferredResult<AzureLoadBalancerContext> getPublicIPAddress(AzureLoadBalancerContext ctx) {
    if (ctx.publicIPAddressInner == null) {
        // No public IP address created -> do nothing.
        return DeferredResult.completed(ctx);
    }
    NetworkManagementClientImpl client = ctx.azureSdkClients.getNetworkManagementClientImpl();
    String msg = "Get public IP address for resource group [" + ctx.resourceGroupName + "] and name [" + ctx.publicIPAddressInner.name() + "].";
    AzureDeferredResultServiceCallback<PublicIPAddressInner> callback = new AzureDeferredResultServiceCallback<PublicIPAddressInner>(ctx.service, msg) {

        @Override
        protected DeferredResult<PublicIPAddressInner> consumeSuccess(PublicIPAddressInner result) {
            ctx.publicIPAddressInner = result;
            ctx.loadBalancerStateExpanded.address = result.ipAddress();
            return DeferredResult.completed(result);
        }
    };
    client.publicIPAddresses().getByResourceGroupAsync(ctx.resourceGroupName, ctx.publicIPAddressInner.name(), null, callback);
    return callback.toDeferredResult().thenApply(ignored -> ctx);
}
Also used : NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner)

Aggregations

NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)6 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)3 ResourceManagementClientImpl (com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)3 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)3 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)3 Before (org.junit.Before)3 ComputeManagementClientImpl (com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl)2 PublicIPAddressInner (com.microsoft.azure.management.network.implementation.PublicIPAddressInner)2 VirtualNetworkInner (com.microsoft.azure.management.network.implementation.VirtualNetworkInner)2 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)2 AzureEnvironment (com.microsoft.azure.AzureEnvironment)1 AddressSpace (com.microsoft.azure.management.network.AddressSpace)1 NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)1 ResourceGroupInner (com.microsoft.azure.management.resources.implementation.ResourceGroupInner)1 StorageManagementClientImpl (com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl)1 AzureTestUtil.createDefaultResourceGroupState (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState)1 AzureTestUtil.randomString (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)1 NetworkInterfaceStateWithDescription (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription)1