Ejemplo n.º 1
0
def get_driver(username, password):
    OpenStack = libcloud_get_driver(Provider.OPENSTACK)
    return OpenStack(
        key=username,
        secret=password,
        ex_tenant_name='LSST',
        ex_force_auth_url='http://nebula.ncsa.illinois.edu:5000/v2.0/tokens/',
        ex_force_auth_version='2.0_password')    
Ejemplo n.º 2
0
    def get_driver(self, auth_data, datacenter=None):
        """
        Get the compute driver from the auth data

        Arguments:
            - auth(Authentication): parsed authentication tokens.
            - datacenter(str): datacenter to connect.

        Returns: a :py:class:`libcloud.compute.base.NodeDriver` or None in case of error
        """
        auths = auth_data.getAuthInfo(self.type)
        if not auths:
            raise Exception("No auth data has been specified to GCE.")
        else:
            auth = auths[0]

        if self.driver and self.auth.compare(
                auth_data, self.type) and self.datacenter == datacenter:
            return self.driver
        else:
            self.auth = auth_data
            self.datacenter = datacenter

            if 'username' in auth and 'password' in auth and 'project' in auth:
                cls = libcloud_get_driver(Provider.GCE)
                # Patch to solve some client problems with \\n
                auth['password'] = auth['password'].replace('\\n', '\n')
                lines = len(auth['password'].replace(" ", "").split())
                if lines < 2:
                    raise Exception(
                        "The certificate provided to the GCE plugin has an incorrect format."
                        " Check that it has more than one line.")

                driver = cls(auth['username'],
                             auth['password'],
                             project=auth['project'],
                             datacenter=datacenter)

                self.driver = driver
                return driver
            else:
                self.log_error(
                    "No correct auth data has been specified to GCE: username, password and project"
                )
                self.log_debug(auth)
                raise Exception(
                    "No correct auth data has been specified to GCE: username, password and project"
                )
Ejemplo n.º 3
0
 def _driver(self):
     provider = self['provider']
     DriverClass = libcloud_get_driver(getattr(Provider, provider.upper()))
     credentials = [self['user']]
     if issubclass(DriverClass.connectionCls, ConnectionUserAndKey):
         credentials.append(self['secret'])
     if issubclass(DriverClass, ec2.EC2NodeDriver):
         # Respect AWS environment variables
         user_key, secret_key = ("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY")
         if all (k in os.environ for k in (user_key, secret_key)):
             credentials = os.environ[user_key], os.environ[secret_key]
     try:
         driver = DriverClass(*credentials)
     except TypeError, e:
         raise ConfigError, 'API Access credentials for %s provider ' \
                            'are missing or wrong' % self['provider']