Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 234493

Re: How to get Snapshot space using vi java api??

$
0
0
HostDatastoreBrowserSearchSpec hdbss = new HostDatastoreBrowserSearchSpec();
hdbss.setQuery(new FileQuery[] {new VmDiskFileQuery(),new VmSnapshotFileQuery() });
FileQueryFlags fqf = new FileQueryFlags();
fqf.setFileSize(true);
fqf.setModification(true);
fqf.setFileType(true);
hdbss.setDetails(fqf);
hdbss.setSearchCaseInsensitive(false);                  
hdbss.setSortFoldersFirst(true);
String s1="*-00000*.vmdk";
String s2="*.vmsn";
hdbss.setMatchPattern(new String[] {s1,s2});
Task task=null;
try
{                  
task = hdb.searchDatastoreSubFolders_Task(dspath, hdbss);
}
catch(Exception e)
{
System.out.println("Task Object :: "+task);
System.out.println("Wrong Datastore path.? ::: "+e.getMessage());
e.printStackTrace();
Flag=false;
}
if(task.waitForMe()==Task.SUCCESS)
{
Object obj = task.getTaskInfo().getResult();
if(obj instanceof ArrayOfHostDatastoreBrowserSearchResults)
{
HostDatastoreBrowserSearchResults[] results =((ArrayOfHostDatastoreBrowserSearchResults)obj).getHostDatastoreBrowserSearchResults();
                 
for(int i=0; i<results.length; i++)
{
HostDatastoreBrowserSearchResults result = results[i];
FileInfo[] fis = result.getFile();
if(fis!=null && fis.length>0)
{
String Filename=null;
float totalSnapSize=0.0f;
for(int j=0; j<fis.length; j++)
{
totalSnapSize=totalSnapSize+fis[j].getFileSize();
Filename=fis[j].getPath();
System.out.println("* File name :: "+Filename);
System.out.println("* Snapshot Size in KB :: "+ totalSnapSize/(1024.00f)+" KB");
System.out.println("Modified:"+ fis[j].getModification().getTime());
//                                        System.out.println("Modified:"+ fis[j].getModification().getTime());//
}
System.out.println("* VM Name :: "+vmname);
System.out.println("* File name :: "+Filename);
System.out.println("* No of Snapshots :: "+fis.length);
System.out.println("* Snapshot Size in KB :: "+ totalSnapSize/(1024.00f)+" KB");
if(totalSnapSize/(1024.00f)>999.00)
{
System.out.println("* Snapshot Size in MB :: "+ totalSnapSize/(1024.00f*1024.00f)+" MB");
}
if(totalSnapSize/(1024.00f*1024.00f)>999.00)
{
                       System.out.println("* File Size in GB :: "+ totalSnapSize/(1024.00f*1024.00f*1024.00f)+" GB");
}
System.out.println("==============================================================================");
}
else
{
System.out.println("Error Message :: Snapshot file not found....!!!");
Flag=false;
}
}

Viewing all articles
Browse latest Browse all 234493

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>