def send_special_data(): (remote_url, uid) = get_url_and_uid() remote = BibOSAdmin(remote_url) remote.push_config_keys(uid, { "_os2borgerpc.client_version": BIBOS_CLIENT_VERSION })
def send_security_events(now): (remote_url, uid) = get_url_and_uid() remote = BibOSAdmin(remote_url) try: securitycheck_file = open(SECURITY_DIR + "/security_check_" + now + ".csv", "r") except IOError: # File does not exist. No events occured, since last check. return False csv_data = [line for line in securitycheck_file] securitycheck_file.close() try: result = remote.push_security_events(uid, csv_data) if result == 0: check_file = open(SECURITY_DIR + "/lastcheck.txt", "w") check_file.write(now) check_file.close() os.remove(SECURITY_DIR + "/securityevent.csv") return result except Exception as e: print >> os.sys.stderr, "Error while sending security events:" + str(e) return False finally: os.remove(SECURITY_DIR + "/security_check_" + now + ".csv")
def report_job_results(joblist): (remote_url, uid) = get_url_and_uid() remote = BibOSAdmin(remote_url) remote.send_status_info(uid, None, joblist, update_required=check_outstanding_packages())
def get_instructions(): (remote_url, uid) = get_url_and_uid() remote = BibOSAdmin(remote_url) tmpfilename, updated_pkgs, removed_pkgs = get_local_package_diffs() try: instructions = remote.get_instructions(uid, { 'updated_packages': updated_pkgs, 'removed_packages': removed_pkgs }) # Everything went well, overwrite old package list if tmpfilename: subprocess.call(['mv', tmpfilename, PACKAGE_LIST_FILE]) except Exception as e: print >>os.sys.stderr, "Error while getting instructions:" + str(e) if tmpfilename: subprocess.call(['rm', tmpfilename]) return False if 'configuration' in instructions: # Update configuration bibos_config = BibOSConfig() local_config = {} for key, value in bibos_config.get_data().items(): # We only care about string values if isinstance(value, basestring): local_config[key] = value for key, value in instructions['configuration'].items(): bibos_config.set_value(key, value) if key in local_config: del local_config[key] # Anything left in local_config needs to be removed for key in local_config.keys(): bibos_config.remove_key(key) bibos_config.save() # Import jobs if 'jobs' in instructions: for j in instructions['jobs']: local_job = LocalJob(data=j) local_job.save() local_job.logline("Job imported at %s" % datetime.datetime.now()) if ('do_send_package_info' in instructions and instructions['do_send_package_info']): try: # Send full package info to server. upload_packages() except Exception as e: print >>os.sys.stderr, "Package upload failed" + str(e)
def get_instructions(): (remote_url, uid) = get_url_and_uid() remote = BibOSAdmin(remote_url) tmpfilename, updated_pkgs, removed_pkgs = get_local_package_diffs() try: instructions = remote.get_instructions(uid, { 'updated_packages': updated_pkgs, 'removed_packages': removed_pkgs }) # Everything went well, overwrite old package list if tmpfilename: subprocess.call(['mv', tmpfilename, PACKAGE_LIST_FILE]) except Exception as e: print >> os.sys.stderr, "Error while getting instructions:" + str(e) if tmpfilename: subprocess.call(['rm', tmpfilename]) # No instructions likely = no network. Do not continue. raise if 'configuration' in instructions: # Update configuration bibos_config = BibOSConfig() local_config = {} for key, value in bibos_config.get_data().items(): # We only care about string values if isinstance(value, basestring): local_config[key] = value for key, value in instructions['configuration'].items(): bibos_config.set_value(key, value) if key in local_config: del local_config[key] # Anything left in local_config needs to be removed for key in local_config.keys(): bibos_config.remove_key(key) bibos_config.save() # Import jobs if 'jobs' in instructions: for j in instructions['jobs']: local_job = LocalJob(data=j) local_job.save() local_job.logline("Job imported at %s" % datetime.now()) # if security dir exists if os.path.isdir(SECURITY_DIR): # Always remove old security scripts. # Could be pc is moved to another group, # and does not need security scripts any more. os.popen('rm -f ' + SECURITY_DIR + '/s_*') # Import security scripts if 'security_scripts' in instructions: for s in instructions['security_scripts']: fpath = SECURITY_DIR + '/s_' + str(s['name']).replace(' ', '') fh = open(fpath, 'w') fh.write(s['executable_code'].encode("utf8")) fh.close() os.chmod(fpath, stat.S_IRWXU) if ('do_send_package_info' in instructions and instructions['do_send_package_info']): try: # Send full package info to server. upload_packages() except Exception as e: print >> os.sys.stderr, "Package upload failed" + str(e)
def send_special_data(): (remote_url, uid) = get_url_and_uid() remote = BibOSAdmin(remote_url) remote.push_config_keys( uid, {"_os2borgerpc.client_version": BIBOS_CLIENT_VERSION})