Procházet zdrojové kódy

Merged in gabriel-samfira/coriolis-core/parse-os-release (pull request #52)

parse /etc/os-release where available
Gabriel-Adrian Samfira před 8 roky
rodič
revize
29864632f6

+ 1 - 1
coriolis/osmorphing/base.py

@@ -164,7 +164,7 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
         if self._test_path(resolv_conf_path):
             self._exec_cmd(
                 "sudo mv -f %s %s" % (resolv_conf_path, resolv_conf_path_old))
-        self._exec_cmd("sudo cp --remove-destination /etc/resolv.conf %s" %
+        self._exec_cmd('sudo cp --remove-destination /etc/resolv.conf %s' %
                        resolv_conf_path)
 
     def _restore_resolv_conf(self):

+ 21 - 0
coriolis/osmorphing/osmount/base.py

@@ -72,6 +72,19 @@ class BaseLinuxOSMountTools(BaseSSHOSMountTools):
     def _exec_cmd(self, cmd):
         return utils.exec_ssh_cmd(self._ssh, cmd)
 
+    def _get_pvs(self):
+        out = self._exec_cmd("sudo pvdisplay -c").decode().split("\n")
+        pvs = {}
+        for l in out:
+            if l == "":
+                continue
+            line = l.strip().split(":")
+            if pvs.get(line[1]) is None:
+                pvs[line[1]] = [line[0], ]
+            else:
+                pvs[line[1]].append(line[0])
+        return pvs
+
     def _get_vgnames(self):
         vg_names = []
         vgscan_out_lines = self._exec_cmd(
@@ -121,7 +134,15 @@ class BaseLinuxOSMountTools(BaseSSHOSMountTools):
             dev_paths += self._exec_cmd(
                 "sudo ls %s*" % volume_dev).decode().split('\n')[:-1]
 
+        pvs = self._get_pvs()
         for vg_name in self._get_vgnames():
+            found = False
+            for pv in pvs[vg_name]:
+                if pv in dev_paths:
+                    found = True
+                    break
+            if not found:
+                continue
             self._exec_cmd("sudo vgchange -ay %s" % vg_name)
             lvm_dev_paths = self._exec_cmd(
                 "sudo ls /dev/%s/*" % vg_name).decode().split('\n')[:-1]

+ 2 - 1
coriolis/osmorphing/osmount/redhat.py

@@ -14,7 +14,8 @@ class RedHatOSMountTools(base.BaseLinuxOSMountTools):
         # make sure the package redhat-lsb-core is installed
         os_info = utils.get_linux_os_info(self._ssh)
         if os_info and os_info[0] in [
-                'RedHatEnterpriseServer', 'CentOS', 'OracleServer']:
+                'RedHatEnterpriseServer', 'CentOS', 'OracleServer',
+                'rhel', 'centos', 'ol']:
             return True
 
     def _pre_mount_os(self):

+ 1 - 1
coriolis/osmorphing/osmount/ubuntu.py

@@ -12,7 +12,7 @@ LOG = logging.getLogger(__name__)
 class UbuntuOSMountTools(base.BaseLinuxOSMountTools):
     def check_os(self):
         os_info = utils.get_linux_os_info(self._ssh)
-        if os_info and os_info[0] == 'Ubuntu':
+        if os_info and os_info[0] in ('Ubuntu', 'ubuntu'):
             return True
 
     def _pre_mount_os(self):

+ 24 - 1
coriolis/utils.py

@@ -99,7 +99,22 @@ def get_udev_net_rules(net_ifaces_info):
     return content
 
 
-def get_linux_os_info(ssh):
+def parse_os_release(ssh):
+    os_release_info = exec_ssh_cmd(
+        ssh, "[ -f '/etc/os-release' ] && cat /etc/os-release || true").decode()
+    info = {}
+    for line in os_release_info.splitlines():
+        if "=" not in line:
+            continue
+        k, v = line.split("=")
+        info[k] = v.strip('"')
+    if info.get("ID") and info.get("VERSION_ID"):
+        return (info.get("ID"), info.get("VERSION_ID"))
+
+
+def parse_lsb_release(ssh):
+    os_release_info = exec_ssh_cmd(
+        ssh, "[ -f '/etc/os-release' ] && cat /etc/os-release || true").decode()
     out = exec_ssh_cmd(ssh, "lsb_release -a || true").decode()
     dist_id = re.findall('^Distributor ID:\s(.*)$', out, re.MULTILINE)
     release = re.findall('^Release:\s(.*)$', out, re.MULTILINE)
@@ -107,6 +122,14 @@ def get_linux_os_info(ssh):
         return (dist_id[0], release[0])
 
 
+def get_linux_os_info(ssh):
+    info = parse_os_release(ssh)
+    if info is None:
+        #fall back to lsb_release
+        return parse_lsb_release(ssh)
+    return info
+
+
 @retry_on_error()
 def test_ssh_path(ssh, remote_path):
     sftp = ssh.open_sftp()