Esempio n. 1
0
    def test_client_logger(self):
        cl1 = client.HTTPClient("username", "password", "project_id",
                                "auth_test", http_log_debug=True)
        self.assertEqual(len(cl1._logger.handlers), 1)

        cl2 = client.HTTPClient("username", "password", "project_id",
                                "auth_test", http_log_debug=True)
        self.assertEqual(len(cl2._logger.handlers), 1)
Esempio n. 2
0
def token_create(request, tenant, username, password):
    '''
    Creates a token using the username and password provided. If tenant
    is provided it will retrieve a scoped token and the service catalog for
    the given tenant. Otherwise it will return an unscoped token and without
    a service catalog.
    '''
    c = base_nova_client.HTTPClient(username, password, tenant,
                                    settings.OPENSTACK_KEYSTONE_URL)
    c.version = 'v2.0'
    try:
        c.authenticate()
    except nova_exceptions.AuthorizationFailure as e:
        # When authenticating without a tenant, novaclient raises a KeyError
        # (which is caught and raised again as an AuthorizationFailure)
        # if no service catalog is returned. However, in this case if we got
        # back a token we're good. If not then it really is a failure.
        if c.service_catalog.get_token():
            pass
        else:
            raise
    access = c.service_catalog.catalog['access']
    return Token(id=c.auth_token,
                 serviceCatalog=access.get('serviceCatalog', None),
                 user=access['user'],
                 tenant_id=tenant)
Esempio n. 3
0
    def __init__(self):
        self.nova = client.HTTPClient(
            cfg.CONF['mgm']['nova_user'],
            cfg.CONF['mgm']['nova_pass'],
            cfg.CONF['mgm']['nova_tenant'],
            cfg.CONF['mgm']['nova_auth_url'],
            region_name=cfg.CONF['mgm']['nova_region'],
            no_cache=True,
            insecure=cfg.CONF['mgm']['nova_insecure'],
            tenant_id=cfg.CONF['mgm']['nova_tenant_id'],
            bypass_url=cfg.CONF['mgm']['nova_bypass_url'],
            service_type='compute')
        self.keyname = cfg.CONF['mgm']['nova_keyname']
        self.secgroup = cfg.CONF['mgm']['nova_secgroup']
        self.node_basename = cfg.CONF['mgm']['node_basename']
        self.az = cfg.CONF['mgm']['nova_az_name']
        self.net_id = cfg.CONF['mgm']['nova_net_id']
        self.rm_fip_ignore_500 = cfg.CONF['mgm']['rm_fip_ignore_500']

        # Replace '_' with '-' in basename
        if self.node_basename:
            self.node_basename = self.node_basename.replace('_', '-')

        self.image = cfg.CONF['mgm']['nova_image']

        image_size = cfg.CONF['mgm']['nova_image_size']
        if image_size.isdigit():
            self.node_type = image_size
        else:
            self.node_type = self._get_flavor(image_size)
Esempio n. 4
0
    def __init__(self,
                 username,
                 api_key,
                 project_id,
                 auth_url=None,
                 insecure=False,
                 timeout=None,
                 token=None,
                 region_name=None,
                 endpoint_name='publicURL'):

        # FIXME(comstud): Rename the api_key argument above when we
        # know it's not being used as keyword argument
        password = api_key
        self.accounts = accounts.AccountManager(self)
        self.backup_schedules = backup_schedules.BackupScheduleManager(self)
        self.flavors = flavors.FlavorManager(self)
        self.images = images.ImageManager(self)
        self.ipgroups = ipgroups.IPGroupManager(self)
        self.servers = servers.ServerManager(self)
        self.zones = zones.ZoneManager(self)

        _auth_url = auth_url or 'https://auth.api.rackspacecloud.com/v1.0'

        self.client = client.HTTPClient(username,
                                        password,
                                        project_id,
                                        _auth_url,
                                        insecure=insecure,
                                        timeout=timeout,
                                        token=token,
                                        region_name=region_name,
                                        endpoint_name=endpoint_name)
