From 746780d0ea04b233b6f51858550fd94c696768b0 Mon Sep 17 00:00:00 2001 From: Chris Holcombe Date: Mon, 24 Oct 2016 14:34:08 -0700 Subject: [PATCH] Add actions to set,get and remove quotas --- src/README.md | 26 +++++++++++++------- src/actions.yaml | 18 +++++++++----- src/actions/get-quota | 1 + src/actions/get-quota.py | 45 +++++++++++++++++++++++++++++++++++ src/actions/remove-quota | 1 + src/actions/remove-quota.py | 44 ++++++++++++++++++++++++++++++++++ src/actions/set-quota | 1 + src/actions/set-quota.py | 47 +++++++++++++++++++++++++++++++++++++ src/config.yaml | 12 +++------- src/layer.yaml | 2 +- src/wheelhouse.txt | 2 +- 11 files changed, 173 insertions(+), 26 deletions(-) create mode 120000 src/actions/get-quota create mode 100755 src/actions/get-quota.py create mode 120000 src/actions/remove-quota create mode 100755 src/actions/remove-quota.py create mode 120000 src/actions/set-quota create mode 100755 src/actions/set-quota.py diff --git a/src/README.md b/src/README.md index dcbbee5..c01cee6 100644 --- a/src/README.md +++ b/src/README.md @@ -6,22 +6,30 @@ Ceph is a distributed storage and network file system designed to provide excellent performance, reliability, and scalability. This charm deploys a Ceph MDS cluster. -juju Usage ===== - -Boot things up by using:: + +Boot things up by using: juju deploy -n 3 --config ceph.yaml ceph-mon juju deploy -n 3 --config ceph.yaml ceph-osd - -You can then deploy this charm by simply doing:: +In my example deployments on EC2 the following ceph.yaml will work: +``` +ceph-mon: + source: cloud:trusty-mitaka +ceph-osd: + osd-devices: /dev/xvdb + ephemeral-unmount: "/mnt" + source: cloud:trusty-mitaka +``` +You can then deploy this charm by simply doing: - juju deploy -n 3 --config ceph.yaml ceph-fs + juju deploy --config ceph.yaml ceph-fs juju add-relation ceph-fs ceph-mon - -Once the ceph-mon and osd charms have bootstrapped the cluster, it will notify the ceph-fs charm. + +Once the ceph-mon and osd charms have bootstrapped the cluster, the ceph-mon +charm will notify the ceph-fs charm. Contact Information =================== @@ -30,4 +38,4 @@ Contact Information - [Ceph website](http://ceph.com) - [Ceph mailing lists](http://ceph.com/resources/mailing-list-irc/) -- [Ceph bug tracker](http://tracker.ceph.com/projects/ceph) \ No newline at end of file +- [Ceph bug tracker](http://tracker.ceph.com/projects/ceph) diff --git a/src/actions.yaml b/src/actions.yaml index 77651dc..8620d24 100644 --- a/src/actions.yaml +++ b/src/actions.yaml @@ -5,12 +5,14 @@ get-quota: type: boolean description: | The limit of how many files can be written. Use either this or - max-bytes but not both. + max-bytes but not both. The action tries max-files first and then + falls back on max-bytes if both are set max-bytes: type: integer description: | The maximum number of bytes that are allowed to be written. Use - either this or max-files but not both. + either this or max-files but not both. The action tries max-files + first and then falls back on max-bytes if both are set directory: type: string description: | @@ -24,12 +26,14 @@ remove-quota: type: boolean description: | The limit of how many files can be written. Use either this or - max-bytes but not both. + max-bytes but not both. The action tries max-files first and then + falls back on max-bytes if both are set max-bytes: type: integer description: | The maximum number of bytes that are allowed to be written. Use - either this or max-files but not both. + either this or max-files but not both. The action tries max-files + first and then falls back on max-bytes if both are set directory: type: string description: | @@ -43,12 +47,14 @@ set-quota: type: integer description: | The limit of how many files can be written. Use either this or - max-bytes but not both. + max-bytes but not both. The action tries max-files + first and then falls back on max-bytes if both are set max-bytes: type: integer description: | The maximum number of bytes that are allowed to be written. Use - either this or max-files but not both. + either this or max-files but not both. The action tries max-files + first and then falls back on max-bytes if both are set directory: type: string description: | diff --git a/src/actions/get-quota b/src/actions/get-quota new file mode 120000 index 0000000..a1d07b4 --- /dev/null +++ b/src/actions/get-quota @@ -0,0 +1 @@ +get-quota.py \ No newline at end of file diff --git a/src/actions/get-quota.py b/src/actions/get-quota.py new file mode 100755 index 0000000..c9c17f6 --- /dev/null +++ b/src/actions/get-quota.py @@ -0,0 +1,45 @@ +#!/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. +import os +from charmhelpers.core.hookenv import action_get, action_fail, action_set +import xattr + +__author__ = 'Chris Holcombe ' + + +def get_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.{}" + if max_files: + attr.format("max_files") + elif max_bytes: + attr.format("max_bytes") + + try: + quota_value = xattr.getxattr(directory, attr) + action_set({'{} quota'.format(directory): quota_value}) + except IOError as err: + action_fail( + "Unable to get xattr on {}. Error: {}".format(directory, err)) + + +if __name__ == '__main__': + get_quota() diff --git a/src/actions/remove-quota b/src/actions/remove-quota new file mode 120000 index 0000000..dee3039 --- /dev/null +++ b/src/actions/remove-quota @@ -0,0 +1 @@ +remove-quota.py \ No newline at end of file diff --git a/src/actions/remove-quota.py b/src/actions/remove-quota.py new file mode 100755 index 0000000..c068cc2 --- /dev/null +++ b/src/actions/remove-quota.py @@ -0,0 +1,44 @@ +#!/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. +import os +from charmhelpers.core.hookenv import action_get, action_fail, action_set +import xattr + +__author__ = 'Chris Holcombe ' + + +def remove_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.{}" + if max_files: + attr.format("max_files") + elif max_bytes: + attr.format("max_bytes") + + try: + xattr.setxattr(directory, attr, str(0)) + except IOError as err: + action_fail( + "Unable to set xattr on {}. Error: {}".format(directory, err)) + + +if __name__ == '__main__': + remove_quota() diff --git a/src/actions/set-quota b/src/actions/set-quota new file mode 120000 index 0000000..79af9e2 --- /dev/null +++ b/src/actions/set-quota @@ -0,0 +1 @@ +set-quota.py \ No newline at end of file diff --git a/src/actions/set-quota.py b/src/actions/set-quota.py new file mode 100755 index 0000000..bba5a50 --- /dev/null +++ b/src/actions/set-quota.py @@ -0,0 +1,47 @@ +#!/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 ' +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.format("max_files") + value = str(max_files) + elif max_bytes: + 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() diff --git a/src/config.yaml b/src/config.yaml index f0b9fa4..3b86e9e 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,4 +1,7 @@ options: + apt: + packages: + - python3-pyxattr ceph-public-network: type: string default: @@ -8,15 +11,6 @@ options: . If multiple networks are to be used, a space-delimited list of a.b.c.d/x can be provided. - ceph-cluster-network: - type: string - default: - description: | - The IP address and netmask of the cluster (back-side) network (e.g., - 192.168.0.0/24) - . - If multiple networks are to be used, a space-delimited list of a.b.c.d/x - can be provided. loglevel: default: 1 type: int diff --git a/src/layer.yaml b/src/layer.yaml index 77414bb..9f2a750 100644 --- a/src/layer.yaml +++ b/src/layer.yaml @@ -1,2 +1,2 @@ -includes: ['layer:ceph-base', 'interface:/home/chris/repos/juju-interface-ceph-mds'] # if you use any interfaces, add them here +includes: ['layer:apt', 'layer:ceph-base', 'interface:/home/chris/repos/juju-interface-ceph-mds'] # if you use any interfaces, add them here repo: git@github.com:cholcombe973/charm-ceph-fs.git diff --git a/src/wheelhouse.txt b/src/wheelhouse.txt index f34b89e..8501e11 100644 --- a/src/wheelhouse.txt +++ b/src/wheelhouse.txt @@ -1 +1 @@ -ceph_api \ No newline at end of file +ceph_api