Exemplo n.º 1
0
class ExportdAgent(Agent):
    """ exportd agent """
    def __init__(self, config='/etc/rozofs/export.conf', daemon='exportd'):
        Agent.__init__(self, EXPORTD_MANAGER)
        self._daemon_manager = DaemonManager(daemon, ["-c", config])
        self._reader = ConfigurationReader(config,
                                           ExportdConfigurationParser())
        self._writer = ConfigurationWriter(config,
                                           ExportdConfigurationParser())

    def get_service_config(self):
        configuration = ExportdConfig()
        return self._reader.read(configuration)

    def set_service_config(self, configuration):
        current = ExportdConfig()
        self._reader.read(current)

        current_roots = [e.root for e in current.exports.values()]
        roots = [e.root for e in configuration.exports.values()]

        # create new ones
        for r in [r for r in roots if r not in current_roots]:
            if not os.path.isabs(r):
                raise Exception('%s: not absolute.' % r)

            if not os.path.exists(r):
                os.makedirs(r)

            if not os.path.isdir(r):
                raise Exception('%s: not a directory.' % r)

        self._writer.write(configuration)
        self._daemon_manager.reload()

        # delete no more used ones
        for r in [r for r in current_roots if r not in roots]:
            if os.path.exists(r):
                shutil.rmtree(r)

    def get_service_status(self):
        return self._daemon_manager.status()

    def set_service_status(self, status):
        current_status = self._daemon_manager.status()
        if status == ServiceStatus.STARTED and not current_status:
            self._daemon_manager.start()
        if status == ServiceStatus.STOPPED and current_status:
            self._daemon_manager.stop()
Exemplo n.º 2
0
class ExportdAgent(Agent):
    """ exportd agent """

    def __init__(self, config='/etc/rozofs/export.conf', daemon='exportd'):
        Agent.__init__(self, EXPORTD_MANAGER)
        self._daemon_manager = DaemonManager(daemon, ["-c", config])
        self._reader = ConfigurationReader(config, ExportdConfigurationParser())
        self._writer = ConfigurationWriter(config, ExportdConfigurationParser())

    def get_service_config(self):
        configuration = ExportdConfig()
        return self._reader.read(configuration)

    def set_service_config(self, configuration):
        current = ExportdConfig()
        self._reader.read(current)

        current_roots = [e.root for e in current.exports.values()]
        roots = [e.root for e in configuration.exports.values()]

        # create new ones
        for r in [r for r in roots if r not in current_roots]:
            if not os.path.isabs(r):
                raise Exception('%s: not absolute.' % r)

            if not os.path.exists(r):
                os.makedirs(r)

            if not os.path.isdir(r):
                raise Exception('%s: not a directory.' % r)

        self._writer.write(configuration)
        self._daemon_manager.reload()

        # delete no more used ones
        for r in [r for r in current_roots if r not in roots]:
            if os.path.exists(r):
                shutil.rmtree(r)

    def get_service_status(self):
        return self._daemon_manager.status()

    def set_service_status(self, status):
        current_status = self._daemon_manager.status()
        if status == ServiceStatus.STARTED and not current_status:
            self._daemon_manager.start()
        if status == ServiceStatus.STOPPED and current_status:
            self._daemon_manager.stop()
