Beispiel #1
0
 def _fetch_rbd_cache_config_value_from_file(self, rbd_name, key):
     formats = {
         'cache_service_threads_num': 'cacheservice_threads_num',
         'enable_memory_usage_tracker': 'enable_MemoryUsageTracker'
     }
     key = formats.get(key, key)
     cmd = ['crudini', '--get', RBD_CACHE_CONFIG_FILE_PATH, rbd_name, key]
     out, _ = utils.execute(*cmd, run_as_root=True)
     value = out.strip('\n')
     if value:
         return key, value
     cmd = ['crudini', '--get', RBD_CACHE_CONFIG_FILE_PATH, 'global', key]
     out, _ = utils.execute(*cmd, run_as_root=True)
     value = out.strip('\n')
     return key, value
Beispiel #2
0
 def ceph_version(self):
     cmds = ['ceph', '--version']
     try:
         out, _ = utils.execute(*cmds, run_as_root=True)
         ceph_version = " ".join(out.split(" ")[2:3]).strip("\n").strip(" ")
     except:
         ceph_version = "--"
     return ceph_version
Beispiel #3
0
    def init_node_into_db(self):
        LOG.info("initialize the agent node into db.")

        out, _ = utils.execute("hostname", "-I", run_as_root=True)
        ips_list = out.strip("\n").strip(" ").split(" ")
        ips = None
        for ip in ips_list:
            if not ips:
                ips = ip
            else:
                ips = ips + "," + ip
        LOG.info("ips are %s" % ips)

        out, _ = utils.execute("hostname", run_as_root=True)
        host = out.strip("\n").strip(" ")
        LOG.info("host is %s" % host)

        id_rsa_pub_path = FLAGS.id_rsa_pub
        LOG.info("id_rsa_pub_path is %s" % id_rsa_pub_path)
        id_rsa_pub = utils.read_file_as_root(id_rsa_pub_path).strip(
            "\n").strip(" ")

        server_info = {
            "host": host,
            "ip": ips,
            "status": "available",
            "id_rsa_pub": id_rsa_pub
        }

        server = self.conductor_api.server_get_by_host(self.context, host=host)
        if not server:
            self.conductor_api.server_create(self.context, values=server_info)
        else:
            server_info.pop("status")
            server_id = server.get("id")
            self.conductor_api.server_update(self.context,
                                             server_id=server_id,
                                             values=server_info)
Beispiel #4
0
 def hsm_summary_get(self, context):
     servers = self.conductor_api.server_get_all(context)
     if len(servers) == 0:
         summary = {"ceph_version": "--",
                    "total_hyperstash_instances": "--",
                    "total_rbds": "--"}
     else:
         rand_server = servers[random.randrange(0, len(servers))]
         host = rand_server['host']
         summary = self.agent_api.hsm_summary_get(context, host)
     _, out = utils.execute("hsm", "--version", run_as_root=True)
     hsm_version = out.strip("\n").strip(" ")
     summary["hsm_version"] = hsm_version
     return summary
Beispiel #5
0
 def rbd_info(self, rbd, pool, format="json"):
     cmds = ['rbd', 'info', rbd, '-p', pool, '--format', format]
     out, _ = utils.execute(*cmds, run_as_root=True)
     return out
Beispiel #6
0
 def ceph_osd_pool_ls(self, format="json"):
     cmds = ['ceph', 'osd', 'pool', 'ls', '-f', format]
     out, _ = utils.execute(*cmds, run_as_root=True)
     return out
Beispiel #7
0
 def _set_rbd_cache_config_value_into_file(self, rbd_name, key, value):
     cmd = [
         'crudini', '--set', RBD_CACHE_CONFIG_FILE_PATH, rbd_name, key,
         value
     ]
     utils.execute(*cmd, run_as_root=True)
Beispiel #8
0
    def _update_rbd(self, context):
        LOG.info("Periodic task to update rbd")

        out, _ = utils.execute("hostname", run_as_root=True)
        host = out.strip("\n").strip(" ")
        LOG.info("host is %s" % host)

        hs_instance = self.conductor_api.hs_instance_get_by_host(context, host)
        if not hs_instance:
            return
        hs_instance_id = hs_instance['id']
        rbds_in_db = self.conductor_api.\
            rbd_get_all_by_hs_instance_id(context, hs_instance_id)
        rbds_name_in_db = []
        for rbd_in_db in rbds_in_db:
            rbds_name_in_db.append(rbd_in_db['name'])

        general_conf = "/etc/rbc/general.conf"
        rbds = []
        if os.path.exists(general_conf):
            file_obj = open(general_conf)
            for line in file_obj.readlines():
                line = line.strip("\n")
                if line.startswith("[") and line != "[global]":
                    rbd_name = line.lstrip("[").rstrip("]")
                    rbds.append(rbd_name)
        LOG.info("RBD %s on hyperstash instance %s" %
                 (str(rbds), hs_instance_id))

        pools_list = self.ceph_driver.ceph_osd_pool_ls(format="json")
        pools_list = json.loads(pools_list)
        pools_with_rbds = []
        for pool in pools_list:
            rbds_all = self.ceph_driver.rbd_ls(pool, format="json")
            rbds_all = json.loads(rbds_all)
            pools_with_rbds.append({'pool': pool, 'rbds': rbds_all})
        rbds_name_in_ceph = []
        for rbd in rbds:
            for pool_with_rbd in pools_with_rbds:
                if rbd in pool_with_rbd['rbds']:
                    rbds_name_in_ceph.append(rbd)
                    pool = pool_with_rbd['pool']
                    rbd_info = self.ceph_driver.rbd_info(rbd,
                                                         pool,
                                                         format="json")
                    rbd_info = json.loads(rbd_info)
                    features = rbd_info.get('features', None)
                    _features = None
                    if features:
                        for feature in features:
                            if not _features:
                                _features = feature
                            else:
                                _features = _features + "," + feature
                    rbd_info['features'] = _features
                    flags = rbd_info.get('flags', None)
                    _flags = None
                    if flags:
                        for flag in flags:
                            if not _flags:
                                _flags = flag
                            else:
                                _flags = _flags + "," + flag
                    rbd_info['flags'] = _flags
                    rbd_info['hs_instance_id'] = hs_instance_id
                    if rbd not in rbds_name_in_db:
                        self.conductor_api.rbd_create(context, rbd_info)
                    else:
                        rbd_in_db = self.conductor_api.rbd_get_by_name(
                            context, rbd)
                        rbd_id = rbd_in_db['id']
                        self.conductor_api.rbd_update(context, rbd_id,
                                                      rbd_info)
        for rbd_name_in_db in rbds_name_in_db:
            if rbd_name_in_db not in rbds_name_in_ceph:
                rbd_in_db = self.conductor_api.rbd_get_by_name(
                    context, rbd_name_in_db)
                rbd_id = rbd_in_db['id']
                self.conductor_api.rbd_cache_config_delete_by_rbd_id(
                    context, rbd_id)
                self.conductor_api.rbd_delete(context, rbd_id)