2013-08-15 21:09:44 -07:00
|
|
|
# Copyright 2012 OpenStack Foundation.
|
2012-05-18 09:02:29 +08:00
|
|
|
# All Rights Reserved
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
"""Manage access to the clients, including authenticating when needed.
|
|
|
|
"""
|
|
|
|
|
2016-05-23 12:58:29 -05:00
|
|
|
import debtcollector.renames
|
|
|
|
|
2013-07-02 18:44:42 -04:00
|
|
|
from neutronclient import client
|
|
|
|
from neutronclient.neutron import client as neutron_client
|
2012-12-31 22:25:00 +08:00
|
|
|
|
|
|
|
|
2012-05-18 09:02:29 +08:00
|
|
|
class ClientCache(object):
|
2014-08-21 15:45:10 +03:00
|
|
|
"""Descriptor class for caching created client handles."""
|
2012-05-18 09:02:29 +08:00
|
|
|
|
|
|
|
def __init__(self, factory):
|
|
|
|
self.factory = factory
|
|
|
|
self._handle = None
|
|
|
|
|
|
|
|
def __get__(self, instance, owner):
|
|
|
|
# Tell the ClientManager to login to keystone
|
|
|
|
if self._handle is None:
|
|
|
|
self._handle = self.factory(instance)
|
|
|
|
return self._handle
|
|
|
|
|
|
|
|
|
|
|
|
class ClientManager(object):
|
2014-08-21 15:45:10 +03:00
|
|
|
"""Manages access to API clients, including authentication."""
|
2013-07-02 18:44:42 -04:00
|
|
|
neutron = ClientCache(neutron_client.make_client)
|
2013-10-06 01:39:54 -07:00
|
|
|
# Provide support for old quantum commands (for example
|
|
|
|
# in stable versions)
|
|
|
|
quantum = neutron
|
2012-05-18 09:02:29 +08:00
|
|
|
|
2016-05-23 12:58:29 -05:00
|
|
|
@debtcollector.renames.renamed_kwarg(
|
|
|
|
'tenant_id', 'project_id', replace=True)
|
|
|
|
@debtcollector.renames.renamed_kwarg(
|
|
|
|
'tenant_name', 'project_name', replace=True)
|
2012-05-18 09:02:29 +08:00
|
|
|
def __init__(self, token=None, url=None,
|
|
|
|
auth_url=None,
|
2013-04-30 15:20:10 -06:00
|
|
|
endpoint_type=None,
|
2016-05-23 12:58:29 -05:00
|
|
|
project_name=None,
|
|
|
|
project_id=None,
|
2014-03-06 13:07:49 +00:00
|
|
|
username=None,
|
|
|
|
user_id=None,
|
|
|
|
password=None,
|
2012-05-18 09:02:29 +08:00
|
|
|
region_name=None,
|
|
|
|
api_version=None,
|
2013-03-12 16:14:08 +02:00
|
|
|
auth_strategy=None,
|
2013-03-19 10:45:54 +02:00
|
|
|
insecure=False,
|
|
|
|
ca_cert=None,
|
2013-06-18 13:24:50 +00:00
|
|
|
log_credentials=False,
|
2013-10-30 21:54:32 +09:00
|
|
|
service_type=None,
|
2015-10-17 17:57:32 -04:00
|
|
|
service_name=None,
|
2014-04-24 16:58:50 +02:00
|
|
|
timeout=None,
|
|
|
|
retries=0,
|
2014-05-05 15:00:03 -04:00
|
|
|
raise_errors=True,
|
|
|
|
session=None,
|
|
|
|
auth=None,
|
2012-05-18 09:02:29 +08:00
|
|
|
):
|
|
|
|
self._token = token
|
|
|
|
self._url = url
|
|
|
|
self._auth_url = auth_url
|
2013-10-30 21:54:32 +09:00
|
|
|
self._service_type = service_type
|
2015-10-17 17:57:32 -04:00
|
|
|
self._service_name = service_name
|
2013-04-30 15:20:10 -06:00
|
|
|
self._endpoint_type = endpoint_type
|
2016-05-23 12:58:29 -05:00
|
|
|
self._project_name = project_name
|
|
|
|
self._project_id = project_id
|
2012-05-18 09:02:29 +08:00
|
|
|
self._username = username
|
2014-03-06 13:07:49 +00:00
|
|
|
self._user_id = user_id
|
2012-05-18 09:02:29 +08:00
|
|
|
self._password = password
|
|
|
|
self._region_name = region_name
|
|
|
|
self._api_version = api_version
|
|
|
|
self._service_catalog = None
|
add --fixed-ip argument to create port
add --fixed-ip argument to create port and add list and dict type for unknow option
now we can use known option feature:
quantumv2 create_port --fixed-ip subnet_id=<id>,ip_address=<ip>
--fixed-ip subnet_id=<id>, ip_address=<ip2> network_id
or unknown option feature:
one ip:
quantumv2 create_port network_id --fixed_ips type=dict list=true subnet_id=<id>,ip_address=<ip>
two ips:
quantumv2 create_port network_id --fixed_ips type=dict subnet_id=<id>,ip_address=<ip> subnet_id=<id>,ip_address=<ip2>
to create port
Please download: https://review.openstack.org/#/c/8794/4 and
set core_plugin = quantum.db.db_base_plugin_v2.QuantumDbPluginV2 on quantum server side
Patch 2: support cliff 1.0
Patch 3: support specify auth strategy, for now, any other auth strategy than keystone will disable auth,
format port output
Patch 4: format None as '' when outputing, deal with list of dict, add QUANTUMCLIENT_DEBUG env to enable http req/resp print,
which is helpful for testing nova integration
Patch 5: fix interactive mode, and initialize_app problem
Change-Id: I693848c75055d1947862d55f4b538c1dfb1e86db
2012-06-24 16:11:11 +08:00
|
|
|
self._auth_strategy = auth_strategy
|
2013-03-12 16:14:08 +02:00
|
|
|
self._insecure = insecure
|
2013-03-19 10:45:54 +02:00
|
|
|
self._ca_cert = ca_cert
|
2013-06-18 13:24:50 +00:00
|
|
|
self._log_credentials = log_credentials
|
2014-07-08 01:13:43 -07:00
|
|
|
self._timeout = timeout
|
2014-04-24 16:58:50 +02:00
|
|
|
self._retries = retries
|
|
|
|
self._raise_errors = raise_errors
|
2014-05-05 15:00:03 -04:00
|
|
|
self._session = session
|
|
|
|
self._auth = auth
|
|
|
|
return
|
2012-05-18 09:02:29 +08:00
|
|
|
|
|
|
|
def initialize(self):
|
|
|
|
if not self._url:
|
2014-05-05 15:00:03 -04:00
|
|
|
httpclient = client.construct_http_client(
|
2013-06-18 13:24:50 +00:00
|
|
|
username=self._username,
|
2014-03-06 13:07:49 +00:00
|
|
|
user_id=self._user_id,
|
2016-05-23 12:58:29 -05:00
|
|
|
project_name=self._project_name,
|
|
|
|
project_id=self._project_id,
|
2013-06-18 13:24:50 +00:00
|
|
|
password=self._password,
|
|
|
|
region_name=self._region_name,
|
|
|
|
auth_url=self._auth_url,
|
2013-10-30 21:54:32 +09:00
|
|
|
service_type=self._service_type,
|
2015-10-17 17:57:32 -04:00
|
|
|
service_name=self._service_name,
|
2013-06-18 13:24:50 +00:00
|
|
|
endpoint_type=self._endpoint_type,
|
|
|
|
insecure=self._insecure,
|
|
|
|
ca_cert=self._ca_cert,
|
2014-05-05 15:00:03 -04:00
|
|
|
timeout=self._timeout,
|
|
|
|
session=self._session,
|
|
|
|
auth=self._auth,
|
|
|
|
log_credentials=self._log_credentials)
|
2012-05-18 09:02:29 +08:00
|
|
|
httpclient.authenticate()
|
|
|
|
# Populate other password flow attributes
|
|
|
|
self._token = httpclient.auth_token
|
|
|
|
self._url = httpclient.endpoint_url
|