コード例 #1
0
def run(api, args, logger):

    settings = api.settings()

    manage_dhcp = str(settings.manage_dhcp).lower()
    manage_dns = str(settings.manage_dns).lower()
    manage_tftpd = str(settings.manage_tftpd).lower()
    restart_dhcp = str(settings.restart_dhcp).lower()
    restart_dns = str(settings.restart_dns).lower()

    which_dhcp_module = module_loader.get_module_from_file(
        "dhcp", "module", just_name=True).strip()
    which_dns_module = module_loader.get_module_from_file(
        "dns", "module", just_name=True).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 == "manage_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 == "manage_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 == "manage_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 == "manage_dnsmasq" and not has_restarted_dnsmasq:
            rc = utils.subprocess_call(logger,
                                       "service dnsmasq restart",
                                       shell=True)
        elif which_dns_module == "manage_dnsmasq" and has_restarted_dnsmasq:
            rc = 0
        else:
            logger.error("unknown DNS engine: %s" % which_dns_module)
            rc = 412

    return rc
コード例 #2
0
def run(api,args):

    settings = api.settings()

    manage_dhcp        = str(settings.manage_dhcp).lower()
    manage_dns         = str(settings.manage_dns).lower()
    restart_bin        = str(settings.restart_bin).lower()
    restart_dhcp       = str(settings.restart_dhcp).lower()
    restart_dns        = str(settings.restart_dns).lower()
    dhcpd_bin          = str(settings.dhcpd_bin).lower()
    dhcpd_init         = str(settings.dhcpd_init).lower()
    omapi_enabled      = str(settings.omapi_enabled).lower()
    omapi_port         = str(settings.omapi_port).lower()

    which_dhcp_module = module_loader.get_module_from_file("dhcp","module",just_name=True).strip()
    which_dns_module  = module_loader.get_module_from_file("dns","module",just_name=True).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 == "manage_isc":
            if not omapi_enabled in [ "1", "true", "yes", "y" ] and restart_dhcp:
                rc = utils.os_system("%s -t -q" % dhcpd_bin)
                if rc != 0:
                   print "%s -t failed" % dhcpd_bin
                   return 1
                rc = utils.os_system("%s %s restart" % (restart_bin, dhcpd_init))
        elif which_dhcp_module == "manage_dnsmasq":
            if restart_dhcp:
                rc = utils.os_system("/sbin/service dnsmasq restart")
                has_restarted_dnsmasq = True
        else:
            print "- error: unknown DHCP engine: %s" % which_dhcp_module
            rc = 411

    if manage_dns != "0" and restart_dns != "0":
        if which_dns_module == "manage_bind":
            rc = utils.os_system("/sbin/service named restart")
        elif which_dns_module == "manage_dnsmasq" and not has_restarted_dnsmasq:
            rc = utils.os_system("/sbin/service dnsmasq restart")
        elif which_dns_module == "manage_dnsmasq" and has_restarted_dnsmasq:
            rc = 0
        else:
            print "- error: unknown DNS engine: %s" % which_dns_module
            rc = 412

    return rc
コード例 #3
0
def run(api,args,logger):

    settings = api.settings()

    manage_dhcp        = str(settings.manage_dhcp).lower()
    manage_dns         = str(settings.manage_dns).lower()
    manage_tftpd       = str(settings.manage_tftpd).lower()
    restart_dhcp       = str(settings.restart_dhcp).lower()
    restart_dns        = str(settings.restart_dns).lower()

    which_dhcp_module = module_loader.get_module_from_file("dhcp","module",just_name=True).strip()
    which_dns_module  = module_loader.get_module_from_file("dns","module",just_name=True).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 == "manage_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 == "manage_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 == "manage_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 == "manage_dnsmasq" and not has_restarted_dnsmasq:
            rc = utils.subprocess_call(logger, "service dnsmasq restart", shell=True)
        elif which_dns_module == "manage_dnsmasq" and has_restarted_dnsmasq:
            rc = 0
        else:
            logger.error("unknown DNS engine: %s" % which_dns_module)
            rc = 412

    return rc
コード例 #4
0
    def sync_dhcp(self):
        restart_dhcp = str(self.settings.restart_dhcp).lower()
        which_dhcp_module = module_loader.get_module_from_file(
            "dhcp", "module", just_name=True).strip()

        if self.settings.manage_dhcp:
            self.write_dhcp()
            if which_dhcp_module == "manage_isc":
                service_name = utils.dhcp_service_name(self.api)
                if restart_dhcp != "0":
                    rc = utils.subprocess_call(self.logger,
                                               "dhcpd -t -q",
                                               shell=True)
                    if rc != 0:
                        self.logger.error("dhcpd -t failed")
                        return False
                    service_restart = "service %s restart" % service_name
                    rc = utils.subprocess_call(self.logger,
                                               service_restart,
                                               shell=True)
                    if rc != 0:
                        self.logger.error("%s failed" % service_name)
                        return False
            elif which_dhcp_module == "manage_dnsmasq":
                if restart_dhcp != "0":
                    rc = utils.subprocess_call(self.logger,
                                               "service dnsmasq restart")
                    if rc != 0:
                        self.logger.error("service dnsmasq restart failed")
                        return False
        return True
