Search in sources :

Example 1 with InvalidDatastoreFaultMsg

use of com.vmware.vim25.InvalidDatastoreFaultMsg in project photon-model by vmware.

the class ClientUtils method deleteFolder.

/**
 * Delete a directory at the specified path.
 */
public static void deleteFolder(Connection connection, ManagedObjectReference datacenterMoRef, String path) throws FileFaultFaultMsg, InvalidDatastoreFaultMsg, RuntimeFaultFaultMsg, FileNotFoundFaultMsg, InvalidDatastorePathFaultMsg {
    ManagedObjectReference fileManager = connection.getServiceContent().getFileManager();
    connection.getVimPort().deleteDatastoreFileTask(fileManager, path, datacenterMoRef);
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with InvalidDatastoreFaultMsg

use of com.vmware.vim25.InvalidDatastoreFaultMsg in project photon-model by vmware.

the class DiskClient method createParentFolder.

/**
 * Create parent directory for the disk file to be created.
 */
private void createParentFolder(String path) throws FileFaultFaultMsg, InvalidDatastoreFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference fileManager = this.connection.getServiceContent().getFileManager();
    getVimPort().makeDirectory(fileManager, path, this.diskContext.datacenterMoRef, true);
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 3 with InvalidDatastoreFaultMsg

use of com.vmware.vim25.InvalidDatastoreFaultMsg in project photon-model by vmware.

the class EnumerationClient method queryDisksAvailabilityinVSphere.

/**
 * Utility method that crosschecks the availability of independent disks in vSphere.
 */
public List<String> queryDisksAvailabilityinVSphere(Map<String, Object> diskInfoInLocalIndex) {
    final List<String> unAvailableDisks = new ArrayList<>();
    diskInfoInLocalIndex.entrySet().stream().forEach(entry -> {
        DiskService.DiskState diskState = Utils.fromJson(entry.getValue(), DiskService.DiskState.class);
        String diskDirectoryPath = diskState.customProperties.get(CustomProperties.DISK_PARENT_DIRECTORY);
        String datastoreName = diskState.customProperties.get(CustomProperties.DISK_DATASTORE_NAME);
        HostDatastoreBrowserSearchSpec searchSpec = createHostDatastoreBrowserSearchSpecForDisk(diskState.id);
        try {
            this.getMoRef.entityProps(this.finder.datastore(datastoreName).object, "browser").entrySet().stream().forEach(item -> {
                try {
                    ManagedObjectReference hostBrowser = (ManagedObjectReference) item.getValue();
                    ManagedObjectReference task = connection.getVimPort().searchDatastoreSubFoldersTask(hostBrowser, diskDirectoryPath, searchSpec);
                    TaskInfo info = VimUtils.waitTaskEnd(connection, task);
                    ArrayOfHostDatastoreBrowserSearchResults searchResult = (ArrayOfHostDatastoreBrowserSearchResults) info.getResult();
                    if (searchResult == null) {
                        // Folder is deleted.
                        unAvailableDisks.add(entry.getKey());
                    } else {
                        searchResult.getHostDatastoreBrowserSearchResults().stream().forEach(result -> {
                            // Folder is present but the vmdk file is deleted.
                            if (CollectionUtils.isEmpty(result.getFile())) {
                                unAvailableDisks.add(entry.getKey());
                            }
                        });
                    }
                } catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg | InvalidCollectorVersionFaultMsg | FileFaultFaultMsg | InvalidDatastoreFaultMsg ex) {
                    logger.info("Unable to get the availability status for " + entry.getKey());
                }
            });
        } catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg | FinderException ex) {
            logger.info("Unable to find the datastore : " + datastoreName);
        }
    });
    return unAvailableDisks;
}
Also used : InvalidCollectorVersionFaultMsg(com.vmware.vim25.InvalidCollectorVersionFaultMsg) ArrayList(java.util.ArrayList) HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) DiskService(com.vmware.photon.controller.model.resources.DiskService) TaskInfo(com.vmware.vim25.TaskInfo) InvalidDatastoreFaultMsg(com.vmware.vim25.InvalidDatastoreFaultMsg) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) ArrayOfHostDatastoreBrowserSearchResults(com.vmware.vim25.ArrayOfHostDatastoreBrowserSearchResults) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with InvalidDatastoreFaultMsg

use of com.vmware.vim25.InvalidDatastoreFaultMsg in project photon-model by vmware.

the class ClientUtils method createFolder.

/**
 * Create a directory at the specified path.
 */
public static void createFolder(Connection connection, ManagedObjectReference datacenterMoRef, String path) throws FileFaultFaultMsg, InvalidDatastoreFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference fileManager = connection.getServiceContent().getFileManager();
    connection.getVimPort().makeDirectory(fileManager, path, datacenterMoRef, true);
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with InvalidDatastoreFaultMsg

use of com.vmware.vim25.InvalidDatastoreFaultMsg in project photon-model by vmware.

the class InstanceDiskClient method uploadISOContents.

/**
 * Uploads ISO content into the chosen datastore
 */
