VMware Cloud Community
randomname
Enthusiast
Enthusiast

SOAP connection to vCenter extensions

I'm trying to fiddle with Image Builder service and need to make a SOAP connection to it, yet I cannot seem to figure out the correct SOAP envelope, or even the values for a simple WebRequest object. There doesn't seem to be a WSDL anywhere that I can find. I know it's possible to do because there is a fling using the Python SDK which does it. I've gone through its code and the Python SDK, but I'm not Python literate to figure out the end result of what the SDK's stub adapter function is assembling for its request.

Short of running the fling and WireSharking it, which I'll probably try soon, I was wondering if anyone (LucD?) has any basic sample PowerShell code for the initial web request?

0 Kudos
3 Replies
LucD
Leadership
Leadership

Which Fling are you referring to?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
randomname
Enthusiast
Enthusiast

LucD,

The Host Profiles CLI fling contains Python code in hpcli_commands, at line 324 for example, which calls a function named SoapStubAdapter from the pyVmomi library SoapAdapter.py. This appears to me to be what's constructing the SOAP envelope used for connections. The function is used throughout the code for SOAP connectivity to both Image Builder and Auto Deploy services.

0 Kudos
randomname
Enthusiast
Enthusiast

LucD,

Never mind. I've made some progress. The imagebuilder log file on the VCSA is logging the SOAP envelopes generated by the fling during its requests. Without API documentation covering all available methods and properties, I'll only be able to do things similar to the fling, but I should be able to do them all in my own PowerShell, which is highly preferred to the Python packaging of the fling. Couple examples below.

Finding the service instance:

$uri = "https://<vcFQDN>:443/vmw/imagebuilder/vmomi"

$webRequest = [System.Net.WebRequest]::Create($uri)

$webRequest.Method = "POST"

$webRequest.Headers.Add("vc-session-id","<vcSessionSecret>")

$webRequest.Headers.Add("SOAPAction","urn:imagebuilder/1.0")

$webRequest.ContentType = "text/xml;charset=utf-8"

$webRequest.Accept = "text/xml"

$requestStream = $webRequest.GetRequestStream()

$body = [xml]@'

<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <soapenv:Body>

        <Fetch xmlns="urn:imagebuilder">

            <_this type="ImageBuilderServiceInstance">ServiceInstance</_this>

            <prop>depotManager</prop>

        </Fetch>

    </soapenv:Body>

</soapenv:Envelope>

'@

$body.Save($requestStream)

$requestStream.Close()

$response = $webRequest.GetResponse()

$responseStream = $response.GetResponseStream()

$soapReader = [System.IO.StreamReader]($responseStream)

$returnXml = [xml]$soapReader.ReadToEnd()

$responseStream.Close()

SOAP envelope for getting all image profiles, which references the service instance (DepotManager) returned from above.

$body = [xml]@'

<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <soapenv:Body>

        <QueryDepotManagerProfiles xmlns="urn:imagebuilder">

            <_this type="DepotManager">DepotManager</_this>

        </QueryDepotManagerProfiles>

    </soapenv:Body>

</soapenv:Envelope>

'@

0 Kudos