charm-ceph-fs/src/actions/set_quota.py
Ryan Beisner caff36e33d Add .gitreview and clean up repo
Several updates to make this consistent with other OpenStack
charms repos, and to enable Gerrit + OSCI test gates.

- Update .gitignore.

- Add .gitreview for gerrit.

- Add copyright file, and copyright headers.

- Add tox.ini and src/tox.ini

- Add tests README

- Fix layer.yaml

- Add unit tests.

- Add amulet tests.

- fixed lint.

See running bug/TODO list:

- https://bugs.launchpad.net/charm-ceph-fs

Change-Id: Iaec5f25706387f9b59b36e307e954318b23c9417
Depends-On: I3f78a5a3231377f5542b81cec27dd4531144cfd1
Closes-Bug: 1640895
Closes-Bug: 1640896
Closes-Bug: 1640898
Closes-Bug: 1640900
Closes-Bug: 1640902
Closes-Bug: 1653767
2017-01-06 08:29:43 -08:00

48 lines
1.4 KiB
Python
Executable File

#!/usr/bin/python3
#
# Copyright 2016 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = 'Chris Holcombe <chris.holcombe@canonical.com>'
import os
from charmhelpers.core.hookenv import action_get, action_fail
import xattr
def set_quota():
max_files = action_get('max-files')
max_bytes = action_get('max-bytes')
directory = action_get('directory')
if not os.path.exists(directory):
action_fail("Directory must exist before setting quota")
attr = "ceph.quota.{}"
value = None
if max_files:
attr = attr.format("max_files")
value = str(max_files)
elif max_bytes:
attr = attr.format("max_bytes")
value = str(max_bytes)
try:
xattr.setxattr(directory, attr, value)
except IOError as err:
action_fail(
"Unable to set xattr on {}. Error: {}".format(directory, err))
if __name__ == '__main__':
set_quota()