Ejemplo n.º 1
0
 def _load_conf(self):
     ftp_conf = {}
     cfg_mgr().check_conf_dir()
     if os.path.exists(self.conf_file):
         ftp_conf = \
             Config.from_file(self.conf_file, self.ftp_conf_schema).conf
     else:
         ftp_conf = self.ftp_conf_schema.validate(ftp_conf)
     return ftp_conf
Ejemplo n.º 2
0
 def _load_conf(self):
     smartd_conf = {}
     cfg_mgr().check_conf_dir()
     if os.path.exists(self.conf_file):
         smartd_conf = \
             Config.from_file(self.conf_file, self.smartd_conf_schema).conf
     else:
         smartd_conf = self.smartd_conf_schema.validate(smartd_conf)
     return smartd_conf
Ejemplo n.º 3
0
 def _load_conf(self):
     zabbix_agent_conf = {}
     cfg_mgr().check_conf_dir()
     if os.path.exists(self.conf_file):
         zabbix_agent_conf = \
             Config.from_file(self.conf_file, self.zabbix_agentd_conf_schema).conf
     else:
         zabbix_agent_conf = self.zabbix_agentd_conf_schema.validate(zabbix_agent_conf)
     return zabbix_agent_conf
Ejemplo n.º 4
0
 def _load_conf(self):
     zabbix_agent_conf = {}
     cfg_mgr().check_conf_dir()
     if os.path.exists(self.conf_file):
         zabbix_agent_conf = \
             Config.from_file(self.conf_file, self.zabbix_agentd_conf_schema).conf
     else:
         zabbix_agent_conf = self.zabbix_agentd_conf_schema.validate(
             zabbix_agent_conf)
     return zabbix_agent_conf
Ejemplo n.º 5
0
 def _load_conf(self):
     fs_dict = {}
     cfg_mgr().check_conf_dir()
     if os.path.exists(self.conf_file):
         fs_dict = \
             Config.from_file(self.conf_file, self.fs_dict_schema).conf
         # check dev_file by uuid
         for fs_name, fs_conf in fs_dict.items():
             if fs_conf["dev_uuid"] != "":
                 fs_conf["dev_file"] = self._uuid_to_dev_file(fs_conf["dev_uuid"])
     return fs_dict
Ejemplo n.º 6
0
    def test_backup(self):

        file_content = ""

        # make test file
        with open("/etc/storlever_test", "w") as f:
            f.write("test")

        mgr = cfg_mgr()

        # backup config
        mgr.backup_to_file("/tmp/storlever_conf_test.tar.gz")

        with open("/etc/storlever_test", "r") as f:
            file_content = f.read()
        self.assertEquals("test", file_content)

        # change test file
        with open("/etc/storlever_test", "w") as f:
            f.write("test2")

        with open("/etc/storlever_test", "r") as f:
            file_content = f.read()
        self.assertEquals("test2", file_content)

        # restore config
        mgr.restore_from_file("/tmp/storlever_conf_test.tar.gz")

        # check test file
        with open("/etc/storlever_test", "r") as f:
            file_content = f.read()
        self.assertEquals("test", file_content)

        # clear backup config file
        os.remove("/tmp/storlever_conf_test.tar.gz")
Ejemplo n.º 7
0
def upload_conf(request):
    """
    upload a config file to storlever

    """

    # the content body of the request should be the download config file
    input_file = request.body_file

    t = datetime.today().strftime("%Y%m%d_%H%M%S")
    file_path = "/tmp/storlever_conf_%s.tar.gz" % t

    with open(file_path, 'wb') as output_file:
        # Finally write the data to a temporary file
        while True:
            data = input_file.read(2 << 16)
            if not data:
                break
            output_file.write(data)

    cfg_mgr = cfgmgr.cfg_mgr()  # get cfg manager
    try:
        cfg_mgr.restore_from_file(
            file_path, user=request.client_addr)  # restore the config
    finally:
        os.remove(file_path)

    return Response(status=200)