Esempio n. 5
0
def _check_keystone_versions(url):
    try:
        httpclient = client.HTTPClient(user=None, password=None,
                            projectid=None, auth_url=None)
        resp, body = httpclient.request(url, "GET",
                                  headers={'Accept': 'application/json'})
        if resp.status in (200, 204):  # in some cases we get No Content
            try:
                print "Keystone found at %s" % url
                if 'version' in body:
                    version = body['version']
                    # Stable/diablo incorrect format
                    _display_version_info(version, url)
                    return True
                if 'versions' in body:
                    # Correct format
                    for version in body['versions']['values']:
                        _display_version_info(version, url)
                    return True
                print "Unrecognized response from %s" % url
            except KeyError:
                raise exceptions.AuthorizationFailure()
        elif resp.status == 305:
            return _check_keystone_versions(resp['location'])
        else:
            raise exceptions.from_response(resp, body)
    except:
        return False
Esempio n. 6
0
    def __init__(self,
                 username,
                 password,
                 project_id,
                 auth_url=None,
                 insecure=False,
                 timeout=None,
                 proxy_tenant_id=None,
                 proxy_token=None,
                 region_name=None,
                 endpoint_type='publicURL',
                 extensions=None,
                 service_type='compute',
                 service_name=None,
                 volume_service_name=None,
                 timings=False,
                 bypass_url=None,
                 os_cache=False,
                 no_cache=True,
                 http_log_debug=False,
                 auth_system='keystone',
                 auth_plugin=None,
                 cacert=None,
                 tenant_id=None):
        self.projectid = project_id
        self.tenant_id = tenant_id
        self.os_cache = os_cache or not no_cache
        #TODO(bnemec): Add back in v3 extensions
        self.hosts = hosts.HostManager(self)

        # Add in any extensions...
        if extensions:
            for extension in extensions:
                if extension.manager_class:
                    setattr(self, extension.name,
                            extension.manager_class(self))

        self.client = client.HTTPClient(
            username,
            password,
            projectid=project_id,
            tenant_id=tenant_id,
            auth_url=auth_url,
            insecure=insecure,
            timeout=timeout,
            auth_system=auth_system,
            auth_plugin=auth_plugin,
            proxy_token=proxy_token,
            proxy_tenant_id=proxy_tenant_id,
            region_name=region_name,
            endpoint_type=endpoint_type,
            service_type=service_type,
            service_name=service_name,
            volume_service_name=volume_service_name,
            timings=timings,
            bypass_url=bypass_url,
            os_cache=os_cache,
            http_log_debug=http_log_debug,
            cacert=cacert)
Esempio n. 7
0
    def __init__(self,
                 username,
                 api_key,
                 project_id,
                 auth_url,
                 insecure=False,
                 timeout=None,
                 token=None,
                 region_name=None,
                 endpoint_name='publicURL',
                 extensions=None):
        # FIXME(comstud): Rename the api_key argument above when we
        # know it's not being used as keyword argument
        password = api_key
        self.flavors = flavors.FlavorManager(self)
        self.images = images.ImageManager(self)
        self.limits = limits.LimitsManager(self)
        self.servers = servers.ServerManager(self)

        # extensions
        self.floating_ips = floating_ips.FloatingIPManager(self)
        self.floating_ip_dns = floating_ip_dns.FloatingIPDNSManager(self)
        self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
        self.volumes = volumes.VolumeManager(self)
        self.volume_snapshots = volume_snapshots.SnapshotManager(self)
        self.keypairs = keypairs.KeypairManager(self)
        self.zones = zones.ZoneManager(self)
        self.quotas = quotas.QuotaSetManager(self)
        self.security_groups = security_groups.SecurityGroupManager(self)
        self.security_group_rules = \
            security_group_rules.SecurityGroupRuleManager(self)
        self.usage = usage.UsageManager(self)
        self.virtual_interfaces = \
            virtual_interfaces.VirtualInterfaceManager(self)

        # Add in any extensions...
        if extensions:
            for extension in extensions:
                if extension.manager_class:
                    setattr(self, extension.name,
                            extension.manager_class(self))

        self.client = client.HTTPClient(username,
                                        password,
                                        project_id,
                                        auth_url,
                                        insecure=insecure,
                                        timeout=timeout,
                                        token=token,
                                        region_name=region_name,
                                        endpoint_name=endpoint_name)
