示例#1
0
    def __init__(self):
        """
        Constructor.
        """
        self.procpool = procpool.Pool()
        self.verbose = False
        self._pcp_metrics_path = None

        if self._initialize():
            self.api = spaceapi.SpaceAPI("http://{0}/rpc/api".format(self.options.fqdn))
            rhnreg.cfg.set("serverURL", "https://{0}/XMLRPC".format(self.options.fqdn))
            rhnreg.getCaps()

        def _getProductProfile():
            '''
            Mocker. Needs to be saved to the SQLite!
            '''
            time.sleep(0.1)
            profile = get_suse_product_profile()
            profile['guid'] = uuid.uuid4().hex
            profile['secret'] = uuid.uuid4().hex

            return profile

        rhnreg.getProductProfile = _getProductProfile
        self.__processes = list()
示例#2
0
    def main(self):
        if self.options.serverUrl:
            rhnreg.cfg.set("serverURL", self.options.serverUrl)
        if self.options.sslCACert:
            rhnreg.cfg.set("sslCACert", self.options.sslCACert)

        if not (self.options.activationkey or
                (self.options.username and self.options.password)):
            print _("A username and password are required "\
                    "to register a system.")
            sys.exit(-1)

        if rhnreg.registered() and not self.options.force:
            print _(
                "This system is already registered. Use --force to override")
            sys.exit(-1)

        rhnreg.getCaps()

        if not self.options.nopackages:
            getArch = 0
            if rhnreg.cfg['supportsExtendedPackageProfile']:
                getArch = 1
            packageList = pkgUtils.getInstalledPackageList(getArch=getArch)
        else:
            packageList = []

        hardwareList = hardware.Hardware()

        if self.options.profilename:
            profilename = self.options.profilename
        else:
            profilename = RegisterKsCli.__generateProfileName(hardwareList)

        other = {}
        if self.options.systemorgid:
            other['org_id'] = self.options.systemorgid

        # Try to get the virt uuid and put it in "other".
        (virt_uuid, virt_type) = rhnreg.get_virt_info()
        if not virt_uuid is None:
            other['virt_uuid'] = virt_uuid
            other['virt_type'] = virt_type

        # If specified, send up the EUS channel label for subscription.
        if self.options.use_eus_channel:
            if self.options.activationkey:
                print _(
                    "Usage of --use-eus-channel option with --activationkey is not supported. Please use username and password instead."
                )
                sys.exit(-1)
            if not rhnreg.server_supports_eus():
                print _(
                    "The server you are registering against does not support EUS."
                )
                sys.exit(-1)

            channels = rhnreg.getAvailableChannels(self.options.username,
                                                   self.options.password)
            other['channel'] = channels['default_channel']

        try:
            systemId = rhnreg.registerSystem(self.options.username,
                                             self.options.password,
                                             profilename,
                                             self.options.activationkey, other)
        except (up2dateErrors.AuthenticationTicketError,
                up2dateErrors.RhnUuidUniquenessError,
                up2dateErrors.CommunicationError,
                up2dateErrors.AuthenticationOrAccountCreationError):
            e = sys.exc_info()[1]
            print "%s" % e.errmsg
            sys.exit(1)

        # collect hardware info, inluding hostname
        if not self.options.nohardware:
            rhnreg.sendHardware(systemId, hardwareList)

        if not self.options.nopackages:
            rhnreg.sendPackages(systemId, packageList)

        if self.options.contactinfo:
            print _(
                "Warning: --contactinfo option has been deprecated. Please login to the server web user Interface and update your contactinfo. "
            )

        # write out the new id
        if isinstance(systemId, unicode):
            rhnreg.writeSystemId(unicode.encode(systemId, 'utf-8'))
        else:
            rhnreg.writeSystemId(systemId)

        # assume successful communication with server
        # remember to save the config options
        rhnreg.cfg.save()

        # Send virtualization information to the server.  We must do this
        # *after* writing out the system id.
        if not self.options.novirtinfo:
            rhnreg.sendVirtInfo(systemId)

        # do this after writing out system id, bug #147513
        if not self.options.norhnsd:
            rhnreg.startRhnsd()

        try:
            present, conf_changed = rhnreg.pluginEnable()
            if not present:
                sys.stderr.write(
                    rhncli.utf8_encode(
                        _("Warning: %s is not present, could not enable it.") %
                        PM_PLUGIN_NAME))
        except IOError:
            e = sys.exc_info()[1]
            sys.stderr.write(
                rhncli.utf8_encode(
                    _("Warning: Could not open %s\n%s is not enabled.\n") %
                    (PM_PLUGIN_CONF, PM_PLUGIN_NAME) + e.errmsg))
        RegisterKsCli.__runRhnCheck(self.options.verbose)
示例#3
0
    def main(self):
        if self.options.serverUrl:
            rhnreg.cfg.set("serverURL", self.options.serverUrl)
        if self.options.sslCACert:
            rhnreg.cfg.set("sslCACert", self.options.sslCACert)

        if not (self.options.activationkey or
                (self.options.username and self.options.password)):
            print _("A username and password are required "\
                    "to register a system.")
            sys.exit(-1)

        if rhnreg.registered() and not self.options.force:
            print _("This system is already registered. Use --force to override")
            sys.exit(-1)

        rhnreg.getCaps()

        if not self.options.nopackages:
            getArch = 0
            if rhnreg.cfg['supportsExtendedPackageProfile']:
                getArch = 1
            packageList = pkgUtils.getInstalledPackageList(getArch=getArch)
        else:
            packageList = []


        hardwareList = hardware.Hardware()

        if self.options.profilename:
            profilename = self.options.profilename
        else:
            profilename = RegisterKsCli.__generateProfileName(hardwareList)

        other = {}
        if self.options.systemorgid:
            other['org_id'] = self.options.systemorgid

        # Try to get the virt uuid and put it in "other".
        (virt_uuid, virt_type) = rhnreg.get_virt_info()
        if not virt_uuid is None:
            other['virt_uuid'] = virt_uuid
            other['virt_type'] = virt_type

        # If specified, send up the EUS channel label for subscription.
        if self.options.use_eus_channel:
            if self.options.activationkey:
                print _("Usage of --use-eus-channel option with --activationkey is not supported. Please use username and password instead.")
                sys.exit(-1)
            if not rhnreg.server_supports_eus():
                print _("The server you are registering against does not support EUS.")
                sys.exit(-1)

            channels = rhnreg.getAvailableChannels(self.options.username,
                                                   self.options.password)
            other['channel'] = channels['default_channel']

        try:
            if self.options.activationkey:
                systemId = rhnreg.registerSystem(token = self.options.activationkey,
                                                 profileName = profilename,
                                                 other = other)
            else:
                systemId = rhnreg.registerSystem(self.options.username,
                    self.options.password, profilename, other = other)
        except (up2dateErrors.AuthenticationTicketError,
                up2dateErrors.RhnUuidUniquenessError,
                up2dateErrors.CommunicationError,
                up2dateErrors.AuthenticationOrAccountCreationError), e:
            print "%s" % e.errmsg
            sys.exit(1)
示例#4
0
    def main(self):
        if self.options.serverUrl:
            rhnreg.cfg.set("serverURL", self.options.serverUrl)
        if self.options.sslCACert:
            rhnreg.cfg.set("sslCACert", self.options.sslCACert)

        if not (self.options.activationkey or
                (self.options.username and self.options.password)):
            print _("A username and password are required "\
                    "to register a system.")
            sys.exit(-1)

        if rhnreg.registered() and not self.options.force:
            print _("This system is already registered. Use --force to override")
            sys.exit(-1)

        rhnreg.getCaps()

        if not self.options.nopackages:
            getArch = 0
            if rhnreg.cfg['supportsExtendedPackageProfile']:
                getArch = 1
            packageList = pkgUtils.getInstalledPackageList(getArch=getArch)
        else:
            packageList = []


        hardwareList = hardware.Hardware()

        if self.options.profilename:
            profilename = self.options.profilename
        else:
            profilename = RegisterKsCli.__generateProfileName(hardwareList)

        other = {}
        if self.options.systemorgid:
            other['org_id'] = self.options.systemorgid

        # Try to get the virt uuid and put it in "other".
        (virt_uuid, virt_type) = rhnreg.get_virt_info()
        if not virt_uuid is None:
            other['virt_uuid'] = virt_uuid
            other['virt_type'] = virt_type

        # If specified, send up the EUS channel label for subscription.
        if self.options.use_eus_channel:
            if self.options.activationkey:
                print _("Usage of --use-eus-channel option with --activationkey is not supported. Please use username and password instead.")
                sys.exit(-1)
            if not rhnreg.server_supports_eus():
                print _("The server you are registering against does not support EUS.")
                sys.exit(-1)

            channels = rhnreg.getAvailableChannels(self.options.username,
                                                   self.options.password)
            other['channel'] = channels['default_channel']

        try:
            if self.options.activationkey:
                systemId = rhnreg.registerSystem(token = self.options.activationkey,
                                                 profileName = profilename,
                                                 other = other)
            else:
                systemId = rhnreg.registerSystem(self.options.username,
                    self.options.password, profilename, other = other)
        except (up2dateErrors.AuthenticationTicketError,
                up2dateErrors.RhnUuidUniquenessError,
                up2dateErrors.CommunicationError,
                up2dateErrors.AuthenticationOrAccountCreationError), e:
            print "%s" % e.errmsg
            sys.exit(1)
