def create_volume(esh_driver, identity_uuid, name, size, description=None, metadata=None, snapshot=None, image=None, raise_exception=False): quota = get_quota(identity_uuid) if not has_storage_quota(esh_driver, quota, size): raise exceptions.OverQuotaError( message="Maximum total size of Storage Volumes Exceeded") if not has_storage_count_quota(esh_driver, quota, 1): raise exceptions.OverQuotaError( message="Maximum # of Storage Volumes Exceeded") # NOTE: Calling non-standard create_volume_obj so we know the ID # of newly created volume. Libcloud just returns 'True'... --Steve success, esh_volume = esh_driver.create_volume(size=size, name=name, metadata=metadata, snapshot=snapshot, image=image) if not success and raise_exception: raise exceptions.VolumeError("The volume failed to be created.") return success, esh_volume
def create_volume(esh_driver, identity_uuid, name, size, description=None, metadata=None, snapshot=None, image=None, raise_exception=False): quota = get_quota(identity_uuid) if not has_storage_quota(esh_driver, quota, size): raise exceptions.OverQuotaError( message="Maximum total size of Storage Volumes Exceeded") if not has_storage_count_quota(esh_driver, quota, 1): raise exceptions.OverQuotaError( message="Maximum # of Storage Volumes Exceeded") # NOTE: Calling non-standard create_volume_obj so we know the ID # of newly created volume. Libcloud just returns 'True'... --Steve conn_kwargs = {'max_attempts': 1} success, esh_volume = esh_driver.create_volume( size=size, name=name, metadata=metadata, snapshot=snapshot, image=image, **conn_kwargs) if not success and raise_exception: raise exceptions.VolumeError("The volume failed to be created.") return success, esh_volume
def check_over_storage_quota( username, identity_uuid, new_snapshot_size=0, new_volume_size=0, raise_exc=True ): """ Checks quota based on current limits. param - new_snapshot_size - if included and non-zero, increase snapshot_count param - new_volume_size - if included and non-zero, add to storage total & increase storage_count param - raise_exc - if True, raise ValidationError, otherwise return False return True if passing return False if ValidationError occurs and raise_exc=False By default, allow ValidationError to raise. """ memberships_available = IdentityMembership.objects.filter( identity__uuid=identity_uuid, member__memberships__user__username=username ) if memberships_available: membership = memberships_available.first() identity = membership.identity quota = identity.quota driver = get_cached_driver(identity=identity) # FIXME: I don't believe that 'snapshot' size and 'volume' size share # the same quota, so for now we ignore 'snapshot-size', # and only care that value is 0 or >1 new_snapshot = 1 if new_snapshot_size > 0 else 0 new_disk = new_volume_size new_volume = 1 if new_volume_size > 0 else 0 # Will throw ValidationError if false. try: has_storage_quota(driver, quota, new_disk) has_storage_count_quota(driver, quota, new_volume) has_snapshot_count_quota(driver, quota, new_snapshot) return True except ValidationError: if raise_exc: raise return False
def create_volume(esh_driver, identity_id, name, size, description=None): identity = Identity.objects.get(id=identity_id) quota = get_quota(identity_id) if not has_storage_quota(esh_driver, quota, size): raise OverQuotaError("Maximum total size of Storage Volumes Exceeded") if not has_storage_count_quota(esh_driver, quota, 1): raise OverQuotaError("Maximum # of Storage Volumes Exceeded") success, esh_volume = esh_driver.create_volume(name=name, size=size, description=description) return success, esh_volume
def check_over_storage_quota( username, identity_uuid, new_snapshot_size=0, new_volume_size=0, raise_exc=True): """ Checks quota based on current limits. param - new_snapshot_size - if included and non-zero, increase snapshot_count param - new_volume_size - if included and non-zero, add to storage total & increase storage_count param - raise_exc - if True, raise ValidationError, otherwise return False return True if passing return False if ValidationError occurs and raise_exc=False By default, allow ValidationError to raise. """ memberships_available = IdentityMembership.objects.filter( identity__uuid=identity_uuid, member__memberships__user__username=username) if memberships_available: membership = memberships_available.first() identity = membership.identity quota = identity.quota driver = get_cached_driver(identity=identity) # FIXME: I don't believe that 'snapshot' size and 'volume' size share # the same quota, so for now we ignore 'snapshot-size', # and only care that value is 0 or >1 new_snapshot = 1 if new_snapshot_size > 0 else 0 new_disk = new_volume_size new_volume = 1 if new_volume_size > 0 else 0 # Will throw ValidationError if false. try: has_storage_quota(driver, quota, new_disk) has_storage_count_quota(driver, quota, new_volume) has_snapshot_count_quota(driver, quota, new_snapshot) return True except ValidationError: if raise_exc: raise return False
def create_volume(esh_driver, identity_id, name, size, description=None): identity = Identity.objects.get(id=identity_id) quota = get_quota(identity_id) if not has_storage_quota(esh_driver, quota, size): raise OverQuotaError( "Maximum total size of Storage Volumes Exceeded") if not has_storage_count_quota(esh_driver, quota, 1): raise OverQuotaError( "Maximum # of Storage Volumes Exceeded") success, esh_volume = esh_driver.create_volume( name=name, size=size, description=description) return success, esh_volume
def create_volume(esh_driver, identity_uuid, name, size, description=None, metadata=None, snapshot=None, image=None): identity = Identity.objects.get(uuid=identity_uuid) quota = get_quota(identity_uuid) if not has_storage_quota(esh_driver, quota, size): raise OverQuotaError( message="Maximum total size of Storage Volumes Exceeded") if not has_storage_count_quota(esh_driver, quota, 1): raise OverQuotaError( message="Maximum # of Storage Volumes Exceeded") #NOTE: Calling non-standard create_volume_obj so we know the ID # of newly created volume. Libcloud just returns 'True'... --Steve success, esh_volume = esh_driver.create_volume( size=size, name=name, metadata=metadata, snapshot=snapshot, image=image) return success, esh_volume
def post(self, request, provider_id, identity_id): """ Creates a new volume and adds it to the DB """ user = request.user esh_driver = prepare_driver(request, identity_id) data = request.DATA if not data.get('name') or not data.get('size'): errorObj = failureJSON([{ 'code': 400, 'message': 'Missing params: name and size required to create a volume'}]) return Response(errorObj, status=status.HTTP_400_BAD_REQUEST) name = data.get('name') size = data.get('size') quota = get_quota(identity_id) CoreQuota.objects.get(identitymembership__identity__id=identity_id) if not has_storage_quota(esh_driver, quota, size) \ or not has_storage_count_quota(esh_driver, quota, 1): errorObj = failureJSON([{ 'code': 403, 'message': 'Over quota: ' + 'You have used all of your allocated volume quota'}]) return Response(errorObj, status=status.HTTP_403_FORBIDDEN) logger.debug((name, size)) success, esh_volume = esh_driver.create_volume( name=name, size=size, description=data.get('description', '')) if not success: errorObj = failureJSON({'code': 500, 'message': 'Volume creation failed'}) return Response(errorObj, status=status.HTTP_500_INTERNAL_SERVER_ERROR) core_volume = convert_esh_volume(esh_volume, provider_id, identity_id, user) serialized_data = VolumeSerializer(core_volume).data response = Response(serialized_data, status=status.HTTP_201_CREATED) return response
def create_volume(esh_driver, identity_id, name, size, description=None, metadata=None, snapshot=None, image=None): identity = Identity.objects.get(id=identity_id) quota = get_quota(identity_id) if not has_storage_quota(esh_driver, quota, size): raise OverQuotaError( message="Maximum total size of Storage Volumes Exceeded") if not has_storage_count_quota(esh_driver, quota, 1): raise OverQuotaError(message="Maximum # of Storage Volumes Exceeded") #NOTE: Calling non-standard create_volume_obj so we know the ID # of newly created volume. Libcloud just returns 'True'... --Steve success, esh_volume = esh_driver.create_volume(size=size, name=name, metadata=metadata, snapshot=snapshot, image=image) return success, esh_volume