use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.
the class AWSNetworkUtils method mapVPCToNetworkState.
public static NetworkState mapVPCToNetworkState(Vpc vpc, String regionId, String resourcePoolLink, String endpointLink, String authCredentialsLink, String parentComputeLink, List<String> tenantLinks, URI adapterUri) {
if (vpc == null) {
throw new IllegalArgumentException("Cannot map VPC to network state for null instance");
}
NetworkState networkState = new NetworkState();
networkState.id = vpc.getVpcId();
// calculate vpc name
if (vpc.getTags() == null) {
networkState.name = vpc.getVpcId();
} else {
networkState.name = vpc.getTags().stream().filter(tag -> tag.getKey().equals(AWS_TAG_NAME)).map(tag -> tag.getValue()).findFirst().orElse(vpc.getVpcId());
}
networkState.subnetCIDR = vpc.getCidrBlock();
networkState.regionId = regionId;
networkState.resourcePoolLink = resourcePoolLink;
networkState.endpointLink = endpointLink;
if (networkState.endpointLinks == null) {
networkState.endpointLinks = new HashSet<>();
}
networkState.endpointLinks.add(endpointLink);
networkState.authCredentialsLink = authCredentialsLink;
networkState.instanceAdapterReference = adapterUri;
networkState.tenantLinks = tenantLinks;
networkState.computeHostLink = parentComputeLink;
networkState.customProperties = new HashMap<>();
networkState.customProperties.put("defaultInstance", String.valueOf(vpc.isDefault()));
return networkState;
}
use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.
the class ResourceOperationUtils method lookupByResourceState.
/**
* Lookup for {@link ResourceOperationSpec} by given {@code resourceState} and {@code operation}
* @param host
* host to use to create operation
* @param refererURI
* the referer to use when send the operation
* @param resourceState
* the resource state specialization for which to lookup the spec
* @param operation
* the operation
* @param authorizationContext
* authorization context that will be used for operations (if set to null the context
* will not be changed)
* @return
*/
public static <T extends ResourceState> DeferredResult<List<ResourceOperationSpec>> lookupByResourceState(ServiceHost host, URI refererURI, T resourceState, String operation, AuthorizationContext authorizationContext) {
AssertUtil.assertNotNull(resourceState, "'resourceState' must be set.");
String endpointLink = null;
// All endpoint links have to be of the same type, so it's enough to get the first one
if (resourceState.endpointLinks != null && !resourceState.endpointLinks.isEmpty()) {
endpointLink = resourceState.endpointLinks.iterator().next();
}
ResourceType resourceType;
if (resourceState instanceof ComputeState) {
ComputeState compute = (ComputeState) resourceState;
endpointLink = endpointLink == null ? compute.endpointLink : endpointLink;
resourceType = ResourceType.COMPUTE;
} else if (resourceState instanceof NetworkState) {
NetworkState network = (NetworkState) resourceState;
endpointLink = endpointLink == null ? network.endpointLink : endpointLink;
resourceType = ResourceType.NETWORK;
} else {
throw new IllegalArgumentException("Unsupported resource state: " + resourceState.getClass().getName());
}
AssertUtil.assertNotNull(endpointLink, " must be set.");
return host.sendWithDeferredResult(Operation.createGet(host, endpointLink).setReferer(refererURI), EndpointState.class).thenCompose(ep -> lookUp(host, refererURI, (ep).endpointType, resourceType, operation, resourceState.tenantLinks, authorizationContext));
}
use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.
the class BaseVSphereAdapterTest method createNetwork.
protected NetworkState createNetwork(String name) throws Throwable {
if (name == null) {
name = "name-not-defined";
}
NetworkState net = new NetworkState();
net.adapterManagementReference = getAdapterManagementReference();
net.authCredentialsLink = this.auth.documentSelfLink;
net.name = name;
net.instanceAdapterReference = UriUtils.buildUri(this.host, VSphereUriPaths.INSTANCE_SERVICE);
net.subnetCIDR = "0.0.0.0/0";
net.resourcePoolLink = this.resourcePool.documentSelfLink;
if (this.datacenterId == null) {
net.regionId = "datacenter-not-defined";
} else {
net.regionId = this.datacenterId;
}
ManagedObjectReference ref = new ManagedObjectReference();
ref.setValue("network-3");
ref.setType(VimNames.TYPE_NETWORK);
CustomProperties.of(net).put(CustomProperties.TYPE, VimNames.TYPE_NETWORK).put(CustomProperties.MOREF, ref);
return TestUtils.doPost(this.host, net, NetworkState.class, UriUtils.buildUri(this.host, NetworkService.FACTORY_LINK));
}
use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.
the class TestVSpherePortgroupProvisioning method createPortgroup.
@Test
public void createPortgroup() throws Throwable {
this.endpoint = createEndpoint(cs -> this.computeHost = cs, null);
// enumerate all resources hoping to find the template
doRefresh();
snapshotFactoryState("networks", NetworkService.class);
NetworkState dvsSwitch = fetchServiceState(NetworkState.class, findDvs(networkId));
SubnetState subnet = new SubnetState();
subnet.subnetCIDR = "0.0.0.0/0";
subnet.networkLink = dvsSwitch.documentSelfLink;
subnet.name = nextName("pg");
subnet.instanceAdapterReference = UriUtils.buildUri(this.host, DvsNetworkService.SELF_LINK);
subnet = TestUtils.doPost(this.host, subnet, SubnetState.class, UriUtils.buildUri(this.host, SubnetService.FACTORY_LINK));
ProvisionSubnetTaskState createTask = new ProvisionSubnetTaskState();
createTask.options = createOptions();
createTask.requestType = InstanceRequestType.CREATE;
createTask.subnetLink = subnet.documentSelfLink;
createTask = TestUtils.doPost(this.host, createTask, ProvisionSubnetTaskState.class, UriUtils.buildUri(this.host, ProvisionSubnetTaskService.FACTORY_LINK));
awaitTaskEnd(createTask);
// refresh state
subnet = getSubnetState(subnet);
// delete the portgroup
deleteThePortgroup(subnet);
}
use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.
the class AzureSubnetTaskServiceTest 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;
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);
}
Aggregations