Created
December 9, 2016 22:43
-
-
Save vmwarecode/0d5e6a32bc383c483914f2974fbd57e3 to your computer and use it in GitHub Desktop.
Decode vSphere License
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2016, VMware, Inc. All Rights Reserved | |
// | |
// VMware vRealize Orchestrator action sample | |
// | |
// Decodes the 'Product Name' and 'Product Version' from a vSphere license string. | |
// Also does some basic license key format validation | |
// | |
//Action Inputs: | |
// vCenterConnection - VC:SdkConnection | |
// licenseKey - string | |
// | |
//Return type: void | |
//validate that we have a license key that is 5, 5 character strings delimited by a '-' | |
var licenseParts = licenseKey.split('-'); | |
if (licenseParts.length != 5) { | |
throw("license key is not complete"); | |
} | |
for each (var part in licenseParts) { | |
if (part.length < 5) { | |
throw("license key is invalid. Section: '"+part+"' of '"+licenseKey+"' is too short"); | |
} | |
if (part.length > 5) { | |
throw("license key is invalid. Section: '"+part+"' of '"+licenseKey+"' is too long"); | |
} | |
} | |
var licenseInfo = vCenterConnection.licenseManager.decodeLicense(licenseKey); | |
System.log("License Name: "+licenseInfo.name); | |
var licenseProps = licenseInfo.properties; | |
for each (var licenseProp in licenseProps) { | |
if (licenseProp.key === "ProductName") { | |
System.log("Product Name: "+licenseProp.value); | |
} else if (licenseProp.key === "ProductVersion") { | |
System.log("Product Version: "+licenseProp.value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment