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;
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations