Example #1
0
 def get_ruleset_id(self, context, group_id):
     LOG.info("Get ruleset id via storage_group id.")
     storage_group = db.storage_group_get(context, group_id)
     return storage_group['rule_id']
 def get_ruleset_id(self, context, group_id):
     LOG.info("Get ruleset id via storage_group id.")
     storage_group = db.storage_group_get(context, group_id)
     return storage_group['rule_id']
    def create(self, req, body=None):
        """Create a storage pool."""
        LOG.info(body)

        #{'pool':
        #    {'replicationFactor': 3,
        #    'name': 'test',
        #    'enablePoolQuota': False,
        #    'storageGroupId': '1',
        #    'u'replicatedStorageGroupId': '1',
        #    'clusterId': '0',
        #    'tag': 'abc',
        #    'createdBy': 'VSM',
        #    'ecProfileId': '1',
        #    'ecFailureDomain': 'osd',
        #    'poolQuota': 0
        #    }
        #}

        if not self.is_valid_body(body, 'pool'):
            raise exc.HTTPUnprocessableEntity()

        context = req.environ['vsm.context']
        pool_dict = body['pool']

        for key in ('name', 'createdBy', 'storageGroupId'):
            if not key in pool_dict:
                msg = _("%s is not defined in pool" % key)
                raise exc.HTTPBadRequest(explanation=msg)

        name = pool_dict['name'].strip()
        created_by = pool_dict['createdBy'].strip()
        storage_group_id = pool_dict['storageGroupId']
        tag = pool_dict['tag'].strip()
        cluster_id = pool_dict['clusterId']

        try:
            cluster_id = int(str(cluster_id))
        except ValueError:
            msg = _('cluster_id must be an interger value')
            raise exc.HTTPBadRequest(explanation=msg)

        osd_num = self.conductor_api.get_osd_num(context, storage_group_id)
        storage_group = db.storage_group_get(context, storage_group_id)
        is_ec_pool = pool_dict.get('ecProfileId')
        if is_ec_pool:
            #erasure code pool 
            body_info = {'name': name,
                        'cluster_id':cluster_id,
                        'storage_group_id':storage_group_id,
                        'ec_profile_id':pool_dict['ecProfileId'],
                        'ec_ruleset_root':storage_group['name'],
                        'ec_failure_domain':pool_dict['ecFailureDomain'],
                        'created_by':created_by,
                        'tag':tag}
             
        else:
            #replicated pool 
            crush_ruleset = self.conductor_api.get_ruleset_id(context, storage_group_id)
            if crush_ruleset < 0:
                msg = _('crush_ruleset must be a non-negative integer value')
                raise exc.HTTPBadRequest(explanation=msg)

            size = pool_dict['replicationFactor']
            replica_storage_group_id = pool_dict['replicatedStorageGroupId']
            try:
                size = int(str(size))
                if size < 1:
                    msg = _('size must be > 1')
                    raise exc.HTTPBadRequest(explanation=msg)

                host_num = self.conductor_api.count_hosts_by_storage_group_id(context, storage_group_id) 
                LOG.info("storage_group_id:%s,host_num:%s", storage_group_id, host_num)
                if size > host_num:
                    msg = "The replication factor must be less than or equal to the number of storage nodes in the specific storage group in cluster!"
                    return {'message': msg}
            except ValueError:
                msg = _('size must be an interger value')
                raise exc.HTTPBadRequest(explanation=msg)

            pg_num = self._compute_pg_num(context, osd_num, size)

            #vsm_id = str(uuid.uuid1()).split('-')[0]
            body_info = {'name': name, #+ "-vsm" + vsm_id,
                        'cluster_id':cluster_id,
                        'storage_group_id':storage_group_id,
                        'replica_storage_group_id':replica_storage_group_id,
                        'crush_ruleset':crush_ruleset,
                        'pg_num':pg_num,
                        'pgp_num':pg_num,
                        'size':size,
                        'min_size':size,
                        'created_by':created_by,
                        'tag':tag}

        body_info.update({
            "quota": pool_dict.get("poolQuota"),
            "enable_quota": pool_dict.get("enablePoolQuota"),
            "max_pg_num_per_osd": pool_dict.get("max_pg_num_per_osd") or 100,
        })

        return self.scheduler_api.create_storage_pool(context, body_info)
    def create(self, req, body=None):
        """Create a storage pool."""
        LOG.info(body)

        #{'pool':
        #    {'replicationFactor': 3,
        #    'name': 'test',
        #    'enablePoolQuota': False,
        #    'storageGroupId': '1',
        #    'u'replicatedStorageGroupId': '1',
        #    'clusterId': '0',
        #    'tag': 'abc',
        #    'createdBy': 'VSM',
        #    'ecProfileId': '1',
        #    'ecFailureDomain': 'osd',
        #    'poolQuota': 0
        #    }
        #}

        if not self.is_valid_body(body, 'pool'):
            raise exc.HTTPUnprocessableEntity()

        context = req.environ['vsm.context']
        pool_dict = body['pool']

        for key in ('name', 'createdBy', 'storageGroupId'):
            if not key in pool_dict:
                msg = _("%s is not defined in pool" % key)
                raise exc.HTTPBadRequest(explanation=msg)

        name = pool_dict['name'].strip()
        created_by = pool_dict['createdBy'].strip()
        storage_group_id = pool_dict['storageGroupId']
        tag = pool_dict['tag'].strip()
        cluster_id = pool_dict['clusterId']

        try:
            cluster_id = int(str(cluster_id))
        except ValueError:
            msg = _('cluster_id must be an interger value')
            raise exc.HTTPBadRequest(explanation=msg)

        osd_num = self.conductor_api.get_osd_num(context, storage_group_id)
        storage_group = db.storage_group_get(context, storage_group_id)
        is_ec_pool = pool_dict.get('ecProfileId')
        if is_ec_pool:
            #erasure code pool 
            body_info = {'name': name,
                        'cluster_id':cluster_id,
                        'storage_group_id':storage_group_id,
                        'ec_profile_id':pool_dict['ecProfileId'],
                        'ec_ruleset_root':storage_group['name'],
                        'ec_failure_domain':pool_dict['ecFailureDomain'],
                        'created_by':created_by,
                        'tag':tag}
             
        else:
            #replicated pool 
            crush_ruleset = self.conductor_api.get_ruleset_id(context, storage_group_id)
            if crush_ruleset < 0:
                msg = _('crush_ruleset must be a non-negative integer value')
                raise exc.HTTPBadRequest(explanation=msg)

            size = pool_dict['replicationFactor']
            replica_storage_group_id = pool_dict['replicatedStorageGroupId']
            try:
                size = int(str(size))
                if size < 1:
                    msg = _('size must be > 1')
                    raise exc.HTTPBadRequest(explanation=msg)

                host_num = self.conductor_api.count_hosts_by_storage_group_id(context, storage_group_id) 
                LOG.info("storage_group_id:%s,host_num:%s", storage_group_id, host_num)
                if size > host_num:
                    msg = "The replication factor must be less than or equal to the number of storage nodes in the specific storage group in cluster!"
                    return {'message': msg}
            except ValueError:
                msg = _('size must be an interger value')
                raise exc.HTTPBadRequest(explanation=msg)

            pg_num = self._compute_pg_num(context, osd_num, size)

            #vsm_id = str(uuid.uuid1()).split('-')[0]
            body_info = {'name': name, #+ "-vsm" + vsm_id,
                        'cluster_id':cluster_id,
                        'storage_group_id':storage_group_id,
                        'replica_storage_group_id':replica_storage_group_id,
                        'crush_ruleset':crush_ruleset,
                        'pg_num':pg_num,
                        'pgp_num':pg_num,
                        'size':size,
                        'min_size':size,
                        'created_by':created_by,
                        'tag':tag}

        body_info.update({
            "quota": pool_dict.get("poolQuota"),
            "enable_quota": pool_dict.get("enablePoolQuota"),
        })

        return self.scheduler_api.create_storage_pool(context, body_info)
Example #5
0
 def storage_group_get(self, context, id):
     return db.storage_group_get(context, id)
Example #6
0
 def storage_group_get(self, context, id):
     return db.storage_group_get(context, id)