Ejemplo n.º 1
0
def activate():
    """
    Run some tests to ensure the module is ready to operate.
    """
    config = MscConfig()
    config.init("msc")
    logger = logging.getLogger()
    if config.disable:
        logger.warning("Plugin msc: disabled by configuration.")
        return False

    if not os.path.isdir(config.qactionspath):
        logger.error(
            "Quick Actions config is invalid: %s is not a directory. Please check msc.ini."
            % config.qactionspath)
        return False

    if not MscDatabase().activate(config):
        return False

    if config.check_db_enable:
        scheduleCheckStatus(config.check_db_interval)

    # Add convergence reschedule task in the task manager
    TaskManager().addTask("msc.convergence_reschedule",
                          (convergence_reschedule, ),
                          cron_expression=config.convergence_reschedule)
    return True
Ejemplo n.º 2
0
    def __init__(self):
        if self.initialized: return
        self.logger = logging.getLogger()
        self.logger.debug("Going to initialize SchedulerApi")
        self.config = MscConfig()
        credentials = ''

        if self.config.sa_enable:
            if self.config.sa_enablessl:
                self.server_addr = 'https://'
            else:
                self.server_addr = 'http://'

            if self.config.sa_username != '':
                self.server_addr += self.config.sa_username
                credentials = self.config.sa_username
                if self.config.sa_password != '':
                    self.server_addr += ":"+self.config.sa_password
                    credentials += ":"+self.config.sa_password
                self.server_addr += "@"

            self.server_addr += self.config.sa_server+':'+str(self.config.sa_port) + self.config.sa_mountpoint
            self.logger.debug('SchedulerApi will connect to %s' % (self.server_addr))

            if self.config.sa_verifypeer:
                self.internal = pulse2.apis.clients.scheduler_api.SchedulerApi(MscConfig().default_scheduler, credentials, self.server_addr, self.config.sa_verifypeer, self.config.sa_cacert, self.config.sa_localcert)
            else:
                self.internal = pulse2.apis.clients.scheduler_api.SchedulerApi(MscConfig().default_scheduler, credentials, self.server_addr)
                
        for method in ('getScheduler', 'getSchedulers', 'getDefaultScheduler'):
            setattr(self, method, getattr(self.internal, method))

        self.internal.setConfig(self.config)
        self.initialized = True
Ejemplo n.º 3
0
def activate():
    """
    Run some tests to ensure the module is ready to operate.
    """
    config = MscConfig()
    config.init("msc")
    logger = logging.getLogger()
    if config.disable:
        logger.warning("Plugin msc: disabled by configuration.")
        return False

    if not os.path.isdir(config.qactionspath):
        logger.error("Quick Actions config is invalid: %s is not a directory. Please check msc.ini." % config.qactionspath)
        return False

    if not MscDatabase().activate(config):
        return False

    if config.check_db_enable:
        scheduleCheckStatus(config.check_db_interval)

    # Add convergence reschedule task in the task manager
    TaskManager().addTask("msc.convergence_reschedule",
                          (convergence_reschedule,),
                          cron_expression=config.convergence_reschedule)
    return True
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    def _gotScheduler(self, result):
        """
        Called when a scheduler has been found to start the download
        """
        if not result:
            scheduler_name = MscConfig().default_scheduler
        else:
            scheduler_name = result
        if scheduler_name not in MscConfig().schedulers:
            return twisted.internet.defer.fail(
                twisted.python.failure.Failure("scheduler %s does not exist" %
                                               (scheduler_name)))

        # Create the lock file
        f = file(self.lockfile, 'w+')
        f.close()
        # Start download process
        d = getProxy(MscConfig().schedulers[scheduler_name]).callRemote(
            'download_file', self.computer[1]['objectUUID'][0],
            self.computer[1]['fullname'], self.computer[1]['cn'][0],
            self.computer[1]['ipHostNumber'], self.computer[1]['macAddress'],
            self.dlpath, self.bwlimit)
        # Add callback
        d.addCallback(self._cbDownloadOk).addErrback(self._cbDownloadErr)
        d.addBoth(self._cbDownloadCleanup)
Ejemplo n.º 6
0
def activate_2():
    conf = MscConfig()
    conf.init('msc')
    dldir = conf.download_directory_path
    # Clean all lock or error status file in the download directory pool
    if os.path.exists(dldir):
        logging.getLogger().info('Cleaning lock file in %s' % dldir)
        for root, dirs, files in os.walk(dldir):
            for name in files:
                if name.endswith(MscDownloadedFiles.LOCKEXT) or name.endswith(MscDownloadedFiles.ERROREXT):
                    os.remove(os.path.join(root, name))
    return True
Ejemplo n.º 7
0
def create_update_command(ctx, target, update_list, gid=None):
    """
    Create the Windows Update command.

    @param target: list of target UUIDs
    @type target: list

    @param update_list: list of KB numbers to install
    @type update_list: list

    @param gid: group id - if not None, apply command to a group of machine
    @type gid: str

    @return: command id
    @rtype: Deferred
    """
    if update_list:
        cmd = "%s -i %s" % (MscConfig().wu_command, " ".join(update_list))
    else:
        cmd = ''
    cmd = cmd + ("\n%s -l --json" % MscConfig().wu_command)
    desc = "Install Windows Updates"

    if gid:
        target = ComputerGroupManager().get_group_results(
            ctx, gid, 0, -1, '', True)

    do_wol = "disable"
    if MscConfig().web_def_awake == 1:
        do_wol = "enable"

    # set end_date to now() + 24H Refs #2313
    fmt = "%Y-%m-%d %H:%M:%S"
    end_date = (datetime.datetime.now() +
                datetime.timedelta(days=1)).strftime(fmt)

    d = defer.maybeDeferred(MscDatabase().addCommand,
                            ctx,
                            None,
                            cmd,
                            "", [],
                            target,
                            'push',
                            gid,
                            end_date=end_date,
                            title=desc,
                            do_wol=do_wol,
                            do_windows_update="enable",
                            cmd_type=4)

    d.addCallback(xmlrpcCleanup)

    return d
Ejemplo n.º 8
0
def activate_2():
    conf = MscConfig()
    conf.init('msc')
    dldir = conf.download_directory_path
    # Clean all lock or error status file in the download directory pool
    if os.path.exists(dldir):
        logging.getLogger().info('Cleaning lock file in %s' % dldir)
        for root, dirs, files in os.walk(dldir):
            for name in files:
                if name.endswith(MscDownloadedFiles.LOCKEXT) or name.endswith(MscDownloadedFiles.ERROREXT):
                    os.remove(os.path.join(root, name))
    return True
Ejemplo n.º 9
0
 def download_file(self, uuid):
     path = MscConfig().web_dlpath
     ctx = self.currentContext
     if not path:
         ret = False
     else:
         bwlimit = MscConfig().web_def_dlmaxbw
         ctx = self.currentContext
         computer = ComputerManager().getComputer(ctx, {'uuid': uuid}, True)
         try:  # FIXME: dirty bugfix, should be factorized upstream
             computer[1]['fullname']
         except KeyError:
             computer[1]['fullname'] = computer[1]['cn'][0]
         mscdlp = MscDownloadProcess(ctx.userid, computer, path, bwlimit)
         ret = mscdlp.startDownload()
     return ret
Ejemplo n.º 10
0
 def __init__(self, h_params):
     self.config = MscConfig()
     self.logger = logging.getLogger()
     self.logger.debug("new machine: |%s|" % h_params)
     self.ip = None
     try:
         self.hostname = h_params['cn']
     except:
         try:
             self.hostname = h_params['hostname'][0]
         except:
             self.hostname = '???'
     try:
         self.uuid = h_params['objectUUID'][0]
     except:
         self.uuid = None
     try:
         self.displayname = h_params['displayName'][0]
     except:
         self.displayname = self.hostname
     try:
         self.fullname = h_params['fullname']
     except:
         self.fullname = self.hostname
     self.platform = ''
Ejemplo n.º 11
0
def qa_detailled_info(filename):
    path = MscConfig().qactionspath
    if not os.path.exists(os.path.join(path, filename)):
        return [False, "This quick action don't exists!", filename]

    qa = Qaction(filename)
    qa = qa.read()
    return [True, qa]
Ejemplo n.º 12
0
def activate():
    """
    Run some tests to ensure the module is ready to operate.
    """
    config = MscConfig()
    config.init("msc")
    logger = logging.getLogger()
    if config.disable:
        logger.warning("Plugin msc: disabled by configuration.")
        return False

    if not os.path.isdir(config.qactionspath):
        logger.error("Quick Actions config is invalid: %s is not a directory. Please check msc.ini." % config.qactionspath)
        return False

    if not MscDatabase().activate(config):
        return False

    return True
