$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);
$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: "
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);
}
}
$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";
$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 = "";
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";
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();
}
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();
<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__>
<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>">
<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">
<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>"/>