Beispiel #1
0
 def test_unlimited_gigabytes(self):
     self.flags(quota_volumes=-1, quota_gigabytes=10)
     volumes = quota.allowed_volumes(self.context, 100, 1)
     self.assertEqual(volumes, 10)
     db.quota_create(self.context, self.project_id, "gigabytes", None)
     volumes = quota.allowed_volumes(self.context, 100, 1)
     self.assertEqual(volumes, 100)
     volumes = quota.allowed_volumes(self.context, 101, 1)
     self.assertEqual(volumes, 101)
Beispiel #2
0
 def test_unlimited_gigabytes(self):
     self.flags(quota_volumes=-1, quota_gigabytes=10)
     volumes = quota.allowed_volumes(self.context, 100, 1)
     self.assertEqual(volumes, 10)
     db.quota_create(self.context, self.project_id, 'gigabytes', None)
     volumes = quota.allowed_volumes(self.context, 100, 1)
     self.assertEqual(volumes, 100)
     volumes = quota.allowed_volumes(self.context, 101, 1)
     self.assertEqual(volumes, 101)
Beispiel #3
0
 def test_unlimited_gigabytes(self):
     FLAGS.quota_volumes = -1
     FLAGS.quota_gigabytes = 10
     volumes = quota.allowed_volumes(self.context, 100, 1)
     self.assertEqual(volumes, 10)
     db.quota_create(self.context, self.project_id, 'gigabytes', None)
     volumes = quota.allowed_volumes(self.context, 100, 1)
     self.assertEqual(volumes, 100)
     volumes = quota.allowed_volumes(self.context, 101, 1)
     self.assertEqual(volumes, 101)
Beispiel #4
0
    def create(self, context, size, snapshot_id, name, description):
        if snapshot_id != None:
            snapshot = self.get_snapshot(context, snapshot_id)
            if snapshot['status'] != "available":
                raise exception.ApiError(
                    _("Snapshot status must be available"))
            if not size:
                size = snapshot['volume_size']

        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(_("Quota exceeded for %(pid)s, tried to create"
                    " %(size)sG volume") % locals())
            raise quota.QuotaError(_("Volume quota exceeded. You cannot "
                                     "create a volume of size %sG") % size)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': snapshot_id,
            'availability_zone': FLAGS.storage_availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description}

        volume = self.db.volume_create(context, options)
        rpc.cast(context,
                 FLAGS.scheduler_topic,
                 {"method": "create_volume",
                  "args": {"topic": FLAGS.volume_topic,
                           "volume_id": volume['id'],
                           "snapshot_id": snapshot_id}})
        return volume
Beispiel #5
0
    def create(self, context, size, name, description):
        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(_("Quota exceeeded for %(pid)s, tried to create"
                    " %(size)sG volume") % locals())
            raise quota.QuotaError(_("Volume quota exceeded. You cannot "
                                     "create a volume of size %sG") % size)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'availability_zone': FLAGS.storage_availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description}

        volume = self.db.volume_create(context, options)
        rpc.cast(context,
                 FLAGS.scheduler_topic,
                 {"method": "create_volume",
                  "args": {"topic": FLAGS.volume_topic,
                           "volume_id": volume['id']}})
        return volume
Beispiel #6
0
    def create(self,
               context,
               size,
               snapshot_id,
               name,
               description,
               volume_type=None,
               metadata=None,
               availability_zone=None):
        if snapshot_id is not None:
            snapshot = self.get_snapshot(context, snapshot_id)
            if snapshot['status'] != "available":
                raise exception.ApiError(
                    _("Snapshot status must be available"))
            if not size:
                size = snapshot['volume_size']

        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(
                _("Quota exceeded for %(pid)s, tried to create"
                  " %(size)sG volume") % locals())
            raise exception.QuotaError(
                _("Volume quota exceeded. You cannot "
                  "create a volume of size %sG") % size)

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        if volume_type is None:
            volume_type_id = None
        else:
            volume_type_id = volume_type.get('id', None)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': snapshot_id,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description,
            'volume_type_id': volume_type_id,
            'metadata': metadata,
        }

        volume = self.db.volume_create(context, options)
        rpc.cast(
            context, FLAGS.scheduler_topic, {
                "method": "create_volume",
                "args": {
                    "topic": FLAGS.volume_topic,
                    "volume_id": volume['id'],
                    "snapshot_id": snapshot_id
                }
            })
        return volume
