diff --git a/ccnode/host/__init__.py b/ccnode/host/__init__.py index f73d354dc5f370dcaff550513f705fc8e8ec6b58..8a6004679a7ebb84eb840d5df22562e0d0b0bdf8 100644 --- a/ccnode/host/__init__.py +++ b/ccnode/host/__init__.py @@ -1,9 +1,10 @@ import logging import os.path +from itertools import chain, imap from subprocess import Popen, PIPE, STDOUT -from ccnode.node import DefaultHandler from ccnode.tags import Tag, tag_inspector +from ccnode.plugins import Base as BasePlugin from ccnode.host import tags @@ -25,18 +26,27 @@ def disk_tag_value(disk_name): return size -class Handler(DefaultHandler): +class Handler(BasePlugin): """Handler for host role.""" def __init__(self, *args, **kwargs): - DefaultHandler.__init__(self, *args, **kwargs) + BasePlugin.__init__(self, *args, **kwargs) - for t in tag_inspector(tags): - self.tags[t.name] = t + # add plugin tags + self.tag_db['__main__'].update(dict( + (t.name, t) for t in tag_inspector(tags), + )) # disk related tags - for d in self.tags['disk'].value.split(): - t = Tag('disk%s_size' % d, disk_tag_value(d), 60) - self.tags[t.name] = t + self.tag_db['__main__'].update(dict((t.name, t) for t in imap( + lambda d: Tag('disk%s_size' % d, disk_tag_value(d), 60), + self.tag_db['__main__']['disk']._calculate_value().split(), + ))) + + # rpc handler + self.rpc_handler.update(dict( + execute_command=self.execute_command, + node_shutdown=self.node_shutdown, + )) def execute_command(self, command): """Execute an arbitrary shell command on the host. diff --git a/ccnode/host/tags.py b/ccnode/host/tags.py index 61c3a89b511ca8266b855507739b038fcdea4277..19e28f36119957f151795f4829cba7a65293de9b 100644 --- a/ccnode/host/tags.py +++ b/ccnode/host/tags.py @@ -15,6 +15,7 @@ def h(): """Hostname tag.""" return getfqdn() h.ttl = 3600 * 24 # one day +h.refresh = 5 # CPU related tags @@ -42,6 +43,7 @@ def cpuuse(): """CPU usage in percentage.""" return u'%.1f' % psutil.cpu_percent() cpuuse.ttl = 10 +cpuuse.refresh = 2 # memory related tags @@ -55,12 +57,14 @@ def memfree(): """Available physical memory on system.""" return unicode(psutil.avail_phymem()) memfree.ttl = 5 +memfree.refresh = 10 def memused(): """Used physical memory on system.""" return unicode(psutil.used_phymem()) memused.ttl = 5 +memused.refresh = 10 # disks related tags @@ -126,6 +130,7 @@ def uptime(): """Uptime of the system in seconds.""" return open('/proc/uptime').read().split()[0].split(u'.')[0] or None uptime.ttl = 5 +uptime.refresh = 5 def load(): @@ -138,3 +143,4 @@ def load(): pass return load_ load.ttl = 5 +load.refresh = 5