Example #1
0
def set_vsm_conf(recv):
    """Write vsm conf files."""
    if recv is None:
        return False

    old_recv = recv
    try:
        recv = json.loads(recv)
    except TypeError:
        recv = old_recv
        LOG.info('Maybe recv is not json.')

    if not recv.get("api-paste.ini", None):
        LOG.error('Can not find content of api-paste.ini')
        raise exception.NotFound()

    if not recv.get("vsm.conf", None):
        LOG.error('Can not find content of vsm.conf')
        raise exception.NotFound()

    files = ["api-paste.ini", "vsm.conf"]
    for conf in files:
        conf_path = FLAGS.vsm_config_path + conf
        #conf_file = open(conf_path, 'w')
        #conf_file.write(recv[conf])
        utils.write_file_as_root(conf_path, recv[conf], "w")
        #conf_file.close()

    return True
Example #2
0
def set_vsm_conf(recv):
    """Write vsm conf files."""
    if recv is None:
        return False

    old_recv = recv
    try:
        recv = json.loads(recv)
    except TypeError:
        recv = old_recv
        LOG.info('Maybe recv is not json.')

    if not recv.get("api-paste.ini", None):
        LOG.error('Can not find content of api-paste.ini')
        raise exception.NotFound()

    if not recv.get("vsm.conf", None):
        LOG.error('Can not find content of vsm.conf')
        raise exception.NotFound()

    files = ["api-paste.ini", "vsm.conf"]
    for conf in files:
        conf_path = FLAGS.vsm_config_path + conf
        #conf_file = open(conf_path, 'w')
        #conf_file.write(recv[conf])
        utils.write_file_as_root(conf_path, recv[conf], "w")
        #conf_file.close()

    return True
    def sync_before_read(self, cfgfile, sync=True):
        """
        Check DB cluster:ceph_conf against fp if sync is True. If checksums are different or (only) one of them does
        not exist, compare timestamps. Timestamp of missing entity is always considered older than the existing entity.
        If DB is newer, write DB to file. If file is newer, sync DB from file and signal agents to sync with DB. Parse
        file if it exists.

        :param cfgfile: the file path from which to parse config data (ok for file to not exist).
        :param sync: sync if True, otherwise just parse specified file if exists.
        :return: The latest config content - from db or file (if sync==False, always from file)
        """
        fpinfo = FileConfigInfo(cfgfile, sync)
        latest_content = fpinfo.get_content()
        LOG.debug("fpinfo: %.30s, %s, %d" % (fpinfo.get_content(), fpinfo.get_md5sum(), fpinfo.get_luts()))
        if sync:
            dbinfo = DBConfigInfo(self._cluster_id_accessor, self._context)
            LOG.debug("dbinfo: %.30s, %s, %d" % (dbinfo.get_content(), dbinfo.get_md5sum(), dbinfo.get_luts()))
            if fpinfo.get_md5sum() != dbinfo.get_md5sum():
                LOG.debug("md5sums different, checking last update timestamp")
                if fpinfo.get_luts() > dbinfo.get_luts():
                    LOG.debug("file timestamp greater than db timestamp; writing file to db and notifying agents")
                    self._write_ceph_conf_to_db(latest_content)
                    self._request_all_remote_agents_update_ceph_conf_from_db()
                else:
                    LOG.debug("db timestamp greater than file timestamp; writing db to file")
                    latest_content = dbinfo.get_content() + '\n'
                    utils.write_file_as_root(cfgfile, latest_content, "w")

        return latest_content
Example #4
0
    def save_conf(self, file_path=FLAGS.ceph_conf, sync=True):
        """
        Save the current contents of the parser as a configuration file named as per the file_path argument. If
        sync is True, also write contents into the database and notify remote users to sync with updated content.

        :param file_path: the file to which the parser contents should be saved.
        :param sync: assuming we just updated (because we're saving), write the contents to the db and notify remote
        agents if True, otherwise do not write to db and notify agents.
        """
        content = self.as_str()
        utils.write_file_as_root(file_path, content, "w")
        if sync:
            CephConfigSynchronizer().sync_after_write(content)
    def save_conf(self, file_path=FLAGS.ceph_conf, sync=True):
        """
        Save the current contents of the parser as a configuration file named as per the file_path argument. If
        sync is True, also write contents into the database and notify remote users to sync with updated content.

        :param file_path: the file to which the parser contents should be saved.
        :param sync: assuming we just updated (because we're saving), write the contents to the db and notify remote
        agents if True, otherwise do not write to db and notify agents.
        """
        content = self.as_str()
        utils.write_file_as_root(file_path, content, "w")
        if sync:
            CephConfigSynchronizer().sync_after_write(content)
