Exemplo n.º 1
0
def api_conn(args):
    """Authenticates a user with the Cloud System .

    :param args:

    If authentication is successful, then the system will allow the user
    to deploy through the application to the types.Provider.
    """

    security.CA_CERTS_PATH.append('dist/cacert.pem')

    user_key, key_type = cloud_keys(args)
    _provider = args.get('provider', 'dummy')

    if _provider in providers.DRIVERS:
        driver = providers.get_driver(args.get('provider'))
    else:
        raise ions.SystemError('No Provider Type Found.')

    try:
        if _provider.upper() in ['RACKSPACE', 'OPENSTACK']:
            region = args.get('region', 'RegionOne').lower()

            if key_type is 'api_key':
                auth_type = '2.0_apikey'
            else:
                auth_type = '2.0_password'

            specs = {'ex_force_auth_url': args.get('authurl'),
                     'ex_force_auth_version': auth_type,
                     'ex_tenant_name': args.get('tenant')}

            if _provider.upper() == 'RACKSPACE':
                if region == 'regionone':
                    raise ions.SystemError('No Region Specified')
                else:
                    specs.update({'ex_force_service_region': region,
                                  'datacenter': region,
                                  'region': region})
        else:
            specs = {'ex_force_auth_url': args.get('authurl'),
                     'ex_force_auth_version': args.get('api_version')}

    except Exception as exp:
        LOG.info(exp)
        raise ions.SystemError('System has halted on specified Request.\n'
                               'ERROR: %s' % exp)
    else:
        specs = utils.parse_dictionary(dictionary=specs)
        LOG.info(specs)
        LOG.debug(specs)
        return driver(
            args.get('username'), user_key, **specs
        )
Exemplo n.º 2
0
 def start(self):
     for method in hashes.NODEMTD.keys():
         if method in self.args:
             self.magic(action=hashes.NODEMTD.get(method))
             break
     else:
         raise ions.SystemError('No Parse-able Functions were found.')
Exemplo n.º 3
0
def ret_conn(args):
    """Returns an active connection."""

    conn = cls.api_conn(args=args)
    if not conn:
        raise ions.SystemError('No Connection Available')
    else:
        return conn
Exemplo n.º 4
0
    def info_lookup(self, action, arg):
        """Look up Cloud Information."""

        find = lookup.show(conn=self.conn, args=self.args)
        data = find.magic(action=action, arg=arg)
        if len(data) > 1:
            raise ions.SystemError('More than a single return was found when'
                                   ' performing %s lookup.' % action)
        else:
            return data[0]
Exemplo n.º 5
0
def cloud_keys(args):
    """Figure out the Authentication Key Type.

    :param args:
    """

    if args.get('password'):
        user_key = args.get('password')
        key_type = 'password'
    elif args.get('apikey'):
        user_key = args.get('apikey')
        key_type = 'api_key'
    else:
        raise ions.SystemError('No Password/Key provided in Command')
    return user_key, key_type
Exemplo n.º 6
0
 def security_groups(self, specs):
     if self.args['cloud_provider'].upper() == 'EC2':
         if self.args.get('security_groups'):
             _sg = self.args.get('security_groups')
             specs['ex_securitygroup'] = _sg
     elif self.args['cloud_provider'].upper() == 'OPENSTACK':
         if self.args.get('security_groups'):
             _sec_groups = self.args.get('security_groups')
             _sgns = ''.join(_sec_groups.split()).split(',')
             try:
                 _asg = self.conn.ex_list_security_groups()
             except Exception as exp:
                 LOG.error(exp)
                 raise ions.SystemError('No Security Groups Available')
             else:
                 specs['ex_security_groups'] = [_sg for _sg in _asg
                                                if _sg.name in _sgns]
     return specs