Exemplo n.º 3
0
class ExportdAgent(Agent):
    """ exportd agent """

    def __init__(self, config="%s%s" % (__sysconfdir__, '/rozofs/export.conf'), daemon='exportd'):
        Agent.__init__(self, EXPORTD_MANAGER)
        self._daemon_manager = DaemonManager(daemon, ["-c", config])
        self._reader = ConfigurationReader(config, ExportdConfigurationParser())
        self._writer = ConfigurationWriter(config, ExportdConfigurationParser())

    def _get_volume_stat(self, vid, vstat):
        # vstat = VolumeStat()
        # Did I ever understood python?
        # I can't figure out why the above line does not initialize
        # a new cstats (on second call)
        # vstat.cstats.clear()
        with open('/var/run/exportd/volume_%d' % vid, 'r') as input:
            cid = 0
            sid = 0
            for line in input:

                if line.startswith("bsize"):
                    vstat.bsize = int(line.split(':')[-1])
                if line.startswith("bfree"):
                    vstat.bfree = int(line.split(':')[-1])
                if line.startswith("blocks"):
                    vstat.blocks = int(line.split(':')[-1])
                if line.startswith("cluster"):
                    cid = int(line.split(':')[-1])
                    vstat.cstats[cid] = ClusterStat()
                    # vstat.cstats[cid].sstats.clear()
                if line.startswith("storage"):
                    sid = int(line.split(':')[-1])
                    vstat.cstats[cid].sstats[sid] = StorageStat()
                if line.startswith("host"):
                    vstat.cstats[cid].sstats[sid].host = line.split(':')[-1].rstrip()
                if line.startswith("size"):
                    if len(vstat.cstats[cid].sstats.keys()) == 0:
                        vstat.cstats[cid].size = int(line.split(':')[-1])
                    else:
                        vstat.cstats[cid].sstats[sid].size = int(line.split(':')[-1])
                if line.startswith("free"):
                    if len(vstat.cstats[cid].sstats.keys()) == 0:
                        vstat.cstats[cid].free = int(line.split(':')[-1])
                    else:
                        vstat.cstats[cid].sstats[sid].free = int(line.split(':')[-1])
        # return vstat

    def _get_export_stat(self, eid, estat):
        with open('/var/run/exportd/export_%d' % eid, 'r') as input:
            for line in input:
                if line.startswith("bsize"):
                    estat.bsize = int(line.split(':')[-1])
                if line.startswith("blocks"):
                    estat.blocks = int(line.split(':')[-1])
                if line.startswith("bfree"):
                    estat.bfree = int(line.split(':')[-1])
                if line.startswith("files"):
                    estat.files = int(line.split(':')[-1])
                if line.startswith("ffree"):
                    estat.ffree = int(line.split(':')[-1])
        # return estat

    def get_service_config(self):
        configuration = ExportdConfig()
        self._reader.read(configuration)
        if not self.get_service_status():
            configuration.stats = None
        else:
            for vid in configuration.volumes.keys():
                configuration.stats.vstats[vid] = VolumeStat()
                self._get_volume_stat(vid, configuration.stats.vstats[vid])
            for eid in configuration.exports.keys():
                configuration.stats.estats[eid] = ExportStat()
                self._get_export_stat(eid, configuration.stats.estats[eid])
        return configuration

    def set_service_config(self, configuration):
        current = ExportdConfig()
        self._reader.read(current)

        current_roots = [e.root for e in current.exports.values()]
        roots = [e.root for e in configuration.exports.values()]

        # create new ones
        for r in [r for r in roots if r not in current_roots]:
            if not os.path.isabs(r):
                raise Exception('%s: not absolute.' % r)

            if not os.path.exists(r):
                os.makedirs(r)

            if not os.path.isdir(r):
                raise Exception('%s: not a directory.' % r)

        self._writer.write(configuration)
        self._daemon_manager.reload()

        # delete no more used ones
        for r in [r for r in current_roots if r not in roots]:
            if os.path.exists(r):
                shutil.rmtree(r)

    def get_service_status(self):
        return self._daemon_manager.status()

    def set_service_status(self, status):
        current_status = self._daemon_manager.status()
        if status == ServiceStatus.STARTED and not current_status:
            self._daemon_manager.start()
        if status == ServiceStatus.STOPPED and current_status:
            self._daemon_manager.stop()
