[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCH] Allow disabling DHCP when creating new network in VMM



Hi,
this is the patch to allow disabling DHCP when creating new network in Virt-manager (VMM for short) so please review this one. It's based on the request from one guy in our office and I think it's a good-to-have one.

Thanks,
Michal
diff -r 37a986ce54ce src/virtManager/createnet.py
--- a/src/virtManager/createnet.py	Thu Aug 27 11:07:35 2009 -0400
+++ b/src/virtManager/createnet.py	Wed Sep 09 23:44:17 2009 +0200
@@ -62,6 +62,7 @@
             "on_create_finish_clicked" : self.finish,
             "on_net_forward_toggled" : self.change_forward_type,
             "on_net_network_changed": self.change_network,
+            "on_net_dhcp_enable_toggled": self.change_dhcp_enable,
             "on_net_dhcp_start_changed": self.change_dhcp_start,
             "on_net_dhcp_end_changed": self.change_dhcp_end,
             "on_create_help_clicked": self.show_help,
@@ -162,6 +163,11 @@
             else:
                 self.window.get_widget("net-info-type").set_text(_("Other"))
 
+    def change_dhcp_enable(self, src):
+        val = src.get_active()
+        self.window.get_widget("net-dhcp-start").set_sensitive(val)
+        self.window.get_widget("net-dhcp-end").set_sensitive(val)
+
     def change_dhcp_start(self, src):
         end = self.get_config_dhcp_start()
         self.change_dhcp(src, end)
@@ -219,6 +225,9 @@
             name = model[active][2]
             return [True, name]
 
+    def get_config_dhcp_enable(self):
+            return self.window.get_widget("net-dhcp-enable").get_active()
+
     def page_changed(self, notebook, page, page_number):
         # would you like some spaghetti with your salad, sir?
 
@@ -247,10 +256,21 @@
             self.window.get_widget("summary-ip4-gateway").set_text(str(ip[1]))
             self.window.get_widget("summary-ip4-netmask").set_text(str(ip.netmask()))
 
-            start = self.get_config_dhcp_start()
-            end = self.get_config_dhcp_end()
-            self.window.get_widget("summary-dhcp-start").set_text(str(start))
-            self.window.get_widget("summary-dhcp-end").set_text(str(end))
+            if self.get_config_dhcp_enable():
+                start = self.get_config_dhcp_start()
+                end = self.get_config_dhcp_end()
+                self.window.get_widget("summary-dhcp-start").set_text(str(start))
+                self.window.get_widget("summary-dhcp-end").set_text(str(end))
+                self.window.get_widget("label-dhcp-start").set_text( _("Start address:") )
+                self.window.get_widget("label-dhcp-start").show()
+                self.window.get_widget("label-dhcp-end").show()
+                self.window.get_widget("summary-dhcp-start").show()
+                self.window.get_widget("summary-dhcp-end").show()
+            else:
+                self.window.get_widget("label-dhcp-start").set_text( _("Status:") )
+                self.window.get_widget("summary-dhcp-start").set_text( _("Disabled") )
+                self.window.get_widget("label-dhcp-end").hide()
+                self.window.get_widget("summary-dhcp-end").hide()
 
             fw = self.get_config_forwarding()
             if fw[0]:
@@ -289,9 +309,12 @@
                 xml += "  <forward/>\n"
 
         xml += "  <ip address='%s' netmask='%s'>\n" % (str(ip[1]), str(ip.netmask()))
-        xml += "    <dhcp>\n"
-        xml += "      <range start='%s' end='%s'/>\n" % (str(start), str(end))
-        xml += "    </dhcp>\n"
+
+        if self.get_config_dhcp_enable():
+            xml += "    <dhcp>\n"
+            xml += "      <range start='%s' end='%s'/>\n" % (str(start), str(end))
+            xml += "    </dhcp>\n"
+
         xml += "  </ip>\n"
         xml += "</network>\n"
 
diff -r 37a986ce54ce src/virtManager/host.py
--- a/src/virtManager/host.py	Thu Aug 27 11:07:35 2009 -0400
+++ b/src/virtManager/host.py	Wed Sep 09 23:44:17 2009 +0200
@@ -344,8 +344,12 @@
         self.window.get_widget("net-ip4-network").set_text(str(network))
 
         dhcp = net.get_ipv4_dhcp_range()
