Search in sources :

Example 1 with GuestOperationsFaultFaultMsg

use of com.vmware.vim25.GuestOperationsFaultFaultMsg 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 GuestOperationsFaultFaultMsg

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

the class VSphereFile method copyFileToRemote.

private void copyFileToRemote(String fileName, InputStream in, long length, VsphereConnHandler connHandler, ManagedObjectReference fileManager) throws RemoteException, MalformedURLException, ProtocolException, IOException {
    try {
        String fileUploadUrl = getFileUploadUrl(fileName, length, connHandler, fileManager);
        URLConnection conn = prepareConnection(fileUploadUrl, length);
        sendFile(in, conn);
        parseResponse(conn);
    } catch (InvalidPropertyFaultMsg e) {
        translateandLogException(e);
    } catch (RuntimeFaultFaultMsg e) {
        translateandLogException(e);
    } catch (FileFaultFaultMsg e) {
        translateandLogException(e);
    } catch (GuestOperationsFaultFaultMsg e) {
        translateandLogException(e);
    } catch (InvalidStateFaultMsg e) {
        translateandLogException(e);
    } catch (TaskInProgressFaultMsg e) {
        translateandLogException(e);
    }
}
Also used : InvalidStateFaultMsg(com.vmware.vim25.InvalidStateFaultMsg) TaskInProgressFaultMsg(com.vmware.vim25.TaskInProgressFaultMsg) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) GuestOperationsFaultFaultMsg(com.vmware.vim25.GuestOperationsFaultFaultMsg) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 3 with GuestOperationsFaultFaultMsg

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

the class VSphereFile method getFileUploadUrl.

private String getFileUploadUrl(String remotePathName, long fileSize, VsphereConnHandler connHandler, ManagedObjectReference fileManager) throws RemoteException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FileFaultFaultMsg, GuestOperationsFaultFaultMsg, InvalidStateFaultMsg, TaskInProgressFaultMsg {
    GuestFileAttributes gfa = new GuestFileAttributes();
    boolean override = true;
    String fileUploadUrl = connHandler.getClient().getVimPort().initiateFileTransferToGuest(fileManager, vm, credentials, remotePathName, gfa, fileSize, override);
    // replace * with the address of the server. see vsphere docs.
    fileUploadUrl = fileUploadUrl.replace("*", connHandler.getClient().getServer());
    return fileUploadUrl;
}
Also used : GuestFileAttributes(com.vmware.vim25.GuestFileAttributes)

Example 4 with GuestOperationsFaultFaultMsg

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

the class VSphereFile method getInputStream.

@Override
public InputStream getInputStream() throws IOException, UnsupportedFileOperationException {
    VsphereConnHandler connHandler = null;
    try {
        connHandler = getConnHandler();
        ManagedObjectReference fileManager = getFileManager(connHandler);
        FileTransferInformation fileDlInfo = connHandler.getClient().getVimPort().initiateFileTransferFromGuest(fileManager, vm, credentials, getPathInVm());
        String fileDlUrl = fileDlInfo.getUrl().replace("*", connHandler.getClient().getServer());
        // http://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java
        URL website = new URL(fileDlUrl);
        return website.openStream();
    } catch (InvalidPropertyFaultMsg e) {
        translateandLogException(e);
    } catch (RuntimeFaultFaultMsg e) {
        translateandLogException(e);
    } catch (FileFaultFaultMsg e) {
        translateandLogException(e);
    } catch (GuestOperationsFaultFaultMsg e) {
        translateandLogException(e);
    } catch (InvalidStateFaultMsg e) {
        translateandLogException(e);
    } catch (TaskInProgressFaultMsg e) {
        translateandLogException(e);
    } finally {
        releaseConnHandler(connHandler);
    }
    return null;
}
Also used : InvalidStateFaultMsg(com.vmware.vim25.InvalidStateFaultMsg) FileTransferInformation(com.vmware.vim25.FileTransferInformation) TaskInProgressFaultMsg(com.vmware.vim25.TaskInProgressFaultMsg) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) GuestOperationsFaultFaultMsg(com.vmware.vim25.GuestOperationsFaultFaultMsg) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) URL(java.net.URL) FileURL(com.mucommander.commons.file.FileURL) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with GuestOperationsFaultFaultMsg

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

the class VSphereFile method renameTo.

@Override
public void renameTo(AbstractFile destFile) throws IOException, UnsupportedFileOperationException {
    // can't copy\rename to a different host
    // os might be windows, so can't rename with different case.
    checkRenamePrerequisites(destFile, false, false);
    VsphereConnHandler connHandler = null;
    try {
        connHandler = getConnHandler();
        ManagedObjectReference fileManager = getFileManager(connHandler);
        if (isDirectory()) {
            connHandler.getClient().getVimPort().moveDirectoryInGuest(fileManager, vm, credentials, getPathInVm(), ((VSphereFile) destFile).getPathInVm());
        } else {
            connHandler.getClient().getVimPort().moveFileInGuest(fileManager, vm, credentials, getPathInVm(), ((VSphereFile) destFile).getPathInVm(), true);
        }
    } 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);
    } finally {
        releaseConnHandler(connHandler);
    }
}
Also used : InvalidStateFaultMsg(com.vmware.vim25.InvalidStateFaultMsg) TaskInProgressFaultMsg(com.vmware.vim25.TaskInProgressFaultMsg) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) GuestOperationsFaultFaultMsg(com.vmware.vim25.GuestOperationsFaultFaultMsg) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

FileFaultFaultMsg (com.vmware.vim25.FileFaultFaultMsg)6 GuestOperationsFaultFaultMsg (com.vmware.vim25.GuestOperationsFaultFaultMsg)6 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)6 InvalidStateFaultMsg (com.vmware.vim25.InvalidStateFaultMsg)6 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)6 TaskInProgressFaultMsg (com.vmware.vim25.TaskInProgressFaultMsg)6 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 FileURL (com.mucommander.commons.file.FileURL)2 GuestFileAttributes (com.vmware.vim25.GuestFileAttributes)2 GuestFileInfo (com.vmware.vim25.GuestFileInfo)2 GuestListFileInfo (com.vmware.vim25.GuestListFileInfo)2 AbstractFile (com.mucommander.commons.file.AbstractFile)1 FileTransferInformation (com.vmware.vim25.FileTransferInformation)1 HttpURLConnection (java.net.HttpURLConnection)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1