Ejemplo n.º 8
0
    def test_backup(self):

        file_content = ""

        # make test file
        with open("/etc/storlever_test", "w") as f:
            f.write("test")

        mgr = cfg_mgr()

        # backup config
        mgr.backup_to_file("/tmp/storlever_conf_test.tar.gz")

        with open("/etc/storlever_test", "r") as f:
            file_content = f.read()
        self.assertEquals("test", file_content)

        # change test file
        with open("/etc/storlever_test", "w") as f:
            f.write("test2")

        with open("/etc/storlever_test", "r") as f:
            file_content = f.read()
        self.assertEquals("test2", file_content)

        # restore config
        mgr.restore_from_file("/tmp/storlever_conf_test.tar.gz")

        # check test file
        with open("/etc/storlever_test", "r") as f:
            file_content = f.read()
        self.assertEquals("test", file_content)

        # clear backup config file
        os.remove("/tmp/storlever_conf_test.tar.gz")
Ejemplo n.º 9
0
def upload_conf(request):
    """
    upload a config file to storlever

    """

    # the content body of the request should be the download config file
    input_file = request.body_file

    t = datetime.today().strftime("%Y%m%d_%H%M%S")
    file_path = "/tmp/storlever_conf_%s.tar.gz" % t

    with open(file_path, 'wb') as output_file:
        # Finally write the data to a temporary file
        while True:
            data = input_file.read(2 << 16)
            if not data:
                break
            output_file.write(data)

    cfg_mgr = cfgmgr.cfg_mgr()      # get cfg manager
    try:
        cfg_mgr.restore_from_file(file_path, user=request.client_addr)   # restore the config
    finally:
        os.remove(file_path)

    return Response(status=200)
Ejemplo n.º 10
0
def restore_conf_from_file(request):

    params = get_params_from_request(request)

    # check params
    if "file" not in params:
        raise StorLeverError("\"file\" params must be given", 400)

    cfg_mgr = cfgmgr.cfg_mgr()      # get cfg manager

    cfg_mgr.restore_from_file(params["file"], user=request.client_addr)

    return Response(status=200)
Ejemplo n.º 11
0
def backup_conf_to_file(request):

    params = get_params_from_request(request)

    # check params
    if "file" not in params:
        raise StorLeverError("\"file\" params must be given", 400)

    cfg_mgr = cfgmgr.cfg_mgr()      # get cfg manager

    cfg_mgr.backup_to_file(params["file"])

    return Response(status=200)
Ejemplo n.º 12
0
def backup_conf_to_file(request):

    params = get_params_from_request(request)

    # check params
    if "file" not in params:
        raise StorLeverError("\"file\" params must be given", 400)

    cfg_mgr = cfgmgr.cfg_mgr()  # get cfg manager

    cfg_mgr.backup_to_file(params["file"])

    return Response(status=200)
Ejemplo n.º 13
0
def restore_conf_from_file(request):

    params = get_params_from_request(request)

    # check params
    if "file" not in params:
        raise StorLeverError("\"file\" params must be given", 400)

    cfg_mgr = cfgmgr.cfg_mgr()  # get cfg manager

    cfg_mgr.restore_from_file(params["file"], user=request.client_addr)

    return Response(status=200)
Ejemplo n.º 14
0
def download_conf(request):
    cfg_mgr = cfgmgr.cfg_mgr()      # get cfg manager

    # the tmp file name
    t = datetime.today().strftime("%Y%m%d_%H%M%S")
    request.storlever_tmp_file = "/tmp/storlever_conf_%s.tar.gz" % t

    cfg_mgr.backup_to_file(request.storlever_tmp_file)
    response = FileResponse(request.storlever_tmp_file,
                            request=request,
                            content_type='application/force-download')
    response.headers['Content-Disposition'] = \
        'attachment; filename=%s' % \
        (os.path.basename(request.storlever_tmp_file))

    request.add_finished_callback(remove_tmp_conf_file)  # remove the temp file

    return response
Ejemplo n.º 15
0
def download_conf(request):
    cfg_mgr = cfgmgr.cfg_mgr()  # get cfg manager

    # the tmp file name
    t = datetime.today().strftime("%Y%m%d_%H%M%S")
    request.storlever_tmp_file = "/tmp/storlever_conf_%s.tar.gz" % t

    cfg_mgr.backup_to_file(request.storlever_tmp_file)
    response = FileResponse(request.storlever_tmp_file,
                            request=request,
                            content_type='application/force-download')
    response.headers['Content-Disposition'] = \
        'attachment; filename=%s' % \
        (os.path.basename(request.storlever_tmp_file))

    request.add_finished_callback(remove_tmp_conf_file)  # remove the temp file

    return response
