]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/ceph-volume/ceph_volume/api/lvm.py
update sources to v12.2.3
[ceph.git] / ceph / src / ceph-volume / ceph_volume / api / lvm.py
index d82aee685f7b2bba90d80f5e35bc725e4c838230..868effb8309b7e771755960084e27a0a1d40eba7 100644 (file)
@@ -63,6 +63,8 @@ def parse_tags(lv_tags):
     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
 
@@ -76,7 +78,7 @@ def get_api_vgs():
 
     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
@@ -84,7 +86,7 @@ def get_api_vgs():
     """
     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)
 
@@ -96,14 +98,14 @@ def get_api_lvs():
 
     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)
 
@@ -113,19 +115,19 @@ def get_api_pvs():
     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)
@@ -184,7 +186,6 @@ def create_pv(device):
     to journals.
     """
     process.run([
-        'sudo',
         'pvcreate',
         '-v',  # verbose
         '-f',  # force it
@@ -202,7 +203,6 @@ def create_vg(name, *devices):
     Once created the volume group is returned as a ``VolumeGroup`` object
     """
     process.run([
-        'sudo',
         'vgcreate',
         '--force',
         '--yes',
@@ -213,6 +213,38 @@ def create_vg(name, *devices):
     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.
@@ -222,7 +254,6 @@ def remove_lv(path):
     """
     stdout, stderr, returncode = process.call(
         [
-            'sudo',
             'lvremove',
             '-v',  # verbose
             '-f',  # force it
@@ -259,7 +290,6 @@ def create_lv(name, group, size=None, tags=None):
     }
     if size:
         process.run([
-            'sudo',
             'lvcreate',
             '--yes',
             '-L',
@@ -270,7 +300,6 @@ def create_lv(name, group, size=None, tags=None):
     # system call is different for LVM
     else:
         process.run([
-            'sudo',
             'lvcreate',
             '--yes',
             '-l',
@@ -658,7 +687,7 @@ class Volume(object):
         """
         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):
         """
@@ -689,11 +718,11 @@ class Volume(object):
         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
             ]
         )
@@ -752,11 +781,11 @@ class PVolume(object):
         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
             ]
         )