How to use the cobbler.utils.subprocess_call function in cobbler

To help you get started, we’ve selected a few cobbler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cobbler / cobbler / cobbler / modules / installation / install_post_puppet.py View on Github external
return 0

    system = api.find_system(name)
    system = utils.blender(api, False, system)
    hostname = system["hostname"]
    if not re.match(r'[\w-]+\..+', hostname):
        search_domains = system['name_servers_search']
        if search_domains:
            hostname += '.' + search_domains[0]
    puppetca_path = settings.puppetca_path
    cmd = [puppetca_path, 'cert', 'sign', hostname]

    rc = 0

    try:
        rc = utils.subprocess_call(logger, cmd, shell=False)
    except:
        if logger is not None:
            logger.warning("failed to execute %s" % puppetca_path)

    if rc != 0:
        if logger is not None:
            logger.warning("signing of puppet cert for %s failed" % name)

    return 0
github cobbler / cobbler / cobbler / modules / scm_track.py View on Github external
return 0

    elif mode == "hg":
        # use mercurial
        old_dir = os.getcwd()
        os.chdir("/var/lib/cobbler")
        if os.getcwd() != "/var/lib/cobbler":
            raise CX("danger will robinson")

        if not os.path.exists("/var/lib/cobbler/.hg"):
            utils.subprocess_call(logger, "hg init", shell=True)

        # FIXME: if we know the remote user of an XMLRPC call
        # use them as the user
        utils.subprocess_call(logger, "hg add config", shell=True)
        utils.subprocess_call(logger, "hg add autoinstall_templates", shell=True)
        utils.subprocess_call(logger, "hg add snippets", shell=True)
        utils.subprocess_call(logger, "hg commit -m 'API update' --user '{0}'".format(author), shell=True)

        if push_script:
            utils.subprocess_call(logger, push_script, shell=True)

        os.chdir(old_dir)
        return 0

    else:
        raise CX("currently unsupported SCM type: %s" % mode)
github cobbler / cobbler / cobbler / modules / sync_post_restart_services.py View on Github external
which_dns_module = module_loader.get_module_name("dns", "module").strip()

    # special handling as we don't want to restart it twice
    has_restarted_dnsmasq = False

    rc = 0
    if manage_dhcp != "0":
        if which_dhcp_module == "managers.isc":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "dhcpd -t -q", shell=True)
                if rc != 0:
                    logger.error("dhcpd -t failed")
                    return 1
                dhcp_service_name = utils.dhcp_service_name(api)
                dhcp_restart_command = "service %s restart" % dhcp_service_name
                rc = utils.subprocess_call(logger, dhcp_restart_command, shell=True)
        elif which_dhcp_module == "managers.dnsmasq":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "service dnsmasq restart")
                has_restarted_dnsmasq = True
        else:
            logger.error("unknown DHCP engine: %s" % which_dhcp_module)
            rc = 411

    if manage_dns != "0" and restart_dns != "0":
        if which_dns_module == "managers.bind":
            named_service_name = utils.named_service_name(api)
            dns_restart_command = "service %s restart" % named_service_name
            rc = utils.subprocess_call(logger, dns_restart_command, shell=True)
        elif which_dns_module == "managers.dnsmasq" and not has_restarted_dnsmasq:
            rc = utils.subprocess_call(logger, "service dnsmasq restart", shell=True)
        elif which_dns_module == "managers.dnsmasq" and has_restarted_dnsmasq:
