def updatePackageProfile(timeout=None): """ 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(timeout=timeout) 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)
def update(errataidlist, cache_only=None): packagelist = [] if type(errataidlist) not in [type([]), type(())]: errataidlist = [ errataidlist ] for errataid in errataidlist: tmpList = __getErrataInfo(errataid) packagelist = packagelist + tmpList current_packages_with_arch = {} current_packages ={} for p in pkgUtils.getInstalledPackageList(getArch=1): current_packages_with_arch[p['name'] + p['arch']] = p current_packages[p['name']] = p u = {} # only update packages that are currently installed # since an "applicable errata" may only contain some packages # that actually apply. aka kernel. Fun fun fun. if len(packagelist[0]) > 4: # Newer sats send down arch, filter using name+arch for p in packagelist: if "%s%s" % (p[0], p[4]) in current_packages_with_arch: u[p[0] + p[4]] = p elif "%snoarch" % p[0] in current_packages_with_arch: u[p[0] + p[4]] = p elif p[4] == "noarch" and p[0] in current_packages: u[p[0]] = p else: # 5.2 and older sats + hosted dont send arch for p in packagelist: if p[0] in current_packages: u[p[0]] = p # XXX: Fix me - once we keep all errata packages around, # this is the WRONG thing to do - we want to keep the specific versions # that the user has asked for. packagelist = list(u.values()) if packagelist == []: data = {} data['version'] = "0" data['name'] = "errata.update.no_packages" data['erratas'] = errataidlist return (39, "No packages from that errata are available", data) return packages.update(packagelist, cache_only)
def __init__(self, screen, tui): self.screen = screen self.tui = tui size = snack._snack.size() toplevel = snack.GridForm(screen, sstr(PACKAGES_WINDOW), 1, 5) self.g = toplevel text = snack.TextboxReflowed(size[0] - 10, sstr(PACKAGES_WINDOW_DESC1)) toplevel.add(text, 0, 0, anchorLeft=1) self.packagesButton = snack.Checkbox(sstr(PACKAGES_WINDOW_DESC2), 1) toplevel.add(self.packagesButton, 0, 1, padding=(0, 1, 0, 1), anchorLeft=1) label = snack.Label(sstr(PACKAGES_WINDOW_UNCHECK)) toplevel.add(label, 0, 2, anchorLeft=1) #self.packageList = snack.Listbox(size[1]-18, 1, width = size[0]-10) self.packageList = snack.CheckboxTree(size[1] - 18, 1) toplevel.add(self.packageList, 0, 3) # do we need to read the packages from disk? if tui.packageList == []: self.pwin = snack.GridForm(screen, sstr(PACKAGES_WINDOW_PKGLIST), 1, 1) self.scale = snack.Scale(40, 100) self.pwin.add(self.scale, 0, 0) self.pwin.draw() self.screen.refresh() getArch = 0 if rhnreg.cfg['supportsExtendedPackageProfile']: getArch = 1 tui.packageList = pkgUtils.getInstalledPackageList(getArch=getArch) self.screen.popWindow() for package in tui.packageList: self.packageList.append( "%s-%s-%s" % (sstr(package['name']), sstr( package['version']), sstr(package['release'])), item=sstr(package['name']), selected=1) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(sstr(NEXT), "next"), (sstr(BACK), "back"), (sstr(CANCEL), "cancel")]) toplevel.add(self.bb, 0, 4, padding=(0, 1, 0, 0), growx=1)
def __init__(self, screen, tui): self.screen = screen self.tui = tui size = snack._snack.size() toplevel = snack.GridForm(screen, sstr(PACKAGES_WINDOW), 1, 5) self.g = toplevel text = snack.TextboxReflowed(size[0]-10, sstr(PACKAGES_WINDOW_DESC1)) toplevel.add(text, 0, 0, anchorLeft = 1) self.packagesButton = snack.Checkbox(sstr(PACKAGES_WINDOW_DESC2), 1) toplevel.add(self.packagesButton, 0, 1, padding = (0, 1, 0, 1), anchorLeft = 1) label = snack.Label(sstr(PACKAGES_WINDOW_UNCHECK)) toplevel.add(label, 0, 2, anchorLeft = 1) #self.packageList = snack.Listbox(size[1]-18, 1, width = size[0]-10) self.packageList = snack.CheckboxTree(size[1]-18, 1) toplevel.add(self.packageList, 0, 3) # do we need to read the packages from disk? if tui.packageList == []: self.pwin = snack.GridForm(screen, sstr(PACKAGES_WINDOW_PKGLIST), 1, 1) self.scale = snack.Scale(40, 100) self.pwin.add(self.scale, 0, 0) self.pwin.draw() self.screen.refresh() getArch = 0 if rhnreg.cfg['supportsExtendedPackageProfile']: getArch = 1 tui.packageList = pkgUtils.getInstalledPackageList(getArch=getArch) self.screen.popWindow() for package in tui.packageList: self.packageList.append("%s-%s-%s" % (sstr(package['name']), sstr(package['version']), sstr(package['release'])), item = sstr(package['name']), selected = 1) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(sstr(NEXT), "next"), (sstr(BACK), "back"), (sstr(CANCEL), "cancel")]) toplevel.add(self.bb, 0, 4, padding = (0, 1, 0, 0), growx = 1)
def __init__(self, hostname, idx=0): """ Constructor. Parameters idx: Index of the node. This is like "seed" to the random, to make distinct MAC, IPs etc. """ store.CMDBBaseProfile.__init__(self) self.idx = idx self.params = dict() self.hostname = hostname self.id = self.hostname self.packages = pkgUtils.getInstalledPackageList( getArch=(rhnreg.cfg['supportsExtendedPackageProfile'] and 1 or 0)) self.src = None self._gen_hardware() self._get_virtuid()
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)
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)
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)
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. from __future__ import print_function import sys # Once we have the up2date stuff in a site-packages, # we won't have to do path magic. import warnings warnings.filterwarnings("ignore", message='the md5 module is deprecated; use hashlib instead') sys.path.append("/usr/share/rhn/") from up2date_client import up2dateAuth from up2date_client import up2dateErrors from up2date_client import rhnserver from up2date_client import pkgUtils if __name__ == '__main__': systemid = up2dateAuth.getSystemId() if systemid: try: print("Apt-Spacewalk: Updating package profile") s = rhnserver.RhnServer() s.registration.update_packages(systemid, pkgUtils.getInstalledPackageList(getArch=1)) except up2dateErrors.RhnServerException as e: print("Package profile information could not be sent.") print(str(e))