Search in sources :

Example 1 with FileInfo

use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.

the class DatastoreMO method fileExists.

public boolean fileExists(String fileFullPath) throws Exception {
    DatastoreFile file = new DatastoreFile(fileFullPath);
    DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    s_logger.info("Search file " + file.getFileName() + " on " + dirFile.getPath());
    HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(dirFile.getPath(), file.getFileName(), true);
    if (results != null) {
        FileInfo[] info = results.getFile();
        if (info != null && info.length > 0) {
            s_logger.info("File " + fileFullPath + " exists on datastore");
            return true;
        }
    }
    s_logger.info("File " + fileFullPath + " does not exist on datastore");
    return false;
/*		
		String[] fileNames = listDirContent(dirFile.getPath());
		
		String fileName = file.getFileName();
		for(String name : fileNames) {
			if(name.equalsIgnoreCase(fileName))
				return true;
		} 
		
		return false;
*/
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo)

Example 2 with FileInfo

use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.

the class DatastoreMO method folderExists.

public boolean folderExists(String folderParentDatastorePath, String folderName) throws Exception {
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(folderParentDatastorePath, folderName, true);
    if (results != null) {
        FileInfo[] info = results.getFile();
        if (info != null && info.length > 0) {
            s_logger.info("Folder " + folderName + " exists on datastore");
            return true;
        }
    }
    s_logger.info("Folder " + folderName + " does not exist on datastore");
    return false;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo)

Example 3 with FileInfo

use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method getVmxHttpAccessUrl.

public String getVmxHttpAccessUrl() throws Exception {
    Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
    VirtualMachineFileInfo fileInfo = getFileInfo();
    String vmxFilePath = fileInfo.getVmPathName();
    String[] vmxPathTokens = vmxFilePath.split("\\[|\\]|/");
    StringBuffer sb = new StringBuffer("https://" + _context.getServerAddress() + "/folder/");
    sb.append(URLEncoder.encode(vmxPathTokens[2].trim()));
    sb.append("/");
    sb.append(URLEncoder.encode(vmxPathTokens[3].trim()));
    sb.append("?dcPath=");
    sb.append(URLEncoder.encode(dcInfo.second()));
    sb.append("&dsName=");
    sb.append(URLEncoder.encode(vmxPathTokens[1].trim()));
    return sb.toString();
}
Also used : VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo)

Example 4 with FileInfo

use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method getHttpAccessPathInfo.

/**
	 * Retrieve path info to access VM files via vSphere web interface 
	 * @return [0] vm-name, [1] data-center-name, [2] datastore-name 
	 * @throws Exception
	 */
public String[] getHttpAccessPathInfo() throws Exception {
    String[] pathInfo = new String[3];
    Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
    VirtualMachineFileInfo fileInfo = getFileInfo();
    String vmxFilePath = fileInfo.getVmPathName();
    String[] vmxPathTokens = vmxFilePath.split("\\[|\\]|/");
    assert (vmxPathTokens.length == 4);
    // vSphere vm name
    pathInfo[1] = vmxPathTokens[1].trim();
    // vSphere datacenter name
    pathInfo[2] = dcInfo.second();
    // vSphere datastore name
    pathInfo[3] = vmxPathTokens[0].trim();
    return pathInfo;
}
Also used : VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo)

Example 5 with FileInfo

use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method getSnapshotDescriptorDatastorePath.

public String getSnapshotDescriptorDatastorePath() throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.setPathSet(new String[] { "name", "config.files" });
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.FALSE);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    assert (ocs != null);
    String vmName = null;
    VirtualMachineFileInfo fileInfo = null;
    assert (ocs.length == 1);
    for (ObjectContent oc : ocs) {
        DynamicProperty[] props = oc.getPropSet();
        if (props != null) {
            assert (props.length == 2);
            for (DynamicProperty prop : props) {
                if (prop.getName().equals("name")) {
                    vmName = prop.getVal().toString();
                } else {
                    fileInfo = (VirtualMachineFileInfo) prop.getVal();
                }
            }
        }
    }
    assert (vmName != null);
    assert (fileInfo != null);
    // .vmsd file exists at the same directory of .vmx file
    DatastoreFile vmxFile = new DatastoreFile(fileInfo.getVmPathName());
    return vmxFile.getCompanionPath(vmName + ".vmsd");
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo)

Aggregations

VirtualMachineFileInfo (com.vmware.vim25.VirtualMachineFileInfo)11 FileInfo (com.vmware.vim25.FileInfo)8 HostDatastoreBrowserSearchResults (com.vmware.vim25.HostDatastoreBrowserSearchResults)8 FileInfo (com.intellij.openapi.util.io.win32.FileInfo)4 CloudException (com.cloud.exception.CloudException)3 DatastoreFile (com.cloud.hypervisor.vmware.mo.DatastoreFile)3 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)3 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)3 InternalErrorException (com.cloud.exception.InternalErrorException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)2 DynamicProperty (com.vmware.vim25.DynamicProperty)2 FileQueryFlags (com.vmware.vim25.FileQueryFlags)2 HostDatastoreBrowserSearchSpec (com.vmware.vim25.HostDatastoreBrowserSearchSpec)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 ObjectContent (com.vmware.vim25.ObjectContent)2 ObjectSpec (com.vmware.vim25.ObjectSpec)2 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)2