def sendPackages(systemId, packageList): s = rhnserver.RhnServer() if not s.capabilities.hasCapability('xmlrpc.packages.extended_profile', 2): # for older satellites and hosted - convert to old format packageList = convertPackagesFromHashToList(packageList) s.registration.add_packages(systemId, packageList)
def listPackages(systemId): s = rhnserver.RhnServer() print(s.registration.list_packages,systemId())
def getCaps(): s = rhnserver.RhnServer() # figure out if were missing any needed caps s.capabilities.validate()
def reserveUser(username, password): s = rhnserver.RhnServer() return s.registration.reserve_user(username, password)
def read_cpuinfo(): def get_entry(a, entry): e = entry.lower() if not e in a: return "" return a[e] # read cpu list and return number of cpus and list as dictionary def get_cpulist_as_dict(cpulist): count = 0 tmpdict = {} for cpu in cpulist.split("\n\n"): if not len(cpu): continue count = count + 1 if count > 1: break # no need to parse rest for cpu_attr in cpu.split("\n"): if not len(cpu_attr): continue vals = cpu_attr.split(":") if len(vals) != 2: # XXX: make at least some effort to recover this data... continue name, value = vals[0].strip(), vals[1].strip() tmpdict[name.lower()] = value return tmpdict if not os.access("/proc/cpuinfo", os.R_OK): return {} # Okay, the kernel likes to give us the information we need in the # standard "C" locale. if locale: # not really needed if you don't plan on using atof() locale.setlocale(locale.LC_NUMERIC, "C") cpulist = open("/proc/cpuinfo", "r").read() uname = os.uname()[4].lower() count = cpu_count() # This thing should return a hwdict that has the following # members: # # class, desc (required to identify the hardware device) # count, type, model, model_number, model_ver, model_rev # bogomips, platform, speed, cache hwdict = { 'class': "CPU", "desc": "Processor", } if uname[0] == "i" and uname[-2:] == "86" or (uname == "x86_64"): # IA32 compatible enough tmpdict = get_cpulist_as_dict(cpulist) if uname == "x86_64": hwdict['platform'] = 'x86_64' else: hwdict['platform'] = "i386" hwdict['count'] = count hwdict['type'] = get_entry(tmpdict, 'vendor_id') hwdict['model'] = get_entry(tmpdict, 'model name') hwdict['model_number'] = get_entry(tmpdict, 'cpu family') hwdict['model_ver'] = get_entry(tmpdict, 'model') hwdict['model_rev'] = get_entry(tmpdict, 'stepping') hwdict['cache'] = get_entry(tmpdict, 'cache size') hwdict['bogomips'] = get_entry(tmpdict, 'bogomips') hwdict['other'] = get_entry(tmpdict, 'flags') mhz_speed = get_entry(tmpdict, 'cpu mhz') if mhz_speed == "": # damn, some machines don't report this mhz_speed = "-1" try: hwdict['speed'] = int(round(float(mhz_speed)) - 1) except ValueError: hwdict['speed'] = -1 elif uname in ["alpha", "alphaev6"]: # Treat it as an an Alpha tmpdict = get_cpulist_as_dict(cpulist) hwdict['platform'] = "alpha" hwdict['count'] = get_entry(tmpdict, 'cpus detected') hwdict['type'] = get_entry(tmpdict, 'cpu') hwdict['model'] = get_entry(tmpdict, 'cpu model') hwdict['model_number'] = get_entry(tmpdict, 'cpu variation') hwdict['model_version'] = "%s/%s" % (get_entry( tmpdict, 'system type'), get_entry(tmpdict, 'system variation')) hwdict['model_rev'] = get_entry(tmpdict, 'cpu revision') hwdict['cache'] = "" # pitty the kernel doesn't tell us this. hwdict['bogomips'] = get_entry(tmpdict, 'bogomips') hwdict['other'] = get_entry(tmpdict, 'platform string') hz_speed = get_entry(tmpdict, 'cycle frequency [Hz]') # some funky alphas actually report in the form "462375000 est." hz_speed = hz_speed.split() try: hwdict['speed'] = int(round(float(hz_speed[0]))) / 1000000 except ValueError: hwdict['speed'] = -1 elif uname in ["ia64"]: tmpdict = get_cpulist_as_dict(cpulist) hwdict['platform'] = uname hwdict['count'] = count hwdict['type'] = get_entry(tmpdict, 'vendor') hwdict['model'] = get_entry(tmpdict, 'family') hwdict['model_ver'] = get_entry(tmpdict, 'archrev') hwdict['model_rev'] = get_entry(tmpdict, 'revision') hwdict['bogomips'] = get_entry(tmpdict, 'bogomips') mhz_speed = tmpdict['cpu mhz'] try: hwdict['speed'] = int(round(float(mhz_speed)) - 1) except ValueError: hwdict['speed'] = -1 hwdict['other'] = get_entry(tmpdict, 'features') elif uname in ['ppc64']: tmpdict = get_cpulist_as_dict(cpulist) hwdict['platform'] = uname hwdict['count'] = count hwdict['model'] = get_entry(tmpdict, "cpu") hwdict['model_ver'] = get_entry(tmpdict, 'revision') hwdict['bogomips'] = get_entry(tmpdict, 'bogomips') hwdict['type'] = get_entry(tmpdict, 'machine') # strings are postpended with "mhz" mhz_speed = get_entry(tmpdict, 'clock')[:-3] try: hwdict['speed'] = int(round(float(mhz_speed)) - 1) except ValueError: hwdict['speed'] = -1 elif uname in ['s390', 's390x']: tmpdict = {} for cpu in cpulist.split("\n"): vals = cpu.split(": ") if len(vals) != 2: continue tmpdict[vals[0].strip()] = vals[1].strip() hwdict['platform'] = uname hwdict['type'] = get_entry(tmpdict, 'vendor_id') hwdict['model'] = uname hwdict['count'] = count hwdict['bogomips'] = get_entry(tmpdict, 'bogomips per cpu') hwdict['model_number'] = "" hwdict['model_ver'] = "" hwdict['model_rev'] = "" hwdict['cache'] = "" hwdict['other'] = get_entry(tmpdict, 'features') hwdict['speed'] = 0 else: # XXX: expand me. Be nice to others hwdict['platform'] = uname hwdict['count'] = count hwdict['type'] = uname hwdict['model'] = uname hwdict['model_number'] = "" hwdict['model_ver'] = "" hwdict['model_rev'] = "" hwdict['cache'] = "" hwdict['bogomips'] = "" hwdict['other'] = "" hwdict['speed'] = 0 # make sure we get the right number here if not hwdict["count"]: hwdict["count"] = 1 else: try: hwdict["count"] = int(hwdict["count"]) except: hwdict["count"] = 1 else: if hwdict["count"] == 0: # we have at least one hwdict["count"] = 1 # Network communication doesn't really belong in here. Sadly though # this is the only single place we can put this check. If it's not # here then it would need to be in five or six other places, which # is not good from a DRY and quality-assurance perspective. s = rhnserver.RhnServer() if s.capabilities.hasCapability('cpu_sockets'): # If we know it add in the number of sockets number_sockets = __get_number_sockets() if number_sockets: hwdict['socket_count'] = number_sockets # This whole things hurts a lot. return hwdict
def welcomeText(): s = rhnserver.RhnServer() return s.registration.welcome_message()
def __getErrataInfo(errata_id): s = rhnserver.RhnServer() return s.errata.getErrataInfo(up2dateAuth.getSystemId(), errata_id)
def hasChannelChecksumCapability(rpc_server): """ check whether server supports getPackageChecksumBySession function""" server = rhnserver.RhnServer() # pylint: disable=W0212 server._server = rpc_server return server.capabilities.hasCapability('xmlrpc.packages.checksums')
def report(problem_dir): problem_dir = os.path.normpath(os.path.abspath(problem_dir)) basename = os.path.basename(problem_dir) log = up2dateLog.initLog() if not (os.path.exists(problem_dir) and os.path.isdir(problem_dir)): log.log_me("The specified path [%s] is not a valid directory." % problem_dir) return -1 crash_items = ['analyzer', 'cmdline', 'reason'] if os.path.exists(os.path.join(problem_dir, 'vmcore')): crash_items = ['analyzer', 'vmcore-dmesg.txt'] for item in crash_items: item_path = os.path.join(problem_dir, item) if not os.path.exists(item_path): log.log_me("Crash directory [%s] is incomplete or invalid" % problem_dir) return -1 server = rhnserver.RhnServer() if not server.capabilities.hasCapability('abrt'): return -1 systemid = up2dateAuth.getSystemId() # Package information pkg_data = {} for item in ['package', 'pkg_name', 'pkg_epoch', 'pkg_version', 'pkg_release', 'pkg_arch']: pkg_item_path = os.path.join(problem_dir, item) if os.path.exists(pkg_item_path): filecontent = _readline(pkg_item_path) if filecontent: pkg_data[item] = filecontent # Crash information crash_data = {'crash': basename, 'path': problem_dir} # Crash count crash_count = _readline(os.path.join(problem_dir, 'count')) if crash_count: crash_data['count'] = crash_count # Create record about the crash r = server.abrt.create_crash(systemid, crash_data, pkg_data) if (r < 0): # Error creating new crash report log.log_me("Error creating new crash report.") return -1 # Upload every particular file in the problem directory to the server for i in os.listdir(problem_dir): path = os.path.join(problem_dir, i) if not os.path.isfile(path): continue filesize = os.stat(path).st_size crash_file_data = {'filename': os.path.basename(i), 'path': path, 'filesize': filesize, 'filecontent': base64.encodestring(""), 'content-encoding': 'base64'} if server.abrt.is_crashfile_upload_enabled(systemid) and filesize <= server.abrt.get_crashfile_uploadlimit(systemid): f = open(path, 'r') try: crash_file_data['filecontent'] = base64.encodestring(f.read()) finally: f.close() server.abrt.upload_crash_file(systemid, basename, crash_file_data) return 1
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. from __future__ import print_function import sys # Once we have the up2date stuff in a site-packages, # we won't have to do path magic. import warnings warnings.filterwarnings("ignore", message='the md5 module is deprecated; use hashlib instead') sys.path.append("/usr/share/rhn/") from up2date_client import up2dateAuth from up2date_client import up2dateErrors from up2date_client import rhnserver from up2date_client import pkgUtils if __name__ == '__main__': systemid = up2dateAuth.getSystemId() if systemid: try: print("Apt-Spacewalk: Updating package profile") s = rhnserver.RhnServer() s.registration.update_packages(systemid, pkgUtils.getInstalledPackageList(getArch=1)) except up2dateErrors.RhnServerException as e: print("Package profile information could not be sent.") print(str(e))
def registerSystem2(username=None, password=None, profileName=None, packages=None, activationKey=None, other={}): """Uses the new xmlrpcs to register a system. Returns a dict instead of just system id. The main differences between this and registerSystem and that this doesn't do activation and does child channel subscriptions if possible. See the documentation for the xmlrpc handlers in backend for more detail. If nothing is going to be in other, it can be {} or None. New in RHEL 5. """ if other is None: other = {} if activationKey: assert username is None assert password is None assert activationKey is not None else: assert username is not None assert password is not None assert activationKey is None for key in other.keys(): assert key in [ 'registration_number', 'org_id', 'virt_uuid', 'virt_type', 'channel' ] if cfg['supportsSMBIOS']: other["smbios"] = _encode_characters(hardware.get_smbios()) s = rhnserver.RhnServer() registerSystemAddProductProfile(s, other) if activationKey: info = s.registration.new_system_activation_key( profileName, up2dateUtils.getOSRelease(), up2dateUtils.getVersion(), up2dateUtils.getArch(), activationKey, other) else: info = s.registration.new_system_user_pass(profileName, up2dateUtils.getOSRelease(), up2dateUtils.getVersion(), up2dateUtils.getArch(), username, password, other) log.log_debug("Returned:\n%s" % info) result = RegistrationResult(info['system_id'], info['channels'], info['failed_channels'], info['system_slots'], info['failed_system_slots'], info['universal_activation_key'], rawDict=info) return result
def unsubscribeChannels(channels, username, passwd): s = rhnserver.RhnServer() return s.up2date.unsubscribeChannels(up2dateAuth.getSystemId(), channels, username, passwd)
def hasChannelChecksumCapability(rpc_server): """ check whether server supports getPackageChecksumBySession function""" server = rhnserver.RhnServer(rpcServerOverride=rpc_server) return server.capabilities.hasCapability('xmlrpc.packages.checksums')