This file is indexed.

/usr/share/pyshared/archipelagenthypervisornetwork/network.py is in archipel-agent-hypervisor-network 0.6.0-1.

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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# -*- coding: utf-8 -*-
#
# network.py
#
# Copyright (C) 2010 Antoine Mercadal <antoine.mercadal@inframonde.eu>
# Copyright, 2011 - Franck Villaume <franck.villaume@trivialdev.com>
# This file is part of ArchipelProject
# http://archipelproject.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import commands
import libvirt
import os
import xmpp

from archipelcore.archipelPlugin import TNArchipelPlugin
from archipelcore.utils import build_error_iq, build_error_message

from archipel.archipelLibvirtEntity import ARCHIPEL_NS_LIBVIRT_GENERIC_ERROR


ARCHIPEL_NS_HYPERVISOR_NETWORK              = "archipel:hypervisor:network"
ARCHIPEL_ERROR_CODE_NETWORKS_DEFINE         = -7001
ARCHIPEL_ERROR_CODE_NETWORKS_UNDEFINE       = -7002
ARCHIPEL_ERROR_CODE_NETWORKS_CREATE         = -7003
ARCHIPEL_ERROR_CODE_NETWORKS_DESTROY        = -7004
ARCHIPEL_ERROR_CODE_NETWORKS_GET            = -7005
ARCHIPEL_ERROR_CODE_NETWORKS_BRIDGES        = -7006
ARCHIPEL_ERROR_CODE_NETWORKS_GETNAMES       = -7007
ARCHIPEL_ERROR_CODE_NETWORKS_GETNICS        = -7008
ARCHIPEL_ERROR_CODE_NETWORKS_GETNWFILTERS   = -7009