Example #6
0
    def _load_ceph_conf_from_db(self):
        if not self.cluster_id:
            if not self._get_cluster_id():
                LOG.debug('Can not get cluster_id')
                return

        ceph_conf = db.cluster_get_ceph_conf(self.context, self.cluster_id)

        if not ceph_conf:
            return

        utils.write_file_as_root(FLAGS.ceph_conf, ceph_conf, 'w')

        # We try to update fstab here.
        utils.execute('sed',
                      '-i',
                      '/forvsmosd/d',
                      '/etc/fstab',
                      run_as_root=True)

        parser = Parser()
        parser.read(FLAGS.ceph_conf)
        fs_type = parser.get('osd', 'osd mkfs type', 'xfs')
        cluster = db.cluster_get_all(self.context)[0]
        mount_option = cluster['mount_option']
        if not mount_option:
            mount_option = utils.get_fs_options(fs_type)[1]
        mount_attr = parser.get('osd', 'osd mount options %s' % fs_type,
                                mount_option)

        for sec in parser.sections():
            if sec.find('osd.') != -1:
                osd_id = sec.split('.')[1]
                mount_path = os.path.join(FLAGS.osd_data_path,
                                          "osd%s" % osd_id)
                mount_disk = parser.get(sec, 'devs')
                mount_host = parser.get(sec, 'host')
                if FLAGS.host == mount_host:
                    line = mount_disk + ' ' + mount_path
                    line = line + ' ' + fs_type
                    line = line + ' ' + mount_attr + ' 0 0'
                    line = line + ' ' + '## forvsmosd'
                    utils.write_file_as_root('/etc/fstab', line)
    def _load_ceph_conf_from_db(self):
        if not self.cluster_id:
            if not self._get_cluster_id():
                LOG.debug('Can not get cluster_id')
                return

        ceph_conf = db.cluster_get_ceph_conf(self.context,
                                             self.cluster_id)

        if not ceph_conf:
            return

        utils.write_file_as_root(FLAGS.ceph_conf, ceph_conf, 'w')

        # We try to update fstab here.
        utils.execute('sed',
                      '-i',
                      '/forvsmosd/d',
                      '/etc/fstab',
                      run_as_root=True)

        parser = Parser()
        parser.read(FLAGS.ceph_conf)
        fs_type = parser.get('osd', 'osd mkfs type', 'xfs')
        cluster = db.cluster_get_all(self.context)[0]
        mount_option = cluster['mount_option']
        if not mount_option:
            mount_option = utils.get_fs_options(fs_type)[1]
        mount_attr = parser.get('osd', 'osd mount options %s' % fs_type, mount_option)

        for sec in parser.sections():
            if sec.find('osd.') != -1:
                osd_id = sec.split('.')[1]
                mount_path = os.path.join(FLAGS.osd_data_path, "osd%s" % osd_id)
                mount_disk = parser.get(sec, 'devs')
                mount_host = parser.get(sec, 'host')
                if FLAGS.host == mount_host:
                    line = mount_disk + ' ' + mount_path
                    line = line + ' ' + fs_type
                    line = line + ' ' + mount_attr + ' 0 0'
                    line = line + ' ' + '## forvsmosd'
                    utils.write_file_as_root('/etc/fstab', line)
Example #8
0
    def sync_before_read(self, cfgfile, sync=True):
        """
        Check DB cluster:ceph_conf against fp if sync is True. If checksums are different or (only) one of them does
        not exist, compare timestamps. Timestamp of missing entity is always considered older than the existing entity.
        If DB is newer, write DB to file. If file is newer, sync DB from file and signal agents to sync with DB. Parse
        file if it exists.

        :param cfgfile: the file path from which to parse config data (ok for file to not exist).
        :param sync: sync if True, otherwise just parse specified file if exists.
        :return: The latest config content - from db or file (if sync==False, always from file)
        """
        fpinfo = FileConfigInfo(cfgfile, sync)
        latest_content = fpinfo.get_content()
        LOG.debug(
            "fpinfo: %.30s, %s, %d" %
            (fpinfo.get_content(), fpinfo.get_md5sum(), fpinfo.get_luts()))
        if sync:
            dbinfo = DBConfigInfo(self._cluster_id_accessor, self._context)
            LOG.debug(
                "dbinfo: %.30s, %s, %d" %
                (dbinfo.get_content(), dbinfo.get_md5sum(), dbinfo.get_luts()))
            if fpinfo.get_md5sum() != dbinfo.get_md5sum():
                LOG.debug("md5sums different, checking last update timestamp")
                if fpinfo.get_luts() > dbinfo.get_luts():
                    LOG.debug(
                        "file timestamp greater than db timestamp; writing file to db and notifying agents"
                    )
                    self._write_ceph_conf_to_db(latest_content)
                    self._request_all_remote_agents_update_ceph_conf_from_db()
                else:
                    LOG.debug(
                        "db timestamp greater than file timestamp; writing db to file"
                    )
                    latest_content = dbinfo.get_content() + '\n'
                    utils.write_file_as_root(cfgfile, latest_content, "w")

        return latest_content
Example #9
0
def set_keyring_admin(keyring_admin):
    """Set keyring admin file."""
    if not os.path.exists(FLAGS.keyring_admin):
        #open(FLAGS.keyring_admin, 'w').write(keyring_admin)
        utils.write_file_as_root(FLAGS.keyring_admin, keyring_admin, "w")
    else:
        LOG.info('Error keyring file exists')
        LOG.info('Back up & cover the old version')
        old_content = open(FLAGS.keyring_admin, 'r').read()
        # if not the same. cmp('a', 'a') == 0
        if cmp(keyring_admin.strip(), old_content.strip()):
            bfx = time.asctime().replace(' ','_').replace(':','_')
            old_fname = FLAGS.keyring_admin + bfx
            #open(old_fname, 'w').write(old_content)
            utils.write_file_as_root(old_fname, old_content, "w")
            # write the newer version.
            #open(FLAGS.keyring_admin, 'w').write(keyring_admin)
            utils.write_file_as_root(FLAGS.keyring_admin, keyring_admin, "w")
        else:
            LOG.info('Have the same content, pass')
Example #10
0
def set_keyring_admin(keyring_admin):
    """Set keyring admin file."""
    if not os.path.exists(FLAGS.keyring_admin):
        #open(FLAGS.keyring_admin, 'w').write(keyring_admin)
        utils.write_file_as_root(FLAGS.keyring_admin, keyring_admin, "w")
    else:
        LOG.info('Error keyring file exists')
        LOG.info('Back up & cover the old version')
        old_content = open(FLAGS.keyring_admin, 'r').read()
        # if not the same. cmp('a', 'a') == 0
        if cmp(keyring_admin.strip(), old_content.strip()):
            bfx = time.asctime().replace(' ', '_').replace(':', '_')
            old_fname = FLAGS.keyring_admin + bfx
            #open(old_fname, 'w').write(old_content)
            utils.write_file_as_root(old_fname, old_content, "w")
            # write the newer version.
            #open(FLAGS.keyring_admin, 'w').write(keyring_admin)
            utils.write_file_as_root(FLAGS.keyring_admin, keyring_admin, "w")
        else:
            LOG.info('Have the same content, pass')
Example #11
0
 def save_conf(self, file_path=FLAGS.ceph_conf):
     content = self.content()
     utils.write_file_as_root(file_path, content)
     self._update_ceph_conf_into_db(content)
     self._push_db_conf_to_all_agents()
 def save_conf(self, file_path=FLAGS.ceph_conf):
     content = self.content()
     utils.write_file_as_root(file_path, content)
     self._update_ceph_conf_into_db(content)
     self._push_db_conf_to_all_agents()