Exemplo n.º 1
0
def add_tools_channel(server_id, action_id, dry_run=0):
    log_debug(3)
    if (not dry_run):
        subscribe_to_tools_channel(server_id)
    else:
        log_debug(4, "dry run requested")
    raise ShadowAction("Subscribed guest to tools channel.")
Exemplo n.º 2
0
def schedule_deploy(server_id, action_id, dry_run=0):
    log_debug(2, server_id, action_id)
    s = rhnServer.search(server_id)

    # Schedule an rhncfg install
    new_action_id = server_kickstart.schedule_rhncfg_install(server_id,
                                                             action_id,
                                                             scheduler=None)

    new_action_id_2 = rhnAction.schedule_server_action(
        server_id,
        action_type='configfiles.deploy',
        action_name="Activation Key Config Auto-Deploy",
        delta_time=0,
        scheduler=None,
        org_id=s.server['org_id'],
        prerequisite=new_action_id,
    )

    if (not dry_run):
        h = rhnSQL.prepare(_query_copy_revs_from_shadow_action)
        h.execute(action_id=action_id,
                  new_action_id=new_action_id_2,
                  server_id=server_id)
    else:
        log_debug(4, "dry run requested")

    log_debug(4, "scheduled config deploy for activation key")

    raise ShadowAction("Config deploy scheduled")
Exemplo n.º 3
0
def schedule_virt_host_pkg_install(server_id, action_id, dry_run=0):
    """
        ShadowAction that schedules a package installation action for the
        rhn-virtualization-host and osad packages.
    """
    log_debug(3)

    virt_host_package_name = "mgr-virtualization-host"
    messaging_package_name = "mgr-osad"

    tools_channel = SubscribedChannel(server_id, "rhn-tools")
    found_tools_channel = tools_channel.is_subscribed_to_channel()

    if not found_tools_channel:
        raise InvalidAction("System not subscribed to the Tools channel.")

    rhn_v12n_package = ChannelPackage(server_id, virt_host_package_name)

    if not rhn_v12n_package.exists():
        raise InvalidAction(
            "Could not find the mgr-virtualization-host package.")

    messaging_package = ChannelPackage(server_id, messaging_package_name)

    if not messaging_package.exists():
        raise InvalidAction("Could not find the mgr-osad package.")

    try:
        rhn_v12n_install_scheduler = PackageInstallScheduler(
            server_id, action_id, rhn_v12n_package)
        messaging_package = PackageInstallScheduler(server_id, action_id,
                                                    messaging_package)
        if (not dry_run):
            rhn_v12n_install_scheduler.schedule_package_install()
            messaging_package.schedule_package_install()
        else:
            log_debug(4, "dry run requested")
    except NoActionInfo:
        nai = sys.exc_info()[1]
        raise_with_tb(InvalidAction(str(nai)), sys.exc_info()[2])
    except PackageNotFound:
        pnf = sys.exc_info()[1]
        raise_with_tb(InvalidAction(str(pnf)), sys.exc_info()[2])
    except Exception:
        e = sys.exc_info()[1]
        raise_with_tb(InvalidAction(str(e)), sys.exc_info()[2])

    log_debug(
        3,
        "Completed scheduling install of mgr-virtualization-host and mgr-osad!"
    )
    raise ShadowAction(
        "Scheduled installation of Virtualization Host packages.")
Exemplo n.º 4
0
def schedule_pkg_install(server_id, action_id, dry_run=0):
    s = rhnServer.search(server_id)

    new_action_id = rhnAction.schedule_server_action(
        server_id,
        action_type='packages.update',
        action_name="Activation Key Package Auto-Install",
        delta_time=0,
        scheduler=None,
        org_id=s.server['org_id'],
    )

    if (not dry_run):
        h = rhnSQL.prepare(_query_copy_pkgs_from_shadow_action)
        h.execute(action_id=action_id, new_action_id=new_action_id)
    else:
        log_debug(4, "dry run requested")

    log_debug(4, "scheduled pkg install for activation key")

    raise ShadowAction("Package install scheduled")
Exemplo n.º 5
0
    try:
        install_scheduler = PackageInstallScheduler(server_id, action_id,
                                                    rhn_v12n_package)
        if (not dry_run):
            install_scheduler.schedule_package_install()
        else:
            log_debug(4, "dry run requested")
    except NoActionInfo, nai:
        raise InvalidAction(str(nai)), None, sys.exc_info()[2]
    except PackageNotFound, pnf:
        raise InvalidAction(str(pnf)), None, sys.exc_info()[2]
    except Exception, e:
        raise InvalidAction(str(e)), None, sys.exc_info()[2]

    log_debug(3, "Completed scheduling install of rhn-virtualization-guest!")
    raise ShadowAction(
        "Scheduled installation of RHN Virtualization Guest packages.")


