It drives me kind of crazy that I can't get the family and fullName directly from the VC:VirtualMachineGuestOsIdentifier. Or maybe you can and I am being dense? From what I have gathered from the documentation these values will vary based upon the HostSystem being deployed to (at least the available os's will. Not sure if family and fullName vary between supported virtual hardware versions). Anyway I don't like presenting people with a list of VC:VirtualMachineGuestOsIdentifier's so I created an action that grabs all of the id's then creates and object indexed either by the id, fullName, or family. I can then use this information in forms and for quickly grabbing whatever of these 3 attributes I need. I also needed to map os descriptions to the naming conventions we use. For example we might call windows 8, Windows 8 Server, Win 8 Server, Windows SRV 8, etc . In a configuration element I am keeping a list of these where attribute name = VC:VirtualMachineGuestOsIdentifier.id and the value of the attribute is an array of strings.
I am also using this to build the list of OS's I present in the forms so they see a more descriptive name than something like otherGuest.
Anyway if I just did a bunch of work for no reason and there is a simpler way someone let me know. The code is below. You'll need to inputs environmentBrowserRoot (optional VC:HostSystem) and indexType (string either id, fullName, or family) . Also you will see one line where I am loading a configuration element. Replace with however you like to do that sort of thing:
// code starts here
if (! indexType) var indexType = "fullName";
indexType = indexType.toLowerCase();
// Load any defined mappings
var qcOsDefinitions = System.getModule("com.whatever.basic").getConfigurationElement("ConfigElementCategory","Guest OS Description Maps" ).attributes;
// Grab a host to query for guest os type descriptions including all the default full names
if (environmentBrowserRoot == null || environmentBrowserRoot == undefined) {
var hosts = Server.findAllForType("VC:HostSystem");
for each (host in hosts) {
if (host.runtime.connectionState.value == "connected") {
var vmHost = host;
System.log("environmentBrowserRoot set to: " + host.name);
var environmentBrowser = host.parent.environmentBrowser;
break;
}
}
}
else {
var environmentBrowser = environmentBrowserRoot.parent.environmentBrowser;
}
// execute the query
var osDescriptions = environmentBrowser.queryConfigOption(null,null).guestOSDescriptor;
// create JSON and merge data
// create multiple indexs now and in the future we can expand lookup and return types. For now just mapping a description to an osType
var idIndex = {};
var fullNameIndex = {};
var familyIndex = {};
for each (var description in osDescriptions) {
// Always build this index. We'll use it in this action.
if ( ! idIndex[description.id.toLowerCase()] ) idIndex[description.id.toLowerCase()] = {"id" : description.id, "fullNames" : [], "family" : description.family};
idIndex[description.id.toLowerCase()]["fullNames"].push(description.fullName);
if (indexType == "fullname") {
fullNameIndex[description.fullName.toLowerCase()] = {"id" : description.id, "fullName" : description.fullName, "family" : description.family};
}
if (indexType == "family") {
if ( ! familyIndex[description.family.toLowerCase()] ) familyIndex[description.family.toLowerCase()] = {"family" : description.family, "ids" : {}};
familyIndex[description.family.toLowerCase()]["ids"][description.id] = {"id" : description.id, "fullName" : description.fullName};
}
}
// merge in QC defined operating systems
for each (var qcOs in qcOsDefinitions) {
var currSearchKey = qcOs.name.toLowerCase();
var currOsType = idIndex[currSearchKey];
if ( ! currOsType ) {
System.log("No match found for osType: " + currSearchKey ) ;
}
else {
for each (var name in qcOs.value) {
if (indexType == "id") idIndex[currSearchKey]["fullNames"].push(name);
if (indexType == "fullname") fullNameIndex[name.toLowerCase()] = {"id" : idIndex[currSearchKey]["id"], "fullName" : name.toLowerCase(), "family" : idIndex[currSearchKey]["family"]};
if (indexType == "family") familyIndex[idIndex[currSearchKey]["family"].toLowerCase()]["ids"][description.id] = {"id" : idIndex[currSearchKey]["id"], "fullName" : idIndex[currSearchKey]["fullName"]};
}
}
}
var index = "";
if (indexType == "fullname") index = JSON.stringify(fullNameIndex);
if (indexType == "id") index = JSON.stringify(idIndex);
if (indexType == "family") index = JSON.stringify(familyIndex);
System.log(indexType + " Index:\n\n" + index);
return index;