Exemplo n.º 4
0
class ExportdAgent(Agent):
    """ exportd agent """
    def __init__(self,
                 config="%s%s" % (__sysconfdir__, '/rozofs/export.conf'),
                 daemon='exportd'):
        Agent.__init__(self, EXPORTD_MANAGER)
        self._daemon_manager = DaemonManager(daemon, ["-c", config])
        self._reader = ConfigurationReader(config,
                                           ExportdConfigurationParser())
        self._writer = ConfigurationWriter(config,
                                           ExportdConfigurationParser())

    def _get_volume_stat(self, vid, vstat):
        # vstat = VolumeStat()
        # Did I ever understood python?
        # I can't figure out why the above line does not initialize
        # a new cstats (on second call)
        # vstat.cstats.clear()
        with open('/var/run/exportd/volume_%d' % vid, 'r') as input:
            cid = 0
            sid = 0
            for line in input:

                if line.startswith("bsize"):
                    vstat.bsize = int(line.split(':')[-1])
                if line.startswith("bfree"):
                    vstat.bfree = int(line.split(':')[-1])
                if line.startswith("blocks"):
                    vstat.blocks = int(line.split(':')[-1])
                if line.startswith("cluster"):
                    cid = int(line.split(':')[-1])
                    vstat.cstats[cid] = ClusterStat()
                    # vstat.cstats[cid].sstats.clear()
                if line.startswith("storage"):
                    sid = int(line.split(':')[-1])
                    vstat.cstats[cid].sstats[sid] = StorageStat()
                if line.startswith("host"):
                    vstat.cstats[cid].sstats[sid].host = line.split(
                        ':')[-1].rstrip()
                if line.startswith("size"):
                    if len(vstat.cstats[cid].sstats.keys()) == 0:
                        vstat.cstats[cid].size = int(line.split(':')[-1])
                    else:
                        vstat.cstats[cid].sstats[sid].size = int(
                            line.split(':')[-1])
                if line.startswith("free"):
                    if len(vstat.cstats[cid].sstats.keys()) == 0:
                        vstat.cstats[cid].free = int(line.split(':')[-1])
                    else:
                        vstat.cstats[cid].sstats[sid].free = int(
                            line.split(':')[-1])
        # return vstat

    def _get_export_stat(self, eid, estat):
        with open('/var/run/exportd/export_%d' % eid, 'r') as input:
            for line in input:
                if line.startswith("bsize"):
                    estat.bsize = int(line.split(':')[-1])
                if line.startswith("blocks"):
                    estat.blocks = int(line.split(':')[-1])
                if line.startswith("bfree"):
                    estat.bfree = int(line.split(':')[-1])
                if line.startswith("files"):
                    estat.files = int(line.split(':')[-1])
                if line.startswith("ffree"):
                    estat.ffree = int(line.split(':')[-1])
        # return estat

    def get_service_config(self):
        configuration = ExportdConfig()
        self._reader.read(configuration)
        if not self.get_service_status():
            configuration.stats = None
        else:
            for vid in configuration.volumes.keys():
                configuration.stats.vstats[vid] = VolumeStat()
                self._get_volume_stat(vid, configuration.stats.vstats[vid])
            for eid in configuration.exports.keys():
                configuration.stats.estats[eid] = ExportStat()
                self._get_export_stat(eid, configuration.stats.estats[eid])
        return configuration

    def set_service_config(self, configuration):
        current = ExportdConfig()
        self._reader.read(current)

        current_roots = [e.root for e in current.exports.values()]
        roots = [e.root for e in configuration.exports.values()]

        # create new ones
        for r in [r for r in roots if r not in current_roots]:
            if not os.path.isabs(r):
                raise Exception('%s: not absolute.' % r)

            if not os.path.exists(r):
                os.makedirs(r)

            if not os.path.isdir(r):
                raise Exception('%s: not a directory.' % r)

        self._writer.write(configuration)
        self._daemon_manager.reload()

        # delete no more used ones
        for r in [r for r in current_roots if r not in roots]:
            if os.path.exists(r):
                shutil.rmtree(r)

    def get_service_status(self):
        return self._daemon_manager.status()

    def set_service_status(self, status):
        current_status = self._daemon_manager.status()
        if status == ServiceStatus.STARTED and not current_status:
            self._daemon_manager.start()
        if status == ServiceStatus.STOPPED and current_status:
            self._daemon_manager.stop()