Beispiel #1
0
def doCall(method, *args, **kwargs):
    log = rhnLog.initLog()
    cfg = config.initUp2dateConfig()
    ret = None

    attempt_count = 1
    attempts = cfg["networkRetries"] or 5

    while 1:
        failure = 0
        ret = None
        try:
            ret = apply(method, args, kwargs)
        except KeyboardInterrupt:
            raise rhnErrors.CommunicationError(_(
                "Connection aborted by the user"))
        # if we get a socket error, keep tryingx2
        except (socket.error, socket.sslerror), e:
            log.log_me("A socket error occurred: %s, attempt #%s" % (
                e, attempt_count))
            if attempt_count >= attempts:
                if len(e.args) > 1:
                    raise rhnErrors.CommunicationError(e.args[1])
                else:
                    raise rhnErrors.CommunicationError(e.args[0])
            else:
                failure = 1
        except httplib.IncompleteRead:
            print "httplib.IncompleteRead"
            raise rhnErrors.CommunicationError("httplib.IncompleteRead")
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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)
Beispiel #7
0
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)
Beispiel #8
0
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)
Beispiel #9
0
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)
Beispiel #10
0
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)
Beispiel #11
0
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)
Beispiel #12
0
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)
Beispiel #13
0
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
Beispiel #14
0
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)
Beispiel #15
0
                    raise rhnErrors.CommunicationError(e.args[1])
                else:
                    raise rhnErrors.CommunicationError(e.args[0])
            else:
                failure = 1
        except httplib.IncompleteRead:
            print "httplib.IncompleteRead"
            raise rhnErrors.CommunicationError("httplib.IncompleteRead")

        except urllib2.HTTPError, e:
            msg = "\nAn HTTP error occurred:\n"
            msg = msg + "URL: %s\n" % e.filename
            msg = msg + "Status Code: %s\n" % e.code
            msg = msg + "Error Message: %s\n" % e.msg
            log.log_me(msg)
            raise rhnErrors.CommunicationError(msg)

        except xmlrpclib.ProtocolError, e:

            log.log_me("A protocol error occurred: %s , attempt #%s," % (
                e.errmsg, attempt_count))
            (errCode, errMsg) = rpclib.reportError(e.headers)
            reset = 0
            if abs(errCode) == 34:
                log.log_me("Auth token timeout occurred\n errmsg: %s" % errMsg)
                # this calls login, which in tern calls doCall (ie,
                # this function) but login should never get a 34, so
                # should be safe from recursion

                # PORTME : needs to do login without repoDirector preferbly
#                rd = repoDirector.initRepoDirector()