Beispiel #1
0
    def edit_uri(self, uri, hostname, port):
        split = list(uriutil.uri_split(uri))

        hostname = hostname or split[2]
        if port:
            if hostname.count(":"):
                hostname = hostname.split(":")[0]
            hostname += ":%s" % port

        split[2] = hostname
        return uri_join(tuple(split))
Beispiel #2
0
    def _get_pretty_desc(self, active, shorthost, show_trans):
        def match_whole_string(orig, reg):
            match = re.match(reg, orig)
            if not match:
                return False

            return ((match.end() - match.start()) == len(orig))

        def is_ip_addr(orig):
            return match_whole_string(orig, "[0-9.]+")

        (scheme, username, hostname, path, ignore,
         ignore) = uriutil.uri_split(self.get_uri())

        hv = ""
        rest = ""
        transport = ""
        port = ""
        if scheme.count("+"):
            transport = scheme.split("+")[1]
            scheme = scheme.split("+")[0]

        if hostname.count(":"):
            port = hostname.split(":")[1]
            hostname = hostname.split(":")[0]

        if hostname:
            if shorthost and not is_ip_addr(hostname):
                rest = hostname.split(".")[0]
            else:
                rest = hostname
        else:
            rest = "localhost"

        pretty_map = {
            "esx": "ESX",
            "gsx": "GSX",
            "libxl": "libxl",
            "lxc": "LXC",
            "openvz": "OpenVZ",
            "phyp": "phyp",
            "qemu": "QEMU",
            "test": "test",
            "uml": "UML",
            "vbox": "VBox",
            "vmware": "VMWare",
            "xen": "xen",
            "xenapi": "XenAPI",
        }

        hv = scheme
        if scheme in pretty_map:
            hv = pretty_map[scheme]

        if hv == "QEMU" and active and self.is_kvm_supported():
            hv += "/KVM"

        if show_trans:
            if transport:
                hv += "+" + transport
            if username:
                hostname = username + "@" + hostname
            if port:
                hostname += ":" + port

        if path and path != "/system" and path != "/":
            if path == "/session":
                hv += " Usermode"
            else:
                hv += " %s" % os.path.basename(path)

        return "%s (%s)" % (rest, hv)
Beispiel #3
0
 def is_test_conn(self):
     (scheme, ignore, ignore, ignore, ignore,
      ignore) = uriutil.uri_split(self.get_uri())
     if scheme.startswith("test"):
         return True
     return False
Beispiel #4
0
 def is_session_uri(self):
     path = uriutil.uri_split(self.get_uri())[3]
     return path == "/session"
Beispiel #5
0
    def is_qemu(self):
        if self._is_virtinst_test_uri:
            return self.get_uri().count(",qemu")

        scheme = uriutil.uri_split(self.get_uri())[0]
        return scheme.startswith("qemu")
Beispiel #6
0
 def is_qemu_session(self):
     (scheme, ignore, ignore, path, ignore,
      ignore) = uriutil.uri_split(self.get_uri())
     if path == "/session" and scheme.startswith("qemu"):
         return True
     return False
Beispiel #7
0
    def is_lxc(self):
        if self._is_virtinst_test_uri:
            self.get_uri().count(",lxc")

        return uriutil.uri_split(self.get_uri())[0].startswith("lxc")
Beispiel #8
0
 def is_openvz(self):
     return uriutil.uri_split(self.get_uri())[0].startswith("openvz")
Beispiel #9
0
 def is_session_uri(self):
     path = uriutil.uri_split(self.get_uri())[3]
     return path == "/session"
Beispiel #10
0
    def _get_pretty_desc(self, active, shorthost, show_trans):
        def match_whole_string(orig, reg):
            match = re.match(reg, orig)
            if not match:
                return False

            return ((match.end() - match.start()) == len(orig))

        def is_ip_addr(orig):
            return match_whole_string(orig, "[0-9.]+")

        (scheme, username, hostname,
         path, ignore, ignore) = uriutil.uri_split(self.get_uri())

        hv = ""
        rest = ""
        transport = ""
        port = ""
        if scheme.count("+"):
            transport = scheme.split("+")[1]
            scheme = scheme.split("+")[0]

        if hostname.count(":"):
            port = hostname.split(":")[1]
            hostname = hostname.split(":")[0]

        if hostname:
            if shorthost and not is_ip_addr(hostname):
                rest = hostname.split(".")[0]
            else:
                rest = hostname
        else:
            rest = "localhost"

        pretty_map = {
            "esx"       : "ESX",
            "gsx"       : "GSX",
            "libxl"     : "libxl",
            "lxc"       : "LXC",
            "openvz"    : "OpenVZ",
            "phyp"      : "phyp",
            "qemu"      : "QEMU",
            "test"      : "test",
            "uml"       : "UML",
            "vbox"      : "VBox",
            "vmware"    : "VMWare",
            "xen"       : "xen",
            "xenapi"    : "XenAPI",
        }

        hv = scheme
        if scheme in pretty_map:
            hv = pretty_map[scheme]

        if hv == "QEMU" and active and self.is_kvm_supported():
            hv += "/KVM"

        if show_trans:
            if transport:
                hv += "+" + transport
            if username:
                hostname = username + "@" + hostname
            if port:
                hostname += ":" + port

        if path and path != "/system" and path != "/":
            if path == "/session":
                hv += " Usermode"
            else:
                hv += " %s" % os.path.basename(path)

        return "%s (%s)" % (rest, hv)
Beispiel #11
0
 def is_test_conn(self):
     (scheme, ignore, ignore,
      ignore, ignore, ignore) = uriutil.uri_split(self.get_uri())
     if scheme.startswith("test"):
         return True
     return False
Beispiel #12
0
 def is_qemu_session(self):
     (scheme, ignore, ignore,
      path, ignore, ignore) = uriutil.uri_split(self.get_uri())
     if path == "/session" and scheme.startswith("qemu"):
         return True
     return False
Beispiel #13
0
    def is_qemu(self):
        if self._is_virtinst_test_uri:
            return self.get_uri().count(",qemu")

        scheme = uriutil.uri_split(self.get_uri())[0]
        return scheme.startswith("qemu")
Beispiel #14
0
 def is_openvz(self):
     return uriutil.uri_split(self.get_uri())[0].startswith("openvz")
Beispiel #15
0
    def is_lxc(self):
        if self._is_virtinst_test_uri:
            self.get_uri().count(",lxc")

        return uriutil.uri_split(self.get_uri())[0].startswith("lxc")