use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class VSphereResourcePoolEnumerationHelper method makeDescriptionFromChanges.
private static ComputeDescription makeDescriptionFromChanges(ResourcePoolOverlay rp, String selfLink, String ownerName) {
ComputeDescription res = new ComputeDescription();
res.name = rp.getNameOrNull();
res.documentSelfLink = buildUriPath(ComputeDescriptionService.FACTORY_LINK, UriUtils.getLastPathSegment(selfLink));
res.totalMemoryBytes = rp.getMemoryReservationBytes();
return res;
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class VSphereResourcePoolEnumerationHelper method updateResourcePool.
private static void updateResourcePool(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, String ownerName, String selfLink, ResourcePoolOverlay rp, boolean fullUpdate, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ComputeState state;
ComputeDescription desc;
if (fullUpdate) {
state = makeResourcePoolFromResults(enumerationProgress, rp, selfLink, client);
state.name = rp.makeUserFriendlyName(ownerName);
state.tenantLinks = enumerationProgress.getTenantLinks();
state.resourcePoolLink = null;
desc = makeDescriptionForResourcePool(enumerationProgress, rp, selfLink);
} else {
state = makeResourcePoolFromChanges(rp, selfLink, ownerName);
desc = makeDescriptionFromChanges(rp, selfLink, ownerName);
}
state.descriptionLink = desc.documentSelfLink;
service.logFine(() -> String.format("Refreshed ResourcePool %s", state.name));
Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), selfLink)).setBody(state).setCompletion(trackResourcePool(enumerationProgress, rp)).sendWith(service);
Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), desc.documentSelfLink)).setBody(desc).sendWith(service);
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class VSphereVirtualMachineEnumerationHelper method createNewVm.
static void createNewVm(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, VmOverlay vm) {
ComputeDescription desc = makeDescriptionForVm(service, enumerationProgress, vm);
desc.tenantLinks = enumerationProgress.getTenantLinks();
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeDescriptionService.FACTORY_LINK)).setBody(desc).sendWith(service);
ComputeState state = makeVmFromResults(enumerationProgress, vm);
state.descriptionLink = desc.documentSelfLink;
state.tenantLinks = enumerationProgress.getTenantLinks();
List<Operation> operations = new ArrayList<>();
VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
VsphereEnumerationHelper.populateTags(service, enumerationProgress, vm, state);
state.networkInterfaceLinks = new ArrayList<>();
Map<String, List<String>> nicToIPv4Addresses = vm.getMapNic2IpV4Addresses();
for (VirtualEthernetCard nic : vm.getNics()) {
VirtualDeviceBackingInfo backing = nic.getBacking();
if (backing instanceof VirtualEthernetCardNetworkBackingInfo) {
VirtualEthernetCardNetworkBackingInfo veth = (VirtualEthernetCardNetworkBackingInfo) backing;
NetworkInterfaceState iface = new NetworkInterfaceState();
iface.networkLink = enumerationProgress.getNetworkTracker().getSelfLink(veth.getNetwork());
iface.name = nic.getDeviceInfo().getLabel();
iface.documentSelfLink = buildUriPath(NetworkInterfaceService.FACTORY_LINK, service.getHost().nextUUID());
iface.address = getPrimaryIPv4Address(nic, nicToIPv4Addresses);
CustomProperties.of(iface).put(CustomProperties.DATACENTER_SELF_LINK, enumerationProgress.getDcLink());
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), NetworkInterfaceService.FACTORY_LINK)).setBody(iface).sendWith(service);
state.networkInterfaceLinks.add(iface.documentSelfLink);
} else if (backing instanceof VirtualEthernetCardDistributedVirtualPortBackingInfo) {
VirtualEthernetCardDistributedVirtualPortBackingInfo veth = (VirtualEthernetCardDistributedVirtualPortBackingInfo) backing;
String portgroupKey = veth.getPort().getPortgroupKey();
Operation op = addNewInterfaceState(service, enumerationProgress, state, portgroupKey, InterfaceStateMode.INTERFACE_STATE_WITH_DISTRIBUTED_VIRTUAL_PORT, SubnetState.class, SubnetState.class, getPrimaryIPv4Address(nic, nicToIPv4Addresses));
if (op != null) {
operations.add(op);
}
} else if (backing instanceof VirtualEthernetCardOpaqueNetworkBackingInfo) {
VirtualEthernetCardOpaqueNetworkBackingInfo veth = (VirtualEthernetCardOpaqueNetworkBackingInfo) backing;
String opaqueNetworkId = veth.getOpaqueNetworkId();
Operation op = addNewInterfaceState(service, enumerationProgress, state, opaqueNetworkId, InterfaceStateMode.INTERFACE_STATE_WITH_OPAQUE_NETWORK, NetworkState.class, NetworkState.class, getPrimaryIPv4Address(nic, nicToIPv4Addresses));
if (op != null) {
operations.add(op);
}
} else {
// TODO add support for DVS
service.logFine(() -> String.format("Will not add nic of type %s", backing.getClass().getName()));
}
}
// Process all the disks attached to the VM
List<VirtualDevice> disks = vm.getDisks();
if (CollectionUtils.isNotEmpty(disks)) {
state.diskLinks = new ArrayList<>(disks.size());
for (VirtualDevice device : disks) {
Operation vdOp = processVirtualDevice(service, null, device, enumerationProgress, state.diskLinks, VimUtils.convertMoRefToString(vm.getId()), null);
if (vdOp != null) {
operations.add(vdOp);
}
}
}
service.logFine(() -> String.format("Found new VM %s", vm.getInstanceUuid()));
if (operations.isEmpty()) {
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeService.FACTORY_LINK)).setBody(state).setCompletion(trackVm(enumerationProgress)).sendWith(service);
} else {
OperationJoin.create(operations).setCompletion((operationMap, exception) -> {
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeService.FACTORY_LINK)).setBody(state).setCompletion(updateVirtualDisksAndTrackVm(service, enumerationProgress, operationMap)).sendWith(service);
}).sendWith(service);
}
});
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class VSphereVirtualMachineEnumerationHelper method makeDescriptionForVm.
static ComputeDescription makeDescriptionForVm(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, VmOverlay vm) {
ComputeDescription res = new ComputeDescription();
res.name = vm.getName();
res.endpointLink = enumerationProgress.getRequest().endpointLink;
AdapterUtils.addToEndpointLinks(res, enumerationProgress.getRequest().endpointLink);
res.documentSelfLink = buildUriPath(ComputeDescriptionService.FACTORY_LINK, service.getHost().nextUUID());
res.instanceAdapterReference = enumerationProgress.getParent().description.instanceAdapterReference;
res.enumerationAdapterReference = enumerationProgress.getParent().description.enumerationAdapterReference;
res.statsAdapterReference = enumerationProgress.getParent().description.statsAdapterReference;
res.powerAdapterReference = enumerationProgress.getParent().description.powerAdapterReference;
res.diskAdapterReference = enumerationProgress.getParent().description.diskAdapterReference;
res.regionId = enumerationProgress.getRegionId();
res.cpuCount = vm.getNumCpu();
res.totalMemoryBytes = vm.getMemoryBytes();
return res;
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class VsphereComputeResourceEnumerationHelper method createNewComputeResource.
private static void createNewComputeResource(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, ComputeResourceOverlay cr, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ComputeDescription desc = makeDescriptionForCluster(service, enumerationProgress, cr);
desc.tenantLinks = enumerationProgress.getTenantLinks();
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeDescriptionService.FACTORY_LINK)).setBody(desc).sendWith(service);
ComputeState state = makeComputeResourceFromResults(enumerationProgress, cr, client);
state.tenantLinks = enumerationProgress.getTenantLinks();
state.descriptionLink = desc.documentSelfLink;
submitWorkToVSpherePool(service, () -> {
VsphereEnumerationHelper.populateTags(service, enumerationProgress, cr, state);
service.logFine(() -> String.format("Found new ComputeResource %s", cr.getId().getValue()));
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ComputeService.FACTORY_LINK)).setBody(state).setCompletion(trackComputeResource(enumerationProgress, cr)).sendWith(service);
});
}
Aggregations