vsphere-infra
Version:
934 lines • 40.9 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findMo = exports.iidParse = exports.getMoTypeByName = exports.Mo = void 0;
const ts_basis_1 = require("ts-basis");
var Mo;
(function (Mo) {
class Base extends ts_basis_1.ix.Entity {
constructor($dc, init, preinit) {
super('ManagedObject', '$guid:' + $dc.key + ':' + init.iid);
this.$dc = null;
this.$type = 'Base';
this.$dirty = false;
this.$initPending = true;
this.$defunct = false;
this.$guid = null;
this.$srcBefore = null;
this.$src = null;
this.$deletedTime = 0;
this.$lastSync = 0;
this.$syncing = null;
this.iid = '';
this.name = '';
this.parent = null;
this.headers = {};
$dc.lifecycle.manage(this);
if (preinit) {
preinit(this);
}
this.$dc = $dc;
this.$guid = '$guid:' + $dc.key + ':' + init.iid;
this.iid = init.iid;
this.$dc.inventory.byGUID[this.$guid] = this;
this.$dc.inventory.byIID[this.iid] = this;
this.updateFrom(init, true);
this.$dc.emitEvent(this.$dc.entryRegister$, { target: this });
}
updateFrom(init, fromBase = false) {
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function* () {
this.$srcBefore = this.$src;
this.$src = init;
this.setName(init);
if (fromBase) {
this.overallStatus = init.overallStatus ? init.overallStatus : '';
this.$lastSync = Date.now();
}
yield this.updateFromExtended(init);
this.$dc.emitEvent(this.$dc.entryRefresh$, { target: this });
if (((_a = this.$src) === null || _a === void 0 ? void 0 : _a.parent) !== ((_b = this.$srcBefore) === null || _b === void 0 ? void 0 : _b.parent)) {
this.$dc.emitEvent(this.$dc.entryMove$, { target: this, from: (_c = this.$srcBefore) === null || _c === void 0 ? void 0 : _c.parent, to: (_d = this.$src) === null || _d === void 0 ? void 0 : _d.parent });
}
return this;
});
}
updateFromExtended(_) {
return __awaiter(this, void 0, void 0, function* () { });
}
unregister() {
if (this.$defunct) {
return;
}
this.$defunct = true;
this.$deletedTime = Date.now();
this.$dc.inventory.deleted.push(this);
delete this.$dc.inventory.byGUID[this.$guid];
delete this.$dc.inventory.byIID[this.iid];
this.unregisterExtended();
this.unsetName();
}
unregisterExtended() { }
setName(init) {
if (!init.name) {
if (this instanceof Mo.ResourcePool) {
init.name = init.summary.name;
}
else {
init.name = this.iid.split(':').pop();
this.$dc.debugOutput(`Cannot resolve entity name of ${this.iid}, using ${init.name} instead.`);
}
}
if (init.name.indexOf('|') > 0) {
init.name = init.name.replace(/\|/g, '%7C');
}
if (this.name !== init.name) {
this.unsetName();
this.name = init.name;
if (!this.$dc.index.byName[this.name]) {
this.$dc.index.byName[this.name] = [];
}
this.$dc.index.byName[this.name].push(this.iid);
}
}
unsetName(name) {
if (!name) {
name = this.name;
}
if (!name) {
return;
}
const nameReg = this.$dc.index.byName[name];
if (nameReg) {
const nameIdx = nameReg.indexOf(this.iid);
if (nameIdx >= 0) {
nameReg.splice(nameIdx, 1);
}
if (nameReg.length === 0) {
delete this.$dc.index.byName[name];
}
}
}
getSourceData() { return this.$src; }
getSourceDataBefore() { return this.$srcBefore; }
toString() { return this.$guid; }
toJSON() { return this.$guid; }
entitySummaryHeaders() { return this.$guid + '|' + this.name + '|' + (this.parent ? this.parent.$guid : '') + '|' + this.getSerializedHeaders(); }
getSerializedHeaders() {
const kvPairs = [];
for (const header of Object.keys(this.headers)) {
const value = encodeURIComponent(this.headers[header]);
kvPairs.push(`${header}=${value}`);
}
return kvPairs.join('&');
}
moBaseSerializable() {
return {
$guid: this.$guid,
$type: this.$type,
$deletedTime: this.$deletedTime,
$lastSync: this.$lastSync,
iid: this.iid,
name: this.name,
parent: this.parent,
overallStatus: this.overallStatus,
};
}
serialize() {
return JSON.stringify(Object.assign({}, this.moBaseSerializable()));
}
refresh() {
if (this.$syncing) {
return this.$syncing;
}
return this.$syncing = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
try {
const conn = this.$dc.pickConnection();
if (!conn) {
return this.$dc.errorNoConnection(resolve);
}
const data = yield conn.api.getManagedObjectData(this.iid);
if (data) {
yield this.updateFrom(data);
}
this.$syncing = null;
resolve(data !== null);
}
catch (e) {
this.$dc.ix.pushError(e);
resolve(null);
}
}));
}
}
Mo.Base = Base;
class Folder extends Mo.Base {
constructor($dc, init) {
super($dc, init, this2 => this2.$type = 'Folder');
this.childEntity = [];
$dc.inventory.folder[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.childEntity.length = 0;
if (init.childEntity) {
for (const iid of init.childEntity) {
findMo($dc, iid, Mo.Base, mo => this.childEntity.push(mo), proms);
}
}
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.folder[this.iid]; }
moFolderSerializable() {
return {
childEntity: this.childEntity,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moFolderSerializable()));
}
}
Mo.Folder = Folder;
class ComputeResource extends Mo.Base {
constructor($dc, init) {
super($dc, init, this2 => this2.$type = 'ComputeResource');
this.datastore = [];
this.datastoreSummary = [];
this.host = [];
this.network = [];
$dc.inventory.computeResource[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.host.length = 0;
this.datastore.length = 0;
this.datastoreSummary.length = 0;
this.network.length = 0;
if (init.host) {
for (const iid of init.host) {
findMo($dc, iid, Mo.HostSystem, mo => this.host.push(mo), proms);
}
}
if (init.datastore) {
for (const iid of init.datastore) {
findMo($dc, iid, Mo.Datastore, mo => {
this.datastoreSummary.push(mo.summary);
this.datastore.push(mo);
}, proms);
}
}
if (init.network) {
for (const iid of init.network) {
findMo($dc, iid, Mo.Network, mo => this.network.push(mo), proms);
}
}
this.configurationEx = init.configurationEx;
this.drsFault = init.drsFault;
this.drsRecommendation = init.drsRecommendation;
this.lifecycleManaged = init.lifecycleManaged;
this.migrationHistory = init.migrationHistory;
this.recommendation = init.recommendation;
this.summary = init.summary;
findMo($dc, init.resourcePool, Mo.ResourcePool, mo => this.resourcePool = mo, proms);
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.computeResource[this.iid]; }
moComputeResourceSerializable() {
return {
configurationEx: this.configurationEx,
datastore: this.datastore,
datastoreSummary: this.datastoreSummary,
drsFault: this.drsFault,
drsRecommendation: this.drsRecommendation,
host: this.host,
lifecycleManaged: this.lifecycleManaged,
migrationHistory: this.migrationHistory,
network: this.network,
recommendation: this.recommendation,
resourcePool: this.resourcePool,
summary: this.summary,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moComputeResourceSerializable()));
}
}
Mo.ComputeResource = ComputeResource;
class HostSystem extends Mo.Base {
constructor($dc, init) {
super($dc, init, this2 => this2.$type = 'HostSystem');
this.datastore = [];
this.datastoreSummary = [];
this.network = [];
this.vm = [];
$dc.inventory.hostSystem[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.datastore.length = 0;
this.datastoreSummary.length = 0;
this.network.length = 0;
this.vm.length = 0;
if (init.datastore) {
for (const iid of init.datastore) {
findMo($dc, iid, Mo.Datastore, mo => {
this.datastoreSummary.push(mo.summary);
this.datastore.push(mo);
}, proms);
}
}
if (init.network) {
for (const iid of init.network) {
findMo($dc, iid, Mo.Network, mo => this.network.push(mo), proms);
}
}
if (init.vm) {
for (const iid of init.vm) {
findMo($dc, iid, Mo.VirtualMachine, mo => this.vm.push(mo), proms);
}
}
this.capability = init.capability;
this.config = init.config;
this.configManager = init.configManager;
this.hardware = init.hardware;
this.licensableResource = init.licensableResource;
this.overallStatus = init.overallStatus;
this.runtime = init.runtime;
this.summary = init.summary;
this.systemResources = init.systemResources;
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.hostSystem[this.iid]; }
moHostSystemSerializable() {
return {
capability: this.capability,
config: this.config,
configManager: this.configManager,
datastore: this.datastore,
datastoreSummary: this.datastoreSummary,
hardware: this.hardware,
licensableResource: this.licensableResource,
network: this.network,
overallStatus: this.overallStatus,
runtime: this.runtime,
summary: this.summary,
systemResources: this.systemResources,
vm: this.vm,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moHostSystemSerializable()));
}
}
Mo.HostSystem = HostSystem;
class Datacenter extends Mo.Base {
constructor($dc, init) {
super($dc, init, this2 => this2.$type = 'Datacenter');
this.datastore = [];
this.network = [];
$dc.inventory.datacenter[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.datastore.length = 0;
this.network.length = 0;
if (init.datastore) {
for (const iid of init.datastore) {
findMo($dc, iid, Mo.Datastore, mo => this.datastore.push(mo), proms);
}
}
if (init.network) {
for (const iid of init.network) {
findMo($dc, iid, Mo.Network, mo => this.network.push(mo), proms);
}
}
findMo($dc, init.datastoreFolder, Mo.Folder, mo => this.datastoreFolder = mo, proms);
findMo($dc, init.hostFolder, Mo.Folder, mo => this.hostFolder = mo, proms);
findMo($dc, init.networkFolder, Mo.Folder, mo => this.networkFolder = mo, proms);
findMo($dc, init.vmFolder, Mo.Folder, mo => this.vmFolder = mo, proms);
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.datacenter[this.iid]; }
moDatacenterSerializable() {
return {
datastore: this.datastore,
datastoreFolder: this.datastoreFolder,
hostFolder: this.hostFolder,
network: this.network,
networkFolder: this.networkFolder,
vmFolder: this.vmFolder,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moDatacenterSerializable()));
}
}
Mo.Datacenter = Datacenter;
class Datastore extends Mo.Base {
constructor($dc, init) {
super($dc, init, this2 => this2.$type = 'Datastore');
this.aliases = [];
this.host = [];
this.vm = [];
$dc.inventory.datastore[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.host.length = 0;
this.vm.length = 0;
if (init.vm) {
for (const iid of init.vm) {
findMo($dc, iid, Mo.VirtualMachine, mo => this.vm.push(mo), proms);
}
}
this.host = init.host;
this.browser = init.browser;
this.capability = init.capability;
this.info = init.info;
this.iormConfiguration = init.iormConfiguration;
this.summary = init.summary;
this.summary.isAlias = (this.info.containerId !== this.info.aliasOf);
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.datastore[this.iid]; }
moDatastoreSerializable() {
return {
aliasOf: this.aliasOf,
aliases: this.aliases,
browser: this.browser,
capability: this.capability,
host: this.host,
info: this.info,
iormConfiguration: this.iormConfiguration,
summary: this.summary,
vm: this.vm,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moDatastoreSerializable()));
}
}
Mo.Datastore = Datastore;
class Network extends Mo.Base {
constructor($dc, init) {
super($dc, init, this2 => this2.$type = 'Network');
this.capability = {};
this.host = [];
this.vm = [];
$dc.inventory.network[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.host.length = 0;
this.vm.length = 0;
if (init.host) {
for (const iid of init.host) {
findMo($dc, iid, Mo.HostSystem, mo => this.host.push(mo), proms);
}
}
if (init.vm) {
for (const iid of init.vm) {
findMo($dc, iid, Mo.VirtualMachine, mo => this.vm.push(mo), proms);
}
}
this.capability = init.capability;
this.extraConfig = init.extraConfig;
this.summary = init.summary;
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.network[this.iid]; }
moNetworkSerializable() {
return {
capability: this.capability,
extraConfig: this.extraConfig,
host: this.host,
summary: this.summary,
vm: this.vm,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moNetworkSerializable()));
}
}
Mo.Network = Network;
class ResourcePool extends Mo.Base {
constructor($dc, init, preinit) {
super($dc, init, preinit ? preinit : this2 => this2.$type = 'ResourcePool');
this.childConfiguration = [];
this.resourcePool = [];
this.vm = [];
$dc.inventory.resourcePool[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
try {
const $dc = this.$dc;
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.resourcePool.length = 0;
this.vm.length = 0;
if (init.resourcePool) {
for (const iid of init.resourcePool) {
findMo($dc, iid, Mo.ResourcePool, mo => { mo.parent = this; this.resourcePool.push(mo); }, proms);
}
}
if (init.vm) {
for (const iid of init.vm) {
findMo($dc, iid, Mo.VirtualMachine, mo => this.vm.push(mo), proms);
}
}
this.childConfiguration = init.childConfiguration;
this.config = init.config;
this.runtime = init.runtime;
this.summary = init.summary;
findMo($dc, init.owner, Mo.ComputeResource, mo => this.owner = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.resourcePool[this.iid]; }
moResourcePoolSerializable() {
return {
childConfiguration: this.childConfiguration,
config: this.config,
owner: this.owner,
resourcePool: this.resourcePool,
runtime: this.runtime,
summary: this.summary,
vm: this.vm,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moResourcePoolSerializable()));
}
}
Mo.ResourcePool = ResourcePool;
class VirtualApp extends Mo.ResourcePool {
constructor($dc, init) {
super($dc, init, this2 => this2.$type = 'VirtualApp');
this.datastore = [];
this.network = [];
this.resourcePool = [];
this.vm = [];
$dc.inventory.virtualApp[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.datastore.length = 0;
this.network.length = 0;
this.resourcePool.length = 0;
this.vm.length = 0;
if (init.datastore) {
for (const iid of init.datastore) {
findMo($dc, iid, Mo.Datastore, mo => this.datastore.push(mo), proms);
}
}
if (init.network) {
for (const iid of init.network) {
findMo($dc, iid, Mo.Network, mo => this.network.push(mo), proms);
}
}
if (init.resourcePool) {
for (const iid of init.resourcePool) {
findMo($dc, iid, Mo.ResourcePool, mo => { mo.parent = this; this.resourcePool.push(mo); }, proms);
}
}
if (init.vm) {
for (const iid of init.vm) {
findMo($dc, iid, Mo.VirtualMachine, mo => this.vm.push(mo), proms);
}
}
this.childConfiguration = init.childConfiguration;
this.config = init.config;
this.runtime = init.runtime;
this.summary = init.summary;
this.vAppConfig = init.vAppConfig;
findMo($dc, init.parentFolder, Mo.Folder, mo => this.parentFolder = mo, proms);
findMo($dc, init.parentVApp, Mo.VirtualApp, mo => this.parentVApp = mo, proms);
findMo($dc, init.owner, Mo.ComputeResource, mo => this.owner = mo, proms);
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.virtualApp[this.iid]; }
moVirtualAppSerializable() {
return {
childConfiguration: this.childConfiguration,
config: this.config,
datastore: this.datastore,
network: this.network,
owner: this.owner,
parentFolder: this.parentFolder,
parentVApp: this.parentVApp,
resourcePool: this.resourcePool,
runtime: this.runtime,
summary: this.summary,
vAppConfig: this.vAppConfig,
vm: this.vm,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moVirtualAppSerializable()));
}
}
Mo.VirtualApp = VirtualApp;
class VirtualMachine extends Mo.Base {
constructor($dc, init) {
super($dc, init, this2 => {
this2.$registeredIP = null;
this2.$type = 'VirtualMachine';
});
this.datastore = [];
this.network = [];
$dc.inventory.virtualMachine[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.datastore.length = 0;
this.network.length = 0;
if (init.datastore) {
for (const iid of init.datastore) {
findMo($dc, iid, Mo.Datastore, mo => this.datastore.push(mo), proms);
}
}
if (init.network) {
for (const iid of init.network) {
findMo($dc, iid, Mo.Network, mo => this.network.push(mo), proms);
}
}
this.linkIP(init);
this.capability = init.capability;
this.config = init.config;
this.guest = init.guest;
this.guestHeartbeatStatus = init.guestHeartbeatStatus;
this.layout = init.layout;
this.resourceConfig = init.resourceConfig;
this.runtime = init.runtime;
this.storage = init.storage;
this.summary = init.summary;
findMo($dc, init.resourcePool, Mo.ResourcePool, mo => this.resourcePool = mo, proms);
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() {
delete this.$dc.inventory.virtualMachine[this.iid];
this.unlinkIP();
}
linkIP(init) {
var _a;
if (this.$registeredIP) {
this.unlinkIP();
}
if ((_a = init.guest) === null || _a === void 0 ? void 0 : _a.ipAddress) {
const ip = init.guest.ipAddress;
if (!this.$dc.index.byIP[ip]) {
this.$dc.index.byIP[ip] = [];
}
this.$dc.index.byIP[ip].push(this.iid);
this.$registeredIP = ip;
}
}
unlinkIP() {
if (this.$registeredIP) {
const ipReg = this.$dc.index.byIP[this.$registeredIP];
if (ipReg) {
const ipIdx = ipReg.indexOf(this.iid);
if (ipIdx >= 0) {
ipReg.splice(ipIdx, 1);
}
if (ipReg.length === 0) {
delete this.$dc.index.byIP[this.$registeredIP];
}
}
}
}
moVirtualMachineSerializable() {
return {
$registeredIP: this.$registeredIP,
capability: this.capability,
config: this.config,
datastore: this.datastore,
guest: this.guest,
guestHeartbeatStatus: this.guestHeartbeatStatus,
layout: this.layout,
network: this.network,
resourceConfig: this.resourceConfig,
resourcePool: this.resourcePool,
runtime: this.runtime,
storage: this.storage,
summary: this.summary,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moVirtualMachineSerializable()));
}
}
Mo.VirtualMachine = VirtualMachine;
class VirtualSwitch extends Mo.Base {
constructor($dc, init) {
super($dc, init, this2 => this2.$type = 'VirtualSwitch');
this.permission = [];
this.portgroup = [];
$dc.inventory.virtualSwitch[this.iid] = this;
this.updateFrom(init);
}
updateFromExtended(init) {
return __awaiter(this, void 0, void 0, function* () {
return this.$initPending = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
const $dc = this.$dc;
try {
yield Promise.resolve($dc.inventoryStubPending);
const proms = [];
this.portgroup.length = 0;
if (init.portgroup) {
for (const iid of init.portgroup) {
findMo($dc, iid, Mo.Network, mo => this.portgroup.push(mo), proms);
}
}
this.capability = init.capability;
this.config = init.config;
this.configStatus = init.configStatus;
this.permission = init.permission;
this.runtime = init.runtime;
this.summary = init.summary;
this.uuid = init.uuid;
findMo($dc, init.parent, Mo.Base, mo => this.parent = mo, proms);
yield ts_basis_1.PromUtil.allSettled(proms);
}
catch (e) {
this.$dc.debugOutput(e);
}
this.$initPending = false;
resolve(false);
}));
});
}
unregisterExtended() { delete this.$dc.inventory.virtualSwitch[this.iid]; }
moVirtualSwitchSerializable() {
return {
capability: this.capability,
config: this.config,
configStatus: this.configStatus,
permission: this.permission,
portgroup: this.portgroup,
runtime: this.runtime,
summary: this.summary,
uuid: this.uuid,
};
}
serialize() {
return JSON.stringify(Object.assign(Object.assign({}, this.moBaseSerializable()), this.moVirtualSwitchSerializable()));
}
}
Mo.VirtualSwitch = VirtualSwitch;
})(Mo || (exports.Mo = Mo = {}));
function getMoTypeByName(moTypeName) {
switch (moTypeName) {
case 'Base': return Mo.Base;
case 'Folder': return Mo.Folder;
case 'HostSystem': return Mo.HostSystem;
case 'Datacenter': return Mo.Datacenter;
case 'Network': return Mo.Network;
case 'Datastore': return Mo.Datastore;
case 'ComputeResource': return Mo.ComputeResource;
case 'ResourcePool': return Mo.ResourcePool;
case 'VirtualApp': return Mo.VirtualApp;
case 'VirtualMachine': return Mo.VirtualMachine;
case 'DistributedVirtualPortgroup': return Mo.Network;
case 'VirtualSwitch':
case 'DistributedVirtualSwitch':
case 'VmwareDistributedVirtualSwitch':
return Mo.VirtualSwitch;
default:
console.log(`Unknown managed object type ${moTypeName}`);
break;
}
return null;
}
exports.getMoTypeByName = getMoTypeByName;
function iidParse(iid) {
if (iid.startsWith('$mo:')) {
return iid;
}
else {
const valueLit = iid.split('-');
const valueType = valueLit[0];
const valueSubtype = valueLit[1];
switch (valueType) {
case 'group': return `$mo:Folder:${iid}`;
case 'datacenter': return `$mo:Datacenter:${iid}`;
case 'network':
case 'dvportgroup':
return `$mo:Network:${iid}`;
case 'datastore': return `$mo:Datastore:${iid}`;
case 'domain': return `$mo:ComputeResource:${iid}`;
case 'resgroup':
if (valueSubtype.startsWith('v')) {
return `$mo:VirtualApp:${iid}`;
}
else {
return `$mo:ResourcePool:${iid}`;
}
case 'host': return `$mo:HostSystem:${iid}`;
case 'vm': return `$mo:VirtualMachine:${iid}`;
case 'dvs': return `$mo:VirtualSwitch:${iid}`;
default:
console.log(`Unknown mo value ${iid}`);
return null;
}
}
}
exports.iidParse = iidParse;
function findMo($dc, iid, typeClass, onresolve, proms) {
const prom = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
let mo = $dc.inventory.byIID[iid];
if (!mo && iid) {
$dc.debugKeep(`${iid} not found during linkage; fetching...`);
mo = yield $dc.get(iid, typeClass);
$dc.debugKeep(`${iid} fetched`);
}
if (onresolve) {
onresolve(mo);
}
return resolve(mo);
}));
if (proms) {
proms.push(prom);
}
return prom;
}
exports.findMo = findMo;
//# sourceMappingURL=managed.objects.js.map