Esempio n. 8
0
    def __init__(self,
                 username,
                 api_key,
                 project_id,
                 auth_url=None,
                 insecure=False,
                 timeout=None,
                 token=None,
                 region_name=None,
                 endpoint_name=None,
                 extensions=None,
                 service_type=None,
                 service_name=None,
                 endpoint_type='publicURL'):

        # FIXME(comstud): Rename the api_key argument above when we
        # know it's not being used as keyword argument
        password = api_key
        self.accounts = accounts.AccountManager(self)
        self.backup_schedules = backup_schedules.BackupScheduleManager(self)
        self.flavors = flavors.FlavorManager(self)
        self.images = images.ImageManager(self)
        self.ipgroups = ipgroups.IPGroupManager(self)
        self.servers = servers.ServerManager(self)
        self.zones = zones.ZoneManager(self)
        #service_type is unused in v1_0
        #service_name is unused in v1_0
        #endpoint_name is unused in v_10
        #endpoint_type was endpoint_name

        # Add in any extensions...
        if extensions:
            for (ext_name, ext_manager_class, ext_module) in extensions:
                setattr(self, ext_name, ext_manager_class(self))

        _auth_url = auth_url or 'https://auth.api.rackspacecloud.com/v1.0'

        self.client = client.HTTPClient(username,
                                        password,
                                        project_id,
                                        _auth_url,
                                        insecure=insecure,
                                        timeout=timeout,
                                        proxy_token=token,
                                        region_name=region_name,
                                        endpoint_type=endpoint_type)
  def test_authenticate_and_tenants(self):
    from novaclient.keystone import client as ks_client
    from novaclient import client as base_client

    port = self.server.socket_info['socket'][1]
    CONF.public_port = port

    # NOTE(termie): novaclient wants a "/" TypeErrorat the end, keystoneclient does not
    # NOTE(termie): projectid is apparently sent as tenantName, so... that's
    #               unfortunate.
    # NOTE(termie): novaclient seems to care about the region more than
    #               keystoneclient
    conn = base_client.HTTPClient(auth_url="http://localhost:%s/v2.0/" % port,
                                  user='******',
                                  password='******',
                                  projectid='BAR',
                                  region_name='RegionOne')
    client = ks_client.Client(conn)
    client.authenticate()
Esempio n. 10
0
def _get_base_client_from_token(tenant_id, token):
    '''
    Helper function to create an instance of novaclient.client.HTTPClient from
    a token and tenant id rather than a username/password.

    The returned client can be passed to novaclient.keystone.client.Client
    without requiring a second authentication call.

    NOTE(gabriel): This ought to live upstream in novaclient, but isn't
    currently supported by the HTTPClient.authenticate() method (which only
    works with a username and password).
    '''
    c = base_nova_client.HTTPClient(None, None, tenant_id,
                                    settings.OPENSTACK_KEYSTONE_URL)
    body = {"auth": {"tenantId": tenant_id, "token": {"id": token}}}
    token_url = urlparse.urljoin(c.auth_url, "tokens")
    resp, body = c.request(token_url, "POST", body=body)
    c._extract_service_catalog(c.auth_url, resp, body)
    return c