示例#5
0
    def main(self):
        if self.options.serverUrl:
            rhnreg.cfg.set("serverURL", self.options.serverUrl)
        if self.options.sslCACert:
            rhnreg.cfg.set("sslCACert", self.options.sslCACert)

        if not (self.options.activationkey or
                (self.options.username and self.options.password)):
            print _("A username and password are required "\
                    "to register a system.")
            sys.exit(-1)

        if rhnreg.registered() and not self.options.force:
            print _("This system is already registered. Use --force to override")
            sys.exit(-1)

        rhnreg.getCaps()

        if not self.options.nopackages:
            getArch = 0
            if rhnreg.cfg['supportsExtendedPackageProfile']:
                getArch = 1
            packageList = pkgUtils.getInstalledPackageList(getArch=getArch)
        else:
            packageList = []


        hardwareList = hardware.Hardware()

        if self.options.profilename:
            profilename = self.options.profilename
        else:
            profilename = RegisterKsCli.__generateProfileName(hardwareList)

        other = {}
        if self.options.systemorgid:
            other['org_id'] = self.options.systemorgid

        # Try to get the virt uuid and put it in "other".
        (virt_uuid, virt_type) = rhnreg.get_virt_info()
        if not virt_uuid is None:
            other['virt_uuid'] = virt_uuid
            other['virt_type'] = virt_type

        # If specified, send up the EUS channel label for subscription.
        if self.options.use_eus_channel:
            if self.options.activationkey:
                print _("Usage of --use-eus-channel option with --activationkey is not supported. Please use username and password instead.")
                sys.exit(-1)
            if not rhnreg.server_supports_eus():
                print _("The server you are registering against does not support EUS.")
                sys.exit(-1)

            channels = rhnreg.getAvailableChannels(self.options.username,
                                                   self.options.password)
            other['channel'] = channels['default_channel']

        try:
            if self.options.activationkey:
                systemId = rhnreg.registerSystem(token = self.options.activationkey,
                                                 profileName = profilename,
                                                 other = other)
            else:
                systemId = rhnreg.registerSystem(self.options.username,
                    self.options.password, profilename, other = other)
        except (up2dateErrors.AuthenticationTicketError,
                up2dateErrors.RhnUuidUniquenessError,
                up2dateErrors.CommunicationError,
                up2dateErrors.AuthenticationOrAccountCreationError):
            e = sys.exc_info()[1]
            print "%s" % e.errmsg
            sys.exit(1)

        # collect hardware info, inluding hostname
        if not self.options.nohardware:
            rhnreg.sendHardware(systemId, hardwareList)

        if not self.options.nopackages:
            rhnreg.sendPackages(systemId, packageList)

        if self.options.contactinfo:
            print _("Warning: --contactinfo option has been deprecated. Please login to the server web user Interface and update your contactinfo. ")

        # write out the new id
        if isinstance(systemId, unicode):
            rhnreg.writeSystemId(unicode.encode(systemId, 'utf-8'))
        else:
            rhnreg.writeSystemId(systemId)

        # assume successful communication with server
        # remember to save the config options
        rhnreg.cfg.save()

        # Send virtualization information to the server.  We must do this
        # *after* writing out the system id.
        if not self.options.novirtinfo:
            rhnreg.sendVirtInfo(systemId)

        # do this after writing out system id, bug #147513
        if not self.options.norhnsd:
            rhnreg.startRhnsd()

        try:
            present, conf_changed = rhnreg.pluginEnable()
            if not present:
                sys.stderr.write(rhncli.utf8_encode(_("Warning: %s is not present, could not enable it.") % PM_PLUGIN_NAME))
        except IOError:
            e = sys.exc_info()[1]
            sys.stderr.write(rhncli.utf8_encode(_("Warning: Could not open %s\n%s is not enabled.\n") % (PM_PLUGIN_CONF, PM_PLUGIN_NAME) + e.errmsg))
        RegisterKsCli.__runRhnCheck(self.options.verbose)