Initial
This commit is contained in:
@@ -784,6 +784,35 @@ function soapRefElement(name, ref, fallbackType) {
|
||||
return `<${name} type="${xmlEscape(ref?.type || fallbackType)}">${xmlEscape(ref?.value || '')}</${name}>`;
|
||||
}
|
||||
|
||||
function soapBoolElement(name, value) {
|
||||
return `<${name}>${value ? 'true' : 'false'}</${name}>`;
|
||||
}
|
||||
|
||||
function propertySpecXml(type, paths = []) {
|
||||
return `<propSet>` +
|
||||
`<type>${xmlEscape(type)}</type>` +
|
||||
soapBoolElement('all', false) +
|
||||
paths.map((pathSet) => `<pathSet>${xmlEscape(pathSet)}</pathSet>`).join('') +
|
||||
`</propSet>`;
|
||||
}
|
||||
|
||||
function objectSpecXml(ref, { skip = false, selectSet = '' } = {}) {
|
||||
return `<objectSet>` +
|
||||
soapRefElement('obj', ref, ref?.type || 'ManagedObjectReference') +
|
||||
soapBoolElement('skip', skip) +
|
||||
selectSet +
|
||||
`</objectSet>`;
|
||||
}
|
||||
|
||||
function traversalSpecXml() {
|
||||
return `<selectSet xsi:type="TraversalSpec">` +
|
||||
`<name>containerViewTraversal</name>` +
|
||||
`<type>ContainerView</type>` +
|
||||
`<path>view</path>` +
|
||||
soapBoolElement('skip', false) +
|
||||
`</selectSet>`;
|
||||
}
|
||||
|
||||
async function connectStandaloneSoap(settings, trace = null) {
|
||||
pushTraceInfo(trace, `Using ${WEB_SERVICES_PROFILE_LABEL}`, {
|
||||
mode: 'web-services',
|
||||
@@ -826,7 +855,7 @@ async function createVmContainerView(settings, refs, trace = null) {
|
||||
return extractManagedObject(response, 'returnval', 'ContainerView');
|
||||
}
|
||||
|
||||
function retrievePropertiesBody(propertyCollector, viewRef, limit = 100) {
|
||||
export function retrievePropertiesBody(propertyCollector, viewRef, limit = 100) {
|
||||
const paths = [
|
||||
'name',
|
||||
'guest.hostName',
|
||||
@@ -841,12 +870,10 @@ function retrievePropertiesBody(propertyCollector, viewRef, limit = 100) {
|
||||
'summary.runtime.powerState'
|
||||
];
|
||||
return `<RetrievePropertiesEx xmlns="urn:vim25" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">` +
|
||||
`${soapRefElement('_this', propertyCollector, 'PropertyCollector')}` +
|
||||
soapRefElement('_this', propertyCollector, 'PropertyCollector') +
|
||||
`<specSet>` +
|
||||
`<propSet><type>VirtualMachine</type><all>false</all>${paths.map((pathSet) => `<pathSet>${pathSet}</pathSet>`).join('')}</propSet>` +
|
||||
`<objectSet>${soapRefElement('obj', viewRef, 'ContainerView')}<skip>true</skip>` +
|
||||
`<selectSet xsi:type="TraversalSpec"><name>containerViewTraversal</name><type>ContainerView</type><path>view</path><skip>false</skip></selectSet>` +
|
||||
`</objectSet>` +
|
||||
propertySpecXml('VirtualMachine', paths) +
|
||||
objectSpecXml(viewRef, { skip: true, selectSet: traversalSpecXml() }) +
|
||||
`</specSet>` +
|
||||
`<options><maxObjects>${Math.max(1, Math.min(Number(limit) || 100, 500))}</maxObjects></options>` +
|
||||
`</RetrievePropertiesEx>`;
|
||||
@@ -888,9 +915,11 @@ async function retrieveStandaloneVmPowerState(settings, vmId, trace = null) {
|
||||
const refs = await connectStandaloneSoap(settings, trace);
|
||||
const vmRef = { type: 'VirtualMachine', value: vmId };
|
||||
const body = `<RetrievePropertiesEx xmlns="urn:vim25" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">` +
|
||||
`${soapRefElement('_this', refs.propertyCollector, 'PropertyCollector')}` +
|
||||
`<specSet><propSet><type>VirtualMachine</type><all>false><pathSet>runtime.powerState</pathSet></propSet>` +
|
||||
`<objectSet>${soapRefElement('obj', vmRef, 'VirtualMachine')}<skip>false</skip></objectSet></specSet>` +
|
||||
soapRefElement('_this', refs.propertyCollector, 'PropertyCollector') +
|
||||
`<specSet>` +
|
||||
propertySpecXml('VirtualMachine', ['runtime.powerState']) +
|
||||
objectSpecXml(vmRef, { skip: false }) +
|
||||
`</specSet>` +
|
||||
`<options><maxObjects>1</maxObjects></options></RetrievePropertiesEx>`;
|
||||
const response = await vSphereSoapFetch(settings, 'RetrievePropertiesEx', body, trace, { cookie: refs.sessionCookie, endpoint: refs.endpoint });
|
||||
const object = parseVmPropertyObjects(response)[0];
|
||||
|
||||
Reference in New Issue
Block a user