Support workflow creation

Can use `evoque workflow-create -s workflow-spec-file`.

Co-Authored-By: Liuqing Jing <lawrancejing@gmail.com>

Change-Id: I8726e5661fb2a206c3e67b18856dcb1878e5a5f1
This commit is contained in:
sin 2015-11-10 16:49:13 +08:00 committed by lawrancejing
parent bcf317c33e
commit 246690b51c
3 changed files with 45 additions and 0 deletions

View File

@ -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)

View File

@ -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="<SPEC_FILE>", required=True,
help=_('The spec file used to create the workflow.'))
@utils.arg("name", metavar="<WORKFLOW_NAME>",
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()
})

View File

@ -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 "<Workflow %s>" % 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)