Search in sources :

Example 1 with HostDatastoreBrowserSearchResults

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

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

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

the class HostDatastoreBrowserMO method searchDatastore.

public HostDatastoreBrowserSearchResults searchDatastore(String datastorePath, String fileName, boolean caseInsensitive) throws Exception {
    HostDatastoreBrowserSearchSpec spec = new HostDatastoreBrowserSearchSpec();
    spec.setSearchCaseInsensitive(caseInsensitive);
    spec.setMatchPattern(new String[] { fileName });
    return searchDatastore(datastorePath, spec);
}
Also used : HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec)

Example 4 with HostDatastoreBrowserSearchResults

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

the class HostDatastoreBrowserMO method searchDatastore.

public HostDatastoreBrowserSearchResults searchDatastore(String datastorePath, HostDatastoreBrowserSearchSpec searchSpec) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - searchDatastore(). target mor: " + _mor.get_value() + ", file datastore path: " + datastorePath);
    try {
        ManagedObjectReference morTask = _context.getService().searchDatastore_Task(_mor, datastorePath, searchSpec);
        String result = _context.getServiceUtil().waitForTask(morTask);
        if (result.equals("sucess")) {
            _context.waitForTaskProgressDone(morTask);
            return (HostDatastoreBrowserSearchResults) _context.getServiceUtil().getDynamicProperty(morTask, "info.result");
        } else {
            s_logger.error("VMware searchDaastore_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
        }
    } finally {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - searchDatastore() done");
    }
    return null;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with HostDatastoreBrowserSearchResults

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

the class HostDatastoreBrowserMO method searchDatastoreSubFolders.

public HostDatastoreBrowserSearchResults searchDatastoreSubFolders(String datastorePath, String folderName, boolean caseInsensitive) throws Exception {
    HostDatastoreBrowserSearchSpec spec = new HostDatastoreBrowserSearchSpec();
    spec.setSearchCaseInsensitive(caseInsensitive);
    spec.setMatchPattern(new String[] { folderName });
    return searchDatastore(datastorePath, spec);
}
Also used : HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec)

Aggregations

HostDatastoreBrowserSearchResults (com.vmware.vim25.HostDatastoreBrowserSearchResults)11 FileInfo (com.vmware.vim25.FileInfo)8 HostDatastoreBrowserSearchSpec (com.vmware.vim25.HostDatastoreBrowserSearchSpec)6 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 FileQueryFlags (com.vmware.vim25.FileQueryFlags)2 ArrayList (java.util.ArrayList)2 CloudException (com.cloud.exception.CloudException)1 DatastoreFile (com.cloud.hypervisor.vmware.mo.DatastoreFile)1 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)1 HostDatastoreBrowserMO (com.cloud.hypervisor.vmware.mo.HostDatastoreBrowserMO)1 Before (org.junit.Before)1