def registerSystem(username=None, password=None, profileName=None, packages=None, token=None, other=None): s = rpcServer.getServer() auth_dict = { "profile_name": profileName, "os_release": rhnUtils.getVersion(), "release_name": rhnUtils.getOSRelease(), "architecture": rhnUtils.getArch() } # dict of other bits to send up if other: for (key, item) in other.items(): auth_dict[key] = item if token: auth_dict["token"] = token else: auth_dict["username"] = username auth_dict["password"] = password auth_dict["uuid"] = cfg["uuid"] or "" auth_dict["rhnuuid"] = cfg["rhnuuid"] or "" try: if packages == None: ret = rpcServer.doCall(s.registration.new_system, auth_dict) else: ret = rpcServer.doCall(s.registration.new_system, auth_dict, packages) except xmlrpclib.Fault, f: if abs(f.faultCode) == 99: raise rhnErrors.DelayError(f.faultString) elif abs(f.faultCode) == 60: raise rhnErrors.AuthenticationTicketError(f.faultString) elif abs(f.faultCode) == 105: raise rhnErrors.RhnUuidUniquenessError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def maybeUpdateVersion(): cfg = config.initUp2dateConfig() try: idVer = xmlrpclib.loads(getSystemId())[0][0]['os_release'] except: # they may not even have a system id yet. return 0 systemVer = rhnUtils.getVersion() if idVer != systemVer: s = rpcServer.getServer() try: newSystemId = rpcServer.doCall(s.registration.upgrade_version, getSystemId(), systemVer) except xmlrpclib.Fault, f: raise rhnErrors.CommunicationError(f.faultString) path = cfg["systemIdPath"] dir = path[:string.rfind(path, "/")] if not os.access(dir, os.W_OK): try: os.mkdir(dir) except: return 0 if not os.access(dir, os.W_OK): return 0 if os.access(path, os.F_OK): # already have systemid file there; let's back it up savePath = path + ".save" try: os.rename(path, savePath) except: return 0 f = open(path, "w") f.write(newSystemId) f.close() try: os.chmod(path, 0600) except: pass
def registerSystem(username = None, password = None, profileName = None, packages = None, token = None, other = None): s = rpcServer.getServer() auth_dict = { "profile_name" : profileName, "os_release" : rhnUtils.getVersion(), "release_name" : rhnUtils.getOSRelease(), "architecture" : rhnUtils.getArch() }; # dict of other bits to send up if other: for (key, item) in other.items(): auth_dict[key] = item if token: auth_dict["token"] = token else: auth_dict["username"] = username auth_dict["password"] = password auth_dict["uuid"] = cfg["uuid"] or "" auth_dict["rhnuuid"] = cfg["rhnuuid"] or "" try: if packages == None: ret = rpcServer.doCall(s.registration.new_system, auth_dict) else: ret = rpcServer.doCall(s.registration.new_system, auth_dict, packages) except rpclib.Fault, f: if abs(f.faultCode) == 99: raise rhnErrors.DelayError(f.faultString) elif abs(f.faultCode) == 60: raise rhnErrors.AuthenticationTicketError(f.faultString) elif abs(f.faultCode) == 105: raise rhnErrors.RhnUuidUniquenessError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)