Beispiel #7
0
    def create_local(self, context, instance_id, device,
                           size, snapshot_id=None, description=None, volume_type=None, metadata=None):

        if not re.match("^/dev/[a-z]d[a-z]+$", device):
            raise exception.ApiError(_("Invalid device specified: %s. "
                                       "Example device: /dev/vdb") % device)

        instance = db.instance_get(context, instance_id)
        host = instance['host']
        LOG.debug('Snapshot id: %s' % snapshot_id)

        if snapshot_id is not None:
            image_info = self.image_service.show(context, snapshot_id)
            deleted = image_info['deleted']
            if deleted:
                raise exception.ApiError(_("Snapshot is deleted: %s") % snapshot_id)

            if not size:
                size = image_info['size']

        size = int(size)

        if quota.allowed_volumes(context, 1, size / (1024 * 1024 * 1024) ) < 1:
            pid = context.project_id
            LOG.warn(_("Quota exceeded for %(pid)s, tried to create"
                       " %(size)s volume") % locals())
            raise quota.QuotaError(_("Volume quota exceeded. You cannot "
                                     "create a volume of size %s") % size)

        if volume_type is None:
            volume_type_id = None
        else:
            volume_type_id = volume_type.get('id', None)

        options = {
            'instance_id': instance_id,
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': snapshot_id,
            'display_description': description,
            'volume_type_id': volume_type_id,
            'metadata': metadata,
            'device': device,
            'status': "creating",
            'attach_status': 'detached'
            }

        volume = self.db.volume_create(context, options, local=True)

        self._call_compute(context, instance, 'create_local_volume', {
            "instance_id": instance_id,
            "device": device,
            "volume_id": volume['id'],
            "snapshot_id" : snapshot_id,
            "size": size
            })
        return volume
Beispiel #8
0
    def create(
        self, context, size, name, description, snapshot=None, volume_type=None, metadata=None, availability_zone=None
    ):
        check_policy(context, "create")
        if snapshot is not None:
            if snapshot["status"] != "available":
                msg = _("status must be available")
                raise exception.InvalidSnapshot(reason=msg)
            if not size:
                size = snapshot["volume_size"]

            snapshot_id = snapshot["id"]
        else:
            snapshot_id = None

        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(_("Quota exceeded for %(pid)s, tried to create" " %(size)sG volume") % locals())
            raise exception.QuotaError(code="VolumeSizeTooLarge")

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        if volume_type is None:
            volume_type_id = None
        else:
            volume_type_id = volume_type.get("id", None)

        options = {
            "size": size,
            "user_id": context.user_id,
            "project_id": context.project_id,
            "snapshot_id": snapshot_id,
            "availability_zone": availability_zone,
            "status": "creating",
            "attach_status": "detached",
            "display_name": name,
            "display_description": description,
            "volume_type_id": volume_type_id,
            "metadata": metadata,
        }

        volume = self.db.volume_create(context, options)
        rpc.cast(
            context,
            FLAGS.scheduler_topic,
            {
                "method": "create_volume",
                "args": {"topic": FLAGS.volume_topic, "volume_id": volume["id"], "snapshot_id": snapshot_id},
            },
        )
        return volume
Beispiel #9
0
    def create(self, context, size, name, description, snapshot=None,
                     volume_type=None, metadata=None, availability_zone=None):
        check_policy(context, 'create')
        if snapshot is not None:
            if snapshot['status'] != "available":
                raise exception.ApiError(
                    _("Snapshot status must be available"))
            if not size:
                size = snapshot['volume_size']

            snapshot_id = snapshot['id']
        else:
            snapshot_id = None

        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(_("Quota exceeded for %(pid)s, tried to create"
                    " %(size)sG volume") % locals())
            raise exception.QuotaError(_("Volume quota exceeded. You cannot "
                                     "create a volume of size %sG") % size)

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        if volume_type is None:
            volume_type_id = None
        else:
            volume_type_id = volume_type.get('id', None)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': snapshot_id,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description,
            'volume_type_id': volume_type_id,
            'metadata': metadata,
            }

        volume = self.db.volume_create(context, options)
        rpc.cast(context,
                 FLAGS.scheduler_topic,
                 {"method": "create_volume",
                  "args": {"topic": FLAGS.volume_topic,
                           "volume_id": volume['id'],
                           "snapshot_id": snapshot_id}})
        return volume