public DeferredResult<DiskService.DiskStateExpanded> uploadISOContents(byte[] contentToUpload) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidDatastoreFaultMsg, FileFaultFaultMsg, FinderException {
    try {
        // 1) fetch data store for the disk
        String dsName = this.context.datastoreName;
        if (dsName == null || dsName.isEmpty()) {
            dsName = ClientUtils.getDefaultDatastore(this.finder);
        }
        String dataStoreName = dsName;
        List<Element> datastoreList = this.finder.datastoreList(dataStoreName);
        ManagedObjectReference dsFromSp;
        Optional<Element> datastoreOpt = datastoreList.stream().findFirst();
        if (datastoreOpt.isPresent()) {
            dsFromSp = datastoreOpt.get().object;
        } else {
            throw new IllegalArgumentException(String.format("No Datastore [%s] present on datacenter", dataStoreName));
        }
        // 2) Get available hosts for direct upload
        String hostName = null;
        ArrayOfDatastoreHostMount dsHosts = this.get.entityProp(dsFromSp, VimPath.res_host);
        if (dsHosts != null && dsHosts.getDatastoreHostMount() != null) {
            DatastoreHostMount dsHost = dsHosts.getDatastoreHostMount().stream().filter(hostMount -> hostMount.getMountInfo() != null && hostMount.getMountInfo().isAccessible() && hostMount.getMountInfo().isMounted()).findFirst().orElse(null);
            if (dsHost != null) {
                hostName = this.get.entityProp(dsHost.getKey(), VimPath.host_summary_config_name);
            }
        }
        if (hostName == null) {
            throw new IllegalStateException(String.format("No host found to upload ISO content " + "for Data Store Disk %s", dataStoreName));
        }
        // 3) Choose some unique filename
        String filename = ClientUtils.getUniqueName(ISO_FILE) + ISO_EXTENSION;
        // 4 ) Choose some unique folder name and create it.
        String folderName = ClientUtils.getUniqueName(ISO_FOLDER);
        ClientUtils.createFolder(this.connection, this.context.datacenterMoRef, String.format(VM_PATH_FORMAT, dataStoreName, folderName));
        // 5) form the upload url and acquire generic service ticket for it
        String isoUrl = String.format(ISO_UPLOAD_URL, hostName, VimUtils.encode(folderName), VimUtils.encode(filename), VimUtils.encode(dataStoreName));
        String ticket = this.connection.getGenericServiceTicket(isoUrl);
        // 6) create external client that accepts all certificates
        TrustManager[] trustManagers = new TrustManager[] { ClientUtils.getDefaultTrustManager() };
        ServiceClient serviceClient = ClientUtils.getCustomServiceClient(trustManagers, this.host, URI.create(isoUrl), this.getClass().getSimpleName());
        // 7) PUT operation for the iso content
        Operation putISO = Operation.createPut(URI.create(isoUrl));
        putISO.setContentType(MEDIA_TYPE_APPLICATION_OCTET_STREAM).setContentLength(contentToUpload.length).addRequestHeader("Cookie", "vmware_cgi_ticket=" + ticket).setBody(contentToUpload).setReferer(this.host.getUri());
        return serviceClient.sendWithDeferredResult(putISO).thenApply(op -> {
            String diskFullPath = String.format(FULL_PATH, dataStoreName, folderName, filename);
            // Update the details of the disk
            CustomProperties.of(this.diskState).put(DISK_FULL_PATH, diskFullPath).put(DISK_PARENT_DIRECTORY, String.format(PARENT_DIR, dataStoreName, folderName)).put(DISK_DATASTORE_NAME, dataStoreName);
            this.diskState.sourceImageReference = VimUtils.datastorePathToUri(diskFullPath);
            return this.diskState;
        });
    } catch (Exception e) {
        return DeferredResult.failed(e);
    }
}
Also used : Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) Operation(com.vmware.xenon.common.Operation) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) TrustManager(javax.net.ssl.TrustManager) ArrayOfDatastoreHostMount(com.vmware.vim25.ArrayOfDatastoreHostMount) ServiceClient(com.vmware.xenon.common.ServiceClient) DatastoreHostMount(com.vmware.vim25.DatastoreHostMount) ArrayOfDatastoreHostMount(com.vmware.vim25.ArrayOfDatastoreHostMount) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)6 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)2 FileFaultFaultMsg (com.vmware.vim25.FileFaultFaultMsg)2 InvalidDatastoreFaultMsg (com.vmware.vim25.InvalidDatastoreFaultMsg)2 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)2 CloudException (com.cloud.exception.CloudException)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 Element (com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element)1 DiskService (com.vmware.photon.controller.model.resources.DiskService)1 ArrayOfDatastoreHostMount (com.vmware.vim25.ArrayOfDatastoreHostMount)1 ArrayOfHostDatastoreBrowserSearchResults (com.vmware.vim25.ArrayOfHostDatastoreBrowserSearchResults)1 ConcurrentAccessFaultMsg (com.vmware.vim25.ConcurrentAccessFaultMsg)1 DatastoreHostMount (com.vmware.vim25.DatastoreHostMount)1 DuplicateNameFaultMsg (com.vmware.vim25.DuplicateNameFaultMsg)1 HostDatastoreBrowserSearchSpec (com.vmware.vim25.HostDatastoreBrowserSearchSpec)1 HttpNfcLeaseDeviceUrl (com.vmware.vim25.HttpNfcLeaseDeviceUrl)1 HttpNfcLeaseInfo (com.vmware.vim25.HttpNfcLeaseInfo)1 HttpNfcLeaseState (com.vmware.vim25.HttpNfcLeaseState)1 InsufficientResourcesFaultFaultMsg (com.vmware.vim25.InsufficientResourcesFaultFaultMsg)1