If the interface's type is 'network', then code uses lease as one of parameters of interface_addresses to get ipv4 and ipv6 address. If the result is negative, then uses agent to try again, If the result is still negative, uses arp for final try. Signed-off-by: Lin Ma <lma@xxxxxxxx> --- ui/details.ui | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ virtManager/details.py | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) diff --git a/ui/details.ui b/ui/details.ui index 5a35a156..be29eb7a 100644 --- a/ui/details.ui +++ b/ui/details.ui @@ -4043,6 +4043,85 @@ <property name="top_attach">3</property> </packing> </child> + <child> + <object class="GtkButton" id="show-ip"> + <property name="label">Show IP</property> + <property name="image">image6</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="on_network_show_ip_clicked" swapped="no"/> + <child> + <object class="GtkImage" id="image6"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="stock">gtk-refresh</property> + </object> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">4</property> + </packing> + </child> + <child> + <object class="GtkGrid" id="grid8"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="column_spacing">3</property> + <child> + <object class="GtkLabel" id="ipv4-label"> + <property name="label" translatable="yes">IPv4:</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="ipv4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="ipv6-label"> + <property name="label" translatable="yes">IPv6:</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="ipv6"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">1</property> + </packing> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">4</property> + </packing> + </child> </object> </child> </object> diff --git a/virtManager/details.py b/virtManager/details.py index e670d21f..67c936b4 100644 --- a/virtManager/details.py +++ b/virtManager/details.py @@ -548,6 +548,7 @@ class vmmDetails(vmmGObjectUI): EDIT_NET_MAC), "on_network_link_state_checkbox_toggled": lambda *x: self.enable_apply(x, EDIT_NET_LINKSTATE), + "on_network_show_ip_clicked": self.show_ip, "on_sound_model_combo_changed": lambda *x: self.enable_apply(x, @@ -1868,6 +1869,60 @@ class vmmDetails(vmmGObjectUI): return self._insert_media(disk) + # Interface IP + def show_ip(self, src_ignore): + def agent_ready(): + chardevs = self.vm.xmlobj.devices.channel + if chardevs: + for dev in chardevs: + if (dev.DEVICE_TYPE == "channel" and dev.type == "unix" and + dev.target_name == "org.qemu.guest_agent.0" and + dev.target_state == "connected"): + return True + return False + + if not self.vm.is_active(): + self.widget("ipv4").set_text("N/A") + self.widget("ipv6").set_text("N/A") + return + + net = self.get_hw_selection(HW_LIST_COL_DEVICE) + if not net: + return + + macaddr = net.macaddr or "" + + if net.type == "network": + addrinfo = self.vm.interface_addresses( + libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE, macaddr) + if addrinfo and (addrinfo["ipv4"] or addrinfo["ipv6"]): + self.widget("ipv4").set_text(addrinfo['ipv4'] if + addrinfo['ipv4'] else "N/A") + self.widget("ipv6").set_text(addrinfo['ipv6'] if + addrinfo['ipv6'] else "N/A") + return + if agent_ready() is True: + addrinfo = self.vm.interface_addresses( + libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT, macaddr) + if addrinfo and (addrinfo["ipv4"] or addrinfo["ipv6"]): + self.widget("ipv4").set_text(addrinfo['ipv4'] + if addrinfo['ipv4'] else "N/A") + self.widget("ipv6").set_text(addrinfo['ipv6'] if + addrinfo['ipv6'] else "N/A") + return + addrinfo = self.vm.interface_addresses( + libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP, macaddr) + if addrinfo and (addrinfo["ipv4"] or addrinfo["ipv6"]): + self.widget("ipv4").set_text(addrinfo['ipv4'] if addrinfo['ipv4'] + else "N/A") + self.widget("ipv6").set_text(addrinfo['ipv6'] if addrinfo['ipv6'] + else "N/A") + return + + self.widget("ipv4").set_text("N/A") + self.widget("ipv6").set_text("N/A") + + ################################################## # Details/Hardware config changes (apply button) # ################################################## @@ -2727,6 +2782,10 @@ class vmmDetails(vmmGObjectUI): state = net.link_state == "up" or net.link_state is None self.widget("network-link-state-checkbox").set_active(state) + if len(self.vm.xmlobj.devices.interface) > 1: + self.widget("ipv4").set_text("") + self.widget("ipv6").set_text("") + self.netlist.set_dev(net) def refresh_input_page(self): -- 2.15.1 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list