def generate_macaddr(conn): newmac = "" try: net = VirtualNetworkInterface(conn=conn.vmm) net.setup(conn.vmm) newmac = net.macaddr except: pass return newmac
def populate_network_list(self): net_box = self.widget("clone-network-box") for c in net_box.get_children(): net_box.remove(c) c.destroy() self.net_list = {} self.mac_list = [] def build_net_row(labelstr, origmac, newmac): label = Gtk.Label(label=labelstr + " (%s)" % origmac) label.set_alignment(0, .5) button = Gtk.Button(_("Details...")) button.connect("clicked", self.net_change_mac, origmac) hbox = Gtk.HBox() hbox.set_spacing(12) hbox.pack_start(label, True, True, 0) hbox.pack_end(button, False, False, False) hbox.show_all() net_box.pack_start(hbox, False, False, False) net_row = [] net_row.insert(NETWORK_INFO_LABEL, labelstr) net_row.insert(NETWORK_INFO_ORIG_MAC, origmac) net_row.insert(NETWORK_INFO_NEW_MAC, newmac) self.net_list[origmac] = net_row self.mac_list.append(origmac) for net in self.orig_vm.get_network_devices(): mac = net.macaddr net_dev = net.get_source() net_type = net.type # Generate a new MAC obj = VirtualNetworkInterface(conn=self.conn.vmm, type=VirtualNetworkInterface.TYPE_USER) obj.setup(self.conn.vmm) newmac = obj.macaddr # [ interface type, device name, origmac, newmac, label ] if net_type == VirtualNetworkInterface.TYPE_USER: label = _("Usermode") elif net_type == VirtualNetworkInterface.TYPE_VIRTUAL: net = self.orig_vm.conn.get_net_by_name(net_dev) if net: label = "" desc = net.pretty_forward_mode() label += "%s" % desc else: label = (_("Virtual Network") + (net_dev and " %s" % net_dev or "")) else: # 'bridge' or anything else label = (net_type.capitalize() + (net_dev and (" %s" % net_dev) or "")) build_net_row(label, mac, newmac) no_net = bool(len(self.net_list.keys()) == 0) self.widget("clone-network-box").set_property("visible", not no_net) self.widget("clone-no-net").set_property("visible", no_net)
def populate_network_list(self): net_box = self.widget("clone-network-box") for c in net_box.get_children(): net_box.remove(c) c.destroy() self.net_list = {} self.mac_list = [] def build_net_row(labelstr, origmac, newmac): label = Gtk.Label(label=labelstr + " (%s)" % origmac) label.set_alignment(0, .5) button = Gtk.Button(_("Details...")) button.connect("clicked", self.net_change_mac, origmac) hbox = Gtk.HBox() hbox.set_spacing(12) hbox.pack_start(label, True, True, 0) hbox.pack_end(button, False, False, False) hbox.show_all() net_box.pack_start(hbox, False, False, False) net_row = [] net_row.insert(NETWORK_INFO_LABEL, labelstr) net_row.insert(NETWORK_INFO_ORIG_MAC, origmac) net_row.insert(NETWORK_INFO_NEW_MAC, newmac) self.net_list[origmac] = net_row self.mac_list.append(origmac) for net in self.orig_vm.get_network_devices(): mac = net.macaddr net_dev = net.get_source() net_type = net.type # Generate a new MAC obj = VirtualNetworkInterface( conn=self.conn.vmm, type=VirtualNetworkInterface.TYPE_USER) obj.setup(self.conn.vmm) newmac = obj.macaddr # [ interface type, device name, origmac, newmac, label ] if net_type == VirtualNetworkInterface.TYPE_USER: label = _("Usermode") elif net_type == VirtualNetworkInterface.TYPE_VIRTUAL: net = self.orig_vm.conn.get_net_by_name(net_dev) if net: label = "" desc = net.pretty_forward_mode() label += "%s" % desc else: label = (_("Virtual Network") + (net_dev and " %s" % net_dev or "")) else: # 'bridge' or anything else label = (net_type.capitalize() + (net_dev and (" %s" % net_dev) or "")) build_net_row(label, mac, newmac) no_net = bool(len(self.net_list.keys()) == 0) self.widget("clone-network-box").set_property("visible", not no_net) self.widget("clone-no-net").set_property("visible", no_net)