コード例 #1
0
def update_actions_for_job(event):
    """
    Takes an salt command return event and sets the
    status of the corresponding Spacewalk job.
    """
    jid = event['data']['jid']
    minion = event['data']['id']

    sid = is_minion_registered(minion)
    if not sid:
        logger.error('minion %s is no longer registered', minion)
        # FIXME: cleanup its actions?
        return

    logger.info('Updating job status for sid %s: (%s) jid: %s', sid, minion,
                jid)

    with transaction(event):
        cursor = rhnSQL.prepare("""
        update rhnServerAction set
        status=:status,
        result_msg=:result_msg,
        result_code=:result_code,
        completion_time=:completion_time
        where action_id in
           (select distinct action_id from rhnActionSaltJob where jid=:jid)
        and server_id=:sid""")

        status = 2 if event['data']['success'] else 1
        cursor.execute(sid=sid,
                       status=status,
                       result_code=event['data']['retcode'],
                       result_msg=json.dumps(event['data']['return'])[:1024],
                       completion_time=event['data']['_stamp'],
                       jid=jid)
コード例 #2
0
ファイル: actions.py プロジェクト: SUSE/spacewalk-saltstack
def update_actions_for_job(event):
    """
    Takes an salt command return event and sets the
    status of the corresponding Spacewalk job.
    """
    jid = event['data']['jid']
    minion = event['data']['id']

    sid = is_minion_registered(minion)
    if not sid:
        logger.error('minion %s is no longer registered', minion)
        # FIXME: cleanup its actions?
        return

    logger.info('Updating job status for sid %s: (%s) jid: %s',
                sid, minion, jid)

    with transaction(event):
        cursor = rhnSQL.prepare("""
        update rhnServerAction set
        status=:status,
        result_msg=:result_msg,
        result_code=:result_code,
        completion_time=:completion_time
        where action_id in
           (select distinct action_id from rhnActionSaltJob where jid=:jid)
        and server_id=:sid""")

        status = 2 if event['data']['success'] else 1
        cursor.execute(sid=sid,
                       status=status,
                       result_code=event['data']['retcode'],
                       result_msg=json.dumps(event['data']['return'])[:1024],
                       completion_time=event['data']['_stamp'],
                       jid=jid)
コード例 #3
0
ファイル: actions.py プロジェクト: SUSE/spacewalk-saltstack
def create_actions_for_job(event):
    """
    For jobs that originated outside of this system
    we create coresponding events in spacewalk
    """
    jid = event['data']['jid']
    minions = event['data']['minions']
    fun = event['data']['fun']

    aid = rhnAction.schedule_action(action_type='salt.job',
                                    action_name='Salt job %s (%s)' %
                                    (jid, fun), org_id=1)

    with transaction(event):
        cursor = rhnSQL.prepare("""
        insert into
        rhnActionSaltJob (action_id, jid, data)
        values (:action_id, :jid, :data)
        """)
        cursor.execute(action_id=aid, jid=jid,
                       data=json.dumps(event['data']))

        for minion in minions:
            sid = is_minion_registered(minion)
            if not sid:
                logger.warn("Skipping reference to unregistered minion: %s",
                            minion)
                continue
            cursor = rhnSQL.prepare("""
            insert into
            rhnServerAction (server_id, action_id, status, pickup_time)
            values (:server_id, :action_id, 0, :pickup_time)
            """)
            cursor.execute(server_id=sid, action_id=aid,
                           pickup_time=event['data']['_stamp'])
コード例 #4
0
ファイル: inventory.py プロジェクト: SUSE/spacewalk-saltstack
def process_network_ifaces_result(minion, event):
    """
    Updates the spacewalk registration for a minion
    with it's currently reported network interface list.
    """
    sid = is_minion_registered(minion)
    if not sid:
        logger.warning("%s is no longer registered. Interfaces ignored.",
                       minion)
        return

    profile = dict()
    interfaces = event.get('data', {}).get('return', {})
    logger.info('Got network interfaces for %s', sid)
    logger.debug(pp.pformat(interfaces))

    profile['class'] = 'NETINTERFACES'
    for iface, details in interfaces.iteritems():
        profile[iface] = dict()
        profile[iface]['ipv6'] = list()
        profile[iface]['hwaddr'] = details['hwaddr']
        # FIXME: how to get the iface module with Salt?
        profile[iface]['module'] = 'Unknown'

        # only one ipv4 addr supported
        for ipv4net in details['inet']:
            profile[iface]['ipaddr'] = ipv4net['address']
            profile[iface]['netmask'] = ipv4net['netmask']
            profile[iface]['broadcast'] = ipv4net['broadcast']
            break

        for ipv6net in details['inet6']:
            ipv6net['scope'] = 'Unknown'
            ipv6net['addr'] = ipv6net['address']
            ipv6net['netmask'] = ipv6net['prefixlen']
            profile[iface]['ipv6'].append(ipv6net)

        server = rhnServer.search(int(sid))

        # No need to delete the hardware as the class seems to ovewrite
        # the previous value
        server.add_hardware(profile)
        server.save_hardware()
コード例 #5
0
ファイル: inventory.py プロジェクト: SUSE/spacewalk-saltstack
def process_package_list_result(minion, event):
    """
    Updates the server registration of the minion with
    the list of packages reported by salt.
    """
    sid = is_minion_registered(minion)
    if not sid:
        logger.warning("%s is no longer registered. Ignoring package list",
                       minion)
        return

    package_list = format_package_list(event.get('data', {}).get('return', {}))

    if not package_list:
        logger.error("Failed to retrieve a current package list for %s",
                     minion)
    else:
        logger.info('Updating package list for Spacewalk sid=%s', sid)
        server = rhnServer.search(int(sid))
        server.dispose_packages()
        for package in package_list:
            server.add_package(package)
        server.save_packages()
コード例 #6
0
def create_actions_for_job(event):
    """
    For jobs that originated outside of this system
    we create coresponding events in spacewalk
    """
    jid = event['data']['jid']
    minions = event['data']['minions']
    fun = event['data']['fun']

    aid = rhnAction.schedule_action(action_type='salt.job',
                                    action_name='Salt job %s (%s)' %
                                    (jid, fun),
                                    org_id=1)

    with transaction(event):
        cursor = rhnSQL.prepare("""
        insert into
        rhnActionSaltJob (action_id, jid, data)
        values (:action_id, :jid, :data)
        """)
        cursor.execute(action_id=aid, jid=jid, data=json.dumps(event['data']))

        for minion in minions:
            sid = is_minion_registered(minion)
            if not sid:
                logger.warn("Skipping reference to unregistered minion: %s",
                            minion)
                continue
            cursor = rhnSQL.prepare("""
            insert into
            rhnServerAction (server_id, action_id, status, pickup_time)
            values (:server_id, :action_id, 0, :pickup_time)
            """)
            cursor.execute(server_id=sid,
                           action_id=aid,
                           pickup_time=event['data']['_stamp'])