Search in sources :

Example 6 with VirtualNetworkInner

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

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

the class AzureTestUtil method createAzureVirtualNetwork.

private static void createAzureVirtualNetwork(String resourceGroupName, AzureNicSpecs azureNicSpecs, NetworkManagementClientImpl networkManagementClient) throws Exception {
    try {
        VirtualNetworkInner vNet = new VirtualNetworkInner();
        vNet.withLocation(azureNicSpecs.network.zoneId);
        AddressSpace addressSpace = new AddressSpace();
        // Azure's custom serializers don't handle well collections constructed with
        // Collections.singletonList(), so initialize an ArrayList
        List<String> cidrs = new ArrayList<>();
        cidrs.add(azureNicSpecs.network.cidr);
        addressSpace.withAddressPrefixes(cidrs);
        vNet.withAddressSpace(addressSpace);
        List<SubnetInner> subnetList = new ArrayList<>();
        for (int i = 0; i < azureNicSpecs.nicSpecs.size(); i++) {
            SubnetInner subnet = new SubnetInner();
            subnet.withName(azureNicSpecs.nicSpecs.get(i).subnetSpec.name);
            subnet.withAddressPrefix(azureNicSpecs.nicSpecs.get(i).subnetSpec.cidr);
            subnetList.add(subnet);
        }
        vNet.withSubnets(subnetList);
        networkManagementClient.virtualNetworks().createOrUpdate(resourceGroupName, azureNicSpecs.network.name, vNet);
        addAzureGatewayToVirtualNetwork(resourceGroupName, azureNicSpecs, networkManagementClient);
    } catch (CloudException ex) {
        /*
             * CloudException is thrown if the vNet already exists and we are trying to do an
             * update, because there are objects (GatewaySubnet) attached to it
             */
        assertTrue(ex.body().code().equals("InUseSubnetCannotBeDeleted"));
    }
}
Also used : VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) AddressSpace(com.microsoft.azure.management.network.AddressSpace) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) ArrayList(java.util.ArrayList) CloudException(com.microsoft.azure.CloudException)

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