"""
fields = 'vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free,vg_free_count'
stdout, stderr, returncode = process.call(
- ['vgs', '--noheadings', '--readonly', '--units=g', '--separator=";"', '-o', fields]
+ ['vgs', '--noheadings', '--readonly', '--units=g', '--separator=";"', '-o', fields],
+ verbose_on_failure=False
)
return _output_parser(stdout, fields)
"""
fields = 'lv_tags,lv_path,lv_name,vg_name,lv_uuid,lv_size'
stdout, stderr, returncode = process.call(
- ['lvs', '--noheadings', '--readonly', '--separator=";"', '-o', fields]
+ ['lvs', '--noheadings', '--readonly', '--separator=";"', '-o', fields],
+ verbose_on_failure=False
)
return _output_parser(stdout, fields)
fields = 'pv_name,pv_tags,pv_uuid,vg_name,lv_uuid'
stdout, stderr, returncode = process.call(
- ['pvs', '--no-heading', '--readonly', '--separator=";"', '-o', fields]
+ ['pvs', '--no-heading', '--readonly', '--separator=";"', '-o', fields],
+ verbose_on_failure=False
)
return _output_parser(stdout, fields)
def remove_pv(pv_name):
"""
- Removes a physical volume.
+ Removes a physical volume using a double `-f` to prevent prompts and fully
+ remove anything related to LVM. This is tremendously destructive, but so is all other actions
+ when zapping a device.
+
+ In the case where multiple PVs are found, it will ignore that fact and
+ continue with the removal, specifically in the case of messages like::
+
+ WARNING: PV $UUID /dev/DEV-1 was already found on /dev/DEV-2
+
+ These situations can be avoided with custom filtering rules, which this API
+ cannot handle while accommodating custom user filters.
"""
fail_msg = "Unable to remove vg %s" % pv_name
process.run(
'pvremove',
'-v', # verbose
'-f', # force it
+ '-f', # force it
pv_name
],
fail_msg=fail_msg,
)
-def remove_lv(path):
+def remove_lv(lv):
"""
Removes a logical volume given it's absolute path.
Will return True if the lv is successfully removed or
raises a RuntimeError if the removal fails.
+
+ :param lv: A ``Volume`` object or the path for an LV
"""
+ if isinstance(lv, Volume):
+ path = lv.lv_path
+ else:
+ path = lv
+
stdout, stderr, returncode = process.call(
[
'lvremove',
self.name = kw['lv_name']
self.tags = parse_tags(kw['lv_tags'])
self.encrypted = self.tags.get('ceph.encrypted', '0') == '1'
+ self.used_by_ceph = 'ceph.osd_id' in self.tags
def __str__(self):
return '<%s>' % self.lv_api['lv_path']
obj['path'] = self.lv_path
return obj
+ def report(self):
+ if not self.used_by_ceph:
+ return {
+ 'name': self.lv_name,
+ 'comment': 'not used by ceph'
+ }
+ else:
+ type_ = self.tags['ceph.type']
+ report = {
+ 'name': self.lv_name,
+ 'osd_id': self.tags['ceph.osd_id'],
+ 'cluster_name': self.tags['ceph.cluster_name'],
+ 'type': type_,
+ 'osd_fsid': self.tags['ceph.osd_fsid'],
+ 'cluster_fsid': self.tags['ceph.cluster_fsid'],
+ }
+ type_uuid = '{}_uuid'.format(type_)
+ report[type_uuid] = self.tags['ceph.{}'.format(type_uuid)]
+ return report
+
def clear_tags(self):
"""
Removes all tags from the Logical Volume.