Ejemplo n.º 13
0
 def establish_vnc_proxy(self, scheduler, uuid, requestor_ip):
     ctx = self.currentContext
     computer = ComputerManager().getComputer(ctx, {'uuid': uuid}, True)
     try:  # FIXME: dirty bugfix, should be factorized upstream
         computer[1]['fullname']
     except KeyError:
         computer[1]['fullname'] = computer[1]['cn'][0]
     return xmlrpcCleanup(
         mmc.plugins.msc.client.scheduler.tcp_sproxy(
             scheduler, computer, requestor_ip,
             MscConfig().web_vnc_port))
Ejemplo n.º 14
0
def qa_list_files():
    path = MscConfig().qactionspath
    if not os.path.exists(path):
        return [False, "Quick action path don't exists", path]

    result = {}
    d = dircache.listdir(path)
    d = d[:]

    for filename in dircache.listdir(path):
        if filename != '..' and filename != '.' and os.path.exists(
                os.path.join(
                    path, filename)) and re.compile('\.msc$').search(filename):
            result[filename] = Qaction(filename).read()

    return [True, result]
Ejemplo n.º 15
0
 def get_web_def_attempts_per_day(self):
     return xmlrpcCleanup(MscConfig().web_def_attempts_per_day)
Ejemplo n.º 16
0
 def get_web_def_coh_life_time(self):
     return xmlrpcCleanup(MscConfig().web_def_coh_life_time)
Ejemplo n.º 17
0
 def get_web_def_use_no_vnc(self):
     return xmlrpcCleanup(MscConfig().web_def_use_no_vnc)
Ejemplo n.º 18
0
 def get_web_def_refresh_time(self):
     return xmlrpcCleanup(MscConfig().web_def_refresh_time)
Ejemplo n.º 19
0
 def get_web_def_vnc_show_icon(self):
     return xmlrpcCleanup(MscConfig().web_vnc_show_icon)
Ejemplo n.º 20
0
 def get_web_def_proxy_selection_mode(self):
     return xmlrpcCleanup(MscConfig().web_def_proxy_selection_mode)
Ejemplo n.º 21
0
 def get_web_def_proxy_number(self):
     return xmlrpcCleanup(MscConfig().web_def_proxy_number)
Ejemplo n.º 22
0
 def get_web_def_max_clients_per_proxy(self):
     return xmlrpcCleanup(MscConfig().web_def_max_clients_per_proxy)
Ejemplo n.º 23
0
 def get_web_def_deployment_intervals(self):
     return xmlrpcCleanup(MscConfig().web_def_deployment_intervals)
Ejemplo n.º 24
0
 def get_web_def_allow_local_proxy(self):
     return xmlrpcCleanup(MscConfig().web_allow_local_proxy)
Ejemplo n.º 25
0
 def get_web_def_vnc_allow_user_control(self):
     return xmlrpcCleanup(MscConfig().web_vnc_allow_user_control)
Ejemplo n.º 26
0
 def get_web_def_vnc_network_connectivity(self):
     return xmlrpcCleanup(MscConfig().web_vnc_network_connectivity)
Ejemplo n.º 27
0
 def get_web_def_allow_delete(self):
     return xmlrpcCleanup(MscConfig().web_def_allow_delete)
Ejemplo n.º 28
0
 def get_web_def_issue_halt_to(self):
     return xmlrpcCleanup(MscConfig().web_def_issue_halt_to)
Ejemplo n.º 29
0
 def get_web_def_show_reboot(self):
     return xmlrpcCleanup(MscConfig().web_show_reboot)
Ejemplo n.º 30
0
 def __init__(self, filename):
     self.filename = filename
     self.fullfilename = os.path.join(MscConfig().qactionspath, filename)
     self.result = {}
     self._parse()
Ejemplo n.º 31
0
 def get_web_def_probe_order_on_demand(self):
     return xmlrpcCleanup(MscConfig().web_probe_order_on_demand)
Ejemplo n.º 32
0
 def get_web_def_local_proxy_mode(self):
     return xmlrpcCleanup(MscConfig().web_def_local_proxy_mode)
Ejemplo n.º 33
0
 def get_web_def_vnc_view_only(self):
     return xmlrpcCleanup(MscConfig().web_vnc_view_only)