02-21-2015 04:30 AM - edited 03-01-2019 06:33 AM
Task Name | VM Deployment with USER IP input |
Description |
|
Prerequisites |
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs |
Instructions for Regular Workflow Use:
The Request
===========
1) Create a snapshot report that can add up the snapshot sizes and produce a total for the vCenter
2) Can run on a schedule
3) Input the destination e-mail address
4) Input the Cloud/vCenter destination
The Workflow
===========
Execution of Workflow
=================
The Run Result
=============
Workflow Input
============
Scheduling of the Workflow
=====================
Right click on the workflow and select schedule:
Select scheduling frequency:
Select scheduling TAB and check result:
The second attachment has the Multi Cloud Option
It Cycles through all the vCenter Accounts
=======================================
Loop #1
======
Loop #2
======
The Code
=======
importPackage(java.util);
importPackage(java.lang);
importPackage(java.io);
importPackage(com.cloupia.model.cEvent.notify);
importPackage(com.cloupia.model.cIM);
importPackage(com.cloupia.lib.util.mail);
importPackage(com.cloupia.fw.objstore);
importPackage(com.cloupia.lib.util.managedreports);
function getMailSettings()
{
return ObjStoreHelper.getStore((new MailSettings()).getClass()).getSingleton();
}
function getReport(reportContext, reportName)
{
var report = null;
try
{
report = ctxt.getAPI().getConfigTableReport(reportContext, reportName);
} catch(e)
{
}
if (report == null)
{
return ctxt.getAPI().getTabularReport(reportName, reportContext);
} else
{
var source = report.getSourceReport();
return ctxt.getAPI().getTabularReport(source, reportContext);
}
}
function getReportView(reportContext, reportName)
{
var report = getReport(reportContext, reportName);
if (report == null)
{
logger.addError("No such report exists for the specified context "+reportName);
return null;
}
return new TableView(report);
}
// Assume the To Email Addres is in the input variable 'Email Address'
var toEmail = [ ctxt.getInput("Email Address") ];
var CloudSelector1 = [ ctxt.getInput("CloudSelector") ];
var message = new EmailMessageRequest();
message.setToAddrs(toEmail);
message.setSubject("Snapshot Size Report");
message.setFromAddress("no-reply@cisco.com");
var buffer = new StringWriter();
var printer = new PrintWriter(buffer);
// Formatter exists in multiple packages, so it needs fully qualified name
var formatter = new com.cloupia.lib.util.managedreports.Formatter(new File("."), printer);
//
// Report Name from Meta button
//
var reportName = "StorageFeature.vmware.snapshot.summary.list";
//
// Context
// Can be obtained from Administration -> User Interface Settings -> Reports Customization
//
//var repContext = util.createContext("global", null, null);
var repContext = util.createContext("cloud", CloudSelector1, null);
var report = getReportView(repContext, reportName);
var a = 0;
var b = 0;
// Filter Active State VMs
// report = report.filterRowsByColumn("CPU Sockets", "Unlocked", false);
var sum = 0;
for (var i=0; i<report.rowCount(); i++) {
var cnt = report.getColumnValue(i, "Snapshot Size (KB)");
logger.addInfo("Raw Number from Report = "+cnt);
if (cnt == null) {
logger.addInfo("Cant add null");
} else {
b = Number(cnt);
logger.addInfo("Convert String (1.4e7) to Number = "+b);
a = parseInt(b, 10);
logger.addInfo("Real to Integer = "+a);
sum = sum + a;
//sum = sum + Integer.valueOf(cnt);
logger.addInfo("SUM ="+sum);
}
}
var MBsum = parseInt(sum/1024 , 10);
var GBsum = parseInt(MBsum/1024, 10);
var TBsum = parseInt(GBsum/1024, 10);
var PBsum = parseInt(TBsum/1024, 10);
logger.addInfo("MB SUM ="+MBsum);
logger.addInfo("GB SUM ="+GBsum);
logger.addInfo("TB SUM ="+TBsum);
logger.addInfo("PB SUM ="+PBsum);
formatter.printTable(report);
printer.close();
var body = "<head><style type='text/css'>";
// Specify CSS for the report
body = body + "table { font-family: Verdana, Geneva, sans-serif; font-size: 12px; border: thin solid #039; border-spacing: 0; background: #ffffff; } ";
body = body + " th { background-color: #6699FF; color: white; font-family: Verdana, Geneva, sans-serif; font-size: 10px; font-weight: bold; border-color: #CCF; border-style: solid; border-width: 1px 1px 0 0; margin: 0; padding: 5px; } ";
body = body + " td { font-family: Verdana, Geneva, sans-serif; font-size: 10px; border-color: #CCF; border-style: solid; border-width: 1px 1px 0 0; margin: 0; padding: 5px; background: #ffffff; }";
body = body + "</style></head>";
body = body + "<body><h1>Snapshot Size Report</h1><br>" + buffer.toString();
body = body+"<br>Snapshot sum:<br>";
body = body+"<br>------------------------------------------------<br>";
body = body + sum.toString() + " KB ";
body = body+"<br>------------------------------------------------<br>";
body = body + MBsum.toString() + " MB ";
body = body+"<br>------------------------------------------------<br>";
body = body + GBsum.toString() + " GB ";
body = body+"<br>------------------------------------------------<br>";
body = body + PBsum.toString() + " PB ";
body = body+"<br>------------------------------------------------<br>";
message.setMessageBody(body);
logger.addInfo("Sending email");
// Now, send the report via email. First parameter is just a label used in the
// internal logs
MailManager.sendEmail("Snapshot Size Report", getMailSettings(), message);
Execution of Workflow
=================
Log File Run
==========
Service Request ID: 4379
Workflow Inputs:
- Email Address
- CloudSelector
Feb 21, 2015 06:15:50 CST Request submitted
Feb 21, 2015 06:15:53 CST Executing workflow item number 1
Feb 21, 2015 06:15:53 CST Completed workflow item number 1, with status Completed
Feb 21, 2015 06:15:56 CST Executing workflow item number 2
Feb 21, 2015 06:15:56 CST Trigger context executeWorkFlowStep called
Feb 21, 2015 06:15:56 CST Executing custom action Report_Snap_shot_with_Counter (ExecuteCloupiaScript)
Feb 21, 2015 06:15:56 CST Executing custom action Report_Snap_shot_with_Counter (ExecuteCloupiaScript)
Feb 21, 2015 06:15:59 CST Executing cloupia script: ReportsSnapShotSizeReport
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =0
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =0
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =0
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =0
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =0
Feb 21, 2015 06:15:59 CST Raw Number from Report = 2.7641546700195312E7
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 27641546.700195312
Feb 21, 2015 06:15:59 CST Real to Integer = 27641546
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =27641546
Feb 21, 2015 06:15:59 CST Raw Number from Report = 1.4321122E7
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 14321122
Feb 21, 2015 06:15:59 CST Real to Integer = 14321122
Feb 21, 2015 06:15:59 CST SUM =41962668
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =41962668
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =41962668
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =41962668
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =41962668
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =41962668
Feb 21, 2015 06:15:59 CST Raw Number from Report = 0.0
Feb 21, 2015 06:15:59 CST Convert String (1.4e7) to Number = 0
Feb 21, 2015 06:15:59 CST Real to Integer = 0
Feb 21, 2015 06:15:59 CST SUM =41962668
Feb 21, 2015 06:15:59 CST MB SUM =40979
Feb 21, 2015 06:15:59 CST GB SUM =40
Feb 21, 2015 06:15:59 CST TB SUM =0
Feb 21, 2015 06:15:59 CST PB SUM =0
Feb 21, 2015 06:15:59 CST Sending email
Feb 21, 2015 06:15:59 CST Completed cloupia script ReportsSnapShotSizeReport
Feb 21, 2015 06:16:00 CST Task #1 (Report_Snap_shot_with_Counter (ExecuteCloupiaScript)) completed successfully in 3 seconds
Feb 21, 2015 06:16:00 CST Input/Output values for Task #1 (Report_Snap_shot_with_Counter (ExecuteCloupiaScript)):
Feb 21, 2015 06:16:00 CST [Local Input: Label = ReportsSnapShotSizeReport]
Feb 21, 2015 06:16:00 CST [Local Input: Script = importPackage(java.util); importPackage(java.lang); importPackage(java.io); importPackage(com.cloupia.model.cEvent.notify); importPackage(com.cloupia.model.cIM); importPackage(com.cloupia.lib.util.mail); importPackage(com.cloupia.fw.objstore); importPackage(com.cloupia.lib.util.managedreports); function getMailSettings() { return ObjStoreHelper.getStore((new MailSettings()).getClass()).getSingleton(); } function getReport(reportContext, reportName) { var report = null; try { report = ctxt.getAPI().getConfigTableReport(reportContext, reportName); } catch(e) { } if (report == null) { return ctxt.getAPI().getTabularReport(reportName, reportContext); } else { var source = report.getSourceReport(); return ctxt.getAPI().getTabularReport(source, reportContext); } } function getReportView(reportContext, reportName) { var report = getReport(reportContext, repor
Feb 21, 2015 06:16:00 CST [Local Input: Undo Script = ]
Feb 21, 2015 06:16:00 CST Completed workflow item number 2, with status Completed
Feb 21, 2015 06:16:02 CST Executing workflow item number 3
Feb 21, 2015 06:16:02 CST Completed workflow item number 3, with status Completed
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: