summaryrefslogtreecommitdiff
path: root/saharaclient
diff options
context:
space:
mode:
authorJamie Lennox <jamielennox@redhat.com>2015-01-16 16:07:32 +1000
committerJamie Lennox <jamielennox@redhat.com>2015-01-16 16:11:38 +1000
commit1e99c7ed93f068efd460259ad9f03b88736967c8 (patch)
treeaa161f206d1e909daecb920af5a82e1b03c9d7f8 /saharaclient
parentb5c60118edbaa8a04b33aed521b1bbe81c9a274f (diff)
downloadpython-saharaclient-1e99c7ed93f068efd460259ad9f03b88736967c8.tar.gz
Remove cyclic dependency
The cyclical dependency from client to manager then back on client has caused problems in other projects as the client doesn't always get properly destroyed which can lead to it holding open network connections. Remove this dependency and instead simply pass the constructed HTTPClient to the managers. Change-Id: Id112ab366ad19bc6ae239cfcadb5eb98f6cb8abf
Diffstat (limited to 'saharaclient')
-rw-r--r--saharaclient/api/base.py10
-rw-r--r--saharaclient/api/client.py32
-rw-r--r--saharaclient/api/images.py10
-rw-r--r--saharaclient/api/job_binaries.py2
-rw-r--r--saharaclient/api/plugins.py10
5 files changed, 33 insertions, 31 deletions
diff --git a/saharaclient/api/base.py b/saharaclient/api/base.py
index be53038..e14473f 100644
--- a/saharaclient/api/base.py
+++ b/saharaclient/api/base.py
@@ -77,7 +77,7 @@ class ResourceManager(object):
def _create(self, url, data, response_key=None, dump_json=True):
if dump_json:
data = json.dumps(data)
- resp = self.api.client.post(url, data, json=dump_json)
+ resp = self.api.post(url, data, json=dump_json)
if resp.status_code != 202:
self._raise_api_exception(resp)
@@ -91,7 +91,7 @@ class ResourceManager(object):
def _update(self, url, data, response_key=None, dump_json=True):
if dump_json:
data = json.dumps(data)
- resp = self.api.client.put(url, data, json=dump_json)
+ resp = self.api.put(url, data, json=dump_json)
if resp.status_code != 202:
self._raise_api_exception(resp)
@@ -102,7 +102,7 @@ class ResourceManager(object):
return self.resource_class(self, data)
def _list(self, url, response_key):
- resp = self.api.client.get(url)
+ resp = self.api.get(url)
if resp.status_code == 200:
data = get_json(resp)[response_key]
@@ -112,7 +112,7 @@ class ResourceManager(object):
self._raise_api_exception(resp)
def _get(self, url, response_key=None):
- resp = self.api.client.get(url)
+ resp = self.api.get(url)
if resp.status_code == 200:
if response_key is not None:
@@ -124,7 +124,7 @@ class ResourceManager(object):
self._raise_api_exception(resp)
def _delete(self, url):
- resp = self.api.client.delete(url)
+ resp = self.api.delete(url)
if resp.status_code != 204:
self._raise_api_exception(resp)
diff --git a/saharaclient/api/client.py b/saharaclient/api/client.py
index 8445a58..931502d 100644
--- a/saharaclient/api/client.py
+++ b/saharaclient/api/client.py
@@ -78,22 +78,24 @@ class Client(object):
if not sahara_catalog_url:
raise RuntimeError("Could not find Sahara endpoint in catalog")
- self.client = httpclient.HTTPClient(sahara_catalog_url,
- input_auth_token)
-
- self.clusters = clusters.ClusterManager(self)
- self.cluster_templates = cluster_templates.ClusterTemplateManager(self)
- self.node_group_templates = (node_group_templates.
- NodeGroupTemplateManager(self))
- self.plugins = plugins.PluginManager(self)
- self.images = images.ImageManager(self)
-
- self.data_sources = data_sources.DataSourceManager(self)
- self.jobs = jobs.JobsManager(self)
- self.job_executions = job_executions.JobExecutionsManager(self)
- self.job_binaries = job_binaries.JobBinariesManager(self)
+ client = httpclient.HTTPClient(sahara_catalog_url, input_auth_token)
+
+ self.clusters = clusters.ClusterManager(client)
+ self.cluster_templates = (
+ cluster_templates.ClusterTemplateManager(client)
+ )
+ self.node_group_templates = (
+ node_group_templates.NodeGroupTemplateManager(client)
+ )
+ self.plugins = plugins.PluginManager(client)
+ self.images = images.ImageManager(client)
+
+ self.data_sources = data_sources.DataSourceManager(client)
+ self.jobs = jobs.JobsManager(client)
+ self.job_executions = job_executions.JobExecutionsManager(client)
+ self.job_binaries = job_binaries.JobBinariesManager(client)
self.job_binary_internals = (
- job_binary_internals.JobBinaryInternalsManager(self)
+ job_binary_internals.JobBinaryInternalsManager(client)
)
def get_keystone_client(self, username=None, api_key=None, auth_url=None,
diff --git a/saharaclient/api/images.py b/saharaclient/api/images.py
index 8606d5e..9ec8487 100644
--- a/saharaclient/api/images.py
+++ b/saharaclient/api/images.py
@@ -40,7 +40,7 @@ class ImageManager(base.ResourceManager):
body = {"username": user_name,
"description": desc}
- resp = self.api.client.post('/images/%s' % image_id, json.dumps(body))
+ resp = self.api.post('/images/%s' % image_id, json.dumps(body))
if resp.status_code != 202:
raise RuntimeError('Failed to register image %s' % image_id)
@@ -54,15 +54,15 @@ class ImageManager(base.ResourceManager):
to_remove = list(old_tags - new_tags)
if len(to_add) != 0:
- resp = self.api.client.post('/images/%s/tag' % image_id,
- json.dumps({'tags': to_add}))
+ resp = self.api.post('/images/%s/tag' % image_id,
+ json.dumps({'tags': to_add}))
if resp.status_code != 202:
raise RuntimeError('Failed to add tags to image %s' % image_id)
if len(to_remove) != 0:
- resp = self.api.client.post('/images/%s/untag' % image_id,
- json.dumps({'tags': to_remove}))
+ resp = self.api.post('/images/%s/untag' % image_id,
+ json.dumps({'tags': to_remove}))
if resp.status_code != 202:
raise RuntimeError('Failed to remove tags from image %s' %
diff --git a/saharaclient/api/job_binaries.py b/saharaclient/api/job_binaries.py
index d6f84c9..b7798e2 100644
--- a/saharaclient/api/job_binaries.py
+++ b/saharaclient/api/job_binaries.py
@@ -44,7 +44,7 @@ class JobBinariesManager(base.ResourceManager):
self._delete('/job-binaries/%s' % job_binary_id)
def get_file(self, job_binary_id):
- resp = self.api.client.get('/job-binaries/%s/data' % job_binary_id)
+ resp = self.api.get('/job-binaries/%s/data' % job_binary_id)
if resp.status_code != 200:
self._raise_api_exception(resp)
diff --git a/saharaclient/api/plugins.py b/saharaclient/api/plugins.py
index 0e877a4..9399ace 100644
--- a/saharaclient/api/plugins.py
+++ b/saharaclient/api/plugins.py
@@ -44,11 +44,11 @@ class PluginManager(base.ResourceManager):
def convert_to_cluster_template(self, plugin_name, hadoop_version,
template_name, filecontent):
- resp = self.api.client.post('/plugins/%s/%s/convert-config/%s' %
- (plugin_name,
- hadoop_version,
- urlparse.quote(template_name)),
- filecontent)
+ resp = self.api.post('/plugins/%s/%s/convert-config/%s' %
+ (plugin_name,
+ hadoop_version,
+ urlparse.quote(template_name)),
+ filecontent)
if resp.status_code != 202:
raise RuntimeError('Failed to upload template file for plugin "%s"'
' and version "%s"' %