Commit 284053f9 by Bach Dániel

vm: add UpdateNodeOperation

parent c2b89065
......@@ -68,6 +68,8 @@ node_ops = OrderedDict([
op='passivate', icon='play-circle-o', effect='info')),
('disable', NodeOperationView.factory(
op='disable', icon='times-circle-o', effect='danger')),
('update_node', NodeOperationView.factory(
op='update_node', icon='refresh', effect='warning')),
('reset', NodeOperationView.factory(
op='reset', icon='stethoscope', effect='danger')),
('flush', NodeOperationView.factory(
......@@ -26,6 +26,7 @@ from StringIO import StringIO
from tarfile import TarFile, TarInfo
import time
from urlparse import urlsplit
from salt.client import LocalClient
from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.utils import timezone
......@@ -1191,6 +1192,62 @@ class DisableOperation(NodeOperation):
class UpdateNodeOperation(NodeOperation):
id = 'update_node'
name = _("update node")
description = _("Update node.")
required_perms = ()
online_required = False
async_queue = ""
def minion_cmd(self, module, params, timeout=3600):
name =
client = LocalClient()
data = client.cmd(
name, module, timeout=timeout, kwarg={'mods': params})
return data[name]
except KeyError:
raise HumanReadableException.create(ugettext_noop(
"No minions matched the target."))
def _operation(self, activity):
with activity.sub_activity(
readable_name=ugettext_noop('upgrade packages')) as sa:
data = self.minion_cmd('pkg.upgrade', [])
upgraded = len(filter(lambda x: x['old'] and x['new'],
installed = len(filter(lambda x: not x['old'] and x['new'],
removed = len(filter(lambda x: x['old'] and not x['new'],
sa.result = create_readable(ugettext_noop(
"Upgraded: %(upgraded)s, Installed: %(installed)s, "
"Removed: %(removed)s"), upgraded=upgraded,
installed=installed, removed=removed)
data = self.minion_cmd('state.sls', ['node', 'nfs-client'])
failed = 0
for k, v in data.iteritems():
logger.debug('salt state %s %s', k, v)
act_name = ': '.join(k.split('_|-')[:2])
if not v["result"] or v["changes"]:
act = activity.create_sub(
act_name[:70], readable_name=act_name)
act.result = create_readable(ugettext_noop(
"Changes: %(changes)s Comment: %(comment)s"),
changes=v["changes"], comment=v["comment"])
if not v["result"]:
failed += 1
if failed:
raise HumanReadableException.create(ugettext_noop(
"Failed: %(failed)s"), failed=failed)
class ScreenshotOperation(RemoteInstanceOperation):
id = 'screenshot'
name = _("screenshot")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment