diff --git a/saharaclient/api/data_sources.py b/saharaclient/api/data_sources.py index 1fa5fb67..2d901327 100644 --- a/saharaclient/api/data_sources.py +++ b/saharaclient/api/data_sources.py @@ -46,3 +46,7 @@ class DataSourceManager(base.ResourceManager): def delete(self, data_source_id): self._delete('/data-sources/%s' % data_source_id) + + def update(self, data_source_id, update_data): + return self._update('/data-sources/%s' % data_source_id, + update_data) diff --git a/saharaclient/api/shell.py b/saharaclient/api/shell.py index 3b46057b..511a9240 100644 --- a/saharaclient/api/shell.py +++ b/saharaclient/api/shell.py @@ -604,6 +604,24 @@ def do_data_source_delete(cs, args): # TODO(mattf): No indication of result +@utils.arg('--name', + help="Name of the data source to update.") +@utils.arg('--id', + help="ID of the data source to update.") +@utils.arg('--json', + default=sys.stdin, + type=argparse.FileType('r'), + help='JSON containing the data source fields to update.') +def do_data_source_update(cs, args): + """Update a data source.""" + update_data = json.loads(args.json.read()) + result = cs.data_sources.update( + args.id or _get_by_id_or_name(cs.data_sources, name=args.name).id, + update_data + ) + _show_data_source(result) + + # # Job Binary Internals # ~~~~~~~~~~~~~~~~~~~~ diff --git a/saharaclient/tests/unit/test_data_sources.py b/saharaclient/tests/unit/test_data_sources.py index d661a5f8..217f1af3 100644 --- a/saharaclient/tests/unit/test_data_sources.py +++ b/saharaclient/tests/unit/test_data_sources.py @@ -39,6 +39,11 @@ class DataSourceTest(base.BaseTestCase): } } + update_json = { + 'name': 'UpdatedName', + 'url': 'hdfs://myfakeserver/fakepath' + } + def test_create_data_sources(self): url = self.URL + '/data-sources' self.responses.post(url, status_code=202, @@ -79,3 +84,11 @@ class DataSourceTest(base.BaseTestCase): self.client.data_sources.delete('id') self.assertEqual(url, self.responses.last_request.url) + + def test_update_data_sources(self): + update_url = self.URL + '/data-sources/id' + self.responses.put(update_url, status_code=202, + json=self.update_json) + updated = self.client.data_sources.update("id", self.update_json) + self.assertEqual(self.update_json["name"], updated.name) + self.assertEqual(self.update_json["url"], updated.url)