tag_mapping = {}
tags = lv_tags.split(',')
for tag_assignment in tags:
+ if not tag_assignment.startswith('ceph.'):
+ continue
key, value = tag_assignment.split('=', 1)
tag_mapping[key] = value
Command and sample delimeted output, should look like::
- $ sudo vgs --noheadings --separator=';' \
+ $ vgs --noheadings --separator=';' \
-o vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free
ubuntubox-vg;1;2;0;wz--n-;299.52g;12.00m
osd_vg;3;1;0;wz--n-;29.21g;9.21g
"""
fields = 'vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free'
stdout, stderr, returncode = process.call(
- ['sudo', 'vgs', '--noheadings', '--separator=";"', '-o', fields]
+ ['vgs', '--noheadings', '--separator=";"', '-o', fields]
)
return _output_parser(stdout, fields)
Command and delimeted output, should look like::
- $ sudo lvs --noheadings --separator=';' -o lv_tags,lv_path,lv_name,vg_name
+ $ lvs --noheadings --separator=';' -o lv_tags,lv_path,lv_name,vg_name
;/dev/ubuntubox-vg/root;root;ubuntubox-vg
;/dev/ubuntubox-vg/swap_1;swap_1;ubuntubox-vg
"""
fields = 'lv_tags,lv_path,lv_name,vg_name,lv_uuid'
stdout, stderr, returncode = process.call(
- ['sudo', 'lvs', '--noheadings', '--separator=";"', '-o', fields]
+ ['lvs', '--noheadings', '--separator=";"', '-o', fields]
)
return _output_parser(stdout, fields)
Return the list of physical volumes configured for lvm and available in the
system using flags to include common metadata associated with them like the uuid
+ This will only return physical volumes set up to work with LVM.
+
Command and delimeted output, should look like::
- $ sudo pvs --noheadings --separator=';' -o pv_name,pv_tags,pv_uuid
+ $ pvs --noheadings --separator=';' -o pv_name,pv_tags,pv_uuid
/dev/sda1;;
/dev/sdv;;07A4F654-4162-4600-8EB3-88D1E42F368D
"""
- fields = 'pv_name,pv_tags,pv_uuid'
+ fields = 'pv_name,pv_tags,pv_uuid,vg_name'
- # note the use of `pvs -a` which will return every physical volume including
- # ones that have not been initialized as "pv" by LVM
stdout, stderr, returncode = process.call(
- ['sudo', 'pvs', '-a', '--no-heading', '--separator=";"', '-o', fields]
+ ['pvs', '--no-heading', '--separator=";"', '-o', fields]
)
return _output_parser(stdout, fields)
to journals.
"""
process.run([
- 'sudo',
'pvcreate',
'-v', # verbose
'-f', # force it
Once created the volume group is returned as a ``VolumeGroup`` object
"""
process.run([
- 'sudo',
'vgcreate',
'--force',
'--yes',
return vg
+def remove_vg(vg_name):
+ """
+ Removes a volume group.
+ """
+ fail_msg = "Unable to remove vg %s".format(vg_name)
+ process.run(
+ [
+ 'vgremove',
+ '-v', # verbose
+ '-f', # force it
+ vg_name
+ ],
+ fail_msg=fail_msg,
+ )
+
+
+def remove_pv(pv_name):
+ """
+ Removes a physical volume.
+ """
+ fail_msg = "Unable to remove vg %s".format(pv_name)
+ process.run(
+ [
+ 'pvremove',
+ '-v', # verbose
+ '-f', # force it
+ pv_name
+ ],
+ fail_msg=fail_msg,
+ )
+
+
def remove_lv(path):
"""
Removes a logical volume given it's absolute path.
"""
stdout, stderr, returncode = process.call(
[
- 'sudo',
'lvremove',
'-v', # verbose
'-f', # force it
}
if size:
process.run([
- 'sudo',
'lvcreate',
'--yes',
'-L',
# system call is different for LVM
else:
process.run([
- 'sudo',
'lvcreate',
'--yes',
'-l',
"""
for k, v in self.tags.items():
tag = "%s=%s" % (k, v)
- process.run(['sudo', 'lvchange', '--deltag', tag, self.lv_path])
+ process.run(['lvchange', '--deltag', tag, self.lv_path])
def set_tags(self, tags):
"""
if self.tags.get(key):
current_value = self.tags[key]
tag = "%s=%s" % (key, current_value)
- process.call(['sudo', 'lvchange', '--deltag', tag, self.lv_api['lv_path']])
+ process.call(['lvchange', '--deltag', tag, self.lv_api['lv_path']])
process.call(
[
- 'sudo', 'lvchange',
+ 'lvchange',
'--addtag', '%s=%s' % (key, value), self.lv_path
]
)
if self.tags.get(key):
current_value = self.tags[key]
tag = "%s=%s" % (key, current_value)
- process.call(['sudo', 'pvchange', '--deltag', tag, self.pv_name])
+ process.call(['pvchange', '--deltag', tag, self.pv_name])
process.call(
[
- 'sudo', 'pvchange',
+ 'pvchange',
'--addtag', '%s=%s' % (key, value), self.pv_name
]
)