class TNHypervisorNetworks (TNArchipelPlugin):

    def __init__(self, configuration, entity, entry_point_group):
        """
        Initialize the plugin.
        @type configuration: Configuration object
        @param configuration: the configuration
        @type entity: L{TNArchipelEntity}
        @param entity: the entity that owns the plugin
        @type entry_point_group: string
        @param entry_point_group: the group name of plugin entry_point
        """
        TNArchipelPlugin.__init__(self, configuration=configuration, entity=entity, entry_point_group=entry_point_group)
        self.folder_nwfilters = self.configuration.get("NETWORKS", "libvirt_nw_filters_path")
        if not os.path.exists(self.folder_nwfilters):
            self.folder_nwfilters = None
            self.entity.log.warning("NETWORK: unable to find network filter folder at path %s. agent will not offer any network filter")

        # permissions
        if self.entity.__class__.__name__ == "TNArchipelVirtualMachine":
            self.entity.permission_center.create_permission("network_getnames", "Authorizes user to get the existing network names", False)
            self.entity.permission_center.create_permission("network_bridges", "Authorizes user to get existing bridges", False)
        elif self.entity.__class__.__name__ == "TNArchipelHypervisor":
            self.entity.permission_center.create_permission("network_define", "Authorizes user to define a network", False)
            self.entity.permission_center.create_permission("network_undefine", "Authorizes user to undefine a network", False)
            self.entity.permission_center.create_permission("network_create", "Authorizes user to create (start) a network", False)
            self.entity.permission_center.create_permission("network_destroy", "Authorizes user to destroy (stop) a network", False)
            self.entity.permission_center.create_permission("network_get", "Authorizes user to get all networks informations", False)
            self.entity.permission_center.create_permission("network_getnames", "Authorizes user to get the existing network names", False)
            self.entity.permission_center.create_permission("network_bridges", "Authorizes user to get existing bridges", False)
            self.entity.permission_center.create_permission("network_getnics", "Authorizes user to get existing network interfaces", False)
            self.entity.permission_center.create_permission("network_getnwfilters", "Authorizes user to get existing libvirt network filters", False)
            registrar_items = [
                                {   "commands" : ["list networks"],
                                    "parameters": [],
                                    "method": self.message_get,
                                    "permissions": ["network_get"],
                                    "description": "List all networks" },
                                {   "commands" : ["create network", "start network"],
                                    "parameters": [{"name": "identifier", "description": "The identifer of the network, UUID or name"}],
                                    "method": self.message_create,
                                    "permissions": ["network_create"],
                                    "description": "Start the given network" },
                                {   "commands" : ["destroy network", "stop network"],
                                    "parameters": [{"name": "identifier", "description": "The identifer of the network, UUID or name"}],
                                    "method": self.message_destroy,
                                    "permissions": ["network_destroy"],
                                    "description": "Stop the given network" },
                                {   "commands" : ["nics", "network cards"],
                                    "parameters": [],
                                    "method": self.message_getnics,
                                    "permissions": ["network_getnics"],
                                    "description": "Get the list of all my network interfaces" }
                                ]

            self.entity.add_message_registrar_items(registrar_items)


    ### Plugin implementation

    def register_handlers(self):
        """
        This method will be called by the plugin user when it will be
        necessary to register module for listening to stanza.
        """
        if self.entity.__class__.__name__ == "TNArchipelVirtualMachine":
            self.entity.xmppclient.RegisterHandler('iq', self.process_iq_for_virtualmachine, ns=ARCHIPEL_NS_HYPERVISOR_NETWORK)
        elif self.entity.__class__.__name__ == "TNArchipelHypervisor":
            self.entity.xmppclient.RegisterHandler('iq', self.process_iq_for_hypervisor, ns=ARCHIPEL_NS_HYPERVISOR_NETWORK)

    def unregister_handlers(self):
        """
        Unregister the handlers.
        """
        if self.entity.__class__.__name__ == "TNArchipelVirtualMachine":
            self.entity.xmppclient.UnregisterHandler('iq', self.process_iq_for_virtualmachine, ns=ARCHIPEL_NS_HYPERVISOR_NETWORK)
        elif self.entity.__class__.__name__ == "TNArchipelHypervisor":
            self.entity.xmppclient.UnregisterHandler('iq', self.process_iq_for_hypervisor, ns=ARCHIPEL_NS_HYPERVISOR_NETWORK)

    @staticmethod
    def plugin_info():
        """
        Return informations about the plugin.
        @rtype: dict
        @return: dictionary contaning plugin informations
        """
        plugin_friendly_name           = "Hypervisor Networks"
        plugin_identifier              = "hypervisor_network"
        plugin_configuration_section   = "NETWORKS"
        plugin_configuration_tokens    = ["libvirt_nw_filters_path"]
        return {    "common-name"               : plugin_friendly_name,
                    "identifier"                : plugin_identifier,
                    "configuration-section"     : plugin_configuration_section,
                    "configuration-tokens"      : plugin_configuration_tokens }

    ### Utilities

    def get_network_with_identifier(self, identifier):
        """
        Return a libvirtNetwork according to the identifier, which can be the name or the UUID
        @type identifier: String
        @param identifier: the name or the UUID of the network
        @rtype: libvirtNetwork
        @return: the network object with given identifier
        """
        try:
            try:
                libvirt_network = self.entity.libvirt_connection.networkLookupByName(identifier)
            except:
                libvirt_network = self.entity.libvirt_connection.networkLookupByUUIDString(identifier)
            return libvirt_network
        except Exception as ex:
            self.entity.log.error("NETWORK: Unable to find a network with identifier %s: %s" % (identifier, str(ex)))
            raise Exception("Unable to find a network with identifier %s" % identifier)


    ### libvirt controls

    def get(self, active=True, inactive=True):
        """
        Get the list of networks.
        @type active: bool
        @param active: if True, will return active network
        @type inactive: bool
        @param inactive: if True, will return not active network
        @rtype: dict
        @return: a list containing networtks
        """
        ret = {}

        if self.entity.__class__.__name__ == "TNArchipelVirtualMachine":
            libvirt_connection = self.entity.hypervisor.libvirt_connection
        else:
            libvirt_connection = self.entity.libvirt_connection

        if active:
            ret["active"] = libvirt_connection.listNetworks()
        if inactive:
            ret["inactive"] = libvirt_connection.listDefinedNetworks()
        return ret

    def create(self, identifier):
        """
        Create (start) the network with given identifier.
        @type identifier: string
        @param identifier: the identifer of the network to create. It can be its name or UUID
        """
        libvirt_network = self.get_network_with_identifier(identifier)
        libvirt_network.create()
        self.entity.log.info("NETWORK: Virtual network %s created." % identifier)
        self.entity.push_change("network", "created")

    def destroy(self, identifier):
        """
        destroy (stop) the network with given identifier
        @type identifier: string
        @param identifier: the identifer of the network to destroy. It can be its name or UUID
        """
        libvirt_network = self.get_network_with_identifier(identifier)
        libvirt_network.destroy()
        self.entity.log.info("NETWORK: virtual network %s destroyed" % identifier)
        self.entity.push_change("network", "destroyed")

    def define(self, definition):
        """
        define the network
        @type definition: string
        @param definition: the XML definition to use
        """
        self.entity.libvirt_connection.networkDefineXML(str(definition))
        self.entity.log.info("NETWORK: Virtual network XML is defined.")
        self.entity.push_change("network", "defined")

    def undefine(self, identifier):
        """
        Undefine the network with given identifier.
        @type identifier: string
        @param identifier: the identifer of the network to destroy. It can be its name or UUID
        """
        libvirt_network = self.get_network_with_identifier(identifier)
        libvirt_network.undefine()
        self.entity.log.info("NETWORK: Virtual network %s is undefined." % identifier)
        self.entity.push_change("network", "undefined")

    def getnics(self):
        """
        Return the list of all network interfaces.
        @rtype: list
        @return: list containing network cards names
        """
        f = open('/proc/net/dev', 'r')
        content = f.read()
        f.close()
        splitted = content.split('\n')[2:-1]
        return map(lambda x: x.split(":")[0].replace(" ", ""), splitted)

    def getnwfilters(self):
        """
        Return the list of all libvirt network filters.
        @rtype: list
        @return: list containing network cards names
        """
        ret = []
        if not self.folder_nwfilters:
            return ret
        for nwfilter in os.listdir(self.folder_nwfilters):
            ret.append(os.path.splitext(nwfilter)[0])
        return ret

    def setAutostart(self, identifier, shouldAutostart):
        """
        Set the network to start with the host
        @type network_identifier: string
        @param identifier: the UUID or the name of the network
        @type identifier: boolean
        @param shouldAutostart: set if autostart should be set
        @rtype: integer
        @return: the result of the libvirt call
        """
        libvirt_network = self.get_network_with_identifier(identifier)
        return libvirt_network.setAutostart(shouldAutostart)

    def getAutostart(self, identifier):
        """
        Set the network to start with the host
        @type identifier: string
        @param identifier: the UUID or the name of the network
        @rtype: Boolean
        @return: True is network is in autostart mode
        """
        libvirt_network = self.get_network_with_identifier(identifier)
        return libvirt_network.autostart()


    ### XMPP Processing

    def process_iq_for_hypervisor(self, conn, iq):
        """
        This method is invoked when a ARCHIPEL_NS_HYPERVISOR_NETWORK IQ is received.
        It understands IQ of type:
            - define
            - undefine
            - create
            - destroy
            - get
            - bridges
            - getnames
            - getnics
        @type conn: xmpp.Dispatcher
        @param conn: ths instance of the current connection that send the stanza
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        """
        reply = None
        action = self.entity.check_acp(conn, iq)
        self.entity.check_perm(conn, iq, action, -1, prefix="network_")
        if action == "define":
            reply = self.iq_define(iq)
        elif action == "undefine":
            reply = self.iq_undefine(iq)
        elif action == "create":
            reply = self.iq_create(iq)
        elif action == "destroy":
            reply = self.iq_destroy(iq)
        elif action == "get":
            reply = self.iq_get(iq)
        elif action == "bridges":
            reply = self.iq_bridges(iq)
        elif action == "getnames":
            reply = self.iq_get_names(iq)
        elif action == "getnics":
            reply = self.iq_get_nics(iq)
        if reply:
            conn.send(reply)
            raise xmpp.protocol.NodeProcessed

    def process_iq_for_virtualmachine(self, conn, iq):
        """
        This method is invoked when a ARCHIPEL_NS_HYPERVISOR_NETWORK IQ is received.
        It understands IQ of type:
            - bridges
            - getnames
            - getnics
            - getnwfilters
        @type conn: xmpp.Dispatcher
        @param conn: ths instance of the current connection that send the stanza
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        """
        reply = None
        action = self.entity.check_acp(conn, iq)
        self.entity.check_perm(conn, iq, action, -1, prefix="network_")
        if action == "getnames":
            reply = self.iq_get_names(iq)
        elif action == "bridges":
            reply = self.iq_bridges(iq)
        elif action == "getnics":
            reply = self.iq_get_nics(iq)
        elif action == "getnwfilters":
            reply = self.iq_get_nwfilters(iq)
        if reply:
            conn.send(reply)
            raise xmpp.protocol.NodeProcessed

    def iq_define(self, iq):
        """
        Define a virtual network in the libvirt according to the XML data
        network passed in argument.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply           = iq.buildReply("result")
            network_node    = iq.getTag("query").getTag("archipel").getTag("network")
            self.define(network_node)
            if iq.getTag("query").getTag("archipel").getAttr("autostart") == "1":
                self.setAutostart(network_node.getTag("uuid").getData(), True)
        except libvirt.libvirtError as ex:
            reply = build_error_iq(self, ex, iq, ex.get_error_code(), ns=ARCHIPEL_NS_LIBVIRT_GENERIC_ERROR)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_DEFINE)
        return reply

    def iq_undefine(self, iq):
        """
        Undefine a virtual network in the libvirt according to name passed in argument.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply = iq.buildReply("result")
            network_uuid = iq.getTag("query").getTag("archipel").getAttr("uuid")
            self.undefine(network_uuid)
        except libvirt.libvirtError as ex:
            reply = build_error_iq(self, ex, iq, ex.get_error_code(), ns=ARCHIPEL_NS_LIBVIRT_GENERIC_ERROR)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_UNDEFINE)
        return reply

    def iq_create(self, iq):
        """
        Create a network using libvirt connection.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            network_uuid = iq.getTag("query").getTag("archipel").getAttr("uuid")
            self.create(network_uuid)
            reply = iq.buildReply("result")
            self.entity.shout("network", "Network %s has been started by %s." % (network_uuid, iq.getFrom()))
        except libvirt.libvirtError as ex:
            reply = build_error_iq(self, ex, iq, ex.get_error_code(), ns=ARCHIPEL_NS_LIBVIRT_GENERIC_ERROR)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_CREATE)
        return reply

    def message_create(self, msg):
        """
        Handle the creation request message.
        @type msg: xmpp.Protocol.Message
        @param msg: the received message
        @rtype: xmpp.Protocol.Message
        @return: a ready to send Message containing the result of the action
        """
        try:
            tokens = msg.getBody().split()
            if not len(tokens) == 3:
                return "I'm sorry, you use a wrong format. You can type 'help' to get help."
            identifier = tokens[-1:][0]
            self.create(identifier)
            return "Starting network %s" % identifier
        except Exception as ex:
            return build_error_message(self, ex, msg)

    def iq_destroy(self, iq):
        """
        Destroy a network using libvirt connection.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            network_uuid = iq.getTag("query").getTag("archipel").getAttr("uuid")
            self.destroy(network_uuid)
            reply = iq.buildReply("result")
            self.entity.shout("network", "Network %s has been shutdowned by %s." % (network_uuid, iq.getFrom()))
        except libvirt.libvirtError as ex:
            reply = build_error_iq(self, ex, iq, ex.get_error_code(), ns=ARCHIPEL_NS_LIBVIRT_GENERIC_ERROR)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_DESTROY)
        return reply

    def message_destroy(self, msg):
        """
        Handle the destroying request message.
        @type msg: xmpp.Protocol.Message
        @param msg: the message containing the request
        @rtype: string
        @return: the answer
        """
        try:
            tokens = msg.getBody().split()
            if not len(tokens) == 3:
                return "I'm sorry, you use a wrong format. You can type 'help' to get help."
            identifier = tokens[-1:][0]
            self.destroy(identifier)
            return "Destroying network %s" % identifier
        except Exception as ex:
            return build_error_message(self, ex, msg)

    def iq_get(self, iq):
        """
        List all virtual networks.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply                   = iq.buildReply("result")
            active_networks_nodes   = []
            inactive_networks_nodes = []
            networks                = self.get()
            for network_name in networks["active"]:
                network = self.entity.libvirt_connection.networkLookupByName(network_name)
                desc = network.XMLDesc(0)
                n = xmpp.simplexml.NodeBuilder(data=desc).getDom()
                n.setAttr("autostart", self.getAutostart(network_name))
                active_networks_nodes.append(n)
            for network_name in networks["inactive"]:
                network = self.entity.libvirt_connection.networkLookupByName(network_name)
                desc = network.XMLDesc(0)
                n = xmpp.simplexml.NodeBuilder(data=desc).getDom()
                n.setAttr("autostart", self.getAutostart(network_name))
                inactive_networks_nodes.append(n)
            active_networks_root_node   = xmpp.Node(tag="activedNetworks", payload=active_networks_nodes)
            inactive_networks_root_node = xmpp.Node(tag="unactivedNetworks", payload=inactive_networks_nodes)
            reply.setQueryPayload([active_networks_root_node, inactive_networks_root_node])
        except libvirt.libvirtError as ex:
            reply = build_error_iq(self, ex, iq, ex.get_error_code(), ns=ARCHIPEL_NS_LIBVIRT_GENERIC_ERROR)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_GET)
        return reply

    def message_get(self, msg):
        """
        Create the message response to list network.
        @type msg: xmpp.Protocol.Message
        @param msg: the message containing the request
        @rtype: string
        @return: the answer
        """
        try:
            networks = self.get()
            ret = "Sure. Here are my current active networks:\n"
            for net in networks["active"]:
                ret += "    - %s\n" % net
            ret += "\n and my unactive network:\n"
            for net in networks["inactive"]:
                ret += "    - %s\n" % net
            return ret
        except Exception as ex:
            return build_error_message(self, ex, msg)

    def iq_get_names(self, iq):
        """
        List all virtual network names.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply = iq.buildReply("result")
            active_networks_nodes = []
            actives_networks_names = self.get(inactive=False)["active"]
            for network_name in actives_networks_names:
                network = xmpp.Node(tag="network", attrs={"name": network_name})
                active_networks_nodes.append(network)
            reply.setQueryPayload(active_networks_nodes)
        except libvirt.libvirtError as ex:
            reply = build_error_iq(self, ex, iq, ex.get_error_code(), ns=ARCHIPEL_NS_LIBVIRT_GENERIC_ERROR)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_GETNAMES)
        return reply

    def iq_bridges(self, iq):
        """
        List all bridge names.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply = iq.buildReply("result")
            output = commands.getoutput("brctl show | grep -v -E '^[[:space:]]'")
            lines = output.split("\n")[1:]
            bridges_names = []
            for line in lines:
                bridge_name = line.split()[0]
                bridge_node = xmpp.Node(tag="bridge", attrs={"name": bridge_name})
                bridges_names.append(bridge_node)
            reply.setQueryPayload(bridges_names)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_BRIDGES)
        return reply

    def iq_get_nics(self, iq):
        """
        List all existing networks cards on the hypervisor.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply = iq.buildReply("result")
            nodes = []
            for n in self.getnics():
                nodes.append(xmpp.Node("nic", attrs={"name": n}))
            reply.setQueryPayload(nodes)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_GETNICS)
        return reply

    def message_getnics(self, msg):
        """
        Get all the nics of the hypervisor.
        @type msg: xmpp.Protocol.Message
        @param msg: the message containing the request
        @rtype: string
        @return: the answer
        """
        try:
            nics = self.getnics()
            ret = "Sure. Here are my current available network interfaces:\n"
            for n in nics:
                ret += "    - %s\n" % n
            return ret
        except Exception as ex:
            return build_error_message(self, ex, msg)

    def iq_get_nwfilters(self, iq):
        """
        List all existing libvirt network filters.
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply = iq.buildReply("result")
            nodes = []
            for nwfilter in self.getnwfilters():
                nodes.append(xmpp.Node("filter", attrs={"name": nwfilter}))
            reply.setQueryPayload(nodes)
        except Exception as ex:
            reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_NETWORKS_GETNWFILTERS)
        return reply