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
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
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
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
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)
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
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
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
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 = ''
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]
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
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))
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]
def get_web_def_attempts_per_day(self): return xmlrpcCleanup(MscConfig().web_def_attempts_per_day)
def get_web_def_coh_life_time(self): return xmlrpcCleanup(MscConfig().web_def_coh_life_time)
def get_web_def_use_no_vnc(self): return xmlrpcCleanup(MscConfig().web_def_use_no_vnc)
def get_web_def_refresh_time(self): return xmlrpcCleanup(MscConfig().web_def_refresh_time)
def get_web_def_vnc_show_icon(self): return xmlrpcCleanup(MscConfig().web_vnc_show_icon)
def get_web_def_proxy_selection_mode(self): return xmlrpcCleanup(MscConfig().web_def_proxy_selection_mode)
def get_web_def_proxy_number(self): return xmlrpcCleanup(MscConfig().web_def_proxy_number)
def get_web_def_max_clients_per_proxy(self): return xmlrpcCleanup(MscConfig().web_def_max_clients_per_proxy)
def get_web_def_deployment_intervals(self): return xmlrpcCleanup(MscConfig().web_def_deployment_intervals)
def get_web_def_allow_local_proxy(self): return xmlrpcCleanup(MscConfig().web_allow_local_proxy)
def get_web_def_vnc_allow_user_control(self): return xmlrpcCleanup(MscConfig().web_vnc_allow_user_control)
def get_web_def_vnc_network_connectivity(self): return xmlrpcCleanup(MscConfig().web_vnc_network_connectivity)
def get_web_def_allow_delete(self): return xmlrpcCleanup(MscConfig().web_def_allow_delete)
def get_web_def_issue_halt_to(self): return xmlrpcCleanup(MscConfig().web_def_issue_halt_to)
def get_web_def_show_reboot(self): return xmlrpcCleanup(MscConfig().web_show_reboot)
def __init__(self, filename): self.filename = filename self.fullfilename = os.path.join(MscConfig().qactionspath, filename) self.result = {} self._parse()
def get_web_def_probe_order_on_demand(self): return xmlrpcCleanup(MscConfig().web_probe_order_on_demand)
def get_web_def_local_proxy_mode(self): return xmlrpcCleanup(MscConfig().web_def_local_proxy_mode)
def get_web_def_vnc_view_only(self): return xmlrpcCleanup(MscConfig().web_vnc_view_only)