Esempio n. 11
0
    def __init__(self,
                 username,
                 api_key,
                 project_id,
                 auth_url,
                 insecure=False,
                 timeout=None,
                 token=None,
                 region_name=None,
                 endpoint_name='publicURL'):
        # FIXME(comstud): Rename the api_key argument above when we
        # know it's not being used as keyword argument
        password = api_key
        self.flavors = flavors.FlavorManager(self)
        self.floating_ips = floating_ips.FloatingIPManager(self)
        self.images = images.ImageManager(self)
        self.servers = servers.ServerManager(self)

        # extensions
        self.volumes = volumes.VolumeManager(self)
        self.volume_snapshots = volume_snapshots.SnapshotManager(self)
        self.keypairs = keypairs.KeypairManager(self)
        self.zones = zones.ZoneManager(self)
        self.quotas = quotas.QuotaSetManager(self)
        self.security_groups = security_groups.SecurityGroupManager(self)
        self.security_group_rules = \
            security_group_rules.SecurityGroupRuleManager(self)

        self.client = client.HTTPClient(username,
                                        password,
                                        project_id,
                                        auth_url,
                                        insecure=insecure,
                                        timeout=timeout,
                                        token=token,
                                        region_name=region_name,
                                        endpoint_name=endpoint_name)
Esempio n. 12
0
    def __init__(self,
                 username,
                 api_key,
                 project_id,
                 auth_url=None,
                 insecure=False,
                 timeout=None,
                 proxy_tenant_id=None,
                 proxy_token=None,
                 region_name=None,
                 endpoint_type='publicURL',
                 extensions=None,
                 service_type='compute',
                 service_name=None,
                 volume_service_name=None,
                 timings=False,
                 bypass_url=None,
                 os_cache=False,
                 no_cache=True,
                 http_log_debug=False,
                 auth_system='keystone',
                 auth_plugin=None,
                 auth_token=None,
                 cacert=None,
                 tenant_id=None,
                 user_id=None,
                 connection_pool=False):
        # FIXME(comstud): Rename the api_key argument above when we
        # know it's not being used as keyword argument
        password = api_key
        self.projectid = project_id
        self.tenant_id = tenant_id
        self.user_id = user_id
        self.flavors = flavors.FlavorManager(self)
        self.flavor_access = flavor_access.FlavorAccessManager(self)
        self.images = images.ImageManager(self)
        self.limits = limits.LimitsManager(self)
        self.servers = servers.ServerManager(self)

        # extensions
        self.agents = agents.AgentsManager(self)
        self.dns_domains = floating_ip_dns.FloatingIPDNSDomainManager(self)
        self.dns_entries = floating_ip_dns.FloatingIPDNSEntryManager(self)
        self.cloudpipe = cloudpipe.CloudpipeManager(self)
        self.certs = certs.CertificateManager(self)
        self.floating_ips = floating_ips.FloatingIPManager(self)
        self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
        self.fping = fping.FpingManager(self)
        self.volumes = volumes.VolumeManager(self)
        self.volume_snapshots = volume_snapshots.SnapshotManager(self)
        self.volume_types = volume_types.VolumeTypeManager(self)
        self.keypairs = keypairs.KeypairManager(self)
        self.networks = networks.NetworkManager(self)
        self.quotas = quotas.QuotaSetManager(self)
        self.security_groups = security_groups.SecurityGroupManager(self)
        self.security_group_rules = \
            security_group_rules.SecurityGroupRuleManager(self)
        self.usage = usage.UsageManager(self)
        self.virtual_interfaces = \
            virtual_interfaces.VirtualInterfaceManager(self)
        self.aggregates = aggregates.AggregateManager(self)
        self.hosts = hosts.HostManager(self)
        self.hypervisors = hypervisors.HypervisorManager(self)
        self.services = services.ServiceManager(self)
        self.fixed_ips = fixed_ips.FixedIPsManager(self)
        self.floating_ips_bulk = floating_ips_bulk.FloatingIPBulkManager(self)
        self.os_cache = os_cache or not no_cache
        self.availability_zones = \
            availability_zones.AvailabilityZoneManager(self)
        self.server_groups = server_groups.ServerGroupsManager(self)

        # Add in any extensions...
        if extensions:
            for extension in extensions:
                if extension.manager_class:
                    setattr(self, extension.name,
                            extension.manager_class(self))

        self.client = client.HTTPClient(
            username,
            password,
            user_id=user_id,
            projectid=project_id,
            tenant_id=tenant_id,
            auth_url=auth_url,
            auth_token=auth_token,
            insecure=insecure,
            timeout=timeout,
            auth_system=auth_system,
            auth_plugin=auth_plugin,
            proxy_token=proxy_token,
            proxy_tenant_id=proxy_tenant_id,
            region_name=region_name,
            endpoint_type=endpoint_type,
            service_type=service_type,
            service_name=service_name,
            volume_service_name=volume_service_name,
            timings=timings,
            bypass_url=bypass_url,
            os_cache=self.os_cache,
            http_log_debug=http_log_debug,
            cacert=cacert,
            connection_pool=connection_pool)
