Exemple #1
0
 def updated(self, properties, prev, next):
     if isinstance(prev, Transport):
         tp = Unskin(prev.options)
         properties.unlink(tp)
     if isinstance(next, Transport):
         tp = Unskin(next.options)
         properties.link(tp)
Exemple #2
0
    def clone(self):
        """
        Get a shallow clone of this object.

        The clone only shares the WSDL. All other attributes are unique to the
        cloned object including options.

        @return: A shallow clone.
        @rtype: L{Client}

        """
        class Uninitialized(Client):
            def __init__(self):
                pass

        clone = Uninitialized()
        clone.options = Options()
        cp = Unskin(clone.options)
        mp = Unskin(self.options)
        cp.update(deepcopy(mp))
        clone.wsdl = self.wsdl
        clone.factory = self.factory
        clone.service = ServiceSelector(clone, self.wsdl.services)
        clone.sd = self.sd
        return clone
Exemple #3
0
    def __init__(self, **kwargs):
        """
        @param kwargs: Keyword arguments.
            - B{proxy} - An http proxy to be specified on requests.
                 The proxy is defined as {protocol:proxy,}
                    - type: I{dict}
                    - default: {}
            - B{timeout} - Set the url open timeout (seconds).
                    - type: I{float}
                    - default: 90
        """
        Transport.__init__(self)

        # Add options to the default set of options in case they do not exist
        Unskin(self.options).definitions['compression'] = Definition(
            'compression', basestring, 'yes')
        Unskin(self.options).definitions['compmethods'] = Definition(
            'compmethods', list, ['gzip', 'deflate', 'bzip2'])
        # Force the new options to take the default value supplied
        Unskin(self.options).prime()

        Unskin(self.options).update(kwargs)
        self.cookiejar = CookieJar()
        self.proxy = dict()
        self.urlopener = None
Exemple #4
0
 def set_options(self, **kwargs):
     """
     Set options.
     @param kwargs: keyword arguments.
     @see: L{Options}
     """
     p = Unskin(self.options)
     p.update(kwargs)
Exemple #5
0
 def set_options(self, **kwargs):
     """
     Set options.
     @param kwargs: keyword arguments.
     @see: L{Options}
     """
     p = Unskin(self.options)
     p.update(kwargs)
    def _getHttpsPolicy(self):
        """
        Helper method that lazily constructs the HTTPS options to use for this
        transport.
        """
        if self._httpsPolicy is not None:
            return self._httpsPolicy

        # Attempt to load the certificate and private key from a file.
        certificate = None
        if self.options.certificate:
            cert_data = self.options.certificate
            if os.path.isfile(cert_data):
                with open(cert_data, "rb") as cert_file:
                    cert_data = cert_file.read()
            certificate = crypto.load_certificate(crypto.FILETYPE_PEM, cert_data)
        priv_key = None
        if self.options.privateKey:
            key_data = self.options.privateKey
            if os.path.isfile(key_data):
                with open(key_data, "rb") as key_file:
                    key_data = key_file.read()
            priv_key = crypto.load_privatekey(crypto.FILETYPE_PEM, key_data)

        # Get the rest of the options for the context factory.
        other_opts = {}
        props = Unskin(self.options)
        for opt_name in ['method', 'verify', 'caCerts', 'verifyDepth', 'trustRoot',
                         'requireCertificate', 'verifyOnce', 'enableSingleUseKeys',
                         'enableSessions', 'fixBrokenPeers', 'enableSessionTickets',
                         'acceptableCiphers']:
            val = getattr(self.options, opt_name)

            # Only pass values that have been specified because OpenSSLCertificateOptions
            # uses _mutuallyExclusiveArguments.
            if val != props.definition(opt_name).default:
                other_opts[opt_name] = val

        self._httpsPolicy = PolicyForHTTPS(privateKey = priv_key,
                                           certificate = certificate,
                                           **other_opts)
        return self._httpsPolicy
Exemple #7
0
 def clone(self):
     """
     Get a shallow clone of this object.
     The clone only shares the WSDL.  All other attributes are
     unique to the cloned object including options.
     @return: A shallow clone.
     @rtype: L{Client}
     """
     class Uninitialized(Client):
         def __init__(self):
             pass
     clone = Uninitialized()
     clone.options = Options()
     cp = Unskin(clone.options)
     mp = Unskin(self.options)
     cp.update(deepcopy(mp))
     clone.wsdl = self.wsdl
     clone.factory = self.factory
     clone.service = ServiceSelector(clone, self.wsdl.services)
     clone.sd = self.sd
     clone.messages = dict(tx=None, rx=None)
     return clone
