use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState in project photon-model by vmware.
the class NetworkInterfaceServiceTest method buildValidStartState.
private static NetworkInterfaceState buildValidStartState(boolean assignHost) {
NetworkInterfaceState networkInterfaceState = new NetworkInterfaceState();
networkInterfaceState.id = UUID.randomUUID().toString();
networkInterfaceState.name = NetworkInterfaceServiceTest.class.getSimpleName();
networkInterfaceState.address = "9.9.9.9";
networkInterfaceState.securityGroupLinks = Collections.singletonList("/resources/security-groups/1");
networkInterfaceState.networkInterfaceDescriptionLink = "/resources/nicDesc/nicDesc9";
networkInterfaceState.subnetLink = "/resources/subnet/subnet9";
if (assignHost) {
networkInterfaceState.computeHostLink = "host-1";
}
return networkInterfaceState;
}
use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState in project photon-model by vmware.
the class TestAWSEnumerationTask method testEnumerationUpdateNICs.
// Runs the enumeration task after a new nic has been added to a CS and then after it has been
// removed
@Test
public void testEnumerationUpdateNICs() throws Throwable {
if (this.isMock) {
return;
}
this.host.log("Running test: " + this.currentTestName.getMethodName());
ComputeState vmState = createAWSVMResource(this.host, this.computeHost, this.endpointState, TestAWSSetupUtils.class, zoneId, regionId, null, this.singleNicSpec, this.awsTestContext);
// Overriding the page size to test the pagination logic with limited instances on AWS.
// This is a functional test
// so the latency numbers maybe higher from this test due to low page size.
setQueryPageSize(DEFAULT_TEST_PAGE_SIZE);
setQueryResultLimit(DEFAULT_TEST_PAGE_SIZE);
// Provision a single VM . Check initial state.
vmState = provisionMachine(this.host, vmState, this.isMock, this.instancesToCleanUp);
// Run enumeration to discover the new VM
enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_INITIAL);
int numberOfNICsBeforeAdding = vmState.networkInterfaceLinks.size();
String newNICId = createNICDirectlyWithEC2Client(this.client, this.host, this.subnetId);
this.nicToCleanUp = newNICId;
String newAWSNicAttachmentId = addNICDirectlyWithEC2Client(vmState, this.client, this.host, newNICId);
// Run enumeration to discover the changes in the NICs in the new VM
enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_ADDITIONAL_NIC);
// validate NICs
ComputeState updatedComputeState = getComputeByAWSId(this.host, vmState.id);
// New NIC State link should have been added to the CS
assertEquals(numberOfNICsBeforeAdding + 1, updatedComputeState.networkInterfaceLinks.size());
NetworkInterfaceState addedNetworkInterfaceState = getNICByAWSId(this.host, newNICId);
// Assert that the network interface state has the right internal tag link
assertTrue(addedNetworkInterfaceState.tagLinks.contains(TagsUtil.newTagState(TAG_KEY_TYPE, AWSResourceType.ec2_net_interface.toString(), false, this.endpointState.tenantLinks).documentSelfLink));
// NIC State with the new ID should have been created
assertNotNull(addedNetworkInterfaceState);
detachNICDirectlyWithEC2Client(vmState.id, newAWSNicAttachmentId, newNICId, this.client, this.host);
// Run again enumeration to discover the changes in the NICs in the new VM
enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_REMOVED_NIC);
// validate NICs
ComputeState updatedAgainComputeState = getComputeByAWSId(this.host, vmState.id);
// The link to the removed NIC State should have been removed
assertEquals(numberOfNICsBeforeAdding, updatedAgainComputeState.networkInterfaceLinks.size());
NetworkInterfaceState removedNetworkInterfaceState = getNICByAWSId(this.host, newNICId);
// NIC State with this ID should have been removed
assertEquals(null, removedNetworkInterfaceState);
}
use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createNic.
private void createNic(Map<String, Pair<NetworkInterfaceInner, String>> remoteStates, EnumerationContext ctx, Map<String, String> subnetPerNicId, List<DeferredResult<NetworkInterfaceState>> ops) {
remoteStates.values().stream().forEach(p -> {
NetworkInterfaceInner remoteNic = p.getLeft();
NetworkInterfaceState state = new NetworkInterfaceState();
processCreateUpdateNicRequest(state, remoteNic, ctx, ops, subnetPerNicId, true);
});
}
use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method processCreateUpdateNicRequest.
/**
* Processes request for creating and updating Network interface resources.
*/
private void processCreateUpdateNicRequest(NetworkInterfaceState nic, NetworkInterfaceInner remoteNic, EnumerationContext ctx, List<DeferredResult<NetworkInterfaceState>> ops, Map<String, String> subnetPerNicId, boolean isCreate) {
nic.name = remoteNic.name();
nic.subnetLink = subnetPerNicId.get(remoteNic.id());
NicMetadata nicMeta = new NicMetadata();
nicMeta.state = nic;
nicMeta.macAddress = remoteNic.macAddress();
// else will default to original ID for PATCH requests
if (isCreate) {
nic.id = remoteNic.id();
nic.endpointLink = ctx.request.endpointLink;
AdapterUtils.addToEndpointLinks(nic, ctx.request.endpointLink);
nic.tenantLinks = ctx.parentCompute.tenantLinks;
nic.regionId = remoteNic.location();
nic.computeHostLink = ctx.parentCompute.documentSelfLink;
} else {
if (StringUtils.isEmpty(nic.endpointLink)) {
nic.endpointLink = ctx.request.endpointLink;
}
nic.endpointLinks.add(ctx.request.endpointLink);
}
List<NetworkInterfaceIPConfigurationInner> ipConfigurations = remoteNic.ipConfigurations();
if (ipConfigurations == null || ipConfigurations.isEmpty()) {
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
return;
}
NetworkInterfaceIPConfigurationInner nicIPConf = ipConfigurations.get(0);
nic.address = nicIPConf.privateIPAddress();
if (nicIPConf.publicIPAddress() == null) {
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
return;
}
// IP address is not directly available in NetworkInterfaceIPConfigurationInner.
// It is available as a SubResource, We use the SubResource ID of IP address from
// NetworkInterfaceIPConfigurationInner to obtain the IP address.
Consumer<Throwable> failure = e -> {
logWarning("Error getting public IP address from Azure [endpointLink:%s], [Exception:%s]", ctx.request.endpointLink, e.getMessage());
handleError(ctx, e);
};
PhotonModelUtils.runInExecutor(this.executorService, () -> {
Azure azure = ctx.azureSdkClients.getAzureClient();
azure.publicIPAddresses().getByIdAsync(nicIPConf.publicIPAddress().id()).subscribe(injectOperationContext(new Action1<PublicIPAddress>() {
@Override
public void call(PublicIPAddress publicIPAddress) {
nicMeta.publicIp = publicIPAddress.ipAddress();
if (publicIPAddress.inner().dnsSettings() != null) {
nicMeta.publicDnsName = publicIPAddress.inner().dnsSettings().fqdn();
}
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
}
}));
}, failure);
}
use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState in project photon-model by vmware.
the class TestAWSProvisionTask method assertVmNetworksConfiguration.
private void assertVmNetworksConfiguration(Instance awsInstance) throws Throwable {
// This assert is only suitable for real (non-mocking env).
if (this.isMock) {
return;
}
this.host.log(Level.INFO, "%s: Assert network configuration for [%s] VM", this.currentTestName.getMethodName(), this.vmState.name);
ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
assertNotNull("ComputeState.address should be set to public IP.", vm.address);
assertEquals("ComputeState.address should be set to AWS Instance public IP.", awsInstance.getPublicIpAddress(), vm.address);
for (String nicLink : vm.networkInterfaceLinks) {
NetworkInterfaceState nicState = this.host.getServiceState(null, NetworkInterfaceState.class, UriUtils.buildUri(this.host, nicLink));
// for now validate only the 0 NIC as we are creating single NIC VM
if (nicState.deviceIndex != 0) {
continue;
}
InstanceNetworkInterface awsNic = null;
for (InstanceNetworkInterface nic : awsInstance.getNetworkInterfaces()) {
if (nic.getAttachment().getDeviceIndex() == nicState.deviceIndex) {
awsNic = nic;
break;
}
}
assertNotNull("Unable to find AWS NIC with device index " + nicState.deviceIndex, awsNic);
assertEquals("NetworkInterfaceState[" + nicState.deviceIndex + "].address should be set to AWS NIC private IP.", awsNic.getPrivateIpAddress(), nicState.address);
}
assertVMSercurityGroupsConfiguration(awsInstance, vm);
}
Aggregations