Search in sources :

Example 1 with GuestListFileInfo

use of com.vmware.vim25.GuestListFileInfo in project mucommander by mucommander.

the class VSphereFile method ls.

@Override
public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
    List<GuestFileInfo> fileInfos = new ArrayList<GuestFileInfo>();
    int index = 0;
    VsphereConnHandler connHandler = null;
    try {
        connHandler = getConnHandler();
        ManagedObjectReference fileManager = getFileManager(connHandler);
        boolean haveRemaining;
        do {
            GuestListFileInfo res = connHandler.getClient().getVimPort().listFilesInGuest(fileManager, vm, credentials, getPathInVm(), index, null, null);
            haveRemaining = (res.getRemaining() != 0);
            fileInfos.addAll(res.getFiles());
            index = fileInfos.size();
        } while (haveRemaining);
        String parentPath = PathUtils.removeTrailingSeparator(fileURL.getPath()) + SEPARATOR;
        Collection<AbstractFile> res = new ArrayList<AbstractFile>();
        for (GuestFileInfo f : fileInfos) {
            final String name = getFileName(f.getPath());
            if (name.equals(".") || name.equals("..")) {
                continue;
            }
            FileURL childURL = (FileURL) fileURL.clone();
            childURL.setPath(parentPath + name);
            AbstractFile newFile = new VSphereFile(childURL, this, f);
            res.add(newFile);
        }
        return res.toArray(new AbstractFile[0]);
    } catch (FileFaultFaultMsg e) {
        translateandLogException(e);
    } catch (GuestOperationsFaultFaultMsg e) {
        translateandLogException(e);
    } catch (InvalidStateFaultMsg e) {
        translateandLogException(e);
    } catch (RuntimeFaultFaultMsg e) {
        translateandLogException(e);
    } catch (TaskInProgressFaultMsg e) {
        translateandLogException(e);
    } catch (InvalidPropertyFaultMsg e) {
        translateandLogException(e);
    } catch (URISyntaxException e) {
        translateandLogException(e);
    } finally {
        releaseConnHandler(connHandler);
    }
    // we never get here..
    return null;
}
Also used : GuestListFileInfo(com.vmware.vim25.GuestListFileInfo) GuestFileInfo(com.vmware.vim25.GuestFileInfo) AbstractFile(com.mucommander.commons.file.AbstractFile) TaskInProgressFaultMsg(com.vmware.vim25.TaskInProgressFaultMsg) ArrayList(java.util.ArrayList) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) URISyntaxException(java.net.URISyntaxException) FileURL(com.mucommander.commons.file.FileURL) InvalidStateFaultMsg(com.vmware.vim25.InvalidStateFaultMsg) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) GuestOperationsFaultFaultMsg(com.vmware.vim25.GuestOperationsFaultFaultMsg) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with GuestListFileInfo

use of com.vmware.vim25.GuestListFileInfo in project mucommander by mucommander.

the class VSphereFile method checkAttributues.

private void checkAttributues(VsphereConnHandler connHandler) throws IOException, FileFaultFaultMsg, GuestOperationsFaultFaultMsg, InvalidStateFaultMsg, RuntimeFaultFaultMsg, TaskInProgressFaultMsg, InvalidPropertyFaultMsg {
    ManagedObjectReference fileManager = getFileManager(connHandler);
    GuestListFileInfo res = null;
    try {
        res = connHandler.getClient().getVimPort().listFilesInGuest(fileManager, vm, credentials, getPathInVm(), null, null, null);
    } catch (SOAPFaultException e) {
        if (isFileNotFound(e)) {
            return;
        }
        throw e;
    }
    if (res.getFiles().size() == 1) {
        // only one result - it's a file
        GuestFileInfo guestFileInfo = res.getFiles().get(0);
        updateAttributes(guestFileInfo);
    } else {
        // find the entry for "."
        for (GuestFileInfo f : res.getFiles()) {
            if (f.getPath().equals(".")) {
                updateAttributes(f);
                break;
            }
        }
    }
}
Also used : GuestListFileInfo(com.vmware.vim25.GuestListFileInfo) GuestFileInfo(com.vmware.vim25.GuestFileInfo) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

GuestFileInfo (com.vmware.vim25.GuestFileInfo)2 GuestListFileInfo (com.vmware.vim25.GuestListFileInfo)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 AbstractFile (com.mucommander.commons.file.AbstractFile)1 FileURL (com.mucommander.commons.file.FileURL)1 FileFaultFaultMsg (com.vmware.vim25.FileFaultFaultMsg)1 GuestOperationsFaultFaultMsg (com.vmware.vim25.GuestOperationsFaultFaultMsg)1 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)1 InvalidStateFaultMsg (com.vmware.vim25.InvalidStateFaultMsg)1 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)1 TaskInProgressFaultMsg (com.vmware.vim25.TaskInProgressFaultMsg)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1