コード例 #1
0
ファイル: rhnreg.py プロジェクト: yanheven/spacewalk
def registerSystem(username = None, password = None,
                   profileName = None, packages = None,
                   token = None, other = None):
    """Wrapper for the old xmlrpc to register a system. Activates subscriptions
    if a reg num is given.

    """
    auth_dict = { "profile_name" : profileName,
                  "os_release" : up2dateUtils.getVersion(),
                  "release_name" : up2dateUtils.getOSRelease(),
                  "architecture" : up2dateUtils.getArch() }
    # dict of other bits to send
    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

    if cfg['supportsSMBIOS']:
        auth_dict["smbios"] = _encode_characters(hardware.get_smbios())

    s = rhnserver.RhnServer()
    if packages == None:
        ret = s.registration.new_system(auth_dict)
    else:
        ret = s.registration.new_system(auth_dict, packages)

    return ret
コード例 #2
0
ファイル: rhnChannel.py プロジェクト: yanheven/spacewalk
def getChannels(force=None, label_whitelist=None, timeout=None):
    """ return rhnChannelList containing list of channel we are subscribed to """
    cfg = config.initUp2dateConfig()
    global selected_channels
    if not selected_channels and not force:
        selected_channels = rhnChannelList()
        s = rhnserver.RhnServer(timeout=timeout)

        if not up2dateAuth.getSystemId():
            raise up2dateErrors.NoSystemIdError(_("Unable to Locate SystemId"))

        up2dateChannels = s.up2date.listChannels(up2dateAuth.getSystemId())

        for chan in up2dateChannels:
            if label_whitelist and not label_whitelist.has_key(chan['label']):
                continue

            channel = rhnChannel(type='up2date', url=config.getServerlURL())
            for key in chan.keys():
                if key == "last_modified":
                    channel['version'] = chan['last_modified']
                else:
                    channel[key] = chan[key]
            selected_channels.addChannel(channel)

    if len(selected_channels.list) == 0:
        raise up2dateErrors.NoChannelsError(
            _("This system may not be updated until it is associated with a channel."
              ))

    return selected_channels
コード例 #3
0
ファイル: rhnreg.py プロジェクト: yanheven/spacewalk
def sendHardware(systemId, hardwareList):
    def remove_ip6addr(x):
        if x['class'] == 'NETINFO' and 'ip6addr' in x:
            del x['ip6addr']
        return x
    s = rhnserver.RhnServer()
    if not s.capabilities.hasCapability('ipv6', 1):
        hardwareList = map(remove_ip6addr, hardwareList)
    s.registration.add_hw_profile(systemId, _encode_characters(hardwareList))
コード例 #4
0
def updatePackageProfile():
    """ get a list of installed packages and send it to rhnServer """
    log = up2dateLog.initLog()
    log.log_me("Updating package profile")
    packages = pkgUtils.getInstalledPackageList(getArch=1)
    s = rhnserver.RhnServer()
    if not s.capabilities.hasCapability('xmlrpc.packages.extended_profile', 2):
        # for older satellites and hosted - convert to old format
        packages = convertPackagesFromHashToList(packages)
    s.registration.update_packages(up2dateAuth.getSystemId(), packages)
コード例 #5
0
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 = rhnserver.RhnServer()

      newSystemId = s.registration.upgrade_version(getSystemId(), systemVer)

      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
コード例 #6
0
def login(systemId=None, forceUpdate=False, timeout=None):
    log = up2dateLog.initLog()
    log.log_debug("login(forceUpdate=%s) invoked" % (forceUpdate))
    if not forceUpdate and not loginInfo:
        if readCachedLogin():
            return loginInfo

    server = rhnserver.RhnServer(timeout=timeout)

    # 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")

    li = server.up2date.login(systemId)

    # figure out if were missing any needed caps
    server.capabilities.validate()
    _updateLoginInfo(li) #update global var, loginInfo
    writeCachedLogin() #pickle global loginInfo

    if loginInfo:
        log.log_me("successfully retrieved authentication token "
                   "from up2date server")

    log.log_debug("logininfo:", loginInfo)
    return loginInfo
コード例 #7
0
ファイル: hardware.py プロジェクト: ggainey/spacewalk
def read_cpuinfo():
    def get_entry(a, entry):
        e = entry.lower()
        if not a.has_key(e):
            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
コード例 #8
0
ファイル: rhnChannel.py プロジェクト: yanheven/spacewalk
def unsubscribeChannels(channels, username, passwd):
    s = rhnserver.RhnServer()
    return s.up2date.unsubscribeChannels(up2dateAuth.getSystemId(), channels,
                                         username, passwd)