Update for API bindings

All occurrences of tenant replaced with project (where applicable).

Partially Implements blueprint: keystone-v3

Change-Id: I4919745aa59863f99c7740e730d8cbfd91c2f646
This commit is contained in:
Dariusz Smigiel 2016-05-23 12:58:29 -05:00
parent 53a59e5aa2
commit 343e4b186f
7 changed files with 134 additions and 75 deletions

View File

@ -33,11 +33,11 @@ First create a client instance.
>>> from neutronclient.v2_0 import client
>>> username='adminUser'
>>> password='secretword'
>>> tenant_name='openstackDemo'
>>> project_name='openstackDemo'
>>> auth_url='http://192.168.206.130:5000/v2.0'
>>> neutron = client.Client(username=username,
... password=password,
... tenant_name=tenant_name,
... project_name=project_name,
... auth_url=auth_url)
Now you can call various methods on the client instance.

View File

@ -21,6 +21,7 @@ except ImportError:
import logging
import os
import debtcollector.renames
from keystoneauth1 import access
from keystoneauth1 import adapter
import requests
@ -49,8 +50,12 @@ class HTTPClient(object):
USER_AGENT = 'python-neutronclient'
CONTENT_TYPE = 'application/json'
@debtcollector.renames.renamed_kwarg(
'tenant_id', 'project_id', replace=True)
@debtcollector.renames.renamed_kwarg(
'tenant_name', 'project_name', replace=True)
def __init__(self, username=None, user_id=None,
tenant_name=None, tenant_id=None,
project_name=None, project_id=None,
password=None, auth_url=None,
token=None, region_name=None, timeout=None,
endpoint_url=None, insecure=False,
@ -61,8 +66,8 @@ class HTTPClient(object):
self.username = username
self.user_id = user_id
self.tenant_name = tenant_name
self.tenant_id = tenant_id
self.project_name = project_name
self.project_id = project_id
self.password = password
self.auth_url = auth_url.rstrip('/') if auth_url else None
self.service_type = service_type
@ -199,12 +204,12 @@ class HTTPClient(object):
creds = {'username': self.username,
'password': self.password}
if self.tenant_id:
if self.project_id:
body = {'auth': {'passwordCredentials': creds,
'tenantId': self.tenant_id, }, }
'tenantId': self.project_id, }, }
else:
body = {'auth': {'passwordCredentials': creds,
'tenantName': self.tenant_name, }, }
'tenantName': self.project_name, }, }
if self.auth_url is None:
raise exceptions.NoAuthURLProvided()
@ -344,10 +349,13 @@ class SessionClient(adapter.Adapter):
# FIXME(bklei): Should refactor this to use kwargs and only
# explicitly list arguments that are not None.
@debtcollector.renames.renamed_kwarg('tenant_id', 'project_id', replace=True)
@debtcollector.renames.renamed_kwarg(
'tenant_name', 'project_name', replace=True)
def construct_http_client(username=None,
user_id=None,
tenant_name=None,
tenant_id=None,
project_name=None,
project_id=None,
password=None,
auth_url=None,
token=None,
@ -376,8 +384,8 @@ def construct_http_client(username=None,
# refactor to use kwargs.
return HTTPClient(username=username,
password=password,
tenant_id=tenant_id,
tenant_name=tenant_name,
project_id=project_id,
project_name=project_name,
user_id=user_id,
auth_url=auth_url,
token=token,

View File

@ -19,6 +19,8 @@
import logging
import debtcollector.renames
from neutronclient import client
from neutronclient.neutron import client as neutron_client
@ -47,11 +49,15 @@ class ClientManager(object):
# in stable versions)
quantum = neutron
@debtcollector.renames.renamed_kwarg(
'tenant_id', 'project_id', replace=True)
@debtcollector.renames.renamed_kwarg(
'tenant_name', 'project_name', replace=True)
def __init__(self, token=None, url=None,
auth_url=None,
endpoint_type=None,
tenant_name=None,
tenant_id=None,
project_name=None,
project_id=None,
username=None,
user_id=None,
password=None,
@ -75,8 +81,8 @@ class ClientManager(object):
self._service_type = service_type
self._service_name = service_name
self._endpoint_type = endpoint_type
self._tenant_name = tenant_name
self._tenant_id = tenant_id
self._project_name = project_name
self._project_id = project_id
self._username = username
self._user_id = user_id
self._password = password
@ -99,8 +105,8 @@ class ClientManager(object):
httpclient = client.construct_http_client(
username=self._username,
user_id=self._user_id,
tenant_name=self._tenant_name,
tenant_id=self._tenant_id,
project_name=self._project_name,
project_id=self._project_id,
password=self._password,
region_name=self._region_name,
auth_url=self._auth_url,

View File

@ -35,7 +35,7 @@ def make_client(instance):
url = instance._url
url = url.rstrip("/")
client = neutron_client(username=instance._username,
tenant_name=instance._tenant_name,
project_name=instance._project_name,
password=instance._password,
region_name=instance._region_name,
auth_url=instance._auth_url,

View File

@ -36,8 +36,7 @@ class LibraryTestBase(base.BaseTestCase):
class Libv2HTTPClientTestBase(LibraryTestBase):
def _get_client(self):
def _setup_creds(self):
creds = func_base.credentials()
cloud_config = func_base.get_cloud_config()
@ -52,13 +51,29 @@ class Libv2HTTPClientTestBase(LibraryTestBase):
# whether v3 also exists or is configured
v2_auth_url = keystone_auth.get_endpoint(
ks_session, interface=ksa_plugin.AUTH_INTERFACE, version=(2, 0))
return v2_auth_url, creds
class Libv2HTTPClientTenantTestBase(Libv2HTTPClientTestBase):
def _get_client(self):
v2_auth_url, creds = self._setup_creds()
return v2_client.Client(username=creds['username'],
password=creds['password'],
tenant_name=creds['project_name'],
auth_url=v2_auth_url)
class Libv2HTTPClientProjectTestBase(Libv2HTTPClientTestBase):
def _get_client(self):
v2_auth_url, creds = self._setup_creds()
return v2_client.Client(username=creds['username'],
password=creds['password'],
project_name=creds['project_name'],
auth_url=v2_auth_url)
class Libv2SessionClientTestBase(LibraryTestBase):
def _get_client(self):
@ -92,7 +107,13 @@ class LibraryTestCase(object):
self.client.show_network(net_id)
class LibraryHTTPClientTest(LibraryTestCase, Libv2HTTPClientTestBase):
class LibraryHTTPClientTenantTest(LibraryTestCase,
Libv2HTTPClientTenantTestBase):
pass
class LibraryHTTPClientProjectTest(LibraryTestCase,
Libv2HTTPClientProjectTestBase):
pass

View File

@ -20,6 +20,7 @@ import itertools
import logging
import time
import debtcollector.renames
import requests
import six.moves.urllib.parse as urlparse
from six import string_types
@ -184,8 +185,10 @@ class ClientBase(object):
:param string user_id: User ID for authentication. (optional)
:param string password: Password for authentication. (optional)
:param string token: Token for authentication. (optional)
:param string tenant_name: Tenant name. (optional)
:param string tenant_id: Tenant id. (optional)
:param string tenant_name: DEPRECATED! Use project_name instead.
:param string project_name: Project name. (optional)
:param string tenant_id: DEPRECATED! Use project_id instead.
:param string project_id: Project id. (optional)
:param string auth_strategy: 'keystone' by default, 'noauth' for no
authentication against keystone. (optional)
:param string auth_url: Keystone service endpoint for authorization.
@ -220,7 +223,7 @@ class ClientBase(object):
from neutronclient.v2_0 import client
neutron = client.Client(username=USER,
password=PASS,
tenant_name=TENANT_NAME,
project_name=PROJECT_NAME,
auth_url=KEYSTONE_URL)
nets = neutron.list_networks()
@ -231,6 +234,8 @@ class ClientBase(object):
# This variable should be overridden by a child class.
EXTED_PLURALS = {}
@debtcollector.renames.renamed_kwarg(
'tenant_id', 'project_id', replace=True)
def __init__(self, **kwargs):
"""Initialize a new client for the Neutron v2.0 API."""
super(ClientBase, self).__init__()
@ -257,7 +262,7 @@ class ClientBase(object):
exception_handler_v20(status_code, error_body)
def do_request(self, method, action, body=None, headers=None, params=None):
# Add format and tenant_id
# Add format and project_id
action += ".%s" % self.format
action = self.action_prefix + action
if isinstance(params, dict) and params:
@ -584,24 +589,30 @@ class Client(ClientBase):
return self.delete(path % id)
def get_quotas_tenant(self, **_params):
"""Fetch tenant info for following quota operation."""
"""Fetch project info for following quota operation."""
return self.get(self.quota_path % 'tenant', params=_params)
def list_quotas(self, **_params):
"""Fetch all tenants' quotas."""
"""Fetch all projects' quotas."""
return self.get(self.quotas_path, params=_params)
def show_quota(self, tenant_id, **_params):
"""Fetch information of a certain tenant's quotas."""
return self.get(self.quota_path % (tenant_id), params=_params)
@debtcollector.renames.renamed_kwarg(
'tenant_id', 'project_id', replace=True)
def show_quota(self, project_id, **_params):
"""Fetch information of a certain project's quotas."""
return self.get(self.quota_path % (project_id), params=_params)
def update_quota(self, tenant_id, body=None):
"""Update a tenant's quotas."""
return self.put(self.quota_path % (tenant_id), body=body)
@debtcollector.renames.renamed_kwarg(
'tenant_id', 'project_id', replace=True)
def update_quota(self, project_id, body=None):
"""Update a project's quotas."""
return self.put(self.quota_path % (project_id), body=body)
def delete_quota(self, tenant_id):
"""Delete the specified tenant's quota values."""
return self.delete(self.quota_path % (tenant_id))
@debtcollector.renames.renamed_kwarg(
'tenant_id', 'project_id', replace=True)
def delete_quota(self, project_id):
"""Delete the specified project's quota values."""
return self.delete(self.quota_path % (project_id))
def list_extensions(self, **_params):
"""Fetch a list of all extensions on server side."""
@ -612,7 +623,7 @@ class Client(ClientBase):
return self.get(self.extension_path % ext_alias, params=_params)
def list_ports(self, retrieve_all=True, **_params):
"""Fetches a list of all ports for a tenant."""
"""Fetches a list of all ports for a project."""
# Pass filters in "params" argument to do_request
return self.list('ports', self.ports_path, retrieve_all,
**_params)
@ -634,7 +645,7 @@ class Client(ClientBase):
return self.delete(self.port_path % (port))
def list_networks(self, retrieve_all=True, **_params):
"""Fetches a list of all networks for a tenant."""
"""Fetches a list of all networks for a project."""
# Pass filters in "params" argument to do_request
return self.list('networks', self.networks_path, retrieve_all,
**_params)
@ -656,7 +667,7 @@ class Client(ClientBase):
return self.delete(self.network_path % (network))
def list_subnets(self, retrieve_all=True, **_params):
"""Fetches a list of all subnets for a tenant."""
"""Fetches a list of all subnets for a project."""
return self.list('subnets', self.subnets_path, retrieve_all,
**_params)
@ -677,7 +688,7 @@ class Client(ClientBase):
return self.delete(self.subnet_path % (subnet))
def list_subnetpools(self, retrieve_all=True, **_params):
"""Fetches a list of all subnetpools for a tenant."""
"""Fetches a list of all subnetpools for a project."""
return self.list('subnetpools', self.subnetpools_path, retrieve_all,
**_params)
@ -698,7 +709,7 @@ class Client(ClientBase):
return self.delete(self.subnetpool_path % (subnetpool))
def list_routers(self, retrieve_all=True, **_params):
"""Fetches a list of all routers for a tenant."""
"""Fetches a list of all routers for a project."""
# Pass filters in "params" argument to do_request
return self.list('routers', self.routers_path, retrieve_all,
**_params)
@ -720,7 +731,7 @@ class Client(ClientBase):
return self.delete(self.router_path % (router))
def list_address_scopes(self, retrieve_all=True, **_params):
"""Fetches a list of all address scopes for a tenant."""
"""Fetches a list of all address scopes for a project."""
return self.list('address_scopes', self.address_scopes_path,
retrieve_all, **_params)
@ -762,7 +773,7 @@ class Client(ClientBase):
body={'router': {'external_gateway_info': {}}})
def list_floatingips(self, retrieve_all=True, **_params):
"""Fetches a list of all floatingips for a tenant."""
"""Fetches a list of all floatingips for a project."""
# Pass filters in "params" argument to do_request
return self.list('floatingips', self.floatingips_path, retrieve_all,
**_params)
@ -793,7 +804,7 @@ class Client(ClientBase):
security_group, body=body)
def list_security_groups(self, retrieve_all=True, **_params):
"""Fetches a list of all security groups for a tenant."""
"""Fetches a list of all security groups for a project."""
return self.list('security_groups', self.security_groups_path,
retrieve_all, **_params)
@ -816,7 +827,7 @@ class Client(ClientBase):
(security_group_rule))
def list_security_group_rules(self, retrieve_all=True, **_params):
"""Fetches a list of all security group rules for a tenant."""
"""Fetches a list of all security group rules for a project."""
return self.list('security_group_rules',
self.security_group_rules_path,
retrieve_all, **_params)
@ -827,7 +838,7 @@ class Client(ClientBase):
params=_params)
def list_endpoint_groups(self, retrieve_all=True, **_params):
"""Fetches a list of all VPN endpoint groups for a tenant."""
"""Fetches a list of all VPN endpoint groups for a project."""
return self.list('endpoint_groups', self.endpoint_groups_path,
retrieve_all, **_params)
@ -849,7 +860,7 @@ class Client(ClientBase):
return self.delete(self.endpoint_group_path % endpoint_group)
def list_vpnservices(self, retrieve_all=True, **_params):
"""Fetches a list of all configured VPN services for a tenant."""
"""Fetches a list of all configured VPN services for a project."""
return self.list('vpnservices', self.vpnservices_path, retrieve_all,
**_params)
@ -870,7 +881,7 @@ class Client(ClientBase):
return self.delete(self.vpnservice_path % (vpnservice))
def list_ipsec_site_connections(self, retrieve_all=True, **_params):
"""Fetches all configured IPsecSiteConnections for a tenant."""
"""Fetches all configured IPsecSiteConnections for a project."""
return self.list('ipsec_site_connections',
self.ipsec_site_connections_path,
retrieve_all,
@ -897,7 +908,7 @@ class Client(ClientBase):
return self.delete(self.ipsec_site_connection_path % (ipsecsite_conn))
def list_ikepolicies(self, retrieve_all=True, **_params):
"""Fetches a list of all configured IKEPolicies for a tenant."""
"""Fetches a list of all configured IKEPolicies for a project."""
return self.list('ikepolicies', self.ikepolicies_path, retrieve_all,
**_params)
@ -918,7 +929,7 @@ class Client(ClientBase):
return self.delete(self.ikepolicy_path % (ikepolicy))
def list_ipsecpolicies(self, retrieve_all=True, **_params):
"""Fetches a list of all configured IPsecPolicies for a tenant."""
"""Fetches a list of all configured IPsecPolicies for a project."""
return self.list('ipsecpolicies',
self.ipsecpolicies_path,
retrieve_all,
@ -941,7 +952,7 @@ class Client(ClientBase):
return self.delete(self.ipsecpolicy_path % (ipsecpolicy))
def list_loadbalancers(self, retrieve_all=True, **_params):
"""Fetches a list of all loadbalancers for a tenant."""
"""Fetches a list of all loadbalancers for a project."""
return self.list('loadbalancers', self.lbaas_loadbalancers_path,
retrieve_all, **_params)
@ -975,7 +986,7 @@ class Client(ClientBase):
params=_params)
def list_listeners(self, retrieve_all=True, **_params):
"""Fetches a list of all lbaas_listeners for a tenant."""
"""Fetches a list of all lbaas_listeners for a project."""
return self.list('listeners', self.lbaas_listeners_path,
retrieve_all, **_params)
@ -1044,7 +1055,7 @@ class Client(ClientBase):
return self.delete(self.lbaas_l7rule_path % (l7policy, l7rule))
def list_lbaas_pools(self, retrieve_all=True, **_params):
"""Fetches a list of all lbaas_pools for a tenant."""
"""Fetches a list of all lbaas_pools for a project."""
return self.list('pools', self.lbaas_pools_path,
retrieve_all, **_params)
@ -1067,7 +1078,7 @@ class Client(ClientBase):
return self.delete(self.lbaas_pool_path % (lbaas_pool))
def list_lbaas_healthmonitors(self, retrieve_all=True, **_params):
"""Fetches a list of all lbaas_healthmonitors for a tenant."""
"""Fetches a list of all lbaas_healthmonitors for a project."""
return self.list('healthmonitors', self.lbaas_healthmonitors_path,
retrieve_all, **_params)
@ -1091,12 +1102,12 @@ class Client(ClientBase):
(lbaas_healthmonitor))
def list_lbaas_loadbalancers(self, retrieve_all=True, **_params):
"""Fetches a list of all lbaas_loadbalancers for a tenant."""
"""Fetches a list of all lbaas_loadbalancers for a project."""
return self.list('loadbalancers', self.lbaas_loadbalancers_path,
retrieve_all, **_params)
def list_lbaas_members(self, lbaas_pool, retrieve_all=True, **_params):
"""Fetches a list of all lbaas_members for a tenant."""
"""Fetches a list of all lbaas_members for a project."""
return self.list('members', self.lbaas_members_path % lbaas_pool,
retrieve_all, **_params)
@ -1119,7 +1130,7 @@ class Client(ClientBase):
return self.delete(self.lbaas_member_path % (lbaas_pool, lbaas_member))
def list_vips(self, retrieve_all=True, **_params):
"""Fetches a list of all load balancer vips for a tenant."""
"""Fetches a list of all load balancer vips for a project."""
# Pass filters in "params" argument to do_request
return self.list('vips', self.vips_path, retrieve_all,
**_params)
@ -1141,7 +1152,7 @@ class Client(ClientBase):
return self.delete(self.vip_path % (vip))
def list_pools(self, retrieve_all=True, **_params):
"""Fetches a list of all load balancer pools for a tenant."""
"""Fetches a list of all load balancer pools for a project."""
# Pass filters in "params" argument to do_request
return self.list('pools', self.pools_path, retrieve_all,
**_params)
@ -1167,7 +1178,7 @@ class Client(ClientBase):
return self.get(self.pool_path_stats % (pool), params=_params)
def list_members(self, retrieve_all=True, **_params):
"""Fetches a list of all load balancer members for a tenant."""
"""Fetches a list of all load balancer members for a project."""
# Pass filters in "params" argument to do_request
return self.list('members', self.members_path, retrieve_all,
**_params)
@ -1189,7 +1200,9 @@ class Client(ClientBase):
return self.delete(self.member_path % (member))
def list_health_monitors(self, retrieve_all=True, **_params):
"""Fetches a list of all load balancer health monitors for a tenant."""
"""Fetches a list of all load balancer health monitors for a project.
"""
# Pass filters in "params" argument to do_request
return self.list('health_monitors', self.health_monitors_path,
retrieve_all, **_params)
@ -1227,7 +1240,7 @@ class Client(ClientBase):
return self.post(self.qos_queues_path, body=body)
def list_qos_queues(self, **_params):
"""Fetches a list of all queues for a tenant."""
"""Fetches a list of all queues for a project."""
return self.get(self.qos_queues_path, params=_params)
def show_qos_queue(self, queue, **_params):
@ -1364,7 +1377,7 @@ class Client(ClientBase):
% bgp_dragent, params=_params)
def list_firewall_rules(self, retrieve_all=True, **_params):
"""Fetches a list of all firewall rules for a tenant."""
"""Fetches a list of all firewall rules for a project."""
# Pass filters in "params" argument to do_request
return self.list('firewall_rules', self.firewall_rules_path,
@ -1388,7 +1401,7 @@ class Client(ClientBase):
return self.delete(self.firewall_rule_path % (firewall_rule))
def list_firewall_policies(self, retrieve_all=True, **_params):
"""Fetches a list of all firewall policies for a tenant."""
"""Fetches a list of all firewall policies for a project."""
# Pass filters in "params" argument to do_request
return self.list('firewall_policies', self.firewall_policies_path,
@ -1423,7 +1436,7 @@ class Client(ClientBase):
body=body)
def list_firewalls(self, retrieve_all=True, **_params):
"""Fetches a list of all firewalls for a tenant."""
"""Fetches a list of all firewalls for a project."""
# Pass filters in "params" argument to do_request
return self.list('firewalls', self.firewalls_path, retrieve_all,
@ -1486,7 +1499,7 @@ class Client(ClientBase):
return self.delete(self.metering_label_path % (label))
def list_metering_labels(self, retrieve_all=True, **_params):
"""Fetches a list of all metering labels for a tenant."""
"""Fetches a list of all metering labels for a project."""
return self.list('metering_labels', self.metering_labels_path,
retrieve_all, **_params)
@ -1523,7 +1536,7 @@ class Client(ClientBase):
return self.put(self.rbac_policy_path % rbac_policy_id, body=body)
def list_rbac_policies(self, retrieve_all=True, **_params):
"""Fetch a list of all RBAC policies for a tenant."""
"""Fetch a list of all RBAC policies for a project."""
return self.list('rbac_policies', self.rbac_policies_path,
retrieve_all, **_params)
@ -1537,7 +1550,7 @@ class Client(ClientBase):
return self.delete(self.rbac_policy_path % rbac_policy_id)
def list_qos_policies(self, retrieve_all=True, **_params):
"""Fetches a list of all qos policies for a tenant."""
"""Fetches a list of all qos policies for a project."""
# Pass filters in "params" argument to do_request
return self.list('policies', self.qos_policies_path,
retrieve_all, **_params)
@ -1628,7 +1641,7 @@ class Client(ClientBase):
return self.delete(self.flavor_path % (flavor))
def list_flavors(self, retrieve_all=True, **_params):
"""Fetches a list of all Neutron service flavors for a tenant."""
"""Fetches a list of all Neutron service flavors for a project."""
return self.list('flavors', self.flavors_path, retrieve_all,
**_params)
@ -1678,18 +1691,22 @@ class Client(ClientBase):
return self.list('availability_zones', self.availability_zones_path,
retrieve_all, **_params)
def get_auto_allocated_topology(self, tenant_id, **_params):
"""Fetch information about a tenant's auto-allocated topology."""
@debtcollector.renames.renamed_kwarg(
'tenant_id', 'project_id', replace=True)
def get_auto_allocated_topology(self, project_id, **_params):
"""Fetch information about a project's auto-allocated topology."""
return self.get(
self.auto_allocated_topology_path % tenant_id,
self.auto_allocated_topology_path % project_id,
params=_params)
def validate_auto_allocated_topology_requirements(self, tenant_id):
@debtcollector.renames.renamed_kwarg(
'tenant_id', 'project_id', replace=True)
def validate_auto_allocated_topology_requirements(self, project_id):
"""Validate requirements for getting an auto-allocated topology."""
return self.get_auto_allocated_topology(tenant_id, fields=['dry-run'])
return self.get_auto_allocated_topology(project_id, fields=['dry-run'])
def list_bgp_speakers(self, retrieve_all=True, **_params):
"""Fetches a list of all BGP speakers for a tenant."""
"""Fetches a list of all BGP speakers for a project."""
return self.list('bgp_speakers', self.bgp_speakers_path, retrieve_all,
**_params)

View File

@ -0,0 +1,7 @@
---
deprecations:
- |
Keystone v3 support for CLI
* Using 'tenant_id' and 'tenant_name' arguments in API bindings is
deprecated. Use 'project_id' and 'project_name' arguments instead.