summaryrefslogtreecommitdiff
path: root/quantumclient/client.py
diff options
context:
space:
mode:
authorYong Sheng Gong <gongysh@cn.ibm.com>2012-06-24 16:11:11 +0800
committerYong Sheng Gong <gongysh@cn.ibm.com>2012-06-25 18:19:18 +0800
commit50c46f61d1a76b5429c20ad61203afedc7c508bb (patch)
tree96ea2c8215533a36441a2005e4f1c15b822382a6 /quantumclient/client.py
parentdd803f8e26f4c3a3b8f1b9e7526d0e1980b2491c (diff)
downloadpython-neutronclient-50c46f61d1a76b5429c20ad61203afedc7c508bb.tar.gz
add --fixed-ip argument to create port0.1.0
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
Diffstat (limited to 'quantumclient/client.py')
-rw-r--r--quantumclient/client.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/quantumclient/client.py b/quantumclient/client.py
index b892d30..03c590a 100644
--- a/quantumclient/client.py
+++ b/quantumclient/client.py
@@ -20,6 +20,7 @@ try:
except ImportError:
import simplejson as json
import logging
+import os
import urlparse
# Python 2.5 compat fix
if not hasattr(urlparse, 'parse_qsl'):
@@ -33,6 +34,11 @@ from quantumclient.common import utils
_logger = logging.getLogger(__name__)
+if 'QUANTUMCLIENT_DEBUG' in os.environ and os.environ['QUANTUMCLIENT_DEBUG']:
+ ch = logging.StreamHandler()
+ _logger.setLevel(logging.DEBUG)
+ _logger.addHandler(ch)
+
class ServiceCatalog(object):
"""Helper methods for dealing with a Keystone Service Catalog."""
@@ -86,7 +92,8 @@ class HTTPClient(httplib2.Http):
def __init__(self, username=None, tenant_name=None,
password=None, auth_url=None,
token=None, region_name=None, timeout=None,
- endpoint_url=None, insecure=False, **kwargs):
+ endpoint_url=None, insecure=False,
+ auth_strategy='keystone', **kwargs):
super(HTTPClient, self).__init__(timeout=timeout)
self.username = username
self.tenant_name = tenant_name
@@ -96,6 +103,7 @@ class HTTPClient(httplib2.Http):
self.auth_token = token
self.content_type = 'application/json'
self.endpoint_url = endpoint_url
+ self.auth_strategy = auth_strategy
# httplib2 overrides
self.force_exception_to_status_code = True
self.disable_ssl_certificate_validation = insecure
@@ -126,19 +134,21 @@ class HTTPClient(httplib2.Http):
return resp, body
def do_request(self, url, method, **kwargs):
- if not self.endpoint_url or not self.auth_token:
+ if not self.endpoint_url:
self.authenticate()
# Perform the request once. If we get a 401 back then it
# might be because the auth token expired, so try to
# re-authenticate and try again. If it still fails, bail.
try:
- kwargs.setdefault('headers', {})['X-Auth-Token'] = self.auth_token
+ if self.auth_token:
+ kwargs.setdefault('headers', {})
+ kwargs['headers']['X-Auth-Token'] = self.auth_token
resp, body = self._cs_request(self.endpoint_url + url, method,
**kwargs)
return resp, body
except exceptions.Unauthorized as ex:
- if not self.endpoint_url or not self.auth_token:
+ if not self.endpoint_url:
self.authenticate()
resp, body = self._cs_request(
self.management_url + url, method, **kwargs)
@@ -161,6 +171,8 @@ class HTTPClient(httplib2.Http):
endpoint_type='adminURL')
def authenticate(self):
+ if self.auth_strategy != 'keystone':
+ raise exceptions.Unauthorized(message='unknown auth strategy')
body = {'auth': {'passwordCredentials':
{'username': self.username,
'password': self.password, },