From 246690b51cf474f40acc6ddcfef6280f53af69e3 Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 10 Nov 2015 16:49:13 +0800 Subject: [PATCH] Support workflow creation Can use `evoque workflow-create -s workflow-spec-file`. Co-Authored-By: Liuqing Jing Change-Id: I8726e5661fb2a206c3e67b18856dcb1878e5a5f1 --- evoqueclient/v1/client.py | 2 ++ evoqueclient/v1/shell.py | 15 +++++++++++++++ evoqueclient/v1/workflows.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 evoqueclient/v1/workflows.py diff --git a/evoqueclient/v1/client.py b/evoqueclient/v1/client.py index 25f43df..d6810d3 100644 --- a/evoqueclient/v1/client.py +++ b/evoqueclient/v1/client.py @@ -12,6 +12,7 @@ from evoqueclient.common import http from evoqueclient.v1 import tickets +from evoqueclient.v1 import workflows class Client(http.HTTPClient): @@ -23,3 +24,4 @@ class Client(http.HTTPClient): """Initialize a new client for the Evoque v1 API.""" super(Client, self).__init__(*args, **kwargs) self.tickets = tickets.TicketManager(self) + self.workflows = workflows.WorkflowManager(self) diff --git a/evoqueclient/v1/shell.py b/evoqueclient/v1/shell.py index 6a88cd3..9e478e2 100644 --- a/evoqueclient/v1/shell.py +++ b/evoqueclient/v1/shell.py @@ -9,7 +9,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import os +from evoqueclient.common.i18n import _ from evoqueclient.common import utils @@ -28,3 +30,16 @@ def do_ticket_list(ec, args={}): def do_ticket_create(ec, args): """Create a ticket.""" ec.tickets.add({"name": args.name}) + + +@utils.arg("-s", "--spec-file", metavar="", required=True, + help=_('The spec file used to create the workflow.')) +@utils.arg("name", metavar="", + help="Workflow name.") +def do_workflow_create(ec, args): + """Create a workflow.""" + spec_file = os.path.abspath(os.path.expanduser(args.spec_file)) + ec.workflows.add({ + "name": args.name, + "wf_spec": open(spec_file).read() + }) diff --git a/evoqueclient/v1/workflows.py b/evoqueclient/v1/workflows.py new file mode 100644 index 0000000..ae5c3df --- /dev/null +++ b/evoqueclient/v1/workflows.py @@ -0,0 +1,28 @@ +# 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 evoqueclient.common import base + + +class Workflow(base.Resource): + def __repr__(self): + return "" % self._info + + def data(self, **kwargs): + return self.manager.data(self, **kwargs) + + +class WorkflowManager(base.Manager): + resource_class = Workflow + + def add(self, data): + return self._create('/v1/workflow', data)