Search in sources :

Example 36 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class AWSSubnetTaskServiceTest method testCreateSubnet.

@Test
public void testCreateSubnet() throws Throwable {
    SubnetState subnetState = provisionSubnet(AWS_NON_EXISTING_SUBNET_NAME, AWS_NON_EXISTING_SUBNET_CIDR, null);
    assertNotNull(subnetState.id);
    assertEquals(LifecycleState.READY, subnetState.lifecycleState);
    if (!this.isMock) {
        // Verify that the subnet was created.
        DescribeSubnetsRequest describeRequest = new DescribeSubnetsRequest().withSubnetIds(Collections.singletonList(subnetState.id));
        List<Subnet> subnets = this.client.describeSubnets(describeRequest).getSubnets();
        assertNotNull(subnets);
        assertEquals(1, subnets.size());
    }
}
Also used : Subnet(com.amazonaws.services.ec2.model.Subnet) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 37 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class AWSSubnetTaskServiceTest method createSubnetState.

private SubnetState createSubnetState(String awsSubnetId, String name, String subnetCidr, String publicSubnetLink) throws Throwable {
    SubnetState subnetState = new SubnetState();
    subnetState.id = awsSubnetId;
    subnetState.lifecycleState = LifecycleState.PROVISIONING;
    subnetState.name = name;
    subnetState.subnetCIDR = subnetCidr;
    subnetState.networkLink = this.networkState.documentSelfLink;
    subnetState.instanceAdapterReference = UriUtils.buildUri(this.host, AWSSubnetService.SELF_LINK);
    subnetState.endpointLink = this.endpointState.documentSelfLink;
    subnetState.endpointLinks = new HashSet<>();
    subnetState.endpointLinks.add(this.endpointState.documentSelfLink);
    subnetState.externalSubnetLink = publicSubnetLink;
    return postServiceSynchronously(SubnetService.FACTORY_LINK, subnetState, SubnetState.class);
}
Also used : SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 38 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class AWSSubnetTaskServiceTest method testCreateSubnetDuplicatedCIDR.

@Test
public void testCreateSubnetDuplicatedCIDR() throws Throwable {
    Assume.assumeFalse(this.isMock);
    // Provision subnet in AWS.
    SubnetState subnetState = createSubnetState(null, AWS_NON_EXISTING_SUBNET_NAME, AWS_NON_EXISTING_SUBNET_CIDR, null);
    kickOffSubnetProvision(InstanceRequestType.CREATE, subnetState, TaskStage.FINISHED);
    // Try to provision the same subnet second time.
    ProvisionSubnetTaskState state = kickOffSubnetProvision(InstanceRequestType.CREATE, subnetState, TaskStage.FAILED);
    assertTrue(state.taskInfo.failure.message.contains(STATUS_CODE_SUBNET_CONFLICT));
}
Also used : ProvisionSubnetTaskState(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 39 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class AWSSubnetTaskServiceTest method testDeleteSubnet.

@Test
public void testDeleteSubnet() throws Throwable {
    Subnet awsSubnet = createAwsSubnet();
    SubnetState subnetState = createSubnetState(awsSubnet.getSubnetId(), AWS_NON_EXISTING_SUBNET_NAME, AWS_NON_EXISTING_SUBNET_CIDR, null);
    kickOffSubnetProvision(InstanceRequestType.DELETE, subnetState, TaskStage.FINISHED);
    if (!this.isMock) {
        // Verify that the subnet was deleted.
        DescribeSubnetsRequest describeRequest = new DescribeSubnetsRequest().withSubnetIds(Collections.singletonList(awsSubnet.getSubnetId()));
        try {
            this.client.describeSubnets(describeRequest).getSubnets();
            fail("Subnet should not exist in AWS.");
        } catch (AmazonEC2Exception ex) {
            assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ex.getStatusCode());
        }
    }
}
Also used : Subnet(com.amazonaws.services.ec2.model.Subnet) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 40 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class BaseVSphereAdapterTest method createNic.

protected String createNic(String name, String networkLink) throws Throwable {
    // Create Subnet
    this.subnet = new SubnetState();
    this.subnet.networkLink = networkLink;
    this.subnet.endpointLink = "/some/endpoint/link";
    this.subnet.lifecycleState = LifecycleState.READY;
    this.subnet.id = this.subnet.name = this.networkId;
    ManagedObjectReference ref = new ManagedObjectReference();
    ref.setValue("network-4127");
    ref.setType(VimNames.TYPE_NETWORK);
    CustomProperties.of(this.subnet).put(CustomProperties.TYPE, VimNames.TYPE_NETWORK).put(CustomProperties.MOREF, ref);
    this.subnet = TestUtils.doPost(this.host, this.subnet, SubnetState.class, UriUtils.buildUri(this.host, SubnetService.FACTORY_LINK));
    this.nicDescription = new NetworkInterfaceDescription();
    this.nicDescription.assignment = NetworkInterfaceDescriptionService.IpAssignment.DYNAMIC;
    this.nicDescription = TestUtils.doPost(this.host, this.nicDescription, NetworkInterfaceDescription.class, UriUtils.buildUri(this.host, NetworkInterfaceDescriptionService.FACTORY_LINK));
    this.nicDescription.subnetLink = this.subnet.documentSelfLink;
    NetworkInterfaceState nic = new NetworkInterfaceState();
    nic.name = name;
    nic.subnetLink = this.subnet.documentSelfLink;
    nic.networkInterfaceDescriptionLink = this.nicDescription.documentSelfLink;
    nic = TestUtils.doPost(this.host, nic, NetworkInterfaceState.class, UriUtils.buildUri(this.host, NetworkInterfaceService.FACTORY_LINK));
    return nic.documentSelfLink;
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)61 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)22 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)16 Operation (com.vmware.xenon.common.Operation)14 Query (com.vmware.xenon.services.common.QueryTask.Query)12 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)11 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)11 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)11 URI (java.net.URI)11 DeferredResult (com.vmware.xenon.common.DeferredResult)10 HashMap (java.util.HashMap)10 List (java.util.List)10 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)9 StatelessService (com.vmware.xenon.common.StatelessService)9 SubnetService (com.vmware.photon.controller.model.resources.SubnetService)8 UriUtils (com.vmware.xenon.common.UriUtils)8 TagsUtil.newTagState (com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)7 NetworkService (com.vmware.photon.controller.model.resources.NetworkService)7 TagState (com.vmware.photon.controller.model.resources.TagService.TagState)7