importPackage(com.cloupia.model.cIM);
importPackage(com.cloupia.service.cIM.inframgr);
importPackage(org.apache.commons.httpclient);
importPackage(org.apache.commons.httpclient.methods);
importPackage(java.io);
importPackage(org.w3c.dom);
importPackage(com.cloupia.lib.cIaaS.ucs);
importPackage(java.lang);
importPackage(java.util);
importPackage(com.cloupia.lib.cIaaS.ucs);
var DIR_NAME = "/opt/infra/file_storage";
var content = new StringBuffer();
var lineSeparator = java.lang.System.getProperty("line.separator");
var absoluteFilePath = DIR_NAME + File.separator + "vm_"+input.vmId;
var vvm = InfraPersistenceUtil.getVMWareVMSummary(""+input.vmId);
//RAM
var mem = vvm.getMemoryMB();
logger.addInfo("VM Memory size for the VM "+input.vmId+" is : "+mem);
content.append("vmMemory :"+mem);
content.append(lineSeparator);
output.vmMemory = mem;
//CPU
var cpu = vvm.getNumCPUs();
logger.addInfo("VM CPU count for the VM "+input.vmId+" is : "+cpu);
content.append("vmCPU :"+cpu);
content.append(lineSeparator);
output.vmCPU = cpu;
//Disks Count
var diskcount = vvm.getVmDiskCount();
logger.addInfo("Total no. of disks for the VM "+input.vmId+" is : "+diskcount);
content.append("vmDisksCount :"+diskcount);
content.append(lineSeparator);
output.vmDisksCount = diskcount;
//Disk Size
var disksize = vvm.getUnsharedDiskGB();
logger.addInfo("Total unshared disk space for the VM "+input.vmId+" is : "+disksize);
content.append("vmDiskSize :"+disksize);
content.append(lineSeparator);
output.vmDiskSize = disksize;
//VM OS
var vmos = vvm.getGuestOS();
logger.addInfo("The operating system for the VM "+input.vmId+" is : "+vmos);
content.append("vmOS :"+vmos);
content.append(lineSeparator);
output.vmOS = vmos;
//VM Annotation
var vmannotation = vvm.getGuestOS();
logger.addInfo("The annotation for the VM "+input.vmId+" is : "+vmannotation);
output.vmAnnotation = vmannotation;
//VM Path
var vmpath = vvm.getVmPath();
logger.addInfo("The path for the VM "+input.vmId+" is : "+vmpath);
output.vmPath = vmpath;
//VM MAC Address
var vmmac = vvm.getVmMacAddr();
logger.addInfo("The MAC Address for the VM "+input.vmId+" is : "+vmmac);
output.vmMac = vmmac;
//VM Hostname
var vmhostname = vvm.getGuestHostname();
logger.addInfo("The Hostname for the VM is "+input.vmId+" is : "+vmhostname);
output.vmHostname = vmhostname;
//VM Name
var vmname = vvm.getName();
logger.addInfo("The Name for the VM is "+input.vmId+" is : "+vmname);
output.vmName = vmname;
var file = new File(absoluteFilePath);
var absolutePath = file.getAbsolutePath();
logger.addInfo("File Path "+absolutePath);
var dirName = absolutePath.substring(0,absolutePath.lastIndexOf(File.separator));
var dir = new File(dirName);
if (!file.exists()) {
dir.mkdirs();
}
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
var fw = new FileWriter(file.getAbsoluteFile());
var bw = new BufferedWriter(fw);
bw.write(content.toString());
bw.close();
/*registerUndoTask(absolutePath);
function registerUndoTask(filePath) {
// register undo task
var undoHandler = "custom_rollback_for_loop_sample";
var undoContext = ctxt.createInnerTaskContext(undoHandler);
var undoConfig = undoContext.getConfigObject();
undoConfig.absolute_file_path = filePath;
ctxt.getChangeTracker().undoableResourceModified("Delete file",
""+filePath,
"Deleted file from the directory ",
"Deleted file from the directory successfully",
undoHandler,
undoConfig);
}*/
Additional Links: