Beispiel #1
0
    def getErrataInfo(self, system_id, errata_id):
        log_debug(5, system_id, errata_id)
        # Authenticate the server certificate
        self.auth_system(system_id)
        # log this thing
        log_debug(1, self.server_id, errata_id)

        client_caps = rhnCapability.get_client_capabilities()
        log_debug(3, "Client Capabilities", client_caps)
        multiarch = 0
        cap_info = None
        if client_caps and client_caps.has_key("packages.update"):
            cap_info = client_caps["packages.update"]
        if cap_info and cap_info["version"] > 1:
            multiarch = 1

        statement = """
        select distinct
               pn.name,
               pe.epoch,
               pe.version,
               pe.release,
               pa.label arch
        from
               rhnPackageName pn,
               rhnPackageEVR pe,
               rhnPackage p,
               rhnPackageArch pa,
               rhnChannelPackage cp,
               rhnServerChannel sc,
               rhnErrataPackage ep
        where
                   ep.errata_id = :errata_id
               and ep.package_id = p.id
               and p.name_id = pn.id
               and p.evr_id = pe.id
               and p.package_arch_id = pa.id
               and sc.server_id = :server_id
               and sc.channel_id = cp.channel_id
               and cp.package_id = p.id
        """

        h = rhnSQL.prepare(statement)
        h.execute(errata_id=errata_id, server_id=self.server_id)

        packages = h.fetchall_dict()
        ret = []
        if not packages:
            return []

        for package in packages:
            if package["name"] is not None:
                if package["epoch"] is None:
                    package["epoch"] = ""

                pkg_arch = ""
                if multiarch:
                    pkg_arch = package["arch"] or ""
                ret.append([package["name"], package["version"], package["release"], package["epoch"], pkg_arch])
        return ret
Beispiel #2
0
def handle_action(serverId, actionId, packagesIn, dry_run=0):
    log_debug(3, serverId, actionId, dry_run)

    client_caps = rhnCapability.get_client_capabilities()
    log_debug(3, "Client Capabilities", client_caps)
    multiarch = 0
    if client_caps and 'packages.update' in client_caps:
        cap_info = client_caps['packages.update']
        if cap_info['version'] > 1:
            multiarch = 1
    if not packagesIn:
        raise InvalidAction(
            "Packages scheduled in action %s for server %s could not be found."
            % (actionId, serverId))

    packages = []
    for package in packagesIn:
        # Fix the epoch
        if package['epoch'] is None:
            package['epoch'] = ""
        pkg_arch = ''
        if multiarch:
            pkg_arch = package['arch'] or ''

        packages.append([
            package['name'], package['version'] or '', package['release']
            or '', package['epoch'], pkg_arch
        ])

    log_debug(4, packages)
    return packages
Beispiel #3
0
def handle_action(serverId, actionId, packagesIn, dry_run=0):
    log_debug(3, serverId, actionId, dry_run)

    client_caps = rhnCapability.get_client_capabilities()
    log_debug(3,"Client Capabilities", client_caps)
    multiarch = 0
    if client_caps and client_caps.has_key('packages.update'):
        cap_info =  client_caps['packages.update']
        if cap_info['version'] > 1:
            multiarch = 1
    if not packagesIn:
        raise InvalidAction("Packages scheduled in action %s for server %s could not be found." %
            (actionId, serverId))

    packages = []
    for package in packagesIn:
        # Fix the epoch
        if package['epoch'] is None:
            package['epoch'] = ""
        pkg_arch = ''
        if multiarch:
            pkg_arch = package['arch'] or ''

        packages.append([package['name'],
                         package['version'] or '',
                         package['release'] or '',
                         package['epoch'],
                         pkg_arch])

    log_debug(4, packages)
    return packages
Beispiel #4
0
    def _normalize_packages(self, system_id, packages, allow_none=0):
        """ the function checks if list of packages is well formated
            and also converts packages from old list of lists
            (extended_profile >= 2) to new list of dicts (extended_profile = 2)
        """

        if allow_none and packages is None:
                return None
        # we need to be paranoid about the format of the argument because
        # if we accept wrong input then we might end up disposing in error
        # of all packages registered here
        if type(packages) != type([]):
            log_error("Invalid argument type", type(packages))
            raise rhnFault(21)

        # Update the capabilities list
        server = self.auth_system(system_id)
        rhnCapability.update_client_capabilities(self.server_id)

        # old clients send packages as a list of arrays
        # while new (capability packages.extended_profile >= {version: 2, value: 1})
        # use a list of dicts
        client_caps = rhnCapability.get_client_capabilities()
        package_is_dict = 0
        packagesV2 = []
        if client_caps and client_caps.has_key('packages.extended_profile'):
            cap_info = client_caps['packages.extended_profile']
            if cap_info and int(cap_info['version']) >= 2:
                package_is_dict = 1
                packagesV2 = packages

        for package in packages:
            if package_is_dict:
                # extended_profile >= 2
                if type(package) != type({}):
                    log_error("Invalid package spec for extended_profile >= 2",
                         type(package), "len = %d" % len(package))
                    raise rhnFault(21)
            else:
                # extended_profile < 2
                if (type(package) != type([]) or len(package) < 4):
                    log_error("Invalid package spec", type(package),
                          "len = %d" % len(package))
                    raise rhnFault(21)
                else:
                    p = {'name'   : package[0],
                         'version': package[1],
                         'release': package[2],
                         'epoch'  : package[3],
                        }
                    if len(package) > 4:
                        p['arch'] = package[4]
                    if len(package) > 5:
                        p['cookie'] = package[5]
                    packagesV2.append(p)
        return packagesV2
Beispiel #5
0
    def _normalize_packages(self, system_id, packages, allow_none=0):
        """ the function checks if list of packages is well formated
            and also converts packages from old list of lists
            (extended_profile >= 2) to new list of dicts (extended_profile = 2)
        """

        if allow_none and packages is None:
                return None
        # we need to be paranoid about the format of the argument because
        # if we accept wrong input then we might end up disposing in error
        # of all packages registered here
        if type(packages) != type([]):
            log_error("Invalid argument type", type(packages))
            raise rhnFault(21)

        # Update the capabilities list
        server = self.auth_system(system_id)
        rhnCapability.update_client_capabilities(self.server_id)

        # old clients send packages as a list of arrays
        # while new (capability packages.extended_profile >= {version: 2, value: 1})
        # use a list of dicts
        client_caps = rhnCapability.get_client_capabilities()
        package_is_dict = 0
        packagesV2 = []
        if client_caps and client_caps.has_key('packages.extended_profile'):
            cap_info = client_caps['packages.extended_profile']
            if cap_info and int(cap_info['version']) >= 2:
                package_is_dict = 1
                packagesV2 = packages

        for package in packages:
            if package_is_dict:
                # extended_profile >= 2
                if type(package) != type({}):
                    log_error("Invalid package spec for extended_profile >= 2",
                         type(package), "len = %d" % len(package))
                    raise rhnFault(21)
            else:
                # extended_profile < 2
                if (type(package) != type([]) or len(package) < 4):
                    log_error("Invalid package spec", type(package),
                          "len = %d" % len(package))
                    raise rhnFault(21)
                else:
                    p = {'name'   : package[0],
                         'version': package[1],
                         'release': package[2],
                         'epoch'  : package[3],
                        }
                    if len(package) > 4:
                        p['arch'] = package[4]
                    if len(package) > 5:
                        p['cookie'] = package[5]
                    packagesV2.append(p)
        return packagesV2
def format_file_results(row, server=None):
    encoding = ''
    checksum = row['checksum'] or ''
    is_binary = row['is_binary'] == 'Y'
    raw_contents = rhnSQL.read_lob(row['file_contents'])
    if is_binary:
        contents = raw_contents
    else:
        contents = rhnSQL._fix_encoding(raw_contents or '')

    if server and not is_binary and contents:
        interpolator = ServerTemplatedDocument(server,
                                               start_delim=row['delim_start'],
                                               end_delim=row['delim_end'])
        contents = interpolator.interpolate(contents)
        if row['checksum_type']:
            checksummer = hashlib.new(row['checksum_type'])
            checksummer.update(contents.encode())
            checksum = checksummer.hexdigest()

    if contents:
        client_caps = rhnCapability.get_client_capabilities()
        if client_caps and 'configfiles.base64_enc' in client_caps:
            encoding = 'base64'
            if is_binary:
                contents = contents
            else:
                contents = contents.encode()
            contents = base64.encodestring(contents).decode()
    if row.get('modified', False):
        m_date = xmlrpclib.DateTime(str(row['modified']))
    else:
        m_date = ''

    return {
        'path': row['path'],
        'config_channel': row['config_channel'],
        'file_contents': contents,
        'symlink': row['symlink'] or '',
        'checksum_type': row['checksum_type'] or '',
        'checksum': checksum,
        'verify_contents': True,
        'delim_start': row['delim_start'] or '',
        'delim_end': row['delim_end'] or '',
        'revision': row['revision'] or '',
        'username': row['username'] or '',
        'groupname': row['groupname'] or '',
        'filemode': row['filemode'] or '',
        'encoding': encoding or '',
        'filetype': row['label'],
        'selinux_ctx': row['selinux_ctx'] or '',
        'modified': m_date,
        'is_binary': row['is_binary'] or '',
    }
def format_file_results(row, server=None):
    encoding = ''
    contents = None
    contents = rhnSQL.read_lob(row['file_contents']) or ''
    checksum = row['checksum'] or ''

    if server and (row['is_binary'] == 'N') and contents:

        interpolator = ServerTemplatedDocument(server,
                                               start_delim=row['delim_start'],
                                               end_delim=row['delim_end'])
        contents = interpolator.interpolate(contents)
        if row['checksum_type']:
            checksummer = hashlib.new(row['checksum_type'])
            checksummer.update(contents)
            checksum = checksummer.hexdigest()

    if contents:
        client_caps = rhnCapability.get_client_capabilities()
        if client_caps and 'configfiles.base64_enc' in client_caps:
            encoding = 'base64'
            contents = base64.encodestring(contents)
    if row.get('modified', False):
        m_date = xmlrpclib.DateTime(str(row['modified']))
    else:
        m_date = ''

    return {
        'path': row['path'],
        'config_channel': row['config_channel'],
        'file_contents': contents,
        'symlink': row['symlink'] or '',
        'checksum_type': row['checksum_type'] or '',
        'checksum': checksum,
        'verify_contents': True,
        'delim_start': row['delim_start'] or '',
        'delim_end': row['delim_end'] or '',
        'revision': row['revision'] or '',
        'username': row['username'] or '',
        'groupname': row['groupname'] or '',
        'filemode': row['filemode'] or '',
        'encoding': encoding or '',
        'filetype': row['label'],
        'selinux_ctx': row['selinux_ctx'] or '',
        'modified': m_date,
        'is_binary': row['is_binary'] or '',
    }
Beispiel #8
0
def format_file_results(row, server=None):
    encoding = ''
    contents = None
    contents = rhnSQL.read_lob(row['file_contents']) or ''

    if server and (row['is_binary'] == 'N') and contents:

        interpolator = ServerTemplatedDocument(server,
                                               start_delim=row['delim_start'],
                                               end_delim=row['delim_end'])
        contents = interpolator.interpolate(contents)

    if contents:
        client_caps = rhnCapability.get_client_capabilities()
        if client_caps and 'configfiles.base64_enc' in client_caps:
            encoding = 'base64'
            contents = base64.encodestring(contents)
    if row.get('modified', False):
        m_date = xmlrpclib.DateTime(str(row['modified']))
    else:
        m_date = ''

    return {
        'path'          : row['path'],
        'config_channel': row['config_channel'],
        'file_contents' : contents,
        'symlink' : row['symlink'] or '',
        'checksum_type' : row['checksum_type'] or '',
        'checksum'      : row['checksum'] or '',
        'delim_start'   : row['delim_start'] or '',
        'delim_end'     : row['delim_end'] or '',
        'revision'      : row['revision'] or '',
        'username'      : row['username'] or '',
        'groupname'     : row['groupname'] or '',
        'filemode'      : row['filemode'] or '',
        'encoding'      : encoding or '',
        'filetype'      : row['label'],
        'selinux_ctx'   : row['selinux_ctx'] or '',
        'modified'      : m_date,
    }
