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