Beispiel #10
0
    def _do_test_volume_quota(self, resource):

        def _validate(result, request, quota, allow):
            overs = result['overs']
            usages = result['usages']
            quotas = result['quotas']
            allowed = result['allowed']
            self.assertEquals(request > allow, resource in overs)
            self.assertEquals(usages[resource], 0)
            self.assertEquals(quotas[resource], quota)
            self.assertEquals(allowed[resource], allow)

        quota_volumes = 10 if resource == 'volumes' else -1
        quota_gigabytes = 10 if resource == 'gigabytes' else -1
        self.flags(quota_volumes=quota_volumes,
                   quota_gigabytes=quota_gigabytes)
        _validate(quota.allowed_volumes(self.context, 100, 1), 100, 10, 10)

        db.quota_create(self.context, self.project_id, resource, None)
        _validate(quota.allowed_volumes(self.context, 100, 1), 100, None, 100)

        db.quota_create(self.context, self.project_id, resource, -1)
        _validate(quota.allowed_volumes(self.context, 100, 1), 100, None, 100)
        _validate(quota.allowed_volumes(self.context, 101, 1), 101, None, 101)
Beispiel #11
0
    def create(self,
               context,
               size,
               name,
               description,
               snapshot=None,
               volume_type=None,
               metadata=None,
               availability_zone=None):
        check_policy(context, 'create')
        if snapshot is not None:
            if snapshot['status'] != "available":
                msg = _("status must be available")
                raise exception.InvalidSnapshot(reason=msg)
            if not size:
                size = snapshot['volume_size']

            snapshot_id = snapshot['id']
        else:
            snapshot_id = None

        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(
                _("Quota exceeded for %(pid)s, tried to create"
                  " %(size)sG volume") % locals())
            raise exception.QuotaError(code="VolumeSizeTooLarge")

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        if volume_type is None:
            volume_type_id = None
        else:
            volume_type_id = volume_type.get('id', None)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': snapshot_id,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description,
            'volume_type_id': volume_type_id,
            'metadata': metadata,
        }

        volume = self.db.volume_create(context, options)
        rpc.cast(
            context, FLAGS.scheduler_topic, {
                "method": "create_volume",
                "args": {
                    "topic": FLAGS.volume_topic,
                    "volume_id": volume['id'],
                    "snapshot_id": snapshot_id
                }
            })
        return volume
Beispiel #12
0
Datei: api.py Projekt: altai/nova
    def create(self, context, size, name, description, snapshot=None,
                     volume_type=None, metadata=None, availability_zone=None):
        check_policy(context, 'create')
        if snapshot is not None:
            if snapshot['status'] != "available":
                msg = _("status must be available")
                raise exception.InvalidSnapshot(reason=msg)
            if not size:
                size = snapshot['volume_size']

            snapshot_id = snapshot['id']
        else:
            snapshot_id = None

        result = quota.allowed_volumes(context, 1, size)

        overs = result['overs']
        usages = result['usages']
        quotas = result['quotas']
        allowed = result['allowed']

        if allowed['volumes'] < 1:
            pid = context.project_id
            if 'gigabytes' in overs:
                consumed = usages['gigabytes']
                limit = quotas['gigabytes']
                LOG.warn(_("Quota exceeded for %(pid)s, tried to create "
                           "%(size)sG volume (%(consumed)dG of %(limit)dG "
                           "already consumed)") % locals())
                code = "VolumeSizeTooLarge"
            elif 'volumes' in overs:
                consumed = usages['volumes']
                LOG.warn(_("Quota exceeded for %(pid)s, tried to create "
                           "volume (%(consumed)d volumes already consumed)")
                           % locals())
                code = "VolumeLimitExceeded"
            raise exception.QuotaError(code=code)

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        if volume_type is None:
            volume_type_id = None
        else:
            volume_type_id = volume_type.get('id', None)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': snapshot_id,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description,
            'volume_type_id': volume_type_id,
            'metadata': metadata,
            }

        volume = self.db.volume_create(context, options)
        rpc.cast(context,
                 FLAGS.scheduler_topic,
                 {"method": "create_volume",
                  "args": {"topic": FLAGS.volume_topic,
                           "volume_id": volume['id'],
                           "snapshot_id": snapshot_id}})
        return volume