/usr/share/pyshared/psphere/soap.py is in python-psphere 0.5.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | """
A leaky wrapper for the underlying suds library.
"""
# Copyright 2010 Jonathan Kinred
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import urllib2
import suds
from pprint import pprint
logger = logging.getLogger(__name__)
class VimFault(Exception):
def __init__(self, fault):
self.fault = fault
self.fault_type = fault.__class__.__name__
self._fault_dict = {}
for attr in fault:
self._fault_dict[attr[0]] = attr[1]
Exception.__init__(self, "%s: %s" % (self.fault_type, self._fault_dict))
def get_client(url):
client = suds.client.Client(url + "/vimService.wsdl")
client.set_options(location=url)
return client
def create(client, _type, **kwargs):
"""Create a suds object of the requested _type."""
obj = client.factory.create("ns0:%s" % _type)
for key, value in kwargs.items():
setattr(obj, key, value)
return obj
def invoke(client, method, **kwargs):
"""Invoke a method on the underlying soap service."""
try:
# Proxy the method to the suds service
result = getattr(client.service, method)(**kwargs)
except AttributeError, e:
logger.critical("Unknown method: %s", method)
raise
except urllib2.URLError, e:
logger.debug(pprint(e))
logger.debug("A URL related error occurred while invoking the '%s' "
"method on the VIM server, this can be caused by "
"name resolution or connection problems.", method)
logger.debug("The underlying error is: %s", e.reason[1])
raise
except suds.client.TransportError, e:
logger.debug(pprint(e))
logger.debug("TransportError: %s", e)
except suds.WebFault, e:
# Get the type of fault
logger.critical("SUDS Fault: %s" % e.fault.faultstring)
if len(e.fault.faultstring) > 0:
raise
detail = e.document.childAtPath("/Envelope/Body/Fault/detail")
fault_type = detail.getChildren()[0].name
fault = create(fault_type)
if isinstance(e.fault.detail[0], list):
for attr in e.fault.detail[0]:
setattr(fault, attr[0], attr[1])
else:
fault["text"] = e.fault.detail[0]
raise VimFault(fault)
return result
class ManagedObjectReference(suds.sudsobject.Property):
"""Custom class to replace the suds generated class, which lacks _type."""
def __init__(self, _type, value):
suds.sudsobject.Property.__init__(self, value)
self._type = _type
|