Пример #1
0
 def __init__(self,
              version=newestVersions.get('vim'),
              printRequest=False,
              printResponse=False):
     SoapAdapter.SoapStubAdapter.__init__(self, version=version)
     self.ns = VmomiSupport.GetVersionNamespace(version)
     self.soapHandler = SoapHandler.SoapHandler()
     self.soapDeserializer = SoapAdapter.SoapResponseDeserializer(self)
     self.printRequest = printRequest
     self.printResponse = printResponse
     ImportTypesAndManagedObjects()
Пример #2
0
    def InvokeMethod(self, mo, info, args):
        req = self.SerializeRequest(mo, info, args)
        scgireq = ScgiRequest(
            {
                'REQUEST_METHOD': 'POST',
                'HTTP_SOAPACTION': self.versionId[1:-1]
            },
            message=req)
        scgireq.Write(self.p.stdin)
        self.p.stdin.flush()

        try:
            outText = ReadNetString(self.p.stdout)
        except Scgi_EOF:
            errText = "Unexpected EOF reading from process, maybe process died"
            raise self.systemError(msg=errText, reason=errText)
        except Exception as e:
            errText = "Error parsing output from SCGI process: %s" % (e)
            raise self.systemError(msg=errText, reason=errText)

        (responseHeaders,
         responseBody) = SoapAdapter.ParseHttpResponse(outText)

        # Parse status code from response headers [Status: 200 OK]
        error = False
        obj = None
        statusmatch = re.search(r'Status:\s+(\d+)\s+(.+)', responseHeaders)
        if not statusmatch:
            errText = "Could not find SOAP status in SOAP headers (%s)" % (
                responseHeaders)
            raise self.systemError(msg=errText, reason=errText)
        elif statusmatch.group(1) != '200':
            errText = statusmatch.group(2).rstrip()
            error = True

        # SoapResponseDeserializer can only handle XML
        if 'text/xml' in responseHeaders:
            try:
                obj = SoapAdapter.SoapResponseDeserializer(self).Deserialize(
                    responseBody, info.result)
            except:
                errText = "Failure parsing SOAP response (%s)" % (outText)
                raise self.systemError(msg=errText, reason=errText)

        if not error:
            return obj
        elif obj is None:
            raise self.systemError(msg=errText, reason=responseBody)
        else:
            raise obj
Пример #3
0
 def setUp(self):
    self.version = newestVersions.get('vim')
    self.versionUri = VmomiSupport.GetVersionNamespace(self.version)
    self.futureVersionUri = "vim25/foo"
    self.badVersionUri = "notvim/foo"
    self.stub = SoapAdapter.SoapStubAdapter(version=self.version)
    self.deserializer = SoapAdapter.SoapResponseDeserializer(self.stub)
    self.soapHeaderBegin = \
       """<?xml version="1.0" encoding="UTF-8"?>
          <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>"""
    self.soapHeaderEnd = \
       """</soapenv:Body>
          </soapenv:Envelope>"""
    ImportTypesAndManagedObjects()