Commit fd32b062 authored by Carlos Juan's avatar Carlos Juan Committed by Francesc Guasch
Browse files

feature: new button remove node (#912)

* fix: new button remove node

check if the node have active machines, is localhost or have bases
if true, add a var to the list
the value of this var is shown in the template to disabled the button

closes #870

* feat: new button remove node

new remove button on node list
check if the node have active machines, is localhost or has bases
if true, add a var to the list
the value of this var is shown in the template to disabled the remove button
otherwise action call to function  remove_node and delete the node from vms table

fixes #870

* feat: new button remove node

Check it for uninitialized values when evaluate if a node can be remove.
Added bv.enabled=1 into _list_bases_vm for prevent a bug when a base is created in remote and then removed in list_bases.

fixes #870
parent 64650b81
......@@ -469,6 +469,9 @@ sub list_vms($self, $type=undef) {
$row->{bases}= $self->_list_bases_vm($row->{id});
$row->{machines}= $self->_list_machines_vm($row->{id});
$row->{type} = $row->{vm_type};
$row->{action_remove} = 'disabled' if length defined $row->{machines}[0] > 0;
$row->{action_remove} = 'disabled' if $row->{hostname} eq 'localhost';
$row->{action_remove} = 'disabled' if length defined $row->{bases}[0] > 0;
delete $row->{vm_type};
lock_hash(%$row);
push @list,($row);
......@@ -483,6 +486,7 @@ sub _list_bases_vm($self, $id_node) {
." WHERE d.is_base=1"
." AND d.id = bv.id_domain "
." AND bv.id_vm=?"
." AND bv.enabled=1"
);
my @bases;
$sth->execute($id_node);
......@@ -1012,7 +1016,7 @@ sub disconnect_vm {
=head2 enable_node
Enables or disables a node
Enables, disables or delete a node
$rvd->enable_node($id_node, $value);
......@@ -1028,6 +1032,14 @@ sub enable_node($self, $id_node, $value) {
return $value;
}
sub remove_node($self, $id_node, $value) {
my $sth = $CONNECTOR->dbh->prepare("DELETE FROM vms WHERE id=?");
$sth->execute($id_node);
$sth->finish;
return $value;
}
sub add_node($self,%arg) {
my $sql = "INSERT INTO vms "
."("
......
......@@ -1076,3 +1076,4 @@ sub balance_vm($self, $base=undef) {
1;
......@@ -301,6 +301,10 @@ ravadaApp.directive("solShowMachine", swMach)
$http.get('/node/disable/'+id+'.json');
$scope.list_nodes();
};
$scope.node_remove=function(id) {
$http.get('/node/remove/'+id+'.json');
$scope.list_nodes();
};
$scope.list_nodes();
$interval($scope.list_nodes,30 * 1000);
};
......
......@@ -283,6 +283,11 @@ get '/node/disable/(:id).json' => sub {
return access_denied($c) if !$USER->is_admin;
return $c->render(json => {enabled => $RAVADA->enable_node($c->stash('id'),0)});
};
get '/node/remove/(:id).json' => sub {
my $c = shift;
return access_denied($c) if !$USER->is_admin;
return $c->render(json => {remove => $RAVADA->remove_node($c->stash('id'),1)});
};
any '/new_node' => sub {
my $c = shift;
......
......@@ -55,6 +55,11 @@
title="<%=l 'Disable' %>">
<i class="fa fa-window-close"></i>
</a>
<a type="button" class="btn btn-danger btn-sm {{node.action_remove}}"
ng-click="node_remove(node.id)"
title="<%=l 'Remove' %>">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
</tbody>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment