This file is indexed.

/usr/share/virt-manager/virtManager/interface.py is in virt-manager 0.9.1-1ubuntu5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#
# Copyright (C) 2009 Red Hat, Inc.
# Copyright (C) 2009 Cole Robinson <crobinso@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
#

from virtinst import Interface

from virtManager import util
from virtManager.libvirtobject import vmmLibvirtObject

class vmmInterface(vmmLibvirtObject):
    def __init__(self, conn, interface, name, active):
        vmmLibvirtObject.__init__(self, conn)

        self.interface = interface  # Libvirt virInterface object
        self.name = name            # String name
        self.active = active        # bool indicating if it is running

        self._xml = None            # xml cache
        self._xml_flags = None

        (self._inactive_xml_flags,
         self._active_xml_flags) = self.conn.get_interface_flags(
                                                            self.interface)

        self.refresh_xml()

    # Routines from vmmLibvirtObject
    def _XMLDesc(self, flags):
        return self.interface.XMLDesc(flags)

    def _define(self, xml):
        return self.conn.define_interface(xml)

    def xpath(self, *args, **kwargs):
        # Must use this function for ALL XML parsing
        ret = util.xpath(self.get_xml(), *args, **kwargs)
        if ret:
            return ret
        if not self.is_active():
            return ret

        # The running config did not have the info requested
        return util.xpath(self.get_xml(inactive=True), *args, **kwargs)

    def set_active(self, state):
        self.active = state
        self.refresh_xml()

    def is_active(self):
        return self.active

    def get_name(self):
        return self.name

    def get_mac(self):
        return self.xpath("/interface/mac/@address")

    def start(self):
        self.interface.create(0)
        self.refresh_xml()

    def stop(self):
        self.interface.destroy(0)
        self.refresh_xml()

    def delete(self):
        self.interface.undefine()

    def is_bridge(self):
        typ = self.get_type()
        return typ == "bridge"

    def get_type(self):
        return self.xpath("/interface/@type")

    def get_pretty_type(self):
        itype = self.get_type()

        if itype == Interface.Interface.INTERFACE_TYPE_VLAN:
            return "VLAN"
        elif itype:
            return str(itype).capitalize()
        else:
            return "Interface"

    def get_startmode(self):
        return self.xpath("/interface/start/@mode") or "none"

    def set_startmode(self, newmode):
        def set_start_xml(doc, ctx):
            node = ctx.xpathEval("/interface/start[1]")
            node = (node and node[0] or None)
            iface_node = ctx.xpathEval("/interface")[0]

            if not node:
                node = iface_node.newChild(None, "start", None)

            node.setProp("mode", newmode)

            return doc.serialize()

        self._redefine(util.xml_parse_wrapper, set_start_xml)


    def get_slaves(self):
        typ = self.get_type()
        xpath = "/interface/%s/interface/@name" % typ

        def node_func(ctx):
            nodes = ctx.xpathEval(xpath)
            names = map(lambda x: x.content, nodes)
            ret = []

            for name in names:
                type_path = ("/interface/%s/interface[@name='%s']/@type" %
                             (typ, name))
                nodes = ctx.xpathEval(type_path)

                ret.append((name, nodes and nodes[0].content or "Unknown"))

            return ret

        ret = self.xpath(func=node_func)

        if not ret:
            return []
        return ret

    def get_slave_names(self):
        # Returns a list of names of all enslaved interfaces
        slaves = self.get_slaves()
        return map(lambda x: x[0], slaves)

    def get_ipv4(self):
        base_xpath = "/interface/protocol[@family='ipv4']"
        if not self.xpath(base_xpath):
            return []

        dhcp = bool(self.xpath("count(%s/dhcp)" % base_xpath))
        addr = self.xpath(base_xpath + "/ip/@address")
        if addr:
            prefix = self.xpath(base_xpath + "/ip[@address='%s']/@prefix" %
                                addr)
            if prefix:
                addr += "/%s" % prefix

        return [dhcp, addr]

    def get_ipv6(self):
        base_xpath = "/interface/protocol[@family='ipv6']"
        if not self.xpath(base_xpath):
            return []

        dhcp = bool(self.xpath("count(%s/dhcp)" % base_xpath))
        autoconf = bool(self.xpath("count(%s/autoconf)" % base_xpath))

        def addr_func(ctx):
            nodes = ctx.xpathEval(base_xpath + "/ip")
            nodes = nodes or []
            ret = []

            for node in nodes:
                addr = node.prop("address")
                pref = node.prop("prefix")

                if not addr:
                    continue

                if pref:
                    addr += "/%s" % pref
                ret.append(addr)

            return ret

        ret = self.xpath(func=addr_func)

        return [dhcp, autoconf, ret]

    def get_protocol_xml(self):
        def protocol(ctx):
            node = ctx.xpathEval("/interface/protocol")
            node = node and node[0] or None

            ret = None
            if node:
                ret = node.serialize()

            return ret

        ret = self.xpath(func=protocol)
        if ret:
            ret = "  %s\n" % ret
        return ret

    def _redefine(self, xml_func, *args):
        """
        Helper function for altering a redefining VM xml

        @param xml_func: Function to alter the running XML. Takes the
                         original XML as its first argument.
        @param args: Extra arguments to pass to xml_func
        """
        origxml = self._xml_to_redefine()
        # Sanitize origxml to be similar to what we will get back
        origxml = util.xml_parse_wrapper(origxml, lambda d, c: d.serialize())

        newxml = xml_func(origxml, *args)
        self._redefine_xml(newxml)

vmmLibvirtObject.type_register(vmmInterface)