Esempio n. 13
0
def get_client():
    cl = client.HTTPClient("username", "password",
                           "project_id", "auth_test")
    return cl
    def __init__(self, username, password, project_id, auth_url=None,
                  insecure=False, timeout=None, proxy_tenant_id=None,
                  proxy_token=None, region_name=None,
                  endpoint_type='publicURL', extensions=None,
                  service_type='computev3', service_name=None,
                  volume_service_name=None, timings=False,
                  bypass_url=None, os_cache=False, no_cache=True,
                  http_log_debug=False, auth_system='keystone',
                  auth_plugin=None, auth_token=None,
                  cacert=None, tenant_id=None, user_id=None,
                  connection_pool=False):
        self.projectid = project_id
        self.tenant_id = tenant_id
        self.user_id = user_id
        self.os_cache = os_cache or not no_cache
        #TODO(bnemec): Add back in v3 extensions
        self.agents = agents.AgentsManager(self)
        self.aggregates = aggregates.AggregateManager(self)
        self.availability_zones = \
            availability_zones.AvailabilityZoneManager(self)
        self.certs = certs.CertificateManager(self)
        self.list_extensions = list_extensions.ListExtManager(self)
        self.hosts = hosts.HostManager(self)
        self.flavors = flavors.FlavorManager(self)
        self.flavor_access = flavor_access.FlavorAccessManager(self)
        self.hypervisors = hypervisors.HypervisorManager(self)
        self.images = images.ImageManager(self)
        self.keypairs = keypairs.KeypairManager(self)
        self.quotas = quotas.QuotaSetManager(self)
        self.quota_classes = quota_classes.QuotaClassSetManager(self)
        self.servers = servers.ServerManager(self)
        self.services = services.ServiceManager(self)
        self.usage = usage.UsageManager(self)
        self.volumes = volumes.VolumeManager(self)

        # Add in any extensions...
        if extensions:
            for extension in extensions:
                if extension.manager_class:
                    setattr(self, extension.name,
                            extension.manager_class(self))

        self.client = client.HTTPClient(username,
                                    password,
                                    user_id=user_id,
                                    projectid=project_id,
                                    tenant_id=tenant_id,
                                    auth_url=auth_url,
                                    insecure=insecure,
                                    timeout=timeout,
                                    auth_system=auth_system,
                                    auth_plugin=auth_plugin,
                                    auth_token=auth_token,
                                    proxy_token=proxy_token,
                                    proxy_tenant_id=proxy_tenant_id,
                                    region_name=region_name,
                                    endpoint_type=endpoint_type,
                                    service_type=service_type,
                                    service_name=service_name,
                                    volume_service_name=volume_service_name,
                                    timings=timings,
                                    bypass_url=bypass_url,
                                    os_cache=os_cache,
                                    http_log_debug=http_log_debug,
                                    cacert=cacert,
                                    connection_pool=connection_pool)
