def getCaps(): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.welcome_message) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise f
def updatePackages(systemId, packageList): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.update_packages, systemId, packageList) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def sendHardware(systemId, hardwareList): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.add_hw_profile, systemId, hardwareList) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def listPackages(systemId): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.list_packages, systemId) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def listPackages(systemId): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.list_packages,systemId) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def sendHardware(systemId, hardwareList): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.add_hw_profile, systemId, hardwareList) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def getCaps(): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.welcome_message) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise f
def registerProduct(systemId, productInfo): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.register_product, systemId, productInfo) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def registerProduct(systemId, productInfo, oemInfo={}): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.register_product, systemId, productInfo) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def validateRegNum(regNum): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.validate_reg_num, regNum) except xmlrpclib.Fault, f: if f.faultCode == -16: # invalid raise rhnErrors.ValidationError(f.faultString) elif f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def validateRegNum(regNum): s = rpcServer.getServer() try: rpcServer.doCall(s.registration.validate_reg_num,regNum) except rpclib.Fault, f: if f.faultCode == -16: # invalid raise rhnErrors.ValidationError(f.faultString) elif f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def sendSerialNumber(systemId, num): s = rpcServer.getServer() try: if cfg["oemId"] != None: rpcServer.doCall(s.registration.send_serial, systemId, num, cfg["oemId"]) else: rpcServer.doCall(s.registration.send_serial, systemId, num) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def sendSerialNumber(systemId, num): s = rpcServer.getServer() try: if cfg["oemId"] != None: rpcServer.doCall(s.registration.send_serial, systemId, num, cfg["oemId"]) else: rpcServer.doCall(s.registration.send_serial, systemId, num) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def login(systemId=None): server = rpcServer.getServer() log = up2dateLog.initLog() # send up the capabality info headerlist = clientCaps.caps.headerFormat() for (headerName, value) in headerlist: server.add_header(headerName, value) if systemId == None: systemId = getSystemId() if not systemId: return None maybeUpdateVersion() log.log_me("logging into up2date server") # the list of caps the client needs caps = capabilities.Capabilities() global loginInfo try: li = rpcServer.doCall(server.up2date.login, systemId) except rpclib.Fault, f: if abs(f.faultCode) == 49: # print f.faultString raise up2dateErrors.AbuseError(f.faultString) else: raise f
def __call__(self, *args, **kwargs): """ Call the method. Catch faults and translate them. """ method = getattr(self._server, self._method_name) try: return rpcServer.doCall(method, *args, **kwargs) except xmlrpclib.Fault: raise (self.__exception_from_fault(sys.exc_info()[1]), None, sys.exc_info()[2]) except OpenSSL.SSL.Error: # TODO This should probably be moved to rhnlib and raise an # exception that subclasses OpenSSL.SSL.Error # TODO Is there a better way to detect cert failures? error = str(sys.exc_info()[1]) error = error.strip("[()]") pieces = error.split(',') message = "" if len(pieces) > 2: message = pieces[2] elif len(pieces) == 2: message = pieces[1] message = message.strip(" '") if message == 'certificate verify failed': raise (up2dateErrors.SSLCertificateVerifyFailedError(), None, sys.exc_info()[2]) else: raise (up2dateErrors.NetworkError(message), None, sys.exc_info()[2])
def getChannelDetails(): channels = [] sourceChannels = getChannels() useRhn = None for sourceChannel in sourceChannels.channels(): if sourceChannel['type'] == "up2date": useRhn = 1 if useRhn: s = rpcServer.getServer() up2dateChannels = rpcServer.doCall(s.up2date.listChannels, up2dateAuth.getSystemId()) for sourceChannel in sourceChannels.channels(): if sourceChannel['type'] != 'up2date': # FIMXE: kluge since we dont have a good name, maybe be able to fix sourceChannel['name'] = sourceChannel['label'] sourceChannel['description'] = "%s channel %s from %s" % ( sourceChannel['type'], sourceChannel['label'], sourceChannel['url']) channels.append(sourceChannel) continue if useRhn: for up2dateChannel in up2dateChannels: if up2dateChannel['label'] != sourceChannel['label']: continue for key in up2dateChannel.keys(): sourceChannel[key] = up2dateChannel[key] channels.append(sourceChannel) return channels
def login(systemId=None): server = rpcServer.getServer() log = rhnLog.initLog() # send up the capabality info headerlist = clientCaps.caps.headerFormat() for (headerName, value) in headerlist: server.add_header(headerName, value) if systemId == None: systemId = getSystemId() if not systemId: return None maybeUpdateVersion() log.log_me("logging into up2date server") # the list of caps the client needs caps = capabilities.Capabilities() global loginInfo, loginTime, loginOffset try: loginInfo = rpcServer.doCall(server.up2date.login, systemId) loginTime = time.time() loginOffset = float(loginInfo['X-RHN-Auth-Expire-Offset']) - 60.0 except xmlrpclib.Fault, f: if abs(f.faultCode) == 49: # print f.faultString raise rhnErrors.AbuseError(f.faultString) else: raise f
def getChannelDetails(): channels = [] sourceChannels = getChannels() useRhn = None for sourceChannel in sourceChannels.channels(): if sourceChannel["type"] == "up2date": useRhn = 1 if useRhn: s = rpcServer.getServer() up2dateChannels = rpcServer.doCall(s.up2date.listChannels, up2dateAuth.getSystemId()) for sourceChannel in sourceChannels.channels(): if sourceChannel["type"] != "up2date": # FIMXE: kluge since we dont have a good name, maybe be able to fix sourceChannel["name"] = sourceChannel["label"] sourceChannel["description"] = "%s channel %s from %s" % ( sourceChannel["type"], sourceChannel["label"], sourceChannel["url"], ) channels.append(sourceChannel) continue if useRhn: for up2dateChannel in up2dateChannels: if up2dateChannel["label"] != sourceChannel["label"]: continue for key in up2dateChannel.keys(): sourceChannel[key] = up2dateChannel[key] channels.append(sourceChannel) return channels
def getAdvisoryInfo(pkg, warningCallback=None): log = up2dateLog.initLog() cfg = config.initUp2dateConfig() # no errata for non rhn use if not cfg['useRhn']: return None s = rpcServer.getServer() ts = transaction.initReadOnlyTransaction() mi = ts.dbMatch('Providename', pkg[0]) if not mi: return None # odd,set h to last value in mi. mi has to be iterated # to get values from it... h = None for h in mi: break info = None # in case of package less errata that somehow apply if h: try: pkgName = "%s-%s-%s" % (h['name'], h['version'], h['release']) log.log_me("getAdvisoryInfo for %s" % pkgName) info = rpcServer.doCall(s.errata.getPackageErratum, up2dateAuth.getSystemId(), pkg) except rpclib.Fault, f: if warningCallback: warningCallback(f.faultString) return None
def __call__(self, *args, **kwargs): """ Call the method. Catch faults and translate them. """ method = getattr(self._server, self._method_name) try: return rpcServer.doCall(method, *args, **kwargs) except xmlrpclib.Fault, f: raise self.__exception_from_fault(f), None, sys.exc_info()[2]
def __verifyTokens(self, rd): import rhnChannel import rpcServer channels = rhnChannel.getChannels() channel = channels.channels()[0] # if this doesn't throw an auth traceback, the auth doesnt work p, t = rpcServer.doCall(rd.listPackages, channel, msgCallback=None, progressCallback=None)
def subscribeChannels(channels, username, passwd): s = rpcServer.getServer() try: channels = rpcServer.doCall(s.up2date.subscribeChannels, up2dateAuth.getSystemId(), channels, username, passwd) except rpclib.Fault, f: if f.faultCode == -36: raise up2dateErrors.PasswordError(f.faultString) else: raise up2dateErrors.CommunicationError(f.faultString)
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 termsAndConditions(): s = rpcServer.getServer() try: return rpcServer.doCall(s.registration.terms_and_conditions) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def privacyText(): s = rpcServer.getServer() try: return rpcServer.doCall(s.registration.privacy_statement) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
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)
def welcomeText(): s = rpcServer.getServer() try: return rpcServer.doCall(s.registration.welcome_message) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def termsAndConditions(): s = rpcServer.getServer() try: return rpcServer.doCall(s.registration.terms_and_conditions) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def welcomeText(): s = rpcServer.getServer() try: return rpcServer.doCall(s.registration.welcome_message) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def privacyText(): s = rpcServer.getServer() try: return rpcServer.doCall(s.registration.privacy_statement) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def unsubscribeChannels(channels, username, passwd): s = rpcServer.getServer() try: channels = rpcServer.doCall(s.up2date.unsubscribeChannels, up2dateAuth.getSystemId(), channels, username, passwd) except rpclib.Fault, f: if f.faultCode == -36: raise up2dateErrors.PasswordError(f.faultString) else: raise up2dateErrors.CommunicationError(f.faultString)
def finishMessage(systemId): # ret = (-1, "blippyFoobar", "this is some text\n\n\nmore\n\ntext\\n\nfoo") # return ret s = rpcServer.getServer() try: ret = rpcServer.doCall(s.registration.finish_message, systemId) return ret except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def finishMessage(systemId): # ret = (-1, "blippyFoobar", "this is some text\n\n\nmore\n\ntext\\n\nfoo") # return ret s = rpcServer.getServer() try: ret = rpcServer.doCall(s.registration.finish_message, systemId) return ret except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def downloadPackage(channel, pkghash, localfile, serverUrl=None): cfg = config.initUp2dateConfig() serverSettings = ServerSettings() if serverUrl is not None: serverSettings.httpServerUrl = serverUrl li = rhnAuth.getLoginInfo() s = getGETServer(li, serverSettings) fd = rpcServer.doCall(s.getPackage, channel, pkghash) status = s.get_response_status() f2 = _readFD(fd, localfile) f2.close() fd.close()
def maybeUpdateVersion(): cfg = config.initUp2dateConfig() try: idVer = rpclib.xmlrpclib.loads(getSystemId())[0][0]['os_release'] except: # they may not even have a system id yet. return 0 systemVer = up2dateUtils.getVersion() if idVer != systemVer: s = rpcServer.getServer() try: newSystemId = rpcServer.doCall(s.registration.upgrade_version, getSystemId(), systemVer) except rpclib.Fault, f: raise up2dateErrors.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 reserveUser(username, password): s = rpcServer.getServer() try: ret = rpcServer.doCall(s.registration.reserve_user, username, password) except xmlrpclib.Fault, f: if f.faultCode == -3: # account already in use raise rhnErrors.ValidationError(f.faultString) elif f.faultCode == -14: # too short password raise rhnErrors.ValidationError(f.faultString) elif f.faultCode == -15: # bad chars in username raise rhnErrors.ValidationError(f.faultString) elif f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def reserveUser(username, password): s = rpcServer.getServer() try: ret = rpcServer.doCall(s.registration.reserve_user, username, password) except rpclib.Fault, f: if f.faultCode == -3: # account already in use raise rhnErrors.ValidationError(f.faultString) elif f.faultCode == -14: # too short password raise rhnErrors.ValidationError(f.faultString) elif f.faultCode == -15: # bad chars in username raise rhnErrors.ValidationError(f.faultString) elif f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def registerUser(username, password, email=None, orgid=None, orgpassword=None): s = rpcServer.getServer() try: if not email == None: if orgid and orgpassword: rpcServer.doCall(s.registration.new_user, username, password, email, orgid, orgpassword) else: rpcServer.doCall(s.registration.new_user, username, password, email) else: rpcServer.doCall(s.registration.new_user, username, password) except xmlrpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
def registerUser(username, password, email = None, orgid = None, orgpassword = None): s = rpcServer.getServer() try: if not email == None: if orgid and orgpassword: rpcServer.doCall(s.registration.new_user, username, password, email, orgid, orgpassword) else: rpcServer.doCall(s.registration.new_user, username, password, email) else: rpcServer.doCall(s.registration.new_user, username, password) except rpclib.Fault, f: if f.faultCode == 99: raise rhnErrors.DelayError(f.faultString) else: raise rhnErrors.CommunicationError(f.faultString)
for h in mi: break info = None # in case of package less errata that somehow apply if h: try: pkgName = "%s-%s-%s" % (h['name'], h['version'], h['release']) log.log_me("getAdvisoryInfo for %s" % pkgName) info = rpcServer.doCall(s.errata.getPackageErratum, up2dateAuth.getSystemId(), pkg) except rpclib.Fault, f: if warningCallback: warningCallback(f.faultString) return None if info: return info try: log.log_me("getAdvisoryInfo for %s-0-0" % pkg[0]) info = rpcServer.doCall(s.errata.GetByPackage, "%s-0-0" % pkg[0], up2dateUtils.getVersion()) except rpclib.Fault, f: if warningCallback: warningCallback(f.faultString) return None return info
# in case of package less errata that somehow apply if h: try: pkgName = "%s-%s-%s" % (h['name'], h['version'], h['release']) log.log_me("getAdvisoryInfo for %s" % pkgName) info = rpcServer.doCall(s.errata.getPackageErratum, up2dateAuth.getSystemId(), pkg) except rpclib.Fault, f: if warningCallback: warningCallback(f.faultString) return None if info: return info try: log.log_me("getAdvisoryInfo for %s-0-0" % pkg[0]) info = rpcServer.doCall(s.errata.GetByPackage, "%s-0-0" % pkg[0], up2dateUtils.getVersion()) except rpclib.Fault, f: if warningCallback: warningCallback(f.faultString) return None return info