Ejemplo n.º 16
0
 def _save_conf(self, ftp_conf):
     cfg_mgr().check_conf_dir()
     Config.to_file(self.conf_file, ftp_conf)
Ejemplo n.º 17
0
def clear_conf(request):
    cfg_mgr = cfgmgr.cfg_mgr()      # get cfg manager

    cfg_mgr.system_restore(user=request.client_addr)

    return Response(status=200)
Ejemplo n.º 18
0
                user_conf["login_enable"] = login_enable
            if chroot_enable is not None:
                user_conf["chroot_enable"] = chroot_enable

            # save new conf
            self._save_conf(ftp_conf)
            self._sync_to_system_conf(ftp_conf)

        logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
                   "ftp user (%s) config is updated by operator(%s)" %
                   (user_name, operator))

FtpManager = FtpManager()

# register ftp manager callback functions to basic manager
cfg_mgr().register_restore_from_file_cb(FtpManager.sync_to_system_conf)
cfg_mgr().register_system_restore_cb(FtpManager.system_restore_cb)
service_mgr().register_service("ftpd", "vsftpd", "/sbin/vsftpd", "FTP Server(vsftpd)")
ModuleManager.register_module(**MODULE_INFO)

# disable selinux impact
set_selinux_permissive()

def ftp_mgr():
    """return the global user manager instance"""
    return FtpManager




Ejemplo n.º 19
0
            with open(RESOLVE_FILE, "w") as f:
                f.writelines(before_storlever)
                f.write("# begin storlever\n")
                for server_ip in servers:
                    f.write("nameserver %s\n" % server_ip)
                f.write("# end storlever\n")
                f.writelines(after_storlever)

        # log the operation
        logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
                   "Network DNS name server list is updated by user(%s)" %
                   (user))

def dns_mgr():
    """return the global user manager instance"""
    return DnsManager

DnsManager = DnsManager()

# register cfg file
cfg_mgr().register_config_file(RESOLVE_FILE)
ModuleManager.register_module(**MODULE_INFO)








Ejemplo n.º 20
0
 def _save_conf(self, mail_conf):
     cfg_mgr().check_conf_dir()
     Config.to_file(self.conf_file, mail_conf)
Ejemplo n.º 21
0
 def _save_conf(self, zabbix_agent_conf):
     cfg_mgr().check_conf_dir()
     Config.to_file(self.conf_file, zabbix_agent_conf)
Ejemplo n.º 22
0
 def _save_conf(self, smartd_conf):
     cfg_mgr().check_conf_dir()
     Config.to_file(self.conf_file, smartd_conf)
Ejemplo n.º 23
0
                continue

            interfaces.append(dev.name)

        interfaces.sort()

        return interfaces


EthInterfaceManager = EthInterfaceManager()
		
def if_mgr():
    """return the global user manager instance"""
    return EthInterfaceManager



# register cfg file
cfg_mgr().register_config_file("/etc/modprobe.d/bond.conf")
cfg_mgr().register_config_file("/etc/sysconfig/network-scripts", r"^ifcfg-(.+)$")
ModuleManager.register_module(**MODULE_INFO)









Ejemplo n.º 24
0
    def set_active_check_server_list(self, servers=[], operator="unkown",
                                     *args, **kwargs):
        with self.lock:
            zabbix_agent_conf = self._load_conf()
            zabbix_agent_conf["active_check_server_list"] = servers
            # check config conflict
            zabbix_agent_conf = self.zabbix_agentd_conf_schema.validate(zabbix_agent_conf)

            # save new conf
            self._save_conf(zabbix_agent_conf)
            self._sync_to_system_conf(zabbix_agent_conf)

        logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
                   "Zabbix agent active server list is updated by operator(%s)" %
                   (operator))

ZabbixAgentManager = ZabbixAgentManager()

# register ftp manager callback functions to basic manager
cfg_mgr().register_restore_from_file_cb(ZabbixAgentManager.sync_to_system_conf)
cfg_mgr().register_system_restore_cb(ZabbixAgentManager.system_restore_cb)
service_mgr().register_service("zabbix-agent", "zabbix-agent", "/usr/sbin/zabbix_agentd",
                               "zabbix agent for system/network monitor")
