]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/volumes/fs/operations/subvolume.py
c2afe45f3f6cc615a80418a58486182cafcf8854
[ceph.git] / ceph / src / pybind / mgr / volumes / fs / operations / subvolume.py
1 import os
2 import errno
3 from contextlib import contextmanager
4
5 from ..exception import VolumeException
6 from .template import SubvolumeOpType
7
8 from .versions import loaded_subvolumes
9
10 def create_subvol(fs, vol_spec, group, subvolname, size, isolate_nspace, pool, mode, uid, gid):
11 """
12 create a subvolume (create a subvolume with the max known version).
13
14 :param fs: ceph filesystem handle
15 :param vol_spec: volume specification
16 :param group: group object for the subvolume
17 :param size: In bytes, or None for no size limit
18 :param isolate_nspace: If true, use separate RADOS namespace for this subvolume
19 :param pool: the RADOS pool where the data objects of the subvolumes will be stored
20 :param mode: the user permissions
21 :param uid: the user identifier
22 :param gid: the group identifier
23 :return: None
24 """
25 subvolume = loaded_subvolumes.get_subvolume_object_max(fs, vol_spec, group, subvolname)
26 subvolume.create(size, isolate_nspace, pool, mode, uid, gid)
27
28 def create_clone(fs, vol_spec, group, subvolname, pool, source_volume, source_subvolume, snapname):
29 """
30 create a cloned subvolume.
31
32 :param fs: ceph filesystem handle
33 :param vol_spec: volume specification
34 :param group: group object for the clone
35 :param subvolname: clone subvolume nam
36 :param pool: the RADOS pool where the data objects of the cloned subvolume will be stored
37 :param source_volume: source subvolumes volume name
38 :param source_subvolume: source (parent) subvolume object
39 :param snapname: source subvolume snapshot
40 :return None
41 """
42 subvolume = loaded_subvolumes.get_subvolume_object_max(fs, vol_spec, group, subvolname)
43 subvolume.create_clone(pool, source_volume, source_subvolume, snapname)
44
45 def remove_subvol(fs, vol_spec, group, subvolname, force=False, retainsnaps=False):
46 """
47 remove a subvolume.
48
49 :param fs: ceph filesystem handle
50 :param vol_spec: volume specification
51 :param group: group object for the subvolume
52 :param subvolname: subvolume name
53 :param force: force remove subvolumes
54 :return: None
55 """
56 op_type = SubvolumeOpType.REMOVE if not force else SubvolumeOpType.REMOVE_FORCE
57 with open_subvol(fs, vol_spec, group, subvolname, op_type) as subvolume:
58 subvolume.remove(retainsnaps)
59
60 @contextmanager
61 def open_subvol(fs, vol_spec, group, subvolname, op_type):
62 """
63 open a subvolume. This API is to be used as a context manager.
64
65 :param fs: ceph filesystem handle
66 :param vol_spec: volume specification
67 :param group: group object for the subvolume
68 :param subvolname: subvolume name
69 :param op_type: operation type for which subvolume is being opened
70 :return: yields a subvolume object (subclass of SubvolumeTemplate)
71 """
72 subvolume = loaded_subvolumes.get_subvolume_object(fs, vol_spec, group, subvolname)
73 subvolume.open(op_type)
74 yield subvolume