Beispiel #1
0
    def _ensure_conn_descs_dont_collide(self):
        # By default we only show hostname + hypervisor in the conn label.
        # So if we have two URIs like qemu+ssh://host and qemu+tcp://host,
        # we want to add the transport in the description to differentiate
        connrows = [row for row in self.rows.values() if row[ROW_IS_CONN]]
        for row in connrows:
            conn = row[ROW_HANDLE]
            connsplit = util.uri_split(conn.get_uri())
            scheme = connsplit[0]

            show_transport = False
            show_user = False

            for checkrow in connrows:
                checkconn = checkrow[ROW_HANDLE]
                if conn is checkconn:
                    continue
                checkconnsplit = util.uri_split(checkconn.get_uri())
                checkscheme = checkconnsplit[0]

                if ((scheme.split("+")[0] == checkscheme.split("+")[0])
                        and connsplit[2] == checkconnsplit[2]
                        and connsplit[3] == checkconnsplit[3]):
                    show_transport = True
                    if ("+" in scheme and "+" in checkscheme and
                            scheme.split("+")[1] == checkscheme.split("+")[1]):
                        show_user = True

            newname = conn.get_pretty_desc(shorthost=False,
                                           show_transport=show_transport,
                                           show_user=show_user)
            if newname != row[ROW_SORT_KEY]:
                self.conn_state_changed(conn, newname=newname)
Beispiel #2
0
    def edit_uri(self, uri, hostname, port):
        split = list(util.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 #3
0
    def edit_uri(self, uri, hostname, port):
        split = list(util.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 #4
0
    def open(self, passwordcb):
        open_flags = 0
        valid_auth_options = [libvirt.VIR_CRED_AUTHNAME,
                              libvirt.VIR_CRED_PASSPHRASE]
        authcb = self._auth_cb
        authcb_data = passwordcb

        conn = libvirt.openAuth(self._open_uri,
                    [valid_auth_options, authcb,
                    (authcb_data, valid_auth_options)],
                    open_flags)

        self._fixup_virtinst_test_uri(conn)
        self._libvirtconn = conn
        if not self._open_uri:
            self._uri = self._libvirtconn.getURI()
            self._urisplits = util.uri_split(self._uri)
Beispiel #5
0
    def __init__(self, uri):
        self._initial_uri = uri or ""

        self._fake_pretty_name = None
        self._fake_libvirt_version = None
        self._fake_conn_version = None
        self._daemon_version = None
        self._conn_version = None

        if self._initial_uri.startswith(_virtinst_uri_magic):
            # virtinst unit test URI handling
            uri = self._initial_uri.replace(_virtinst_uri_magic, "")
            ret = uri.split(",", 1)
            self._open_uri = ret[0]
            self._test_opts = VirtOptionString(
                len(ret) > 1 and ret[1] or "", [], None).opts
            self._early_virtinst_test_uri()
            self._uri = self._virtinst_uri_make_fake()
        else:
            self._open_uri = self._initial_uri
            self._uri = self._initial_uri
            self._test_opts = {}

        self._libvirtconn = None
        self._urisplits = util.uri_split(self._uri)
        self._caps = None

        self._support_cache = {}
        self._fetch_cache = {}

        # Setting this means we only do fetch_all* once and just carry
        # the result. For the virt-* CLI tools this ensures any revalidation
        # isn't hammering the connection over and over
        self.cache_object_fetch = False

        # These let virt-manager register a callback which provides its
        # own cached object lists, rather than doing fresh calls
        self.cb_fetch_all_guests = None
        self.cb_fetch_all_pools = None
        self.cb_fetch_all_vols = None
        self.cb_clear_cache = None
    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) = util.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.caps.is_kvm_available():
            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)

        if self._backend.fake_name():
            hv = self._backend.fake_name()

        return "%s (%s)" % (rest, hv)
Beispiel #7
0
    def get_pretty_desc(self, shorthost=True, show_transport=False,
        show_user=False, show_kvm=False):
        """
        @show_kvm: Show hv as QEMU/KVM. Only works if connection is
            active though
        """
        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) = util.uri_split(self.get_uri())
        hostname, port = self.get_backend().get_uri_host_port()
        port = port or ""

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

        if hostname:
            if show_user and username:
                hostname = username + "@" + hostname
            if port:
                hostname += ":" + port

            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 show_kvm and self.caps.is_kvm_available():
            hv += "/KVM"

        if show_transport and transport:
            hv += "+" + transport

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

        if self._backend.fake_name():
            hv = self._backend.fake_name()

        return "%s (%s)" % (rest, hv)