ShellBanner
System:Linux MiraNet 3.0.0-14-generic-pae #23-Ubuntu SMP Mon Nov 21 22:07:10 UTC 2011 i686
Software:Apache. PHP/5.3.6-13ubuntu3.10
ID:uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
Safe Mode:OFF
Open_Basedir:OFF
Freespace:21.62 GB of 70.42 GB (30.7%)
MySQL: ON MSSQL: OFF Oracle: OFF PostgreSQL: OFF Curl: OFF Sockets: ON Fetch: OFF Wget: ON Perl: ON
Disabled Functions: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,

/ usr/ share/ pyshared/ landscape/ monitor/ - drwxr-xr-x

Directory:
Viewing file:     hardwareinventory.py (4.41 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
import logging

from twisted.internet.defer import succeed

from landscape.lib.log import log_failure

from landscape.diff import diff
from landscape.monitor.plugin import MonitorPlugin


class HardwareInventory(MonitorPlugin):

    persist_name = "hardware-inventory"

    def __init__(self, hal_manager=None):
        super(HardwareInventory, self).__init__()
        self._persist_sets = []
        self._persist_removes = []
        self.enabled = True
        try:
            from landscape.hal import HALManager
        except ImportError:
            self.enabled = False
        else:
            self._hal_manager = hal_manager or HALManager()

    def register(self, manager):
        if not self.enabled:
            return
        super(HardwareInventory, self).register(manager)
        self.call_on_accepted("hardware-inventory", self.exchange, True)

    def send_message(self, urgent):
        devices = self.create_message()
        if devices:
            message = {"type": "hardware-inventory", "devices": devices}
            result = self.registry.broker.send_message(message, urgent=urgent)
            result.addCallback(self.persist_data)
            result.addErrback(log_failure)
            logging.info("Queueing a message with hardware-inventory "
                         "information.")
        else:
            result = succeed(None)
        return result

    def exchange(self, urgent=False):
        if not self.enabled:
            return
        return self.registry.broker.call_if_accepted("hardware-inventory",
                                                     self.send_message, urgent)

    def persist_data(self, message_id):
        for key, udi, value in self._persist_sets:
            self._persist.set((key, udi), value)
        for key in self._persist_removes:
            self._persist.remove(key)
        del self._persist_sets[:]
        del self._persist_removes[:]
        # This forces the registry to write the persistent store to disk
        # This means that the persistent data reflects the state of the
        # messages sent.
        self.registry.flush()

    def create_message(self):
        # FIXME Using persist to keep track of changes here uses a
        # fair amount of memory.  On my machine a rough test seemed to
        # indicate that memory usage grew by 1.3mb, about 12% of the
        # overall process size.  Look here to save memory.
        del self._persist_sets[:]
        del self._persist_removes[:]
        devices = []
        previous_devices = self._persist.get("devices", {})
        current_devices = set()

        for device in self._hal_manager.get_devices():
            previous_properties = previous_devices.get(device.udi)
            if not previous_properties:
                devices.append(("create", device.properties))
            elif previous_properties != device.properties:
                creates, updates, deletes = diff(previous_properties,
                                                 device.properties)
                devices.append(("update", device.udi,
                                creates, updates, deletes))
            current_devices.add(device.udi)
            self._persist_sets.append(
                ("devices", device.udi, device.properties))

        items_with_parents = {}
        deleted_devices = set()
        for udi, value in previous_devices.iteritems():
            if udi not in current_devices:
                if "info.parent" in value:
                    items_with_parents[udi] = value["info.parent"]
                deleted_devices.add(udi)

        # We remove the deleted devices from our persistent store it's
        # only the information we're sending to the server that we're
        # compressing.
        for udi in deleted_devices:
            self._persist_removes.append(("devices", udi))

        # We can now flatten the list of devices we send to the server
        # For each of the items_with_parents, if both the item and it's parent
        # are in the deleted_devices set, then we can remove this item from the
        # set.
        minimal_deleted_devices = deleted_devices.copy()
        for child, parent in items_with_parents.iteritems():
            if child in deleted_devices and parent in deleted_devices:
                minimal_deleted_devices.remove(child)
        # We now build the deleted devices message
        for udi in minimal_deleted_devices:
            devices.append(("delete", udi))

        return devices
Command:
Quick Commands:
Upload:
[Read-Only] Max size: 100MB
PHP Filesystem: <@ Ú
Search File:
regexp
Create File:
Overwrite [Read-Only]
View File:
Mass Defacement:
[+] Main Directory: [+] Defacement Url:
LmfaoX Shell - Private Build [BETA] - v0.1 -; Generated: 0.2914 seconds