コード例 #5
0
ファイル: action_sync.py プロジェクト: HeidCloud/cobbler
    def sync_dhcp(self):
        restart_dhcp = str(self.settings.restart_dhcp).lower()
        which_dhcp_module = module_loader.get_module_from_file("dhcp","module",just_name=True).strip()

        if self.settings.manage_dhcp:
            self.write_dhcp()
            if which_dhcp_module == "manage_isc":
                service_name = utils.dhcp_service_name(self.api)
                if restart_dhcp != "0":
                    rc = utils.subprocess_call(self.logger, "dhcpd -t -q", shell=True)
                    if rc != 0:
                       self.logger.error("dhcpd -t failed")
                       return False
                    service_restart = "service %s restart" % service_name
                    rc = utils.subprocess_call(self.logger, service_restart, shell=True)
                    if rc != 0:
                       self.logger.error("%s failed" % service_name)
                       return False
            elif which_dhcp_module == "manage_dnsmasq":
                if restart_dhcp != "0":
                    rc = utils.subprocess_call(self.logger, "service dnsmasq restart")
                    if rc != 0:
                       self.logger.error("service dnsmasq restart failed")
                       return False
        return True
コード例 #6
0
ファイル: api.py プロジェクト: akurz/cobbler
 def get_module_from_file(self, section, name, fallback=None):
     """
     Looks in /etc/cobbler/modules.conf for a section called 'section'
     and a key called 'name', and then returns the module that corresponds
     to the value of that key.
     Cobbler internal use only.
     """
     return module_loader.get_module_from_file(section, name, fallback)
コード例 #7
0
 def get_module_from_file(self, section, name, fallback=None):
     """
     Looks in /etc/cobbler/modules.conf for a section called 'section'
     and a key called 'name', and then returns the module that corresponds
     to the value of that key.
     Cobbler internal use only.
     """
     return module_loader.get_module_from_file(section, name, fallback)
コード例 #8
0
def __get_storage_module(collection_type):
    """
    Look up serializer in /etc/cobbler/modules.conf

    :param collection_type: str
    :returns: A Python module.
    """
    return module_loader.get_module_from_file("serializers", collection_type, "serializers.file")
コード例 #9
0
ファイル: module_loader_test.py プロジェクト: RPTST/cobbler
def test_get_module_from_file(module_section, fallback_name, expected_exception):
    # Arrange -> Done in fixtures

    # Act
    with expected_exception:
        result_module = module_loader.get_module_from_file(module_section, "module", fallback_name)

        # Assert
        assert isinstance(result_module.register(), str)
コード例 #10
0
 def __init__(self, collection_mgr, verbose=False, logger=None):
     """
     Constructor
     """
     self.verbose = verbose
     self.collection_mgr = collection_mgr
     self.distros = collection_mgr.distros()
     self.profiles = collection_mgr.profiles()
     self.systems = collection_mgr.systems()
     self.images = collection_mgr.images()
     self.settings = collection_mgr.settings()
     self.repos = collection_mgr.repos()
     if logger is None:
         logger = clogger.Logger()
     self.logger = logger
     self.tftpd = module_loader.get_module_from_file(
         "tftpd", "module", "in_tftpd").get_manager(collection_mgr, logger)
     self.sync = collection_mgr.api.get_sync(verbose, logger=self.logger)
     self.sync.make_tftpboot()
コード例 #11
0
    def __init__(self, collection_mgr, verbose: bool = False):
        """
        Constructor

        :param collection_mgr: The collection manager which has all information.
        :param verbose: Whether the action should be logged verbose.
        """
        self.verbose = verbose
        self.collection_mgr = collection_mgr
        self.distros = collection_mgr.distros()
        self.profiles = collection_mgr.profiles()
        self.systems = collection_mgr.systems()
        self.images = collection_mgr.images()
        self.settings = collection_mgr.settings()
        self.repos = collection_mgr.repos()
        self.logger = logging.getLogger()
        self.tftpd = module_loader.get_module_from_file(
            "tftpd", "module", "in_tftpd").get_manager(collection_mgr)
        self.sync = collection_mgr.api.get_sync(verbose)
        self.sync.make_tftpboot()
コード例 #12
0
ファイル: serializer.py プロジェクト: pombredanne/cobbler-3
def __get_storage_module(collection_type):
    """
    Look up serializer in /etc/cobbler/modules.conf
    """
    return module_loader.get_module_from_file("serializers", collection_type,
                                              "serializer_file")
コード例 #13
0
ファイル: serializer.py プロジェクト: ASyriy/cobbler
def __get_storage_module(collection_type):
    """
    Look up serializer in /etc/cobbler/modules.conf
    """
    return module_loader.get_module_from_file("serializers", collection_type, "serializer_file")