Search in sources :

Example 16 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class AzureLoadBalancerServiceTest method createNetworkState.

private NetworkState createNetworkState(String resourceGroupLink) throws Throwable {
    NetworkState networkState = new NetworkState();
    networkState.id = this.vNetName;
    networkState.name = this.vNetName;
    networkState.subnetCIDR = AZURE_DEFAULT_VPC_CIDR;
    networkState.tenantLinks = endpointState.tenantLinks;
    networkState.endpointLink = endpointState.documentSelfLink;
    // ws "dummy"
    networkState.resourcePoolLink = resourcePool.documentSelfLink;
    networkState.groupLinks = Collections.singleton(resourceGroupLink);
    networkState.regionId = this.regionId;
    networkState.instanceAdapterReference = UriUtils.buildUri(this.host, AzureInstanceService.SELF_LINK);
    return postServiceSynchronously(NetworkService.FACTORY_LINK, networkState, NetworkState.class);
}
Also used : NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState)

Example 17 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method createNetworkState.

private NetworkState createNetworkState(String resourceGroupLink) throws Throwable {
    NetworkState networkState = new NetworkState();
    networkState.id = UUID.randomUUID().toString();
    networkState.name = networkState.id;
    networkState.subnetCIDR = "0.0.0.0/24";
    networkState.tenantLinks = endpointState.tenantLinks;
    networkState.endpointLink = endpointState.documentSelfLink;
    networkState.resourcePoolLink = "dummyResourcePoolLink";
    networkState.groupLinks = Collections.singleton(resourceGroupLink);
    networkState.regionId = this.regionId;
    networkState.instanceAdapterReference = UriUtils.buildUri(this.host, AzureInstanceService.SELF_LINK);
    return postServiceSynchronously(NetworkService.FACTORY_LINK, networkState, NetworkState.class);
}
Also used : NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState)

Example 18 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class TestProvisionAWSNetwork method testProvisionAWSNetwork.