github cobbler / cobbler / cobbler / action_reposync.py View on Github external
Verifies that permissions and contexts after an rsync are as expected.
        Sending proper rsync flags should prevent the need for this, though this is largely
        a safeguard.
        """
        # all_path = os.path.join(repo_path, "*")
        owner = "root:apache"

        (dist, _) = os_release()
        if dist == "suse":
            owner = "root:www"
        elif dist in ("debian", "ubuntu"):
            owner = "root:www-data"

        cmd1 = "chown -R " + owner + " %s" % repo_path

        utils.subprocess_call(self.logger, cmd1)

        cmd2 = "chmod -R 755 %s" % repo_path
        utils.subprocess_call(self.logger, cmd2)
github cobbler / cobbler / cobbler / modules / scm_track.py View on Github external
push_script = str(settings.scm_push_script)

    if mode == "git":
        old_dir = os.getcwd()
        os.chdir("/var/lib/cobbler")
        if os.getcwd() != "/var/lib/cobbler":
            raise CX("danger will robinson")

        if not os.path.exists("/var/lib/cobbler/.git"):
            utils.subprocess_call(logger, "git init", shell=True)

        # FIXME: if we know the remote user of an XMLRPC call
        # use them as the author
        utils.subprocess_call(logger, "git add --all config", shell=True)
        utils.subprocess_call(logger, "git add --all autoinstall_templates", shell=True)
        utils.subprocess_call(logger, "git add --all snippets", shell=True)
        utils.subprocess_call(logger, "git commit -m 'API update' --author '{0}'".format(author), shell=True)

        if push_script:
            utils.subprocess_call(logger, push_script, shell=True)

        os.chdir(old_dir)
        return 0

    elif mode == "hg":
        # use mercurial
        old_dir = os.getcwd()
        os.chdir("/var/lib/cobbler")
        if os.getcwd() != "/var/lib/cobbler":
            raise CX("danger will robinson")

        if not os.path.exists("/var/lib/cobbler/.hg"):
github cobbler / cobbler / cobbler / modules / sync_post_restart_services.py View on Github external
has_restarted_dnsmasq = False

    rc = 0
    if manage_dhcp != "0":
        if which_dhcp_module == "managers.isc":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "dhcpd -t -q", shell=True)
                if rc != 0:
                    logger.error("dhcpd -t failed")
                    return 1
                dhcp_service_name = utils.dhcp_service_name(api)
                dhcp_restart_command = "service %s restart" % dhcp_service_name
                rc = utils.subprocess_call(logger, dhcp_restart_command, shell=True)
        elif which_dhcp_module == "managers.dnsmasq":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "service dnsmasq restart")
                has_restarted_dnsmasq = True
        else:
            logger.error("unknown DHCP engine: %s" % which_dhcp_module)
            rc = 411

    if manage_dns != "0" and restart_dns != "0":
        if which_dns_module == "managers.bind":
            named_service_name = utils.named_service_name(api)
            dns_restart_command = "service %s restart" % named_service_name
            rc = utils.subprocess_call(logger, dns_restart_command, shell=True)
        elif which_dns_module == "managers.dnsmasq" and not has_restarted_dnsmasq:
            rc = utils.subprocess_call(logger, "service dnsmasq restart", shell=True)
        elif which_dns_module == "managers.dnsmasq" and has_restarted_dnsmasq:
            rc = 0
        elif which_dns_module == "managers.ndjbdns":
            # N-DJBDNS picks up configuration changes automatically and does not need to be restarted.
github cobbler / cobbler / cobbler / modules / sync_post_restart_services.py View on Github external
manage_dhcp = str(settings.manage_dhcp).lower()
    manage_dns = str(settings.manage_dns).lower()
    restart_dhcp = str(settings.restart_dhcp).lower()
    restart_dns = str(settings.restart_dns).lower()

    which_dhcp_module = module_loader.get_module_name("dhcp", "module").strip()
    which_dns_module = module_loader.get_module_name("dns", "module").strip()

    # special handling as we don't want to restart it twice
    has_restarted_dnsmasq = False

    rc = 0
    if manage_dhcp != "0":
        if which_dhcp_module == "managers.isc":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "dhcpd -t -q", shell=True)
                if rc != 0:
                    logger.error("dhcpd -t failed")
                    return 1
                dhcp_service_name = utils.dhcp_service_name(api)
                dhcp_restart_command = "service %s restart" % dhcp_service_name
                rc = utils.subprocess_call(logger, dhcp_restart_command, shell=True)
        elif which_dhcp_module == "managers.dnsmasq":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "service dnsmasq restart")
                has_restarted_dnsmasq = True
        else:
            logger.error("unknown DHCP engine: %s" % which_dhcp_module)
            rc = 411

    if manage_dns != "0" and restart_dns != "0":
        if which_dns_module == "managers.bind":
github cobbler / cobbler / cobbler / modules / scm_track.py View on Github external
if scm_track_enabled not in ["y", "yes", "1", "true"]:
        # feature disabled
        return 0

    mode = str(settings.scm_track_mode).lower()
    author = str(settings.scm_track_author)
    push_script = str(settings.scm_push_script)

    if mode == "git":
        old_dir = os.getcwd()
        os.chdir("/var/lib/cobbler")
        if os.getcwd() != "/var/lib/cobbler":
            raise CX("danger will robinson")

        if not os.path.exists("/var/lib/cobbler/.git"):
            utils.subprocess_call(logger, "git init", shell=True)

        # FIXME: if we know the remote user of an XMLRPC call
        # use them as the author
        utils.subprocess_call(logger, "git add --all config", shell=True)
        utils.subprocess_call(logger, "git add --all autoinstall_templates", shell=True)
        utils.subprocess_call(logger, "git add --all snippets", shell=True)
        utils.subprocess_call(logger, "git commit -m 'API update' --author '{0}'".format(author), shell=True)

        if push_script:
            utils.subprocess_call(logger, push_script, shell=True)

        os.chdir(old_dir)
        return 0

    elif mode == "hg":
        # use mercurial
github cobbler / cobbler / cobbler / actions / action_hardlink.py View on Github external
# FIXME: if these directories become configurable some
        # changes will be required here.

        if not os.path.exists(self.hardlink):
            utils.die(self.logger, "please install 'hardlink' (%s) to use this feature" % self.hardlink)

        self.logger.info("now hardlinking to save space, this may take some time.")

        rc = utils.subprocess_call(self.logger, self.hardlink_cmd, shell=True)
        # FIXME: how about settings? (self.settings.webdir)
        webdir = "/var/www/cobbler"
        if os.path.exists("/srv/www"):
            webdir = "/srv/www/cobbler"

        rc = utils.subprocess_call(self.logger, self.hardlink + " -c -v " + webdir + "/distro_mirror /var/www/cobbler/repo_mirror", shell=True)

        return rc