-        self.window.get_widget("net-ip4-dhcp-start").set_text(str(dhcp[0]))
-        self.window.get_widget("net-ip4-dhcp-end").set_text(str(dhcp[1]))
+        if dhcp is not None:
+            self.window.get_widget("net-ip4-dhcp-start").set_text(str(dhcp[0]))
+            self.window.get_widget("net-ip4-dhcp-end").set_text(str(dhcp[1]))
+        else:
+            self.window.get_widget("net-ip4-dhcp-start").set_text("Disabled")
+            self.window.get_widget("net-ip4-dhcp-end").set_text("Disabled")
 
         (forward, forwardDev) = net.get_ipv4_forward()
         if forward:
diff -r 37a986ce54ce src/virtManager/network.py
--- a/src/virtManager/network.py	Thu Aug 27 11:07:35 2009 -0400
+++ b/src/virtManager/network.py	Wed Sep 09 23:44:17 2009 +0200
@@ -109,6 +109,9 @@
         xml = self.get_xml()
         dhcpstart = util.get_xml_path(xml, "/network/ip/dhcp/range[1]/@start")
         dhcpend = util.get_xml_path(xml, "/network/ip/dhcp/range[1]/@end")
+        if not dhcpstart or not dhcpend:
+            return None
+
         return [IP(dhcpstart), IP(dhcpend)]
 
     def is_read_only(self):
diff -r 37a986ce54ce src/vmm-create-net.glade
--- a/src/vmm-create-net.glade	Thu Aug 27 11:07:35 2009 -0400
+++ b/src/vmm-create-net.glade	Wed Sep 09 23:44:17 2009 +0200
@@ -787,11 +787,45 @@
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
-                                <property name="top_attach">2</property>
-                                <property name="bottom_attach">3</property>
+                                <property name="top_attach">4</property>
+                                <property name="bottom_attach">5</property>
                                 <property name="x_options">GTK_FILL</property>
                               </packing>
                             </child>
+<!-- MIG -->
+                            <child>
+                              <widget class="GtkLabel" id="label72">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">Enable DHCP:</property>
+                              </widget>
+                              <packing>
+                                <property name="top_attach">0</property>
+                                <property name="bottom_attach">1</property>
+                                <property name="x_options">GTK_FILL</property>
+                                <property name="y_options"></property>
+                              </packing>
+                            </child>
+                            <child>
+                              <widget class="GtkCheckButton" id="net-dhcp-enable">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="active">True</property>
+                                <property name="use_underline">True</property>
+                                <property name="response_id">0</property>
+                                <property name="draw_indicator">True</property>
+                                <signal name="toggled" handler="on_net_dhcp_enable_toggled"/>
+                              </widget>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                                <property name="top_attach">0</property>
+                                <property name="bottom_attach">1</property>
+                                <property name="x_options">GTK_FILL</property>
+                                <property name="y_options"></property>
+                              </packing>
+                            </child>
+<!-- /MIG -->
                             <child>
                               <widget class="GtkEntry" id="net-dhcp-end">
                                 <property name="visible">True</property>
@@ -804,8 +838,8 @@
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
-                                <property name="top_attach">1</property>
-                                <property name="bottom_attach">2</property>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
                                 <property name="y_options"></property>
                               </packing>
                             </child>
@@ -821,6 +855,8 @@
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
                                 <property name="y_options"></property>
                               </packing>
                             </child>
@@ -831,8 +867,8 @@
                                 <property name="label" translatable="yes">End:</property>
                               </widget>
                               <packing>
-                                <property name="top_attach">1</property>
-                                <property name="bottom_attach">2</property>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options"></property>
                               </packing>
@@ -844,6 +880,8 @@
                                 <property name="label" translatable="yes">Start:</property>
                               </widget>
                               <packing>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options"></property>
                               </packing>
@@ -1195,7 +1233,7 @@
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkLabel" id="label315">
+                          <widget class="GtkLabel" id="label-dhcp-end">
                             <property name="visible">True</property>
                             <property name="xalign">1</property>
                             <property name="label" translatable="yes">End address:</property>
@@ -1211,7 +1249,7 @@
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkLabel" id="label314">
+                          <widget class="GtkLabel" id="label-dhcp-start">
                             <property name="visible">True</property>
                             <property name="xalign">1</property>
                             <property name="label" translatable="yes">Start address:</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]