fix device and device_port delete not to kill nodes

This commit is contained in:
Oliver Gorwits
2013-09-11 23:13:56 +01:00
parent 53caf97036
commit d489093c88
3 changed files with 9 additions and 6 deletions

View File

@@ -133,7 +133,7 @@ sub _set_canonical_ip {
# our special delete which is more efficient
schema('netdisco')->resultset('Device')
->search({ ip => $device->ip })->delete;
->search({ ip => $device->ip })->delete({keep_nodes => 1});
# a new row object from the old one
$device = schema('netdisco')->resultset('Device')
@@ -259,7 +259,7 @@ sub store_interfaces {
}
schema('netdisco')->txn_do(sub {
my $gone = $device->ports->delete;
my $gone = $device->ports->delete({keep_nodes => 1});
debug sprintf ' [%s] interfaces - removed %s interfaces',
$device->ip, $gone;
$device->update_or_insert(undef, {for => 'update'});

View File

@@ -77,13 +77,12 @@ handle the removal or archiving of nodes.
sub delete {
my $self = shift;
my ($opts) = @_;
$opts = {} if (ref {} ne ref $opts);
my $schema = $self->result_source->schema;
my $nodes = $self->search(undef, { columns => 'mac' });
if (ref {} eq ref $opts
and exists $opts->{archive} and $opts->{archive}) {
if (exists $opts->{archive_nodes} and $opts->{archive_nodes}) {
foreach my $set (qw/
NodeIp
NodeNbt
@@ -101,6 +100,10 @@ sub delete {
# avoid letting DBIC delete nodes
return 0E0;
}
elsif (exists $opts->{keep_nodes} and $opts->{keep_nodes}) {
# avoid letting DBIC delete nodes
return 0E0;
}
else {
foreach my $set (qw/
NodeIp

View File

@@ -78,7 +78,7 @@ ajax '/ajax/control/admin/delete' => require_role admin => sub {
->search({ip => param('device')});
# will delete everything related too...
$device->delete;
$device->delete({archive_nodes => param('archive')});
});
};