ModuleManager.register_module(**MODULE_INFO)

def zabbix_agent_mgr():
    """return the global user manager instance"""
    return ZabbixAgentManager

Ejemplo n.º 25
0
 def _save_conf(self, fs_dict):
     cfg_mgr().check_conf_dir()
     Config.to_file(self.conf_file, fs_dict)
Ejemplo n.º 26
0
        logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
                   "filesystem %s (dev:%s, mount_point:%s, option:%s) "
                   "is deleted by user(%s)" %
                   (fs_name, fs_conf['dev_file'],
                    fs_conf['mount_point'], fs_conf['mount_option'],
                    user))

    def mkfs_on_dev(self, type, dev_file, fs_options=""):
        with self.lock:
            cls = self._get_fs_type_cls(type)
        cls.mkfs(type, dev_file, fs_options)


FileSystemManager = FileSystemManager()

cfg_mgr().register_restore_from_file_cb(FileSystemManager.sync_to_fstab)
cfg_mgr().register_system_restore_cb(FileSystemManager.system_restore_cb)
ModuleManager.register_module(**MODULE_INFO)


# disable selinux impact
set_selinux_permissive()

def fs_mgr():
    """return the global user manager instance"""
    return FileSystemManager




Ejemplo n.º 27
0
 def _save_conf(self, zabbix_agent_conf):
     cfg_mgr().check_conf_dir()
     Config.to_file(self.conf_file, zabbix_agent_conf)
Ejemplo n.º 28
0
            zabbix_agent_conf = self._load_conf()
            zabbix_agent_conf["active_check_server_list"] = servers
            # check config conflict
            zabbix_agent_conf = self.zabbix_agentd_conf_schema.validate(
                zabbix_agent_conf)

            # save new conf
            self._save_conf(zabbix_agent_conf)
            self._sync_to_system_conf(zabbix_agent_conf)

        logger.log(
            logging.INFO, logger.LOG_TYPE_CONFIG,
            "Zabbix agent active server list is updated by operator(%s)" %
            (operator))


ZabbixAgentManager = ZabbixAgentManager()

# register ftp manager callback functions to basic manager
cfg_mgr().register_restore_from_file_cb(ZabbixAgentManager.sync_to_system_conf)
cfg_mgr().register_system_restore_cb(ZabbixAgentManager.system_restore_cb)
service_mgr().register_service("zabbix-agent", "zabbix-agent",
                               "/usr/sbin/zabbix_agentd",
                               "zabbix agent for system/network monitor")
ModuleManager.register_module(**MODULE_INFO)


def zabbix_agent_mgr():
    """return the global user manager instance"""
    return ZabbixAgentManager
Ejemplo n.º 29
0
                    raise StorLeverError("Device (%s) not found" % (monitor_conf["dev"]), 404)
                else:
                    mode = os.stat(monitor_conf["dev"])[ST_MODE]
                    if not S_ISBLK(mode):
                        raise StorLeverError("Device (%s) not block device" % (monitor_conf["dev"]), 400)

                if monitor_conf["mail_exec"] != "" and not os.path.exists(monitor_conf["mail_exec"]):
                    raise StorLeverError("mail_exec (%s) not found" % (monitor_conf["mail_exec"]), 404)

            # save new conf
            self._save_conf(smartd_conf)
            self._sync_to_system_conf(smartd_conf)

        logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
                   "Smartd monitor list is updated by operator(%s)" %
                   (operator))

SmartdManager = SmartdManager()

# register ftp manager callback functions to basic manager
cfg_mgr().register_restore_from_file_cb(SmartdManager.sync_to_system_conf)
cfg_mgr().register_system_restore_cb(SmartdManager.system_restore_cb)
service_mgr().register_service("smartd", "smartd", "/usr/sbin/smartd",
                               "Monitor the hard drives which support SMART technology")
ModuleManager.register_module(**MODULE_INFO)

def smartd_mgr():
    """return the global user manager instance"""
    return SmartdManager

Ejemplo n.º 30
0
    def interface_name_list(self):
        interfaces = []
        for dev in ifconfig.iterifs(False):
            if dev.name == "lo":  # loopback interface is not handled
                continue

            if self._get_if_encap(dev.name) != 1:
                # only support Ethernet
                continue

            interfaces.append(dev.name)

        interfaces.sort()

        return interfaces


