]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/scripts/rpc/lvol.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / scripts / rpc / lvol.py
1 def construct_lvol_store(client, bdev_name, lvs_name, cluster_sz=None, clear_method=None):
2 """Construct a logical volume store.
3
4 Args:
5 bdev_name: bdev on which to construct logical volume store
6 lvs_name: name of the logical volume store to create
7 cluster_sz: cluster size of the logical volume store in bytes (optional)
8 clear_method: Change clear method for data region. Available: none, unmap, write_zeroes (optional)
9
10 Returns:
11 UUID of created logical volume store.
12 """
13 params = {'bdev_name': bdev_name, 'lvs_name': lvs_name}
14 if cluster_sz:
15 params['cluster_sz'] = cluster_sz
16 if clear_method:
17 params['clear_method'] = clear_method
18 return client.call('construct_lvol_store', params)
19
20
21 def rename_lvol_store(client, old_name, new_name):
22 """Rename a logical volume store.
23
24 Args:
25 old_name: existing logical volume store name
26 new_name: new logical volume store name
27 """
28 params = {
29 'old_name': old_name,
30 'new_name': new_name
31 }
32 return client.call('rename_lvol_store', params)
33
34
35 def construct_lvol_bdev(client, lvol_name, size, thin_provision=False, uuid=None, lvs_name=None, clear_method=None):
36 """Create a logical volume on a logical volume store.
37
38 Args:
39 lvol_name: name of logical volume to create
40 size: desired size of logical volume in bytes (will be rounded up to a multiple of cluster size)
41 thin_provision: True to enable thin provisioning
42 uuid: UUID of logical volume store to create logical volume on (optional)
43 lvs_name: name of logical volume store to create logical volume on (optional)
44
45 Either uuid or lvs_name must be specified, but not both.
46
47 Returns:
48 Name of created logical volume block device.
49 """
50 if (uuid and lvs_name) or (not uuid and not lvs_name):
51 raise ValueError("Either uuid or lvs_name must be specified, but not both")
52
53 params = {'lvol_name': lvol_name, 'size': size}
54 if thin_provision:
55 params['thin_provision'] = thin_provision
56 if uuid:
57 params['uuid'] = uuid
58 if lvs_name:
59 params['lvs_name'] = lvs_name
60 if clear_method:
61 params['clear_method'] = clear_method
62 return client.call('construct_lvol_bdev', params)
63
64
65 def snapshot_lvol_bdev(client, lvol_name, snapshot_name):
66 """Capture a snapshot of the current state of a logical volume.
67
68 Args:
69 lvol_name: logical volume to create a snapshot from
70 snapshot_name: name for the newly created snapshot
71
72 Returns:
73 Name of created logical volume snapshot.
74 """
75 params = {
76 'lvol_name': lvol_name,
77 'snapshot_name': snapshot_name
78 }
79 return client.call('snapshot_lvol_bdev', params)
80
81
82 def clone_lvol_bdev(client, snapshot_name, clone_name):
83 """Create a logical volume based on a snapshot.
84
85 Args:
86 snapshot_name: snapshot to clone
87 clone_name: name of logical volume to create
88
89 Returns:
90 Name of created logical volume clone.
91 """
92 params = {
93 'snapshot_name': snapshot_name,
94 'clone_name': clone_name
95 }
96 return client.call('clone_lvol_bdev', params)
97
98
99 def rename_lvol_bdev(client, old_name, new_name):
100 """Rename a logical volume.
101
102 Args:
103 old_name: existing logical volume name
104 new_name: new logical volume name
105 """
106 params = {
107 'old_name': old_name,
108 'new_name': new_name
109 }
110 return client.call('rename_lvol_bdev', params)
111
112
113 def resize_lvol_bdev(client, name, size):
114 """Resize a logical volume.
115
116 Args:
117 name: name of logical volume to resize
118 size: desired size of logical volume in bytes (will be rounded up to a multiple of cluster size)
119 """
120 params = {
121 'name': name,
122 'size': size,
123 }
124 return client.call('resize_lvol_bdev', params)
125
126
127 def set_read_only_lvol_bdev(client, name):
128 """Mark logical volume as read only.
129
130 Args:
131 name: name of logical volume to set as read only
132 """
133 params = {
134 'name': name,
135 }
136 return client.call('set_read_only_lvol_bdev', params)
137
138
139 def destroy_lvol_bdev(client, name):
140 """Destroy a logical volume.
141
142 Args:
143 name: name of logical volume to destroy
144 """
145 params = {
146 'name': name,
147 }
148 return client.call('destroy_lvol_bdev', params)
149
150
151 def inflate_lvol_bdev(client, name):
152 """Inflate a logical volume.
153
154 Args:
155 name: name of logical volume to inflate
156 """
157 params = {
158 'name': name,
159 }
160 return client.call('inflate_lvol_bdev', params)
161
162
163 def decouple_parent_lvol_bdev(client, name):
164 """Decouple parent of a logical volume.
165
166 Args:
167 name: name of logical volume to decouple parent
168 """
169 params = {
170 'name': name,
171 }
172 return client.call('decouple_parent_lvol_bdev', params)
173
174
175 def destroy_lvol_store(client, uuid=None, lvs_name=None):
176 """Destroy a logical volume store.
177
178 Args:
179 uuid: UUID of logical volume store to destroy (optional)
180 lvs_name: name of logical volume store to destroy (optional)
181
182 Either uuid or lvs_name must be specified, but not both.
183 """
184 if (uuid and lvs_name) or (not uuid and not lvs_name):
185 raise ValueError("Exactly one of uuid or lvs_name must be specified")
186
187 params = {}
188 if uuid:
189 params['uuid'] = uuid
190 if lvs_name:
191 params['lvs_name'] = lvs_name
192 return client.call('destroy_lvol_store', params)
193
194
195 def get_lvol_stores(client, uuid=None, lvs_name=None):
196 """List logical volume stores.
197
198 Args:
199 uuid: UUID of logical volume store to retrieve information about (optional)
200 lvs_name: name of logical volume store to retrieve information about (optional)
201
202 Either uuid or lvs_name may be specified, but not both.
203 If both uuid and lvs_name are omitted, information about all logical volume stores is returned.
204 """
205 if (uuid and lvs_name):
206 raise ValueError("Exactly one of uuid or lvs_name may be specified")
207 params = {}
208 if uuid:
209 params['uuid'] = uuid
210 if lvs_name:
211 params['lvs_name'] = lvs_name
212 return client.call('get_lvol_stores', params)