use of com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient in project photon-model by vmware.
the class VSphereAdapterImageEnumerationService method refreshResourcesOnce.
private void refreshResourcesOnce(Set<String> oldImages, ImageEnumerateRequest request, ComputeStateWithDescription parent, Connection connection, TaskManager mgr) {
DatacenterLister lister = new DatacenterLister(connection);
try {
for (Element element : lister.listAllDatacenters()) {
ManagedObjectReference datacenter = element.object;
try {
EnumerationClient client = new EnumerationClient(connection, parent, datacenter);
processAllTemplates(oldImages, request.resourceLink(), request.taskLink(), client, parent.tenantLinks);
} catch (Throwable e) {
mgr.patchTaskToFailure("Error processing vm templates in " + element.path, e);
return;
}
}
} catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg e) {
mgr.patchTaskToFailure("Error getting datacenters", e);
return;
}
VapiConnection vapi = VapiConnection.createFromVimConnection(connection);
try {
vapi.login();
LibraryClient libraryClient = vapi.newLibraryClient();
processAllLibraries(oldImages, request.resourceLink(), request.taskLink(), libraryClient, parent.tenantLinks);
mgr.patchTask(TaskStage.FINISHED);
} catch (Throwable t) {
mgr.patchTaskToFailure("Error processing library items", t);
return;
} finally {
vapi.close();
}
// garbage collection runs async
garbageCollectUntouchedImages(oldImages);
}
use of com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient in project photon-model by vmware.
the class VSphereAdapterImageEnumerationService method processAllLibraries.
private void processAllLibraries(Set<String> oldImages, String endpointLink, String taskLink, LibraryClient libraryClient, List<String> tenantLinks) throws IOException, RpcException {
Phaser phaser = new Phaser(1);
for (String libId : libraryClient.listLibs()) {
ObjectNode libModel = libraryClient.loadLib(libId);
for (String itemId : libraryClient.listItemsInLib(libId)) {
ObjectNode itemModel = libraryClient.loadItem(itemId);
String type = VapiClient.getString(itemModel, "type", VapiClient.K_OPTIONAL);
if (!"ovf".equals(type)) {
// only ovfs can be deployed
continue;
}
ImageState state = makeImageFromItem(libModel, itemModel);
state.documentSelfLink = buildStableImageLink(endpointLink, state.id);
state.endpointLink = endpointLink;
state.tenantLinks = tenantLinks;
state.regionId = "";
oldImages.remove(state.documentSelfLink);
phaser.register();
Operation.createPost(PhotonModelUriUtils.createInventoryUri(getHost(), ImageService.FACTORY_LINK)).setBody(state).setCompletion((o, e) -> phaser.arrive()).sendWith(this);
}
}
phaser.arriveAndAwaitAdvance();
}
use of com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient in project photon-model by vmware.
the class InstanceClient method createInstanceFromLibraryItem.
public ComputeState createInstanceFromLibraryItem(ImageState image) throws Exception {
VapiConnection vapi = VapiConnection.createFromVimConnection(this.connection);
vapi.login();
try {
LibraryClient client = vapi.newLibraryClient();
List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.bootDisk);
ManagedObjectReference datastore = getDataStoreForDisk(this.bootDisk, pbmSpec);
Map<String, String> mapping = new HashMap<>();
ObjectNode result = client.deployOvfLibItem(image.id, this.ctx.child.name, getVmFolder(), datastore, pbmSpec != null && !pbmSpec.isEmpty() ? pbmSpec.iterator().next() : null, getResourcePool(), mapping, getDiskProvisioningType(this.bootDisk));
if (!result.get("succeeded").asBoolean()) {
// Log here to understand why deploy from library fails.
logger.warn("Error deploying from library {}", result.toString());
throw new Exception("Error deploying from library");
}
ManagedObjectReference ref = new ManagedObjectReference();
ref.setType(VimNames.TYPE_VM);
ref.setValue(VapiClient.getString(result, "resource_id", VapiClient.K_OPTIONAL, VapiClient.K_STRUCTURE, "com.vmware.vcenter.ovf.library_item.deployable_identity", "id"));
this.vm = ref;
customizeAfterClone();
ComputeState state = new ComputeState();
state.resourcePoolLink = VimUtils.firstNonNull(this.ctx.child.resourcePoolLink, this.ctx.parent.resourcePoolLink);
return state;
} finally {
vapi.close();
}
}
Aggregations