Beispiel #1
0
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()

    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
Beispiel #2
0
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()

    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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
def getAvailableChannels(username, password):
    s = rhnserver.RhnServer()
    server_arch = up2dateUtils.getArch()
    server_version = up2dateUtils.getVersion()
    server_release = up2dateUtils.getRelease()

    availableChannels = None

    try:
        availableChannels = s.registration.available_eus_channels(
            username, password, server_arch, server_version, server_release)
    except xmlrpclib.Fault, f:
        if f.faultCode == 99:
            raise up2dateErrors.DelayError(
                f.faultString), None, sys.exc_info()[2]
        else:
            raise
Beispiel #6
0
def getAvailableChannels(username, password):
    s = rhnserver.RhnServer()
    server_arch = up2dateUtils.getArch()
    server_version = up2dateUtils.getVersion()
    server_release = up2dateUtils.getRelease()

    availableChannels = None

    try:
        availableChannels = s.registration.available_eus_channels(
            username, password, server_arch, server_version, server_release
        )
    except xmlrpclib.Fault, f:
        if f.faultCode == 99:
            raise up2dateErrors.DelayError(f.faultString), None, sys.exc_info()[2]
        else:
            raise
Beispiel #7
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 = 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
Beispiel #8
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 = 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
Beispiel #9
0
    def subArchAndVersion(self, url,name):
        arch = up2dateUtils.getUnameArch()

        # bz:229847 parsing to get correct release 
        # version instead of hardcoding it, for ex:
        # 3Desktop, 4AS, 3AS
        releasever = re.split('[^0-9]', up2dateUtils.getVersion())[0]
        
        url = string.replace(url, "$ARCH", arch)
        name = string.replace(name, "$ARCH", arch)
        url = string.replace(url, "$RELEASE", releasever)
        name = string.replace(name, "$RELEASE", releasever)

        # support the yum format as well
        url = string.replace(url, "$basearch", arch)
        name = string.replace(name, "$basearch", arch)
        url = string.replace(url, "$releasever", releasever)
        name = string.replace(name, "$releasever", releasever)

        return (url, name)
    def subArchAndVersion(self, url, name):
        arch = up2dateUtils.getUnameArch()

        # bz:229847 parsing to get correct release
        # version instead of hardcoding it, for ex:
        # 3Desktop, 4AS, 3AS
        releasever = re.split('[^0-9]', up2dateUtils.getVersion())[0]

        url = string.replace(url, "$ARCH", arch)
        name = string.replace(name, "$ARCH", arch)
        url = string.replace(url, "$RELEASE", releasever)
        name = string.replace(name, "$RELEASE", releasever)

        # support the yum format as well
        url = string.replace(url, "$basearch", arch)
        name = string.replace(name, "$basearch", arch)
        url = string.replace(url, "$releasever", releasever)
        name = string.replace(name, "$releasever", releasever)

        return (url, name)
Beispiel #11
0
def tui_call_wrapper(screen, func, *params):

    try:
        results = func(*params)
    except up2dateErrors.CommunicationError:
        ErrorWindow(screen, HOSTED_CONNECTION_ERROR % config.getServerlURL()[0])
        raise sys.exc_info()[1]
    except up2dateErrors.SSLCertificateVerifyFailedError:
        ErrorWindow(screen, e.errmsg)
        raise sys.exc_info()[1]
    except up2dateErrors.NoBaseChannelError:
        e = sys.exc_info()[1]
        FatalErrorWindow(screen, e.errmsg + '\n' +
                         BASECHANNELERROR % (up2dateUtils.getArch(),
                                             up2dateUtils.getOSRelease(),
                                             up2dateUtils.getVersion()))
    except up2dateErrors.SSLCertificateFileNotFound:
        e = sys.exc_info()[1]
        ErrorWindow(screen, e.errmsg + '\n\n' +
                         SSL_CERT_FILE_NOT_FOUND_ERRER)
        raise e

    return results
