r3792 - in trunk/varnish-tools/webgui: Varnish templates
petter at projects.linpro.no
petter at projects.linpro.no
Fri Feb 20 12:45:31 CET 2009
Author: petter
Date: 2009-02-20 12:45:30 +0100 (Fri, 20 Feb 2009)
New Revision: 3792
Modified:
trunk/varnish-tools/webgui/Varnish/NodeManager.pm
trunk/varnish-tools/webgui/Varnish/RequestHandler.pm
trunk/varnish-tools/webgui/templates/node_management.tmpl
Log:
Added possibility to add nodes to a group without have the settings of the group or node altered, which can be usefull to group node logically if the web GUI is used as a monitoring tool. Also fixed a logical bug in the settings inheritance code.
Modified: trunk/varnish-tools/webgui/Varnish/NodeManager.pm
===================================================================
--- trunk/varnish-tools/webgui/Varnish/NodeManager.pm 2009-02-20 11:05:14 UTC (rev 3791)
+++ trunk/varnish-tools/webgui/Varnish/NodeManager.pm 2009-02-20 11:45:30 UTC (rev 3792)
@@ -21,12 +21,14 @@
$vcl_info->{'vcl'} = $master->get_vcl($name);
}
- my $previous_active_vcl;
+ my $slave_active_vcl = "";
+ my $discard_slave_active_vcl = 0;
my $vcl_infos_ref = $slave->get_vcl_infos();
for my $vcl_info (@$vcl_infos_ref) {
my $name = $vcl_info->{'name'};
if ($vcl_info->{'active'}) {
- $previous_active_vcl = $name;
+ $slave_active_vcl = $name;
+ $discard_slave_active_vcl = 1;
}
else {
$slave->discard_vcl($name);
@@ -39,16 +41,20 @@
$slave->save_vcl($name, $vcl);
if ($vcl_info->{'active'}) {
$slave->make_vcl_active($name);
- if ($previous_active_vcl) {
- $slave->discard_vcl($previous_active_vcl);
- }
}
+ if ($slave_active_vcl eq $name) {
+ $discard_slave_active_vcl = 0;
+ }
}
+ if ($discard_slave_active_vcl) {
+ $slave->discard_vcl($slave_active_vcl);
+ }
}
-
+
sub add_node {
- my ($self, $node, $use_as_group_defaults) = @_;
+ my ($self, $node, $inheritance) = @_;
+ $inheritance ||= 0;
my $management = $node->get_management();
if (!$management->ping()) {
return set_error($self, "Could not connect to management port: "
@@ -57,12 +63,12 @@
Varnish::DB->add_node($node);
my $group_id = $node->get_group_id();
- if ($group_id > 0) {
+ if ($group_id > 0 && $inheritance) {
my $group = get_group($self, $group_id);
- if ($use_as_group_defaults) {
+ if ($inheritance == 1) {
_clone_unit($node, $group);
}
- else {
+ elsif ($inheritance == 2) {
_clone_unit($group, $node);
}
}
Modified: trunk/varnish-tools/webgui/Varnish/RequestHandler.pm
===================================================================
--- trunk/varnish-tools/webgui/Varnish/RequestHandler.pm 2009-02-20 11:05:14 UTC (rev 3791)
+++ trunk/varnish-tools/webgui/Varnish/RequestHandler.pm 2009-02-20 11:45:30 UTC (rev 3792)
@@ -743,7 +743,7 @@
$param{'address'} = $$parameter_ref{'address'} || "";
$param{'port'} ||= "";
$param{'management_port'} ||= "";
- $param{'inherit_settings'} ||= "";
+ $param{'inheritance'} ||= 0;
$param{'edit_node'} ||= -1;
my $template = "node_management.tmpl";
@@ -760,8 +760,8 @@
$tmpl_var{'show_group'} = 0;
$tmpl_var{'show_add_node'} = 1;
$tmpl_var{'show_node_in_backend_health'} = 1;
- $tmpl_var{'inherit_settings'} = 0;
- $tmpl_var{'show_inherit_settings'} = 1;
+ $tmpl_var{'show_inheritance_settings'} = 1;
+ $tmpl_var{'inheritance_settings'} = [];
my $error = "";
my $status = "";
@@ -833,18 +833,21 @@
group_id => $param{'group_id'},
management_port => $param{'management_port'}
});
- my $inherit_settings = $param{'inherit_settings'} ne "";
- Varnish::NodeManager->add_node($node, $inherit_settings);
+ Varnish::NodeManager->add_node($node, $param{'inheritance'});
$status .= "Node " . $node->get_name() . " added successfully.";
my $group = Varnish::NodeManager->get_group($param{'group_id'});
my $group_name = ($group ? $group->get_name() : "");
+ my $inheritance = ($param{'inheritance'} == 0 ? "None" :
+ $param{'inheritance'} == 1 ? "Group inherited node" :
+ "Node inherited group");
log_info("[" . $node->get_name() . "] [Added node]"
. " [name=" . $node->get_name() . "]"
. " [address=" . $node->get_address() . "]"
. " [port=" . $node->get_port() . "]"
. " [group=" . $group_name . "]"
- . " [management_port=" . $node->get_management_port() . "]");
+ . " [management_port=" . $node->get_management_port() . "]"
+ . " [settings_inheritance=$inheritance]");
}
else {
$error .= "Not enough information to add node:\n";
@@ -955,9 +958,6 @@
if ($tmpl_var{'group_id'} != -1) {
$group = Varnish::NodeManager->get_group($tmpl_var{'group_id'});
$nodes_ref = Varnish::NodeManager->get_nodes($group);
- if ($tmpl_var{'group_id'} == 0) {
- $tmpl_var{'show_inherit_settings'} = 0;
- }
}
else {
$nodes_ref = Varnish::NodeManager->get_nodes();
@@ -989,14 +989,35 @@
}
push @{$tmpl_var{'node_infos'}}, $node_info_ref;
}
- if (@$nodes_ref == 0) {
- $tmpl_var{'inherit_settings'} = 1;
- }
}
else {
$tmpl_var{'add_group'} = 1;
}
+ if ($tmpl_var{'group_id'} > 0) {
+ my @inheritance_settings;
+ push @inheritance_settings, {
+ value => 2,
+ name => "Node inherits group",
+ selected => @{$tmpl_var{'node_infos'}} > 0,
+ };
+ push @inheritance_settings, {
+ value => 1,
+ name => "Group inherits node",
+ selected => @{$tmpl_var{'node_infos'}} == 0,
+ };
+ push @inheritance_settings, {
+ value => 0,
+ name => "No inheritance",
+ selected => 0,
+ };
+ $tmpl_var{'inheritance_settings'} = \@inheritance_settings;
+ }
+ else {
+ $tmpl_var{'show_inheritance_settings'} = 0;
+ }
+
+
my $selected_group = Varnish::NodeManager->get_group($tmpl_var{'group_id'});
if ($selected_group) {
$tmpl_var{'group_name'} = $selected_group->get_name();
Modified: trunk/varnish-tools/webgui/templates/node_management.tmpl
===================================================================
--- trunk/varnish-tools/webgui/templates/node_management.tmpl 2009-02-20 11:05:14 UTC (rev 3791)
+++ trunk/varnish-tools/webgui/templates/node_management.tmpl 2009-02-20 11:45:30 UTC (rev 3792)
@@ -43,6 +43,9 @@
<td class="header">Address</td>
<td class="header">Port</td>
<td class="header">Management<br/>port</td>
+<TMPL_IF NAME=SHOW_INHERITANCE_SETTINGS>
+<td class="header">Inheritance<br/>settings</td>
+</TMPL_IF>
<td></td></tr>
<TMPL_LOOP NAME=NODE_INFOS>
<TMPL_IF NAME=__ODD__>
@@ -88,6 +91,9 @@
<td><input type="text" name="address" value="<TMPL_VAR NAME=ADDRESS>"/></td>
<td><input type="text" name="port" value="<TMPL_VAR NAME=PORT>" size=5/></td>
<td><input type="text" name="management_port" value="<TMPL_VAR NAME=MANAGEMENT_PORT>"/></td>
+<TMPL_IF NAME=SHOW_INHERITANCE_SETTINGS>
+<td></td>
+</TMPL_IF>
<td>
<input type="hidden" name="node_id" value="<TMPL_VAR NAME=ID>">
<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>">
@@ -105,6 +111,9 @@
<td><TMPL_VAR NAME=ADDRESS></td>
<td><TMPL_VAR NAME=PORT></td>
<td><a href="/management_console?node_id=<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=MANAGEMENT_PORT></a></td>
+<TMPL_IF NAME=SHOW_INHERITANCE_SETTINGS>
+<td></td>
+</TMPL_IF>
<TMPL_UNLESS NAME=RESTRICTED>
<td>
<form action="node_management" method="POST">
@@ -154,8 +163,14 @@
<td><input type="text" name="address"/></td>
<td><input type="text" name="port" size=5/></td>
<td><input type="text" name="management_port" value="<TMPL_VAR NAME=DEFAULT_MANAGEMENT_PORT>"/></td>
-<TMPL_IF NAME=SHOW_INHERIT_SETTINGS>
-<td colspan=3> <input type="checkbox" name="inherit_settings" value="true" <TMPL_IF NAME=INHERIT_SETTINGS>checked</TMPL_IF>>Group inherit<br/> settings</td>
+<TMPL_IF NAME=SHOW_INHERITANCE_SETTINGS>
+<td>
+<select name="inheritance">
+<TMPL_LOOP NAME=INHERITANCE_SETTINGS>
+<option value="<TMPL_VAR NAME=VALUE>" <TMPL_IF NAME=SELECTED>selected</TMPL_IF>><TMPL_VAR NAME=NAME></option>
+</TMPL_LOOP>
+</select>
+</td>
</TMPL_IF>
<td>
<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>"/>
More information about the varnish-commit
mailing list