@Test
public void testProvisionAWSNetwork() throws Throwable {
    // first create network service
    Operation response = new Operation();
    // create credentials
    Operation credsResponse = new Operation();
    TestUtils.postCredentials(this.host, credsResponse, this.secretKey, this.accessKey);
    AuthCredentialsServiceState creds = credsResponse.getBody(AuthCredentialsServiceState.class);
    // create resource pool
    Operation poolResponse = new Operation();
    TestUtils.postResourcePool(this.host, poolResponse);
    ResourcePoolState pool = poolResponse.getBody(ResourcePoolState.class);
    NetworkState initialState = TestUtils.buildNetworkState(this.host);
    initialState.authCredentialsLink = creds.documentSelfLink;
    initialState.resourcePoolLink = pool.documentSelfLink;
    initialState.regionId = regionId;
    initialState.instanceAdapterReference = UriUtils.buildUri(ServiceHost.LOCAL_HOST, this.host.getPort(), AWSUriPaths.AWS_NETWORK_ADAPTER, null);
    TestUtils.postNetwork(this.host, initialState, response);
    NetworkState networkState = response.getBody(NetworkState.class);
    // set up network task state
    ProvisionNetworkTaskState task = new ProvisionNetworkTaskState();
    task.requestType = NetworkInstanceRequest.InstanceRequestType.CREATE;
    task.networkDescriptionLink = networkState.documentSelfLink;
    Operation provision = new Operation();
    provisionNetwork(task, provision);
    ProvisionNetworkTaskState ps = provision.getBody(ProvisionNetworkTaskState.class);
    waitForTaskCompletion(this.host, UriUtils.buildUri(this.host, ps.documentSelfLink));
    validateAWSArtifacts(networkState.documentSelfLink, creds);
    task.requestType = NetworkInstanceRequest.InstanceRequestType.DELETE;
    Operation remove = new Operation();
    provisionNetwork(task, remove);
    ProvisionNetworkTaskState removeTask = remove.getBody(ProvisionNetworkTaskState.class);
    waitForTaskCompletion(this.host, UriUtils.buildUri(this.host, removeTask.documentSelfLink));
    // verify properties have been set to no-value
    NetworkState removedNetwork = getNetworkState(networkState.documentSelfLink);
    assertTrue(removedNetwork.customProperties.get(AWS_VPC_ID).equalsIgnoreCase(AWSUtils.NO_VALUE));
    assertTrue(removedNetwork.customProperties.get(AWS_GATEWAY_ID).equalsIgnoreCase(AWSUtils.NO_VALUE));
    assertTrue(removedNetwork.customProperties.get(AWS_VPC_ROUTE_TABLE_ID).equalsIgnoreCase(AWSUtils.NO_VALUE));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ProvisionNetworkTaskState(com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState) Operation(com.vmware.xenon.common.Operation) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Test(org.junit.Test)

Example 19 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class TestProvisionAWSNetwork method testInvalidProvisionAWSNetwork.

@Test
public void testInvalidProvisionAWSNetwork() throws Throwable {
    // first create network service
    Operation response = new Operation();
    // create credentials
    Operation authResponse = new Operation();
    TestUtils.postCredentials(this.host, authResponse, this.secretKey, "invalid");
    AuthCredentialsServiceState creds = authResponse.getBody(AuthCredentialsServiceState.class);
    // create resource pool
    Operation poolResponse = new Operation();
    TestUtils.postResourcePool(this.host, poolResponse);
    ResourcePoolState pool = poolResponse.getBody(ResourcePoolState.class);
    NetworkState initialState = TestUtils.buildNetworkState(this.host);
    initialState.authCredentialsLink = creds.documentSelfLink;
    initialState.resourcePoolLink = pool.documentSelfLink;
    initialState.regionId = regionId;
    initialState.instanceAdapterReference = UriUtils.buildUri(ServiceHost.LOCAL_HOST, this.host.getPort(), AWSUriPaths.AWS_NETWORK_ADAPTER, null);
    TestUtils.postNetwork(this.host, initialState, response);
    NetworkState networkState = response.getBody(NetworkState.class);
    // set up network task state
    ProvisionNetworkTaskState task = new ProvisionNetworkTaskState();
    task.requestType = NetworkInstanceRequest.InstanceRequestType.CREATE;
    task.networkDescriptionLink = networkState.documentSelfLink;
    Operation provision = new Operation();
    provisionNetwork(task, provision);
    ProvisionNetworkTaskState ps = provision.getBody(ProvisionNetworkTaskState.class);
    waitForTaskFailure(this.host, UriUtils.buildUri(this.host, ps.documentSelfLink));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ProvisionNetworkTaskState(com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState) Operation(com.vmware.xenon.common.Operation) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Test(org.junit.Test)

Example 20 with NetworkState

use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.

the class TestAWSSetupUtils method createAWSNicStates.

/*
     * NOTE: It is highly recommended to keep this method in sync with its Azure counterpart:
     * AzureTestUtil.createDefaultNicStates
     */
public static List<NetworkInterfaceState> createAWSNicStates(VerificationHost host, ComputeState computeHost, EndpointState endpointState, String vmName, AwsNicSpecs nicSpecs, boolean addNewSecurityGroup, Map<String, Object> awsTestContext) throws Throwable {
    // Create network state.
    NetworkState networkState;
    {
        networkState = new NetworkState();
        networkState.id = nicSpecs.network.id;
        networkState.name = nicSpecs.network.name;
        networkState.subnetCIDR = nicSpecs.network.cidr;
        networkState.authCredentialsLink = endpointState.authCredentialsLink;
        networkState.resourcePoolLink = computeHost.resourcePoolLink;
        networkState.instanceAdapterReference = UriUtils.buildUri(host, AWSUriPaths.AWS_NETWORK_ADAPTER);
        networkState.regionId = regionId;
        networkState.endpointLink = endpointState.documentSelfLink;
        networkState.endpointLinks = new HashSet<String>();
        networkState.endpointLinks.add(endpointState.documentSelfLink);
        networkState.tenantLinks = endpointState.tenantLinks;
        networkState.computeHostLink = computeHost.documentSelfLink;
        networkState = TestUtils.doPost(host, networkState, NetworkState.class, UriUtils.buildUri(host, NetworkService.FACTORY_LINK));
    }
    // Create NIC states.
    List<NetworkInterfaceState> nics = new ArrayList<>();
    for (int i = 0; i < nicSpecs.nicSpecs.size(); i++) {
        // Create subnet state per NIC.
        SubnetState subnetState;
        {
            subnetState = new SubnetState();
            subnetState.id = nicSpecs.nicSpecs.get(i).subnetSpec.id;
            subnetState.name = nicSpecs.nicSpecs.get(i).subnetSpec.name;
            subnetState.subnetCIDR = nicSpecs.nicSpecs.get(i).subnetSpec.cidr;
            subnetState.zoneId = nicSpecs.nicSpecs.get(i).subnetSpec.zoneId;
            subnetState.networkLink = networkState.documentSelfLink;
            subnetState.regionId = regionId;
            subnetState.endpointLink = endpointState.documentSelfLink;
            subnetState.endpointLinks = new HashSet<String>();
            subnetState.endpointLinks.add(endpointState.documentSelfLink);
            subnetState.tenantLinks = endpointState.tenantLinks;
            subnetState = TestUtils.doPost(host, subnetState, SubnetState.class, UriUtils.buildUri(host, SubnetService.FACTORY_LINK));
        }
        // Create NIC description.
        NetworkInterfaceDescription nicDescription;
        NicSpec nicSpec = nicSpecs.nicSpecs.get(0);
        {
            nicDescription = new NetworkInterfaceDescription();
            nicDescription.id = "nicDesc" + i;
            nicDescription.name = "nicDesc" + i;
            nicDescription.deviceIndex = i;
            nicDescription.assignment = nicSpec.getIpAssignment();
            nicDescription.regionId = regionId;
            nicDescription.endpointLink = endpointState.documentSelfLink;
            nicDescription.endpointLinks = new HashSet<String>();
            nicDescription.endpointLinks.add(endpointState.documentSelfLink);
            nicDescription.tenantLinks = endpointState.tenantLinks;
            nicDescription = TestUtils.doPost(host, nicDescription, NetworkInterfaceDescription.class, UriUtils.buildUri(host, NetworkInterfaceDescriptionService.FACTORY_LINK));
        }
        // Create security group state for an existing security group
        SecurityGroupState existingSecurityGroupState = createSecurityGroupState(host, computeHost, endpointState, true, awsTestContext);
        NetworkInterfaceState nicState = new NetworkInterfaceState();
        nicState.id = UUID.randomUUID().toString();
        nicState.name = vmName + "-nic-" + i;
        nicState.deviceIndex = nicDescription.deviceIndex;
        nicState.networkLink = networkState.documentSelfLink;
        nicState.subnetLink = subnetState.documentSelfLink;
        nicState.networkInterfaceDescriptionLink = nicDescription.documentSelfLink;
        nicState.regionId = regionId;
        nicState.endpointLink = endpointState.documentSelfLink;
        nicState.endpointLinks = new HashSet<String>();
        nicState.endpointLinks.add(endpointState.documentSelfLink);
        nicState.tenantLinks = endpointState.tenantLinks;
        nicState.securityGroupLinks = new ArrayList<>();
        nicState.securityGroupLinks.add(existingSecurityGroupState.documentSelfLink);
        if (addNewSecurityGroup) {
            // Create security group state for a new security group
            SecurityGroupState newSecurityGroupState = createSecurityGroupState(host, computeHost, endpointState, false, awsTestContext);
            nicState.securityGroupLinks.add(newSecurityGroupState.documentSelfLink);
        }
        nicState = TestUtils.doPost(host, nicState, NetworkInterfaceState.class, UriUtils.buildUri(host, NetworkInterfaceService.FACTORY_LINK));
        nics.add(nicState);
    }
    return nics;
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ArrayList(java.util.ArrayList) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) NicSpec(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NicSpec) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) HashSet(java.util.HashSet)

Aggregations

NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)43 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)23 Operation (com.vmware.xenon.common.Operation)15 URI (java.net.URI)14 ArrayList (java.util.ArrayList)13 NetworkService (com.vmware.photon.controller.model.resources.NetworkService)10 HashMap (java.util.HashMap)10 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)9 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)9 SubnetService (com.vmware.photon.controller.model.resources.SubnetService)9 UriUtils (com.vmware.xenon.common.UriUtils)9 Query (com.vmware.xenon.services.common.QueryTask.Query)9 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)8 HashSet (java.util.HashSet)8 List (java.util.List)8 TagsUtil.newTagState (com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)7 TagState (com.vmware.photon.controller.model.resources.TagService.TagState)7 DeferredResult (com.vmware.xenon.common.DeferredResult)7 StatelessService (com.vmware.xenon.common.StatelessService)7 Map (java.util.Map)7