def initiate(server_id, action_id, dry_run=0):
    log_debug(3)
    h = rhnSQL.prepare(_query_initiate_guest)
    h.execute(action_id=action_id)
    row = h.fetchone_dict()

    if not row:
        raise InvalidAction("Kickstart action without an associated kickstart")

    kickstart_host = row['kickstart_host']
    virt_type = row['virt_type']
    name = row['guest_name']
    boot_image = "spacewalk-koan"
Exemplo n.º 6
0
def schedule_sync(server_id, action_id, dry_run=0):
    log_debug(3, server_id, action_id)
    if dry_run:
        raise ShadowAction("dry run requested - skipping")

    kickstart_session_id = server_kickstart.get_kickstart_session_id(
        server_id, action_id)

    if kickstart_session_id is None:
        raise InvalidAction("Could not find kickstart session ID")

    row = server_kickstart.get_kickstart_session_info(kickstart_session_id,
                                                      server_id)
    deploy_configs = (row['deploy_configs'] == 'Y')

    ks_package_profile = server_kickstart.get_kisckstart_session_package_profile(
        kickstart_session_id)
    # if the session doesn't have a pkg profile, try from the ks profile itself
    if not ks_package_profile:
        ks_package_profile = server_kickstart.get_kickstart_profile_package_profile(
            kickstart_session_id)

    if not ks_package_profile:
        log_debug(4, "No kickstart package profile")
        # No profile to bring this system to
        if deploy_configs:
            # We have to deploy configs, so pass in a server profile
            server_profile = server_kickstart.get_server_package_profile(
                server_id)
        else:
            # No configs to be deployed
            server_profile = None

        server_kickstart.schedule_config_deploy(server_id,
                                                action_id,
                                                kickstart_session_id,
                                                server_profile=server_profile)
        raise ShadowAction(
            "Package sync not scheduled, missing kickstart "
            "package profile; proceeding with configfiles.deploy")

    server_profile = server_kickstart.get_server_package_profile(server_id)

    installs, removes = server_packages.package_delta(server_profile,
                                                      ks_package_profile)

    if not (installs or removes):
        log_debug(4, "No packages to be installed/removed")
        if not deploy_configs:
            server_profile = None

        server_kickstart.schedule_config_deploy(server_id,
                                                action_id,
                                                kickstart_session_id,
                                                server_profile=None)
        raise ShadowAction("Package sync not scheduled, nothing to do")

    log_debug(4, "Scheduling kickstart delta")
    server_kickstart.schedule_kickstart_delta(server_id, kickstart_session_id,
                                              installs, removes)

    raise ShadowAction("Package sync scheduled")
Exemplo n.º 7
0
def upgrade(serverId, actionId, dry_run=0):
    log_debug(3)

    if dry_run:
        # can happen if future actions are requested
        raise ShadowAction("dry run requested - skipping")

    h = rhnSQL.prepare(_query_dup_data)
    h.execute(action_id=actionId)
    row = h.fetchone_dict()
    if not row:
        # No dup for this action
        raise InvalidAction(
            "distupgrade.upgrade: No action found for action id "
            "%s and server %s" % (actionId, serverId))

    action_dup_id = row['id']

    # get product info

    h = rhnSQL.prepare(_query_products)
    h.execute(action_dup_id=action_dup_id)
    products = h.fetchall_dict() or []

    # only SLE10 products needs to be changed manually
    # remove all not SLE10 based products

    sle10_products = []
    do_change = False
    for product in products:
        if product['version'] == '10':
            do_change = True
            sle10_products.append(product)

    # switch the channels for this server

    h = rhnSQL.prepare(_query_channel_changes)
    h.execute(action_dup_id=action_dup_id)
    channel_changes = h.fetchall_dict() or None

    if not channel_changes:
        # this happens in case a distupgrade failed and the
        # another distupgrade is scheduled to fix the installation
        # we do not have the original channels anymore, so we need
        # to execute a full "dup" without channels
        params = {
            "full_update": (row['full_update'] == 'Y'),
            "change_product": do_change,
            "products": sle10_products,
            "dry_run": (row['dry_run'] == 'Y')
        }
        return (params)

    to_subscribe = filter(lambda x: x['task'] == 'S', channel_changes)
    to_unsubscribe = filter(lambda x: x['task'] == 'U', channel_changes)

    try:
        unsubscribe_channels(serverId, to_unsubscribe)
        subscribe_channels(serverId, to_subscribe)
    except rhnFault, f:
        if f.code == 38:
            # channel is already subscribed, ignore it
            pass
        else:
            raise InvalidAction(str(f)), None, sys.exc_info()[2]
Exemplo n.º 8
0
def subscribe(serverId, actionId, dry_run=0):
    log_debug(3)

    raise ShadowAction(
        "subscribe channel requested - internal DB operation only")