diff --git a/perl-lib/OESS/lib/OESS/DB/Node.pm b/perl-lib/OESS/lib/OESS/DB/Node.pm index d5b0201f7..aeda4072b 100644 --- a/perl-lib/OESS/lib/OESS/DB/Node.pm +++ b/perl-lib/OESS/lib/OESS/DB/Node.pm @@ -20,12 +20,16 @@ sub fetch{ my $node_id = $params{'node_id'}; my $node_name = $params{'name'}; + my $short_name = $params{'short_name'}; my $details; my $node; if (defined $node_id) { $node = $db->execute_query("select * from node join node_instantiation on node.node_id=node_instantiation.node_id where node.node_id=? and node_instantiation.end_epoch=-1", [ $node_id ]); + } + elsif (defined $short_name) { + $node = $db->execute_query("select * from node join node_instantiation on node.node_id=node_instantiation.node_id where node.short_name=? and node_instantiation.end_epoch=-1", [ $short_name ]); } else { $node = $db->execute_query("select * from node join node_instantiation on node.node_id=node_instantiation.node_id where node.name=? and node_instantiation.end_epoch=-1", [ $node_name ]); } diff --git a/perl-lib/OESS/lib/OESS/NSO/FWDCTL.pm b/perl-lib/OESS/lib/OESS/NSO/FWDCTL.pm index 0859fb9f4..02b917705 100644 --- a/perl-lib/OESS/lib/OESS/NSO/FWDCTL.pm +++ b/perl-lib/OESS/lib/OESS/NSO/FWDCTL.pm @@ -254,7 +254,7 @@ sub diff { # Needed to ensure diff state may be set to PENDING_DIFF_NONE after approval my $all_nodes = OESS::DB::Node::fetch_all(db => $self->{db}, controller => 'nso'); foreach my $node (@$all_nodes) { - $network_diff->{$node->{name}} = ""; + $network_diff->{$node->{short_name}} = ""; } foreach my $node_hash (@$all_nodes) { @@ -346,30 +346,30 @@ sub diff { # If the database asserts there is no diff pending but memory # disagrees, then the pending state was modified by an admin. The # pending diff may now proceed. - foreach my $node_name (keys %$network_diff) { - my $node = new OESS::Node(db => $self->{db}, name => $node_name); - my $diff_len = length $network_diff->{$node_name}; + foreach my $short_node_name (keys %$network_diff) { + my $node = new OESS::Node(db => $self->{db}, short_name => $short_node_name); + my $diff_len = length $network_diff->{$short_node_name}; if ($diff_len < 30) { - $self->{pending_diff}->{$node_name} = PENDING_DIFF_NONE; + $self->{pending_diff}->{$short_node_name} = PENDING_DIFF_NONE; $node->pending_diff(PENDING_DIFF_NONE); $node->update; - $self->{logger}->info("Applying network diff. No approval required for $node_name.") if $diff_len > 0; + $self->{logger}->info("Applying network diff. No approval required for $short_node_name.") if $diff_len > 0; } else { - if ($self->{pending_diff}->{$node_name} == PENDING_DIFF_NONE) { - $self->{pending_diff}->{$node_name} = PENDING_DIFF; + if ($self->{pending_diff}->{$short_node_name} == PENDING_DIFF_NONE) { + $self->{pending_diff}->{$short_node_name} = PENDING_DIFF; $node->pending_diff(PENDING_DIFF); $node->update; - $self->{logger}->info("Not applying network diff. Manual approval required for $node_name."); + $self->{logger}->info("Not applying network diff. Manual approval required for $short_node_name."); } - if ($self->{pending_diff}->{$node_name} == PENDING_DIFF && $node->pending_diff == PENDING_DIFF_NONE) { - $self->{pending_diff}->{$node_name} = PENDING_DIFF_APPROVED; - $self->{logger}->info("Applying network diff. Manual approval granted for $node_name."); + if ($self->{pending_diff}->{$short_node_name} == PENDING_DIFF && $node->pending_diff == PENDING_DIFF_NONE) { + $self->{pending_diff}->{$short_node_name} = PENDING_DIFF_APPROVED; + $self->{logger}->info("Applying network diff. Manual approval granted for $short_node_name."); } } - $self->{logger}->debug("Diff for $node_name has length of $diff_len:\n$network_diff->{$node_name}"); + $self->{logger}->debug("Diff for $short_node_name has length of $diff_len:\n$network_diff->{$short_node_name}"); } $self->{logger}->debug('Changes: ' . Dumper($changes)); @@ -380,7 +380,7 @@ sub diff { # If conn endpoint on node with a blocked diff skip my $diff_approval_required = 0; foreach my $ep (@{$conn->endpoints}) { - if ($self->{pending_diff}->{$ep->node} == PENDING_DIFF) { + if ($self->{pending_diff}->{$ep->short_node_name} == PENDING_DIFF) { $diff_approval_required = 1; last; } @@ -402,7 +402,7 @@ sub diff { # If conn endpoint on node with a blocked diff skip my $diff_approval_required = 0; foreach my $ep (@{$conn->endpoints}) { - if ($self->{pending_diff}->{$ep->node} == PENDING_DIFF) { + if ($self->{pending_diff}->{$ep->short_node_name} == PENDING_DIFF) { $diff_approval_required = 1; last; } @@ -424,7 +424,7 @@ sub diff { # If conn endpoint on node with a blocked diff skip my $diff_approval_required = 0; foreach my $ep (@{$conn->{endpoint}}) { - if ($self->{pending_diff}->{$ep->{device}} == PENDING_DIFF) { + if ($self->{pending_diff}->{$ep->{short_node_name}} == PENDING_DIFF) { $diff_approval_required = 1; last; } @@ -445,7 +445,7 @@ sub diff { # If conn endpoint on node with a blocked diff skip my $diff_approval_required = 0; foreach my $ep (@{$conn->endpoints}) { - if ($self->{pending_diff}->{$ep->node} == PENDING_DIFF) { + if ($self->{pending_diff}->{$ep->short_node_name} == PENDING_DIFF) { $diff_approval_required = 1; last; } @@ -467,7 +467,7 @@ sub diff { # If conn endpoint on node with a blocked diff skip my $diff_approval_required = 0; foreach my $ep (@{$conn->endpoints}) { - if ($self->{pending_diff}->{$ep->node} == PENDING_DIFF) { + if ($self->{pending_diff}->{$ep->short_node_name} == PENDING_DIFF) { $diff_approval_required = 1; last; } @@ -489,7 +489,7 @@ sub diff { # If conn endpoint on node with a blocked diff skip my $diff_approval_required = 0; foreach my $ep (@{$conn->{endpoint}}) { - if ($self->{pending_diff}->{$ep->{device}} == PENDING_DIFF) { + if ($self->{pending_diff}->{$ep->{short_node_name}} == PENDING_DIFF) { $diff_approval_required = 1; last; } diff --git a/perl-lib/OESS/lib/OESS/Node.pm b/perl-lib/OESS/lib/OESS/Node.pm index dd66a0401..ac0e09acf 100644 --- a/perl-lib/OESS/lib/OESS/Node.pm +++ b/perl-lib/OESS/lib/OESS/Node.pm @@ -15,10 +15,11 @@ sub new{ my $class = ref($that) || $that; my %args = ( - db => undef, - logger => Log::Log4perl->get_logger("OESS.Node"), - name => undef, - node_id => undef, + db => undef, + logger => Log::Log4perl->get_logger("OESS.Node"), + name => undef, + node_id => undef, + short_name => undef, @_ ); my $self = \%args; @@ -26,7 +27,7 @@ sub new{ bless $self, $class; - if (defined $self->{db} && (defined $self->{name} || defined $self->{node_id})) { + if (defined $self->{db} && (defined $self->{name} || defined $self->{short_name} || defined $self->{node_id})) { $self->_fetch_from_db(); return $self; } else { @@ -97,7 +98,8 @@ sub _fetch_from_db{ my $hash = OESS::DB::Node::fetch( db => $db, name => $self->{name}, - node_id => $self->{node_id} + node_id => $self->{node_id}, + short_name => $self->{short_name} ); $self->from_hash($hash); }