Beispiel #12
0
    def __init__(self, screen, tui):
        self.screen = screen
        self.tui = tui
        size = snack._snack.size()

        #get the virtualization uuid and set it to other.
        (virt_uuid, virt_type) = rhnreg.get_virt_info()
        if not virt_uuid is None:
            self.tui.other['virt_uuid'] = virt_uuid
            self.tui.other['virt_type'] = virt_type

        # read all hardware in
        tui.hardware = hardware.Hardware()

        toplevel = snack.GridForm(screen, HARDWARE_WINDOW.encode('utf-8'), 1,
                                  7)

        text = snack.TextboxReflowed(70, HARDWARE_WINDOW_DESC1.encode('utf-8'))

        toplevel.add(text, 0, 0, anchorLeft=1)

        grid = snack.Grid(2, 2)

        label = snack.Label(_("Profile name:").encode('utf-8'))
        grid.setField(label, 0, 0, padding=(0, 0, 1, 0), anchorRight=1)

        self.profileEntry = snack.Entry(40)
        grid.setField(self.profileEntry, 1, 0, anchorLeft=1)

        toplevel.add(grid, 0, 1, anchorLeft=1)

        if tui.includeHardware:
            self.hardwareButton = snack.Checkbox(
                HARDWARE_WINDOW_CHECKBOX.encode('utf-8'), isOn=1)
        else:
            self.hardwareButton = snack.Checkbox(
                HARDWARE_WINDOW_CHECKBOX.encode('utf-8'))

        toplevel.add(self.hardwareButton,
                     0,
                     2,
                     padding=(0, 1, 0, 0),
                     anchorLeft=1)

        label = snack.Label(DESELECT.encode('utf-8'))
        toplevel.add(label, 0, 3, anchorLeft=1, padding=(0, 0, 0, 1))

        grid = snack.Grid(4, 3)
        hardware_text = ''

        hardware_text += _("Version: ") + up2dateUtils.getVersion() + "  "
        self.versionLabel = snack.Label(_("Version: ").encode('utf-8'))
        grid.setField(self.versionLabel,
                      0,
                      0,
                      padding=(0, 0, 1, 0),
                      anchorLeft=1)

        self.versionLabel2 = snack.Label(up2dateUtils.getVersion())
        grid.setField(self.versionLabel2, 1, 0, anchorLeft=1)

        hardware_text += _("CPU model: ")

        for hw in tui.hardware:
            if hw['class'] == 'CPU':
                hardware_text += hw['model'] + "\n"

        hardware_text += _("Hostname: ")

        for hw in tui.hardware:
            if hw['class'] == 'NETINFO':
                unicode_hostname = idn_pune_to_unicode(hw['hostname'])
                hardware_text += unicode_hostname + "\n"

                if tui.profileName != "":
                    self.profileEntry.set(tui.profileName)
                else:
                    self.profileEntry.set(unicode_hostname.encode('utf-8'))

        hardware_text += _("CPU speed: ")

        for hw in tui.hardware:
            if hw['class'] == 'CPU':
                hardware_text += _("%d MHz") % hw['speed'] + "  "

        hardware_text += _("IP Address: ")

        for hw in tui.hardware:
            if hw['class'] == 'NETINFO':
                if hw['ipaddr']:
                    hardware_text += hw['ipaddr'] + "  "
                elif hw['ip6addr']:
                    hardware_text += hw['ip6addr'] + "  "

        hardware_text += _("Memory: ")

        for hw in tui.hardware:
            if hw['class'] == 'MEMORY':
                hardware_text += _("%s megabytes") % hw['ram']

        tb = snack.TextboxReflowed(80, hardware_text.encode('utf-8'))
        toplevel.add(tb, 0, 4)

        self.additionalHWLabel = snack.TextboxReflowed(
            size[0] - 10, HARDWARE_WINDOW_DESC2.encode('utf-8'))

        toplevel.add(self.additionalHWLabel,
                     0,
                     5,
                     padding=(0, 1, 0, 0),
                     anchorLeft=1)

        # BUTTON BAR
        self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"),
                                           (BACK.encode('utf-8'), "back"),
                                           (CANCEL.encode('utf-8'), "cancel")])
        toplevel.add(self.bb, 0, 6, padding=(0, 1, 0, 0), growx=1)

        self.g = toplevel
Beispiel #13
0
def tui_call_wrapper(screen, func, *params):

    try:
        results = func(*params)
    except up2dateErrors.CommunicationError, e:
        ErrorWindow(screen,
                    HOSTED_CONNECTION_ERROR % config.getServerlURL()[0])
        raise e
    except up2dateErrors.SSLCertificateVerifyFailedError, e:
        ErrorWindow(screen, e.errmsg)
        raise e
    except up2dateErrors.NoBaseChannelError, e:
        FatalErrorWindow(
            screen, e.errmsg + '\n' + BASECHANNELERROR %
            (up2dateUtils.getArch(), up2dateUtils.getOSRelease(),
             up2dateUtils.getVersion()))
    except up2dateErrors.SSLCertificateFileNotFound, e:
        ErrorWindow(screen, e.errmsg + '\n\n' + SSL_CERT_FILE_NOT_FOUND_ERRER)
        raise e

    return results


class WindowSkipException:
    def __init__(self):
        pass


class AlreadyRegisteredWindow:
    name = "AlreadyRegisteredWindow"
