Ejemplo n.º 1
0
 def getMachinesSchedulers(self, target):
     """
     Return a deferred object resulting to a scheduler or a list of
     schedulers.
     """
     if type(target[0]
             ) == list:  # target = [[uuid, hostname], [uuid, target]]
         return SchedulerApi().getSchedulers(map(lambda t: t[0], target))
     else:  # target = [uuid, hostname]
         return SchedulerApi().getScheduler(target[0])
Ejemplo n.º 2
0
 def getMachinesSchedulers(self, target):
     """
     Return a deferred object resulting to a scheduler or a list of
     schedulers.
     """
     if not target:  # We can have this case with a convergence command without targets
         return SchedulerApi().getDefaultScheduler()
     elif type(target[0]
               ) == list:  # target = [[uuid, hostname], [uuid, target]]
         return SchedulerApi().getSchedulers(map(lambda t: t[0], target))
     else:  # target = [uuid, hostname]
         return SchedulerApi().getScheduler(target[0])
Ejemplo n.º 3
0
def process_on_client(proposed_scheduler_name, computer, function, *args):
    """
        proposed_scheduler will be used in emergency case
        expected struct for computer (the target):
            [
                None,
                {
                    'macAddress': ['XX:XX:XX:XX:XX:XX'],
                    'displayName': ['NomType=A Dummy Client'],
                    'cn': ['my-short-name'],
                    'objectUUID': ['UUID1234'],
                    'ipHostNumber': ['IP.AD.DR.ES'],
                    'fullname': 'my-fully.qualified.domain.tld'
                }
            ]

        probe is done using available data:
        - uuid
        - fullname
        - cn[]
        - ipHostNumber[]
        - macAddress[]
    """

    def parseResult(result):
        logging.getLogger().debug("%s %s: %s" % (function, computer, result))
        return result

    def parseError(reason):
        if re.compile("Connection was refused by other side: 111").search(str(reason)):
            logging.getLogger().error("%s %s: %s" % (function, computer, "Connection was refused by other side: 111"))
            return 11
        return reason

    def runResult(result):
        # attempt to fall back on something known

        if not result or result == "":
            scheduler_name = proposed_scheduler_name
            if not scheduler_name or scheduler_name == "":
                scheduler_name = MscConfig().default_scheduler
        else:
            scheduler_name = result
        logging.getLogger().debug("got %s as scheduler for client %s" % (scheduler_name, computer[1]["objectUUID"][0]))

        if scheduler_name not in MscConfig().schedulers:
            logging.getLogger().warn("scheduler %s does not exist" % (scheduler_name))
            return twisted.internet.defer.fail(
                twisted.python.failure.Failure("Invalid scheduler %s (does not seem to exist)" % (scheduler_name))
            )

        mydeffered = getProxy(MscConfig().schedulers[scheduler_name]).callRemote(
            function,
            computer[1]["objectUUID"][0],
            computer[1]["fullname"],
            computer[1]["cn"][0],
            computer[1]["ipHostNumber"],
            computer[1]["macAddress"],
            *args
        )
        mydeffered.addCallback(parseResult).addErrback(parseError)
        return mydeffered

    try:
        mydeffered = SchedulerApi().getScheduler(computer[1]["objectUUID"][0])
        mydeffered.addCallback(runResult).addErrback(lambda reason: reason)
        return mydeffered
    except AttributeError:
        return runResult(MscConfig().default_scheduler)
Ejemplo n.º 4
0
def process_on_client(proposed_scheduler_name, computer, function, *args):
    """
        proposed_scheduler will be used in emergency case
        expected struct for computer (the target):
            [
                None,
                {
                    'macAddress': ['XX:XX:XX:XX:XX:XX'],
                    'displayName': ['NomType=A Dummy Client'],
                    'cn': ['my-short-name'],
                    'objectUUID': ['UUID1234'],
                    'ipHostNumber': ['IP.AD.DR.ES'],
                    'fullname': 'my-fully.qualified.domain.tld',
                    'subnetMask': ['SUB.NET.MA.SK']
                }
            ]

        probe is done using available data:
        - uuid
        - fullname
        - cn[]
        - ipHostNumber[]
        - macAddress[]
    """
    def parseResult(result):
        logging.getLogger().debug('%s %s: %s' % (function, computer, result))
        return result

    def parseError(reason):
        if re.compile('Connection was refused by other side: 111').search(
                str(reason)):
            logging.getLogger().error(
                "%s %s: %s" % (function, computer,
                               "Connection was refused by other side: 111"))
            return 11
        return reason

    def runResult(result):
        # attempt to fall back on something known

        if not result or result == '':
            scheduler_name = proposed_scheduler_name
            if not scheduler_name or scheduler_name == '':
                scheduler_name = MscConfig().default_scheduler
        else:
            scheduler_name = result
        logging.getLogger().debug(
            "got %s as scheduler for client %s" %
            (scheduler_name, computer[1]['objectUUID'][0]))

        if scheduler_name not in MscConfig().schedulers:
            logging.getLogger().warn("scheduler %s does not exist" %
                                     (scheduler_name))
            return twisted.internet.defer.fail(
                twisted.python.failure.Failure(
                    "Invalid scheduler %s (does not seem to exist)" %
                    (scheduler_name)))

        mydeffered = getProxy(
            MscConfig().schedulers[scheduler_name]).callRemote(
                function, computer[1]['objectUUID'][0],
                computer[1]['fullname'], computer[1]['cn'][0],
                noNoneList(computer[1]['ipHostNumber']),
                noNoneList(computer[1]['macAddress']),
                noNoneList(computer[1]['subnetMask']), *args)
        mydeffered.addCallback(parseResult).addErrback(parseError)
        return mydeffered

    try:
        mydeffered = SchedulerApi().getScheduler(computer[1]['objectUUID'][0])
        mydeffered.addCallback(runResult).addErrback(lambda reason: reason)
        return mydeffered
    except AttributeError:
        return runResult(MscConfig().default_scheduler)
Ejemplo n.º 5
0
 def _start():
     # Start download process
     mydeffered = SchedulerApi().getScheduler(self.uuid)
     mydeffered.addCallback(
         self._gotScheduler).addErrback(lambda reason: reason)
Ejemplo n.º 6
0
 def _start():
     # Start download process
     mydeffered = SchedulerApi().getScheduler(self.uuid)
     mydeffered.addCallback(self._gotScheduler).addErrback(lambda reason: reason)