K2LL33D SHELL

 Apache/2.4.7 (Ubuntu)
 Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64
 uid=33(www-data) gid=33(www-data) groups=33(www-data)
 safemode : OFF
 MySQL: ON | Perl: ON | cURL: OFF | WGet: ON
  >  / usr / lib / python2.7 / dist-packages / landscape / manager /
server ip : 172.67.156.115

your ip : 172.69.6.9

H O M E


Filename/usr/lib/python2.7/dist-packages/landscape/manager/plugin.py
Size1.97 kb
Permissionrw-r--r--
Ownerroot : root
Create time27-Apr-2025 09:56
Last modified20-Feb-2014 23:01
Last accessed06-Jul-2025 19:58
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
from twisted.internet.defer import maybeDeferred

from landscape.lib.log import log_failure
from landscape.log import format_object
from landscape.broker.client import BrokerClientPlugin

# Protocol messages! Same constants are defined in the server.
FAILED = 5
SUCCEEDED = 6


class ManagerPlugin(BrokerClientPlugin):

@property
def manager(self):
"""An alias for the C{client} attribute}."""
return self.client

def call_with_operation_result(self, message, callable, *args, **kwargs):
"""Send an operation-result message after calling C{callable}.

If the function returns normally, an operation-result
indicating success will be sent. If the function raises an
exception, an operation-result indicating failure will be
sent.

The function can also return a C{Deferred}, and the behavior above
still applies.

@param message: The original message.
@param callable: The function to call to handle the message.
C{args} and C{kwargs} are passed to it.
"""
deferred = maybeDeferred(callable, *args, **kwargs)

def success(text):
return SUCCEEDED, text

def failure(failure):
text = "%s: %s" % (failure.type.__name__, failure.value)
msg = ("Error occured running message handler %s with "
"args %r %r.", format_object(callable), args, kwargs)
log_failure(failure, msg=msg)
return FAILED, text

def send((status, text)):
result = {"type": "operation-result",
"status": status,
"operation-id": message["operation-id"]}
if text:
result["result-text"] = text
return self.manager.broker.send_message(
result, self._session_id, urgent=True)

deferred.addCallback(success)
deferred.addErrback(failure)
deferred.addCallback(send)

return deferred