diff options
author | Andrey Pavlov <apavlov@mirantis.com> | 2016-01-26 14:39:33 +0300 |
---|---|---|
committer | Andrey Pavlov <apavlov@mirantis.com> | 2016-01-29 15:02:17 +0300 |
commit | adf19185c4e9bbd3d245a15cbccb37f56b7464c5 (patch) | |
tree | 7c227234ce75d7f4e352ff7352aae2006df0aa90 /saharaclient/api | |
parent | 421476157dca5d154c354fb8d00c375a02e2b0d6 (diff) | |
download | python-saharaclient-adf19185c4e9bbd3d245a15cbccb37f56b7464c5.tar.gz |
Adding ability to unset fields with update calls
Adding a sentinel object that will be used as a default
value in update methods. This object will allow to
distinguish whether a field should be unset or should
not be updated.
Change-Id: Ie6679c8f64623e8570176b8009380b08de2be6a5
Closes-bug: #1534050
Diffstat (limited to 'saharaclient/api')
-rw-r--r-- | saharaclient/api/base.py | 11 | ||||
-rw-r--r-- | saharaclient/api/cluster_templates.py | 15 | ||||
-rw-r--r-- | saharaclient/api/clusters.py | 8 | ||||
-rw-r--r-- | saharaclient/api/job_binary_internals.py | 7 | ||||
-rw-r--r-- | saharaclient/api/job_executions.py | 5 | ||||
-rw-r--r-- | saharaclient/api/jobs.py | 7 | ||||
-rw-r--r-- | saharaclient/api/node_group_templates.py | 25 |
7 files changed, 50 insertions, 28 deletions
diff --git a/saharaclient/api/base.py b/saharaclient/api/base.py index a4fc78b..a5323cd 100644 --- a/saharaclient/api/base.py +++ b/saharaclient/api/base.py @@ -64,6 +64,12 @@ def _check_items(obj, searches): return False +class NotUpdated(object): + """A sentinel class to signal that parameter should not be updated.""" + def __repr__(self): + return 'NotUpdated' + + class ResourceManager(object): resource_class = None @@ -88,6 +94,11 @@ class ResourceManager(object): if var_value is not None: data[var_name] = var_value + def _copy_if_updated(self, data, **kwargs): + for var_name, var_value in six.iteritems(kwargs): + if not isinstance(var_value, NotUpdated): + data[var_name] = var_value + def _create(self, url, data, response_key=None, dump_json=True): if dump_json: kwargs = {'json': data} diff --git a/saharaclient/api/cluster_templates.py b/saharaclient/api/cluster_templates.py index f8f516a..04c2585 100644 --- a/saharaclient/api/cluster_templates.py +++ b/saharaclient/api/cluster_templates.py @@ -22,6 +22,7 @@ class ClusterTemplate(base.Resource): class ClusterTemplateManager(base.ResourceManager): resource_class = ClusterTemplate + NotUpdated = base.NotUpdated() def create(self, name, plugin_name, hadoop_version, description=None, cluster_configs=None, node_groups=None, anti_affinity=None, @@ -49,15 +50,17 @@ class ClusterTemplateManager(base.ResourceManager): return self._create('/cluster-templates', data, 'cluster_template') - def update(self, cluster_template_id, name=None, plugin_name=None, - hadoop_version=None, description=None, cluster_configs=None, - node_groups=None, anti_affinity=None, net_id=None, - default_image_id=None, use_autoconfig=None, shares=None, - is_public=None, is_protected=None): + def update(self, cluster_template_id, name=NotUpdated, + plugin_name=NotUpdated, hadoop_version=NotUpdated, + description=NotUpdated, cluster_configs=NotUpdated, + node_groups=NotUpdated, anti_affinity=NotUpdated, + net_id=NotUpdated, default_image_id=NotUpdated, + use_autoconfig=NotUpdated, shares=NotUpdated, + is_public=NotUpdated, is_protected=NotUpdated): """Update a Cluster Template.""" data = {} - self._copy_if_defined(data, name=name, + self._copy_if_updated(data, name=name, plugin_name=plugin_name, hadoop_version=hadoop_version, description=description, diff --git a/saharaclient/api/clusters.py b/saharaclient/api/clusters.py index 049d8f4..f7ae6ba 100644 --- a/saharaclient/api/clusters.py +++ b/saharaclient/api/clusters.py @@ -24,6 +24,7 @@ class Cluster(base.Resource): class ClusterManager(base.ResourceManager): resource_class = Cluster + NotUpdated = base.NotUpdated() def create(self, name, plugin_name, hadoop_version, cluster_template_id=None, default_image_id=None, @@ -116,12 +117,13 @@ class ClusterManager(base.ResourceManager): """Delete a Cluster.""" self._delete('/clusters/%s' % cluster_id) - def update(self, cluster_id, name=None, description=None, is_public=None, - is_protected=None, shares=None): + def update(self, cluster_id, name=NotUpdated, description=NotUpdated, + is_public=NotUpdated, is_protected=NotUpdated, + shares=NotUpdated): """Update a Cluster.""" data = {} - self._copy_if_defined(data, name=name, description=description, + self._copy_if_updated(data, name=name, description=description, is_public=is_public, is_protected=is_protected, shares=shares) diff --git a/saharaclient/api/job_binary_internals.py b/saharaclient/api/job_binary_internals.py index f36b0a6..27f66ce 100644 --- a/saharaclient/api/job_binary_internals.py +++ b/saharaclient/api/job_binary_internals.py @@ -24,6 +24,7 @@ class JobBinaryInternal(base.Resource): class JobBinaryInternalsManager(base.ResourceManager): resource_class = JobBinaryInternal + NotUpdated = base.NotUpdated() def create(self, name, data): """Create a Job Binary Internal. @@ -48,12 +49,12 @@ class JobBinaryInternalsManager(base.ResourceManager): """Delete a Job Binary Internal.""" self._delete('/job-binary-internals/%s' % job_binary_id) - def update(self, job_binary_id, name=None, is_public=None, - is_protected=None): + def update(self, job_binary_id, name=NotUpdated, is_public=NotUpdated, + is_protected=NotUpdated): """Update a Job Binary Internal.""" data = {} - self._copy_if_defined(data, name=name, is_public=is_public, + self._copy_if_updated(data, name=name, is_public=is_public, is_protected=is_protected) return self._patch('/job-binary-internals/%s' % job_binary_id, data) diff --git a/saharaclient/api/job_executions.py b/saharaclient/api/job_executions.py index 078cd84..7a0ca9a 100644 --- a/saharaclient/api/job_executions.py +++ b/saharaclient/api/job_executions.py @@ -22,6 +22,7 @@ class JobExecution(base.Resource): class JobExecutionsManager(base.ResourceManager): resource_class = JobExecution + NotUpdated = base.NotUpdated() def list(self, search_opts=None): """Get a list of Job Executions.""" @@ -52,10 +53,10 @@ class JobExecutionsManager(base.ResourceManager): return self._create(url, data, 'job_execution') - def update(self, obj_id, is_public=None, is_protected=None): + def update(self, obj_id, is_public=NotUpdated, is_protected=NotUpdated): """Update a Job Execution.""" data = {} - self._copy_if_defined(data, is_public=is_public, + self._copy_if_updated(data, is_public=is_public, is_protected=is_protected) return self._patch('/job-executions/%s' % obj_id, data) diff --git a/saharaclient/api/jobs.py b/saharaclient/api/jobs.py index 0638304..374fc78 100644 --- a/saharaclient/api/jobs.py +++ b/saharaclient/api/jobs.py @@ -22,6 +22,7 @@ class Job(base.Resource): class JobsManager(base.ResourceManager): resource_class = Job + NotUpdated = base.NotUpdated() def create(self, name, type, mains=None, libs=None, description=None, interface=None, is_public=None, is_protected=None): @@ -54,12 +55,12 @@ class JobsManager(base.ResourceManager): """Delete a Job""" self._delete('/jobs/%s' % job_id) - def update(self, job_id, name=None, description=None, is_public=None, - is_protected=None): + def update(self, job_id, name=NotUpdated, description=NotUpdated, + is_public=NotUpdated, is_protected=NotUpdated): """Update a Job.""" data = {} - self._copy_if_defined(data, name=name, description=description, + self._copy_if_updated(data, name=name, description=description, is_public=is_public, is_protected=is_protected) return self._patch('/jobs/%s' % job_id, data) diff --git a/saharaclient/api/node_group_templates.py b/saharaclient/api/node_group_templates.py index f4afeb5..f023909 100644 --- a/saharaclient/api/node_group_templates.py +++ b/saharaclient/api/node_group_templates.py @@ -22,6 +22,7 @@ class NodeGroupTemplate(base.Resource): class NodeGroupTemplateManager(base.ResourceManager): resource_class = NodeGroupTemplate + NotUpdated = base.NotUpdated() def create(self, name, plugin_name, hadoop_version, flavor_id, description=None, volumes_per_node=None, volumes_size=None, @@ -74,20 +75,22 @@ class NodeGroupTemplateManager(base.ResourceManager): return self._create('/node-group-templates', data, 'node_group_template') - def update(self, ng_template_id, name=None, plugin_name=None, - hadoop_version=None, flavor_id=None, description=None, - volumes_per_node=None, volumes_size=None, node_processes=None, - node_configs=None, floating_ip_pool=None, security_groups=None, - auto_security_group=None, availability_zone=None, - volumes_availability_zone=None, volume_type=None, - image_id=None, is_proxy_gateway=None, - volume_local_to_instance=None, use_autoconfig=None, - shares=None, is_public=None, is_protected=None, - volume_mount_prefix=None): + def update(self, ng_template_id, name=NotUpdated, plugin_name=NotUpdated, + hadoop_version=NotUpdated, flavor_id=NotUpdated, + description=NotUpdated, volumes_per_node=NotUpdated, + volumes_size=NotUpdated, node_processes=NotUpdated, + node_configs=NotUpdated, floating_ip_pool=NotUpdated, + security_groups=NotUpdated, auto_security_group=NotUpdated, + availability_zone=NotUpdated, + volumes_availability_zone=NotUpdated, volume_type=NotUpdated, + image_id=NotUpdated, is_proxy_gateway=NotUpdated, + volume_local_to_instance=NotUpdated, use_autoconfig=NotUpdated, + shares=NotUpdated, is_public=NotUpdated, + is_protected=NotUpdated, volume_mount_prefix=NotUpdated): """Update a Node Group Template.""" data = {} - self._copy_if_defined( + self._copy_if_updated( data, name=name, plugin_name=plugin_name, hadoop_version=hadoop_version, flavor_id=flavor_id, description=description, volumes_per_node=volumes_per_node, |