Skip to content

Commit

Permalink
[Group] Add Edit method for groups (close #22)
Browse files Browse the repository at this point in the history
Sync the command options for groups with other methods.
Name, appnaem, weight are now specified by options, not
positional arguments
  • Loading branch information
noxiouz committed Jun 12, 2015
1 parent b0b9c0d commit 1ea57b2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
10 changes: 3 additions & 7 deletions cocaine/tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@


class ToolHandler(object):
def __init__(self, Action):
self._Action = Action
def __init__(self, action):
self._Action = action

@coroutine
def execute(self, **config):
Expand Down Expand Up @@ -158,6 +158,7 @@ def _processResult(self, result):
'group:app:remove': ToolHandler(group.RemoveApplication),
'group:create': ToolHandler(group.Create),
'group:copy': ToolHandler(group.Copy),
'group:edit': ToolHandler(interactive.GroupEditor),
'group:list': JsonToolHandler(group.List),
'group:remove': ToolHandler(group.Remove),
'group:rename': ToolHandler(group.Rename),
Expand Down Expand Up @@ -201,8 +202,3 @@ def executeAction(self, actionName, **options):

action = NG_ACTIONS[actionName]
self.loop.run_sync(lambda: action.execute(**options), timeout=self.timeout)

def timeoutErrorback(self):
log.error('Timeout')
self.loop.stop()
exit(errno.ETIMEDOUT)
28 changes: 18 additions & 10 deletions cocaine/tools/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def group_list(options):

@dispatcher.group.command(name='view', usage='NAME')
def group_view(options,
name):
name=('n', '', 'group name')):
"""Show specified routing group.
"""
options.executor.executeAction('group:view', **{
Expand All @@ -664,7 +664,7 @@ def group_view(options,

@dispatcher.group.command(name='create', usage='NAME [CONTENT]')
def group_create(options,
name,
name=('n', '', 'group name'),
content=None):
"""Create routing group.
Expand Down Expand Up @@ -734,11 +734,11 @@ def group_refresh(options,
})


@dispatcher.group.command(name='push', usage='NAME APP WEIGHT')
@dispatcher.group.command(name='push', usage='-n=NAME --app=APP -w=WEIGHT')
def group_push(options,
name,
app,
weight):
name=('n', '', 'group name'),
app=('', '', 'app name'),
weight=('w', '', 'weight')):
"""Add application with its weight into the routing group.
Warning: application weight must be positive integer.
Expand All @@ -751,10 +751,10 @@ def group_push(options,
})


@dispatcher.group.command(name='pop', usage='NAME APP')
@dispatcher.group.command(name='pop', usage='-n NAME --app=APP')
def group_pop(options,
name,
app):
name=('n', '', 'group name'),
app=('', '', 'app name')):
"""Remove application from routing group.
"""
options.executor.executeAction('group:app:remove', **{
Expand All @@ -764,7 +764,15 @@ def group_pop(options,
})


DEFAULT_COCAINE_PROXY_PID_FILE = '/var/run/cocaine-python-proxy.pid'
@dispatcher.group.command(name='edit', usage='-n NAME')
def group_edit(options,
name=('n', '', 'group name')):
"""Edit group in an interactive editor"""
options.executor.timeout = None
options.executor.executeAction('group:edit', **{
'storage': options.getService('storage'),
'name': name,
})


# @proxyDispatcher.command()
Expand Down
16 changes: 14 additions & 2 deletions cocaine/tools/interactive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import tempfile

from cocaine.decorators import coroutine
from cocaine.tools.printer import printer
from cocaine.tools.actions import runlist
from cocaine.tools.actions import group
from cocaine.tools.actions import profile
from cocaine.tools.actions import runlist
from cocaine.tools.helpers.editor import locate_editor
from cocaine.tools.printer import printer


__author__ = 'Evgeny Safronov <division494@gmail.com>'
Expand Down Expand Up @@ -103,3 +104,14 @@ def view(self):

def upload(self, data):
return profile.Upload(self.storage, self.name, data).execute()


class GroupEditor(BaseEditor, group.Specific):
def __init__(self, *args, **kwargs):
super(GroupEditor, self).__init__(*args, **kwargs)

def view(self):
return group.View(self.storage, self.name).execute()

def upload(self, data):
return group.Create(self.storage, self.name, data).execute()

0 comments on commit 1ea57b2

Please sign in to comment.