示例#1
0
    def _get_keyring_admin_from_db(self):
        """Get keyring from DB."""

        # If already have keyring.admin just fetch once.
        if self._cluster_info.get('keyring_admin', None):
            LOG.info(' API contains the keyring.admin')
            return

        cluster_info = self._cluster_info['cluster']
        cluster_name = cluster_info['cluster_name']
        cluster_ref = db.cluster_get_by_name(self._context, cluster_name)

        if not cluster_ref:
            LOG.info(' No keyring_admin cluster = %s' % cluster_name)
            return
        else:
            # NOTE we update the cluster info in DB.
            LOG.info(' Find cluster name = %s' % cluster_name)
            # If we find the cluster, we also return the keyring.admin
            # info for storage nodes.
            info_dict = cluster_ref.get('info_dict', None)
            if info_dict:
                keyring_admin = json.loads(info_dict)
                keyring_admin_info = keyring_admin.get('keyring_admin', None)
                if keyring_admin:
                    self._cluster_info['keyring_admin'] = keyring_admin_info
                    LOG.info(' API get keyring.admin from DB.')
                else:
                    LOG.info('Can not get keyring_admin from DB.')
            else:
                LOG.info('Can not get info_dict from DB.')
            return True
示例#2
0
 def import_ceph_conf(self, req, body=None):
     """
     import_ceph_conf to db and ceph nodes
     """
     LOG.info("CEPH_LOG import_ceph_conf body=%s" % body)
     context = req.environ['vsm.context']
     ceph_conf_path = body["cluster"]["ceph_conf_path"]
     cluster_name = body["cluster"]["cluster_name"]
     cluster = db.cluster_get_by_name(context, cluster_name)
     if cluster:
         ceph_conf_dict_old = cephconfigparser.CephConfigParser(
             FLAGS.ceph_conf)._parser.as_dict()
         ceph_conf_parser = cephconfigparser.CephConfigParser(
             ceph_conf_path)._parser
         ceph_conf_dict = ceph_conf_parser.as_dict()
         check_ret = check_ceph_conf(ceph_conf_dict_old, ceph_conf_dict)
         if check_ret:
             return {"message": "%s" % check_ret}
         self.scheduler_api.import_ceph_conf(context,
                                             cluster_id=cluster.id,
                                             ceph_conf_path=ceph_conf_path)
         return {"message": "Success"}
     else:
         return {
             "message":
             "No such cluster which named  %s in DB" % cluster_name
         }
    def _get_keyring_admin_from_db(self):
        """Get keyring from DB."""

        # If already have keyring.admin just fetch once.
        if self._cluster_info.get('keyring_admin', None):
            LOG.info(' API contains the keyring.admin')
            return

        cluster_info = self._cluster_info['cluster']
        cluster_name = cluster_info['cluster_name']
        cluster_ref = db.cluster_get_by_name(self._context,
                                             cluster_name)

        if not cluster_ref:
            LOG.info(' No keyring_admin cluster = %s' % cluster_name)
            return
        else:
            # NOTE we update the cluster info in DB.
            LOG.info(' Find cluster name = %s' % cluster_name)
            # If we find the cluster, we also return the keyring.admin
            # info for storage nodes.
            info_dict = cluster_ref.get('info_dict', None)
            if info_dict:
                keyring_admin = json.loads(info_dict)
                keyring_admin_info = keyring_admin.get('keyring_admin', None)
                if keyring_admin:
                    self._cluster_info['keyring_admin'] = keyring_admin_info
                    LOG.info(' API get keyring.admin from DB.')
                else:
                    LOG.info('Can not get keyring_admin from DB.')
            else:
                LOG.info('Can not get info_dict from DB.')
            return True
示例#4
0
 def import_ceph_conf(self, req, body=None):
     """
     import_ceph_conf to db and ceph nodes
     """
     LOG.info("CEPH_LOG import_ceph_conf body=%s"%body )
     context = req.environ['vsm.context']
     ceph_conf_path = body["cluster"]["ceph_conf_path"]
     cluster_name = body["cluster"]["cluster_name"]
     cluster = db.cluster_get_by_name(context,cluster_name)
     if cluster:
         ceph_conf_dict_old = CephConfigParser(FLAGS.ceph_conf, sync=False).as_dict()
         ceph_conf_dict = CephConfigParser(ceph_conf_path, sync=False).as_dict()
         check_ret = check_ceph_conf(ceph_conf_dict_old,ceph_conf_dict)
         if check_ret:
             return {"message":"%s"%check_ret}
         self.scheduler_api.import_ceph_conf(context,cluster_id=cluster.id,ceph_conf_path=ceph_conf_path)
         return {"message":"Success"}
     else:
         return {"message":"No such cluster which named  %s in DB"%cluster_name}
    def _write_cluster_info(self):
        """Write cluster info into DB.

        Info includes:

            cluster_name
            file_system
            public_address
            secondary_public_address
            cluster_address
        """
        cluster_info = self._cluster_info['cluster']

        LOG.info(' cluster_info to db = %s' % \
            json.dumps(cluster_info, sort_keys=True, indent=4))

        cluster_name = cluster_info['cluster_name']

        cluster_ref = db.cluster_get_by_name(self._context,
                                             cluster_name)

        if not cluster_ref:
            LOG.info(' Have not find cluster = %s' % cluster_name)
            LOG.info(' Before Writing cluster = %s' % \
            json.dumps(cluster_info, sort_keys=True, indent=4))
            db.cluster_create(self._context, cluster_info)
        else:
            # NOTE we update the cluster info in DB.
            LOG.info(' Find cluster name = %s' % cluster_name)
            db.cluster_update(self._context,
                              cluster_ref['id'],
                              cluster_info)
            # If we find the cluster, we also return the keyring.admin
            # info for storage nodes.
            info_dict = cluster_ref['info_dict']
            if info_dict:
                LOG.info('Get info dict from DB.')
                keyring_admin = json.loads(info_dict).get('keyring_admin', None)
                self._cluster_info['keyring_admin'] = keyring_admin
            else:
                LOG.info('Can not get keyring from DB.')
            return True
示例#6
0
    def _write_cluster_info(self):
        """Write cluster info into DB.

        Info includes:

            cluster_name
            file_system
            public_address
            secondary_public_address
            cluster_address
        """
        cluster_info = self._cluster_info['cluster']

        LOG.info(' cluster_info to db = %s' % \
            json.dumps(cluster_info, sort_keys=True, indent=4))

        cluster_name = cluster_info['cluster_name']

        cluster_ref = db.cluster_get_by_name(self._context, cluster_name)

        if not cluster_ref:
            LOG.info(' Have not find cluster = %s' % cluster_name)
            LOG.info(' Before Writing cluster = %s' % \
            json.dumps(cluster_info, sort_keys=True, indent=4))
            db.cluster_create(self._context, cluster_info)
        else:
            # NOTE we update the cluster info in DB.
            LOG.info(' Find cluster name = %s' % cluster_name)
            db.cluster_update(self._context, cluster_ref['id'], cluster_info)
            # If we find the cluster, we also return the keyring.admin
            # info for storage nodes.
            info_dict = cluster_ref['info_dict']
            if info_dict:
                LOG.info('Get info dict from DB.')
                keyring_admin = json.loads(info_dict).get(
                    'keyring_admin', None)
                self._cluster_info['keyring_admin'] = keyring_admin
            else:
                LOG.info('Can not get keyring from DB.')
            return True
示例#7
0
 def cluster_get_by_name(self, context, name):
     return db.cluster_get_by_name(context, name)
 def cluster_get_by_name(self, context, name):
     return db.cluster_get_by_name(context, name)