コード例 #1
0
 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())
コード例 #2
0
ファイル: storaged.py プロジェクト: baoboa/rozofs
class StoragedAgent(Agent):

    def __init__(self, config="%s%s" % (__sysconfdir__, '/rozofs/storage.conf'), daemon='storaged'):
        Agent.__init__(self, STORAGED_MANAGER)
        self._daemon_manager = DaemonManager(daemon, ["-c", config], 5)
        self._reader = ConfigurationReader(config, StoragedConfigurationParser())
        self._writer = ConfigurationWriter(config, StoragedConfigurationParser())

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

    def set_service_config(self, configuration):
        for r in [s.root for s in configuration.storages.values()]:
            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.restart()

    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()
コード例 #3
0
class StoragedAgent(Agent):

    def __init__(self, config="%s%s" % (__sysconfdir__, '/rozofs/storage.conf'), daemon='storaged'):
        Agent.__init__(self, STORAGED_MANAGER)
        self._daemon_manager = DaemonManager(daemon, ["-c", config], 5)
        self._reader = ConfigurationReader(config, StoragedConfigurationParser())
        self._writer = ConfigurationWriter(config, StoragedConfigurationParser())
        self._rebuilder = "storage_rebuild"

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

    def set_service_config(self, configuration):

        for s in configuration.storages.values():
            if not os.path.isabs(s.root):
                raise Exception('%s: not absolute.' % s.root)
            if not os.path.exists(s.root):
                os.makedirs(s.root)
            if not os.path.isdir(s.root):
                raise Exception('%s: not a directory.' % s.root)
            
            for dev in range(0, s.device_t):
                dev_path="%s/%s" % (s.root, str(dev))
                if not os.path.isabs(dev_path):
                    raise Exception('%s: not absolute.' % dev_path)
                if not os.path.exists(dev_path):
                    os.makedirs(dev_path)
                if not os.path.isdir(dev_path):
                    raise Exception('%s: not a directory.' % dev_path)

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

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

    def set_service_status(self, status):
        current_status = self._daemon_manager.status()
        changes = None
        if status == ServiceStatus.STARTED:
            changes = self._daemon_manager.start()
        if status == ServiceStatus.STOPPED:
            changes = self._daemon_manager.stop()
        return changes

    def start_rebuild(self, exports_list, cid=None, sid=None, device=None):
        if cid is not None and sid is not None:
            if device is not None:
                cmds = self._rebuilder + ' -s ' + str(cid) + '/' + str(sid) + ' -d ' + str(device) + " -r " + "/".join(exports_list)
            else:
                cmds = self._rebuilder + ' -s ' + str(cid) + '/' + str(sid) + " -r " + "/".join(exports_list)
        else:
            cmds = self._rebuilder + " -r " + "/".join(exports_list)

        p = subprocess.Popen(cmds, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
コード例 #4
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()
コード例 #5
0
ファイル: exportd.py プロジェクト: Chethan-Casey/rozofs
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()
コード例 #6
0
ファイル: storaged.py プロジェクト: baoboa/rozofs
 def __init__(self, config="%s%s" % (__sysconfdir__, '/rozofs/storage.conf'), daemon='storaged'):
     Agent.__init__(self, STORAGED_MANAGER)
     self._daemon_manager = DaemonManager(daemon, ["-c", config], 5)
     self._reader = ConfigurationReader(config, StoragedConfigurationParser())
     self._writer = ConfigurationWriter(config, StoragedConfigurationParser())
コード例 #7
0
ファイル: exportd.py プロジェクト: OlivierB/rozofs
 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())
コード例 #8
0
ファイル: exportd.py プロジェクト: OlivierB/rozofs
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()
コード例 #9
0
ファイル: exportd.py プロジェクト: rootfs/rozofs
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()
コード例 #10
0
ファイル: storaged.py プロジェクト: HemanthKumarHC/rozofs
 def __init__(self, config='/etc/rozofs/storage.conf', daemon='storaged'):
     Agent.__init__(self, STORAGED_MANAGER)
     self._daemon_manager = DaemonManager(daemon, ["-c", config], 1)
     self._reader = ConfigurationReader(config, StoragedConfigurationParser())
     self._writer = ConfigurationWriter(config, StoragedConfigurationParser())