@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
123 lines (121 loc) • 5.89 kB
JavaScript
import { map } from 'rxjs/operators';
import { PowerShell } from '../../data/powershell';
import { PowerShellScripts } from '../../generated/powershell-scripts';
import { SharedCache } from '../shared-cache';
import { ServerInventory } from './server-inventory';
/**
* Server Inventory cache class.
*/
export class ServerInventoryCache extends SharedCache {
appContext;
static uniqueId = '@msft-sme/shell:serverInventory';
static uniqueVersion = 17;
/**
* Create Server Inventory data from the script result data.
*
* @param name the name of server node.
* @param data the PowerShell script result data.
*/
static createServerInventoryData(name, data) {
const inventory = new ServerInventory(name);
if (data && data.results && data.results.length > 0) {
const result = data.results[0];
const operatingSystem = result.operatingSystem;
const computerSystem = result.computerSystem;
inventory.isAdministrator = result.isAdministrator;
inventory.isWmfInstalled = result.isWmfInstalled;
inventory.name = operatingSystem.csName ? operatingSystem.csName.toString().toLowerCase() : null;
inventory.operatingSystemName = operatingSystem.caption;
inventory.operatingSystemSKU = operatingSystem.operatingSystemSKU;
inventory.operatingSystemVersion = operatingSystem.version;
inventory.productType = operatingSystem.productType;
inventory.osType = operatingSystem.osType;
inventory.lastBootUpTime = operatingSystem.lastBootUpTime;
inventory.osSerialNumber = operatingSystem.serialNumber;
inventory.buildNumber = operatingSystem.currentBuild;
inventory.updateBuildRevision = operatingSystem.updateBuildRevision;
inventory.operatingSystemDisplayVersion = operatingSystem.displayVersion;
inventory.totalPhysicalMemory = computerSystem.totalPhysicalMemory;
inventory.domainRole = computerSystem.domainRole;
inventory.computerManufacturer = computerSystem.manufacturer;
inventory.computerModel = computerSystem.model;
inventory.totalLogicalProcessors = computerSystem.numberOfLogicalProcessors;
inventory.isRemoteAppEnabled = result.isRemoteAppEnabled;
if (computerSystem.partOfDomain) {
inventory.domainName = computerSystem.domain;
}
else {
inventory.workgroupName = computerSystem.workgroup;
}
inventory.fullyQualifiedDomainName = result.fqdn.toLowerCase();
inventory.fullyQualifiedDomainNameRaw = result.fqdn;
inventory.addressList = result.addressList;
inventory.hostname = result.hostname.toLowerCase();
inventory.hostnameRaw = result.hostname;
inventory.netBios = result.netBios;
inventory.clusterFqdn = result.clusterFqdn ? result.clusterFqdn.toLowerCase() : null;
inventory.isCluster = result.isCluster;
inventory.isManagementToolsAvailable = result.isManagementToolsAvailable;
inventory.isServerManagerAvailable = result.isServerManagerAvailable;
inventory.isS2dEnabled = result.isS2dEnabled;
inventory.isBritannicaEnabled = result.isBritannicaEnabled;
inventory.isHyperVRoleInstalled = result.isHyperVRoleInstalled;
inventory.isHyperVPowershellInstalled = result.isHyperVPowershellInstalled;
inventory.isCredSSPEnabled = result.isCredSSPEnabled;
inventory.smbiosData = result.smbiosData;
inventory.azureArcStatus = result.azureArcStatus;
inventory.systemLockdownPolicy = result.systemLockdownPolicy;
inventory.isHciServer = result.isHciServer;
}
return inventory;
}
/**
* Initializes a new instance of the ServerInventoryCache class.
*
* @param appContext the app context.
* @param options the option of shared cache.
*/
constructor(appContext, options) {
super(ServerInventoryCache.uniqueId, ServerInventoryCache.uniqueVersion, (params) => this.dataInstanceId(params), (instance) => this.dataSerialize(instance), (serialized) => this.dataDeserialize(serialized), (params) => this.dataQuery(params), options);
this.appContext = appContext;
}
/**
* Defines how to collect the server inventory data.
*
* @param params the server inventory query params.
* @return the Observable of ServerInventory data.
*/
dataQuery(params) {
const psSession = this.appContext.powerShell.createSession(params.name, null, { ...{ automatic: true }, ...params.requestOptions });
return this.appContext.powerShell.run(psSession, PowerShell.createCommand(PowerShellScripts.Get_ServerInventory))
.pipe(map((data) => ServerInventoryCache.createServerInventoryData(params.name, data)));
}
/**
* Defines how to identify the cache entry by params.
*
* @param params the server inventory query params.
* @return the id string.
*/
dataInstanceId(params) {
return params.name;
}
/**
* Defines how to deserialize the class object from serialized data.
*
* @param serialized the serialized string;
*/
dataDeserialize(serialized) {
const inventory = JSON.parse(serialized);
return new ServerInventory(inventory.serverName, inventory);
}
/**
* Defines how to serialize the class object to serialized data.
*
* @param instance the class instance.
*/
dataSerialize(instance) {
// automatically stripped out class related data.
return JSON.stringify(instance);
}
}
//# sourceMappingURL=server-inventory-cache.js.map