summaryrefslogtreecommitdiff
path: root/saharaclient/api
diff options
context:
space:
mode:
authorTrevor McKay <tmckay@redhat.com>2015-03-26 15:22:52 -0400
committerTrevor McKay <tmckay@redhat.com>2015-03-26 15:24:36 -0400
commitfb9cf4ed62aa50f3272bab7abe865760baf81442 (patch)
tree9dc4cfbacd4f80251199b1f59102db6042e9bdd9 /saharaclient/api
parent3fa0e0e798db785463711de617052d8bfe5cbe14 (diff)
downloadpython-saharaclient-fb9cf4ed62aa50f3272bab7abe865760baf81442.tar.gz
Add support for job-types-list
This change adds support to the client for the job-types-endpoint. Filtering by a single value for type, plugin, and version is supported. Config hints are not available in this interface. Change-Id: I0240717ac74c52dd915ce1617fb5d34d87660c0b Partial-Implements: blueprint edp-job-types-endpoint
Diffstat (limited to 'saharaclient/api')
-rw-r--r--saharaclient/api/client.py2
-rw-r--r--saharaclient/api/job_types.py28
-rw-r--r--saharaclient/api/shell.py50
3 files changed, 80 insertions, 0 deletions
diff --git a/saharaclient/api/client.py b/saharaclient/api/client.py
index 61b868d..cb6e562 100644
--- a/saharaclient/api/client.py
+++ b/saharaclient/api/client.py
@@ -26,6 +26,7 @@ from saharaclient.api import images
from saharaclient.api import job_binaries
from saharaclient.api import job_binary_internals
from saharaclient.api import job_executions
+from saharaclient.api import job_types
from saharaclient.api import jobs
from saharaclient.api import node_group_templates
from saharaclient.api import plugins
@@ -115,6 +116,7 @@ class Client(object):
self.job_binary_internals = (
job_binary_internals.JobBinaryInternalsManager(client)
)
+ self.job_types = job_types.JobTypesManager(client)
def get_keystone_client(self, username=None, api_key=None, auth_url=None,
token=None, project_id=None, project_name=None):
diff --git a/saharaclient/api/job_types.py b/saharaclient/api/job_types.py
new file mode 100644
index 0000000..1ebc378
--- /dev/null
+++ b/saharaclient/api/job_types.py
@@ -0,0 +1,28 @@
+# Copyright (c) 2015 Red Hat Inc.
+#
+# 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.
+
+from saharaclient.api import base
+
+
+class JobType(base.Resource):
+ resource_name = 'JobType'
+
+
+class JobTypesManager(base.ResourceManager):
+ resource_class = JobType
+
+ def list(self, search_opts=None):
+ query = base.get_query_string(search_opts)
+ return self._list('/job-types%s' % query, 'job_types')
diff --git a/saharaclient/api/shell.py b/saharaclient/api/shell.py
index a350740..057a10f 100644
--- a/saharaclient/api/shell.py
+++ b/saharaclient/api/shell.py
@@ -799,3 +799,53 @@ def do_job_delete(cs, args):
"""Delete a job."""
cs.job_executions.delete(args.id)
# TODO(mattf): No indication of result
+
+
+#
+# Job Types
+# ~~~~~~~~~
+# job-type-list [--type] [--plugin [--plugin-version]]
+#
+
+def _print_plugin_field(job_type):
+
+ def plugin_version_string(plugin):
+ versions = ", ".join(plugin["versions"].keys())
+ if versions:
+ versions = "(" + versions + ")"
+ return plugin["name"] + versions
+
+ return ", ".join(map(lambda x: plugin_version_string(x), job_type.plugins))
+
+
+@utils.arg('--type',
+ metavar='<job_type>',
+ default=None,
+ help='Report only on this job type')
+@utils.arg('--plugin',
+ metavar='<plugin>',
+ default=None,
+ help='Report only job types supported by this plugin.')
+@utils.arg('--plugin-version',
+ metavar='<plugin_version>',
+ default=None,
+ help='Report only on job types supported by this version '
+ 'of a specified plugin. Only valid with --plugin.')
+def do_job_type_list(cs, args):
+ """Show supported job types."""
+ search_opts = {}
+ if args.type:
+ search_opts["type"] = args.type
+ if args.plugin:
+ search_opts["plugin"] = args.plugin
+ if args.plugin_version:
+ search_opts["version"] = args.plugin_version
+ elif args.plugin_version:
+ raise exceptions.CommandError(
+ 'The --plugin-version option is only valid when '
+ '--plugin is specified')
+
+ job_types = cs.job_types.list(search_opts)
+ columns = ('name', 'plugin(versions)')
+ utils.print_list(job_types, columns,
+ {'plugin(versions)': _print_plugin_field})