Beispiel #14
0
    def __init__(self, screen, tui):
        self.screen = screen
        self.tui = tui
        size = snack._snack.size()

        #get the virtualization uuid and set it to other.
        (virt_uuid, virt_type) = rhnreg.get_virt_info()
        if not virt_uuid is None:
            self.tui.other['virt_uuid'] = virt_uuid
            self.tui.other['virt_type'] = virt_type

        # read all hardware in
        tui.hardware = hardware.Hardware()

        toplevel = snack.GridForm(screen, HARDWARE_WINDOW.encode('utf-8'), 1, 7)

        text = snack.TextboxReflowed(70, HARDWARE_WINDOW_DESC1.encode('utf-8'))

        toplevel.add(text, 0, 0, anchorLeft = 1)

        grid = snack.Grid(2, 2)

        label = snack.Label(_("Profile name:").encode('utf-8'))
        grid.setField(label, 0, 0, padding = (0, 0, 1, 0), anchorRight = 1)

        self.profileEntry = snack.Entry(40)
        grid.setField(self.profileEntry, 1, 0, anchorLeft = 1)

        toplevel.add(grid, 0, 1, anchorLeft = 1)

        if tui.includeHardware:
            self.hardwareButton = snack.Checkbox(HARDWARE_WINDOW_CHECKBOX.encode('utf-8'), isOn = 1)
        else:
            self.hardwareButton = snack.Checkbox(HARDWARE_WINDOW_CHECKBOX.encode('utf-8'))

        toplevel.add(self.hardwareButton, 0, 2, padding = (0, 1, 0, 0),
                     anchorLeft = 1)

        label = snack.Label(DESELECT.encode('utf-8'))
        toplevel.add(label, 0, 3, anchorLeft = 1, padding = (0, 0, 0, 1))

        grid = snack.Grid(4, 3)
        hardware_text = ''

        hardware_text += _("Version: ") + up2dateUtils.getVersion() + "  "
        self.versionLabel = snack.Label(_("Version: ").encode('utf-8'))
        grid.setField(self.versionLabel, 0, 0, padding = (0, 0, 1, 0), anchorLeft = 1)

        self.versionLabel2 = snack.Label(up2dateUtils.getVersion())
        grid.setField(self.versionLabel2, 1, 0, anchorLeft = 1)

        hardware_text += _("CPU model: ")

        for hw in tui.hardware:
            if hw['class'] == 'CPU':
                hardware_text += hw['model'] +"\n"

        hardware_text += _("Hostname: ")

        for hw in tui.hardware:
            if hw['class'] == 'NETINFO':
                unicode_hostname = idn_puny_to_unicode(hw['hostname'])
                hardware_text += unicode_hostname + "\n"

                if tui.profileName != "":
                    self.profileEntry.set(tui.profileName)
                else:
                    self.profileEntry.set(unicode_hostname.encode('utf-8'))

        hardware_text += _("CPU speed: ")

        for hw in tui.hardware:
            if hw['class'] == 'CPU':
                hardware_text += _("%d MHz") % hw['speed'] + "  "

        hardware_text += _("IP Address: ")

        for hw in tui.hardware:
            if hw['class'] == 'NETINFO':
                if hw['ipaddr']:
                    hardware_text += hw['ipaddr'] + "  "
                elif hw['ip6addr']:
                    hardware_text += hw['ip6addr'] + "  "

        hardware_text += _("Memory: ")

        for hw in tui.hardware:
            if hw['class'] == 'MEMORY':
                hardware_text += _("%s megabytes") % hw['ram']

        tb = snack.TextboxReflowed(80, hardware_text.encode('utf-8'))
        toplevel.add(tb, 0, 4)

        self.additionalHWLabel = snack.TextboxReflowed(size[0]-10, HARDWARE_WINDOW_DESC2.encode('utf-8'))

        toplevel.add(self.additionalHWLabel, 0, 5, padding = (0, 1, 0, 0),
                     anchorLeft = 1)

        # BUTTON BAR
        self.bb = snack.ButtonBar(screen,
                                  [(NEXT.encode('utf-8'), "next"),
                                   (BACK.encode('utf-8'), "back"),
                                   (CANCEL.encode('utf-8'), "cancel")])
        toplevel.add(self.bb, 0, 6, padding = (0, 1, 0, 0),
                     growx = 1)

        self.g = toplevel
Beispiel #15
0
        return 0


def tui_call_wrapper(screen, func, *params):

    try:
        results = func(*params)
    except up2dateErrors.CommunicationError, e:
        FatalErrorWindow(screen, HOSTED_CONNECTION_ERROR % config.getServerlURL()[0])
    except up2dateErrors.SSLCertificateVerifyFailedError, e:
        FatalErrorWindow(screen, e.errmsg)
    except up2dateErrors.NoBaseChannelError, e:
        FatalErrorWindow(screen, e.errmsg + '\n' +
                         BASECHANNELERROR % (up2dateUtils.getArch(),
                                             up2dateUtils.getOSRelease(),
                                             up2dateUtils.getVersion()))
    except up2dateErrors.SSLCertificateFileNotFound, e:
        FatalErrorWindow(screen, e.errmsg + '\n\n' +
                         SSL_CERT_FILE_NOT_FOUND_ERRER)

    return results

class WindowSkipException:

    def __init__(self):
        pass

class AlreadyRegisteredWindow:

    def __init__(self, screen, tui):