use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createComputeState.
private ComputeState createComputeState(EnumerationContext ctx, VirtualMachineInner virtualMachine) {
List<String> vmDisks = new ArrayList<>();
if (ctx.diskStates != null && ctx.diskStates.size() > 0) {
String diskUri = getVhdUri(virtualMachine);
if (diskUri != null) {
DiskState state = ctx.diskStates.get(diskUri);
if (state != null) {
vmDisks.add(state.documentSelfLink);
}
}
// add all data disk links of VM
List<String> dataDiskIDs = getDataDisksID(virtualMachine, AzureUtils.isDiskManaged(virtualMachine));
if (dataDiskIDs != null) {
dataDiskIDs.forEach(dataDiskID -> {
DiskState dataDiskState = ctx.diskStates.get(dataDiskID);
if (null != dataDiskState) {
vmDisks.add(dataDiskState.documentSelfLink);
}
});
}
}
// Create compute state
ComputeState computeState = new ComputeState();
computeState.documentSelfLink = UUID.randomUUID().toString();
computeState.id = virtualMachine.id().toLowerCase();
computeState.name = virtualMachine.name();
computeState.regionId = virtualMachine.location();
computeState.type = ComputeType.VM_GUEST;
computeState.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
computeState.parentLink = ctx.request.resourceLink();
computeState.descriptionLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, ctx.computeDescriptionIds.get(virtualMachine.name()));
computeState.endpointLink = ctx.request.endpointLink;
AdapterUtils.addToEndpointLinks(computeState, ctx.request.endpointLink);
computeState.resourcePoolLink = ctx.request.resourcePoolLink;
computeState.computeHostLink = ctx.parentCompute.documentSelfLink;
computeState.diskLinks = vmDisks;
if (virtualMachine.hardwareProfile() != null && virtualMachine.hardwareProfile().vmSize() != null) {
computeState.instanceType = virtualMachine.hardwareProfile().vmSize().toString();
}
computeState.instanceAdapterReference = ctx.parentCompute.description.instanceAdapterReference;
computeState.statsAdapterReference = ctx.parentCompute.description.statsAdapterReference;
computeState.customProperties = new HashMap<>();
computeState.customProperties.put(CUSTOM_OS_TYPE, getNormalizedOSType(virtualMachine));
String resourceGroupName = getResourceGroupName(virtualMachine.id());
computeState.customProperties.put(AZURE_RESOURCE_GROUP_NAME, resourceGroupName);
if (virtualMachine.diagnosticsProfile() != null && virtualMachine.diagnosticsProfile().bootDiagnostics() != null && virtualMachine.diagnosticsProfile().bootDiagnostics().storageUri() != null) {
String diagnosticsAccountUri = virtualMachine.diagnosticsProfile().bootDiagnostics().storageUri();
StorageDescription storageDesk = ctx.storageDescriptions.get(diagnosticsAccountUri);
if (storageDesk != null) {
computeState.customProperties.put(AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK, storageDesk.documentSelfLink);
}
}
computeState.tenantLinks = ctx.parentCompute.tenantLinks;
// add tag links
setTagLinksToResourceState(computeState, virtualMachine.getTags(), true);
if (computeState.tagLinks == null) {
computeState.tagLinks = new HashSet<>();
}
// add internal type tags
computeState.tagLinks.addAll(ctx.internalTagLinks);
List<String> networkLinks = new ArrayList<>();
NicMetadata nicMeta = ctx.networkInterfaceIds.remove(virtualMachine.networkProfile().networkInterfaces().get(0).id());
if (nicMeta != null) {
computeState.address = nicMeta.publicIp;
computeState.hostName = nicMeta.publicDnsName;
computeState.primaryMAC = nicMeta.macAddress;
networkLinks.add(nicMeta.state.documentSelfLink);
}
computeState.networkInterfaceLinks = networkLinks;
return computeState;
}
use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.
the class TestProvisionAWSDisk method createAWSDiskState.
public static DiskState createAWSDiskState(VerificationHost host, EndpointState endpointState, String diskName, Boolean persistent, String zoneId, String regionId) throws Throwable {
// Step 1: Create a Disk State
DiskState diskDesc = new DiskState();
diskDesc.name = diskName;
diskDesc.capacityMBytes = EBS_VOLUME_SIZE_IN_MEBI_BYTES;
diskDesc.encrypted = isEncrypted;
diskDesc.zoneId = zoneId;
diskDesc.regionId = regionId;
diskDesc.persistent = persistent;
diskDesc.endpointLink = endpointState.documentSelfLink;
diskDesc.endpointLinks = new HashSet<String>();
diskDesc.endpointLinks.add(endpointState.documentSelfLink);
diskDesc.tenantLinks = endpointState.tenantLinks;
diskDesc.authCredentialsLink = endpointState.authCredentialsLink;
diskDesc.diskAdapterReference = UriUtils.buildUri(host, AWSDiskService.SELF_LINK);
diskDesc.customProperties = new HashMap<>();
diskDesc.customProperties.put("deviceType", "ebs");
diskDesc.customProperties.put("volumeType", "gp2");
DiskState disk = TestUtils.doPost(host, diskDesc, DiskService.DiskState.class, UriUtils.buildUri(host, DiskService.FACTORY_LINK));
return disk;
}
use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.
the class TestAWSProvisionTask method assertBootDiskConfiguration.
protected void assertBootDiskConfiguration(AmazonEC2AsyncClient client, Instance awsInstance, String diskLink) {
DiskState diskState = getDiskState(diskLink);
Volume bootVolume = getVolume(client, awsInstance, awsInstance.getRootDeviceName());
assertEquals("Boot Disk capacity in diskstate is not matching the boot disk size of the " + "vm launched in aws", diskState.capacityMBytes, bootVolume.getSize() * 1024);
assertNotNull("Boot disk creation time cannot be empty", diskState.creationTimeMicros);
assertEquals("Boot disk type in diskstate is not same as the type of the volume attached to the VM", diskState.customProperties.get("volumeType"), bootVolume.getVolumeType());
assertEquals("Boot disk iops in diskstate is the same as the iops of the volume attached to the VM", Integer.parseInt(diskState.customProperties.get("iops")), bootVolume.getIops().intValue());
assertEquals("Boot disk attach status is not matching", DiskService.DiskStatus.ATTACHED, diskState.status);
}
use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.
the class TestAWSProvisionTask method assertStorageConfiguration.
private void assertStorageConfiguration(AmazonEC2AsyncClient client, Instance awsInstance, ComputeState compute) throws Throwable {
// This assert is only suitable for real (non-mock) environment.
if (this.isMock) {
return;
}
this.host.log(Level.INFO, "%s: Assert boot disk size for [%s] VM", this.currentTestName.getMethodName(), this.vmState.name);
ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
List<String> additionalDiskLinks = new ArrayList<>();
List<String> existingDataDiskLinks = new ArrayList<>();
String bootDiskLink = vm.diskLinks.get(0);
for (int i = 1; i < compute.diskLinks.size(); i++) {
DiskState disk = getDiskState(vm.diskLinks.get(i));
if (disk.bootOrder == null) {
additionalDiskLinks.add(disk.documentSelfLink);
} else {
bootDiskLink = disk.documentSelfLink;
}
}
// For now there is a boot disk and one additional disk attached to the compute
assertBootDiskConfiguration(client, awsInstance, bootDiskLink);
// assert additional disk configuration
assertDataDiskConfiguration(client, awsInstance, additionalDiskLinks);
}
use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.
the class TestAWSProvisionTask method assertDataDiskConfiguration.
protected void assertDataDiskConfiguration(AmazonEC2AsyncClient client, Instance awsInstance, List<String> diskLinks) {
List<String> existingNames = new ArrayList<>();
for (String diskLink : diskLinks) {
DiskState diskState = getDiskState(diskLink);
assertEbsDiskConfiguration(client, awsInstance, diskState);
assertDeviceName(awsInstance, diskState, existingNames);
existingNames.add(diskState.customProperties.get(DEVICE_NAME));
}
}
Aggregations