Exemple #8
0
 def __init__(self, **kwargs):
     """
     @param kwargs: Keyword arguments.
         - B{proxy} - An http proxy to be specified on requests.
              The proxy is defined as {protocol:proxy,}
                 - type: I{dict}
                 - default: {}
         - B{timeout} - Set the url open timeout (seconds).
                 - type: I{float}
                 - default: 90
     """
     Transport.__init__(self)
     Unskin(self.options).update(kwargs)
     self.cookiejar = CookieJar()
     self.proxy = {}
     self.urlopener = None
Exemple #9
0
 def __deepcopy__(self, memo={}):
     clone = self.__class__()
     p = Unskin(self.options)
     cp = Unskin(clone.options)
     cp.update(p)
     return clone
Exemple #10
0
 def __deepcopy__(self, memo={}):
     clone = self.__class__()
     p = Unskin(self.options)
     cp = Unskin(clone.options)
     cp.update(p)
     return clone
Exemple #11
0
 def __init__(self, server=None, username=None, password=None,
              wsdl_location="local", timeout=30, init_clone=False, clone=None):
     #self._init_logging()
     self._logged_in = False
     if server is None:
         server = _config_value("general", "server")
     if username is None:
         username = _config_value("general", "username")
     if password is None:
         password = _config_value("general", "password")
     if server is None:
         raise ConfigError("server must be set in config file or Client()")
     if username is None:
         raise ConfigError("username must be set in config file or Client()")
     if password is None:
         raise ConfigError("password must be set in config file or Client()")
     self.server = server
     self.username = username
     self.password = password
     url = "https://%s/sdk" % self.server
     if wsdl_location == "local":
         current_path = os.path.abspath(os.path.dirname(__file__))            
         current_path = current_path.replace('\\', '/')
         if not current_path.startswith('/') :
             current_path = '/' + current_path
         if current_path.endswith('/') :
             current_path = current_path[:-1]
         wsdl_uri = ("file://%s/wsdl/vimService.wsdl" % current_path)
     elif wsdl_location == "remote":
         wsdl_uri = url + "/vimService.wsdl"
     else:
         print("FATAL: wsdl_location must be \"local\" or \"remote\"")
         sys.exit(1)
     # Init the base class
     if clone:
         self.sd=clone.sd
         self.options = Options()
         cp = Unskin(self.options)
         mp = Unskin(clone.options)
         cp.update(deepcopy(mp))
         self.wsdl = clone.wsdl
         self.factory = clone.factory
         self.service = ServiceSelector(self, clone.wsdl.services)
         self.messages = dict(tx=None, rx=None)
     else:
         try:
             suds.client.Client.__init__(self, wsdl_uri)
         except URLError:
             logger.critical("Failed to connect to %s" % self.server)
             raise
         except IOError:
             logger.critical("Failed to load the local WSDL from %s" % wsdl_uri)
             raise
         except TransportError:
             logger.critical("Failed to load the remote WSDL from %s" % wsdl_uri)
             raise
     if init_clone:
         return
     self.options.transport.options.timeout = timeout
     self.set_options(location=url)
     mo_ref = soap.ManagedObjectReference("ServiceInstance",
                                          "ServiceInstance")
     self.si = ServiceInstance(mo_ref, self) 
     try:
         self.sc = self.si.RetrieveServiceContent()
     except URLError, e:
         #print("Failed to connect to %s" % self.server)
         #print("urllib2 said: %s" % e.reason) 
         #sys.exit(1)
         raise
Exemple #12
0
 def __location(self):
     """Returns the SOAP request's target location URL."""
     return Unskin(self.options).get("location", self.method.location)
Exemple #13
0
 def location(self):
     p = Unskin(self.options)
     return p.get('location', self.method.location)
Exemple #14
0
 def location(self):
     p = Unskin(self.options)
     return p.get('location', self.method.location.decode('utf-8'))
Exemple #15
0
 def location(self):
     p = Unskin(self.options)
     return p.get('location', self.method.location)
 def __init__(self, session=None, **kwargs):
     Transport.__init__(self)
     Unskin(self.options).update(kwargs)
     self.session = session or Session()
     # Suds expects support for local files URIs.
     self.session.mount('file://', FileAdapter())