Explorar o código

parse /etc/os-release where available

Gabriel Adrian Samfira %!s(int64=9) %!d(string=hai) anos
pai
achega
bab85d3278

+ 1 - 5
coriolis/db/sqlalchemy/api.py

@@ -20,11 +20,7 @@ _facade = None
 def get_facade():
 def get_facade():
     global _facade
     global _facade
     if not _facade:
     if not _facade:
-        # TODO: investigate why the CONF.database.connection is None!
-        # _facade = db_session.EngineFacade(CONF.database.connection)
-        # _facade = db_session.EngineFacade.from_config(CONF)
-        _facade = db_session.EngineFacade(
-            "mysql://coriolis:Passw0rd@localhost/coriolis")
+        _facade = db_session.EngineFacade(CONF.database.connection)
     return _facade
     return _facade
 
 
 
 

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

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

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

@@ -12,7 +12,7 @@ LOG = logging.getLogger(__name__)
 class UbuntuOSMountTools(base.BaseLinuxOSMountTools):
 class UbuntuOSMountTools(base.BaseLinuxOSMountTools):
     def check_os(self):
     def check_os(self):
         os_info = utils.get_linux_os_info(self._ssh)
         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
             return True
 
 
     def _pre_mount_os(self):
     def _pre_mount_os(self):

+ 26 - 1
coriolis/utils.py

@@ -99,7 +99,24 @@ def get_udev_net_rules(net_ifaces_info):
     return content
     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 = {}
+    LOG.info("got os_release_info: %r" % os_release_info)
+    for line in os_release_info.splitlines():
+        if "=" not in line:
+            continue
+        LOG.info("parsing line: %s" % line)
+        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()
     out = exec_ssh_cmd(ssh, "lsb_release -a || true").decode()
     dist_id = re.findall('^Distributor ID:\s(.*)$', out, re.MULTILINE)
     dist_id = re.findall('^Distributor ID:\s(.*)$', out, re.MULTILINE)
     release = re.findall('^Release:\s(.*)$', out, re.MULTILINE)
     release = re.findall('^Release:\s(.*)$', out, re.MULTILINE)
@@ -107,6 +124,14 @@ def get_linux_os_info(ssh):
         return (dist_id[0], release[0])
         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()
 @retry_on_error()
 def test_ssh_path(ssh, remote_path):
 def test_ssh_path(ssh, remote_path):
     sftp = ssh.open_sftp()
     sftp = ssh.open_sftp()