Beispiel #9
0
def setLocks(serverId, actionId, dry_run=0):
    log_debug(3, serverId, actionId, dry_run)

    client_caps = rhnCapability.get_client_capabilities()
    log_debug(3, "Client Capabilities", client_caps)
    multiarch = 0
    if not client_caps or not client_caps.has_key('packages.setLocks'):
        raise InvalidAction("Client is not capable of locking packages.")

    h = rhnSQL.prepare(_query_action_setLocks)
    h.execute(actionid=actionId, serverid=serverId)
    tmppackages = h.fetchall_dict() or {}

    packages = []

    for package in tmppackages:
        packages.append([
            package['name'], package['version'], package['release'],
            package['epoch'] or '', package['arch'] or ''
        ])
    log_debug(4, packages)
    return packages
Beispiel #10
0
def setLocks(serverId, actionId, dry_run=0):
    log_debug(3, serverId, actionId, dry_run)

    client_caps = rhnCapability.get_client_capabilities()
    log_debug(3,"Client Capabilities", client_caps)
    multiarch = 0
    if not client_caps or not client_caps.has_key('packages.setLocks'):
        raise InvalidAction("Client is not capable of locking packages.")

    h = rhnSQL.prepare(_query_action_setLocks)
    h.execute(actionid=actionId,serverid=serverId)
    tmppackages = h.fetchall_dict() or {}

    packages = []

    for package in tmppackages:
        packages.append([package['name'],
                         package['version'],
                         package['release'],
                         package['epoch'] or '',
                         package['arch'] or ''])
    log_debug(4, packages)
    return packages
def format_file_results(row, server=None):
    encoding = ''
    contents = None 
    contents = rhnSQL.read_lob(row['file_contents']) or ''

    if server and (row['is_binary'] == 'N') and contents:

        interpolator = ServerTemplatedDocument(server,
                                               start_delim=row['delim_start'],
                                               end_delim=row['delim_end'])
        contents = interpolator.interpolate(contents)


    if contents:
        client_caps = rhnCapability.get_client_capabilities()
        if client_caps and client_caps.has_key('configfiles.base64_enc'):
            encoding = 'base64'
            contents = base64.encodestring(contents)
        
    return {
        'path'          : row['path'],
        'config_channel': row['config_channel'],
        'file_contents' : contents,
        'symlink' : row['symlink'] or '', 
        'checksum_type' : row['checksum_type'] or '',
        'checksum'      : row['checksum'] or '',
        'delim_start'   : row['delim_start'] or '',
        'delim_end'     : row['delim_end'] or '',
        'revision'      : row['revision'] or '',
        'username'      : row['username'] or '',
        'groupname'     : row['groupname'] or '',
        'filemode'      : row['filemode'] or '',
        'encoding'      : encoding or '',
        'filetype'      : row['label'],
        'selinux_ctx'   : row['selinux_ctx'] or '',
    }
Beispiel #12
0
    def getErrataInfo(self, system_id, errata_id):
        log_debug(5, system_id, errata_id)
        # Authenticate the server certificate
        self.auth_system(system_id)
        # log this thing
        log_debug(1, self.server_id, errata_id)

        client_caps = rhnCapability.get_client_capabilities()
        log_debug(3, "Client Capabilities", client_caps)
        multiarch = 0
        cap_info = None
        if client_caps and 'packages.update' in client_caps:
            cap_info = client_caps['packages.update']
        if cap_info and cap_info['version'] > 1:
            multiarch = 1

        statement = """
        select distinct
               pn.name,
               pe.epoch,
               pe.version,
               pe.release,
               pa.label arch
        from
               rhnPackageName pn,
               rhnPackageEVR pe,
               rhnPackage p,
               rhnPackageArch pa,
               rhnChannelPackage cp,
               rhnServerChannel sc,
               rhnErrataPackage ep
        where
                   ep.errata_id = :errata_id
               and ep.package_id = p.id
               and p.name_id = pn.id
               and p.evr_id = pe.id
               and p.package_arch_id = pa.id
               and sc.server_id = :server_id
               and sc.channel_id = cp.channel_id
               and cp.package_id = p.id
        """

        h = rhnSQL.prepare(statement)
        h.execute(errata_id=errata_id, server_id=self.server_id)

        packages = h.fetchall_dict()
        ret = []
        if not packages:
            return []

        for package in packages:
            if package['name'] is not None:
                if package['epoch'] is None:
                    package['epoch'] = ""

                pkg_arch = ''
                if multiarch:
                    pkg_arch = package['arch'] or ''
                ret.append([
                    package['name'], package['version'], package['release'],
                    package['epoch'], pkg_arch
                ])
        return ret