Esempio n. 15
0
    def __init__(self,
                 username,
                 api_key,
                 project_id,
                 auth_url=None,
                 insecure=False,
                 timeout=None,
                 proxy_tenant_id=None,
                 proxy_token=None,
                 region_name=None,
                 endpoint_type='publicURL',
                 extensions=None,
                 service_type='compute',
                 service_name=None,
                 volume_service_name=None,
                 timings=False,
                 bypass_url=None,
                 no_cache=False,
                 http_log_debug=False,
                 auth_system='keystone'):
        # FIXME(comstud): Rename the api_key argument above when we
        # know it's not being used as keyword argument
        password = api_key
        self.flavors = flavors.FlavorManager(self)
        self.images = images.ImageManager(self)
        self.limits = limits.LimitsManager(self)
        self.servers = servers.ServerManager(self)

        # extensions
        self.dns_domains = floating_ip_dns.FloatingIPDNSDomainManager(self)
        self.dns_entries = floating_ip_dns.FloatingIPDNSEntryManager(self)
        self.cloudpipe = cloudpipe.CloudpipeManager(self)
        self.certs = certs.CertificateManager(self)
        self.floating_ips = floating_ips.FloatingIPManager(self)
        self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
        self.volumes = volumes.VolumeManager(self)
        self.volume_snapshots = volume_snapshots.SnapshotManager(self)
        self.volume_types = volume_types.VolumeTypeManager(self)
        self.keypairs = keypairs.KeypairManager(self)
        self.quota_classes = quota_classes.QuotaClassSetManager(self)
        self.quotas = quotas.QuotaSetManager(self)
        self.security_groups = security_groups.SecurityGroupManager(self)
        self.security_group_rules = \
            security_group_rules.SecurityGroupRuleManager(self)
        self.usage = usage.UsageManager(self)
        self.virtual_interfaces = \
            virtual_interfaces.VirtualInterfaceManager(self)
        self.aggregates = aggregates.AggregateManager(self)
        self.hosts = hosts.HostManager(self)
        self.hypervisors = hypervisors.HypervisorManager(self)

        # Add in any extensions...
        if extensions:
            for extension in extensions:
                if extension.manager_class:
                    setattr(self, extension.name,
                            extension.manager_class(self))

        self.client = client.HTTPClient(
            username,
            password,
            project_id,
            auth_url,
            insecure=insecure,
            timeout=timeout,
            auth_system=auth_system,
            proxy_token=proxy_token,
            proxy_tenant_id=proxy_tenant_id,
            region_name=region_name,
            endpoint_type=endpoint_type,
            service_type=service_type,
            service_name=service_name,
            volume_service_name=volume_service_name,
            timings=timings,
            bypass_url=bypass_url,
            no_cache=no_cache,
            http_log_debug=http_log_debug)
Esempio n. 16
0
config = ConfigParser.ConfigParser()
config.readfp(conffp)

if options.command == 'list':
    for section in config.sections():
        print section
    exit(0)

words = "status", "tenant"

completer = Completer(words)

readline.parse_and_bind("tab: complete")
readline.set_completer(completer.complete)

api = client.HTTPClient(config.get(options.name, 'os_username'),
                        config.get(options.name, 'os_password'),
                        config.get(options.name, 'os_tenant_name'),
                        config.get(options.name, 'os_auth_url'),
                        region_name=config.get(options.name, 'os_region_name'),
                        service_type='compute')

parser = command_parser.Parser(api)

if not options.exec_command:
    while 1:
        command = raw_input("luminous> ")
        parser.parse(command)
else:
    parser.parse(options.exec_command)
Esempio n. 17
0
    def test_auth_failure_due_to_miss_of_auth_url(self):
        cl = client.HTTPClient("username", "password")

        self.assertRaises(exceptions.AuthorizationFailure, cl.authenticate)
Esempio n. 18
0
def get_client(**kwargs):
    cl = client.HTTPClient("username", "password", "project_id",
                           utils.AUTH_URL_V2, **kwargs)
    return cl