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());
}
}
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);
}
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));
}
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());
}
}
}
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;
}
Aggregations