2012-05-18 09:02:29 +08:00
|
|
|
# Copyright 2012 OpenStack LLC.
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
|
|
|
|
"""Manage access to the clients, including authenticating when needed.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from quantumclient.common import exceptions as exc
|
|
|
|
|
|
|
|
from quantumclient.quantum import client as quantum_client
|
|
|
|
from quantumclient.client import HTTPClient
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class ClientCache(object):
|
|
|
|
"""Descriptor class for caching created client handles.
|
|
|
|
"""
|
|
|
|
|
|
|
|
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):
|
|
|
|
"""Manages access to API clients, including authentication.
|
|
|
|
"""
|
|
|
|
quantum = ClientCache(quantum_client.make_client)
|
|
|
|
|
|
|
|
def __init__(self, token=None, url=None,
|
|
|
|
auth_url=None,
|
|
|
|
tenant_name=None, tenant_id=None,
|
|
|
|
username=None, password=None,
|
|
|
|
region_name=None,
|
|
|
|
api_version=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
|
|
|
auth_strategy=None
|
2012-05-18 09:02:29 +08:00
|
|
|
):
|
|
|
|
self._token = token
|
|
|
|
self._url = url
|
|
|
|
self._auth_url = auth_url
|
|
|
|
self._tenant_name = tenant_name
|
|
|
|
self._tenant_id = tenant_id
|
|
|
|
self._username = username
|
|
|
|
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
|
2012-05-18 09:02:29 +08:00
|
|
|
return
|
|
|
|
|
|
|
|
def initialize(self):
|
|
|
|
if not self._url:
|
|
|
|
httpclient = HTTPClient(username=self._username,
|
|
|
|
tenant_name=self._tenant_name,
|
|
|
|
password=self._password,
|
|
|
|
region_name=self._region_name,
|
|
|
|
auth_url=self._auth_url)
|
|
|
|
httpclient.authenticate()
|
|
|
|
# Populate other password flow attributes
|
|
|
|
self._token = httpclient.auth_token
|
|
|
|
self._url = httpclient.endpoint_url
|