EthInterfaceManager = EthInterfaceManager()


def if_mgr():
    """return the global user manager instance"""
    return EthInterfaceManager


# register cfg file
cfg_mgr().register_config_file("/etc/modprobe.d/bond.conf")
cfg_mgr().register_config_file("/etc/sysconfig/network-scripts",
                               r"^ifcfg-(.+)$")
ModuleManager.register_module(**MODULE_INFO)
Ejemplo n.º 31
0
def clear_conf(request):
    cfg_mgr = cfgmgr.cfg_mgr()  # get cfg manager

    cfg_mgr.system_restore(user=request.client_addr)

    return Response(status=200)
Ejemplo n.º 32
0
            portal, sep, tag = line_list[0].partition(",")
            result.append({"portal": portal, "target": target})

        return result

    def system_restore_cb(self):
        check_output(
            "rm -rf " + os.path.join(ISCSI_INITIATOR_DB_PATH, "nodes/*"), True)
        check_output(
            "rm -rf " + os.path.join(ISCSI_INITIATOR_DB_PATH, "ifaces/*"),
            True)


IscsiInitiatorManager = IscsiInitiatorManager()

# register ftp manager callback functions to basic manager
cfg_mgr().register_system_restore_cb(IscsiInitiatorManager.system_restore_cb)
cfg_mgr().register_config_file(os.path.join(ISCSI_INITIATOR_DB_PATH,
                                            "ifaces/"))
cfg_mgr().register_config_file(os.path.join(ISCSI_INITIATOR_DB_PATH, "nodes/"))
service_mgr().register_service("iscsid", "iscsid", "iscsid",
                               "iSCSI Initiator daemon")
service_mgr().register_service("iscsi", "iscsi", "",
                               "iSCSI Initiator login Script")
ModuleManager.register_module(**MODULE_INFO)


def iscsi_initiator_mgr():
    """return the global block manager instance"""
    return IscsiInitiatorManager
Ejemplo n.º 33
0
            line_list = line.split()
            target = line_list[1]
            portal, sep, tag = line_list[0].partition(",")
            result.append({
                "portal": portal,
                "target": target
            })

        return result

    def system_restore_cb(self):
        check_output("rm -rf " + os.path.join(ISCSI_INITIATOR_DB_PATH, "nodes/*"), True)
        check_output("rm -rf " + os.path.join(ISCSI_INITIATOR_DB_PATH, "ifaces/*"), True)


IscsiInitiatorManager = IscsiInitiatorManager()

# register ftp manager callback functions to basic manager
cfg_mgr().register_system_restore_cb(IscsiInitiatorManager.system_restore_cb)
cfg_mgr().register_config_file(os.path.join(ISCSI_INITIATOR_DB_PATH, "ifaces/"))
cfg_mgr().register_config_file(os.path.join(ISCSI_INITIATOR_DB_PATH, "nodes/"))
service_mgr().register_service("iscsid", "iscsid", "iscsid", "iSCSI Initiator daemon")
service_mgr().register_service("iscsi", "iscsi", "", "iSCSI Initiator login Script")
ModuleManager.register_module(**MODULE_INFO)


def iscsi_initiator_mgr():
    """return the global block manager instance"""
    return IscsiInitiatorManager

Ejemplo n.º 34
0
        if "# end storlever\n" in lines:
            after_storlever = lines[lines.index("# end storlever\n") + 1:-1]
        else:
            after_storlever = []

        with self.lock:
            with open(RESOLVE_FILE, "w") as f:
                f.writelines(before_storlever)
                f.write("# begin storlever\n")
                for server_ip in servers:
                    f.write("nameserver %s\n" % server_ip)
                f.write("# end storlever\n")
                f.writelines(after_storlever)

        # log the operation
        logger.log(
            logging.INFO, logger.LOG_TYPE_CONFIG,
            "Network DNS name server list is updated by user(%s)" % (user))


def dns_mgr():
    """return the global user manager instance"""
    return DnsManager


DnsManager = DnsManager()

# register cfg file
cfg_mgr().register_config_file(RESOLVE_FILE)
ModuleManager.register_module(**MODULE_INFO)