Skip to content

Commit

Permalink
Merge pull request #1090 from GlobalNOC/2.0.8-dev
Browse files Browse the repository at this point in the history
2.0.8 dev
  • Loading branch information
jonstout authored Mar 6, 2020
2 parents bf2b49a + be16346 commit e0748f8
Show file tree
Hide file tree
Showing 69 changed files with 3,103 additions and 1,045 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM centos:7
COPY globalnoc-public-el7.repo /etc/yum.repos.d/globalnoc-public-el7.repo
COPY perl-lib/OESS /
COPY perl-lib/OESS/entrypoint.sh /
RUN yum makecache
RUN yum -y install epel-release
RUN yum -y install perl mariadb-server
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: OESS Test
description: Run OESS test actions
name: OESS Testing
description: Run oess tests
runs:
using: docker
image: Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME= oess-core
VERSION = 2.0.7
VERSION = 2.0.8

rpm: dist
rpmbuild -ta dist/$(NAME)-$(VERSION).tar.gz
Expand Down
4 changes: 2 additions & 2 deletions app/oess-core.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: oess-core
Version: 2.0.7
Version: 2.0.8
Release: 1%{?dist}
Summary: The core OESS service providers

Expand All @@ -20,7 +20,7 @@ Requires: /bin/bash
Requires: /usr/bin/perl
Requires: perl(base), perl(constant), perl(strict), perl(warnings)

Requires: perl-OESS >= 2.0.7
Requires: perl-OESS >= 2.0.8

Requires: perl(AnyEvent), perl(AnyEvent::DBus), perl(AnyEvent::RabbitMQ)
Requires: perl(CPAN), perl(CPAN::Shell)
Expand Down
3 changes: 2 additions & 1 deletion app/oess_pull_aws_interfaces.pl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ sub compare_and_update_vrfs{
next if ( !defined( $endpoint->{cloud_connection_id} ) );
my $connection_id = $endpoint->{cloud_connection_id};
my $aws_peering = get_vrf_aws_details( aws_ints => $aws_ints, cloud_connection_id => $connection_id );
next if (!defined($aws_peering));
next if (!defined($aws_peering));
my $update = update_endpoint_values( $endpoint->{'peers'}->[0], $aws_peering );
if($update){
update_oess_vrf($vrf,$client);
Expand Down Expand Up @@ -177,6 +177,7 @@ sub get_vrf_aws_details {
warn "Found\n";
return $aws
}
return;
}


Expand Down
149 changes: 45 additions & 104 deletions app/oess_pull_azure_interfaces.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,40 @@
use JSON;
use Log::Log4perl;
use XML::Simple;
use GRNOC::WebService::Client;
use OESS::Config;

use OESS::Cloud::Azure;
use OESS::Config;
use OESS::DB;
use OESS::DB::Endpoint;
use OESS::Endpoint;

my $logger;

sub main{
my $logger = Log::Log4perl->get_logger('OESS.Cloud.Azure.Syncer');
my $config = OESS::Config->new();
my $client = connect_to_ws($config);
my $db = OESS::DB->new();

my @azure_cloud_accounts_config = fetch_azure_cloud_account_configs($config);
my $azure = OESS::Cloud::Azure->new();

my ($endpoints, $error) = OESS::DB::Endpoint::fetch_all(
db => $db,
cloud_interconnect_type => 'azure-express-route'
);

my @azure_cloud_accounts_config = fetch_azure_cloud_account_configs($client, $config);
foreach my $cloud (@azure_cloud_accounts_config) {
my $workgroup_name = $cloud->{workgroup};
my $workgroup_id = fetch_workgroup_id_from_name($client, $config, $workgroup_name);
if(!defined($workgroup_id)) {
warn "Could not find workgroup id for workgroup $workgroup_name";
next;
}
$client->set_url($config->base_url() . "/services/vrf.cgi");
my $vrfs = $client->get_vrfs(workgroup_id => $workgroup_id);
if (!($cloud->{interconnect_type} eq 'azure-express-route')) {
next;
}
my $azure = OESS::Cloud::Azure->new();
my $azure_connections = ($azure->expressRouteCrossConnections($cloud->{interconnect_id}));
reconcile_oess_vrfs($config, $vrfs, $azure_connections, $client);
reconcile_oess_endpoints($db, $endpoints, $azure_connections);
}
}

=head2 get_connection_by_id
get_connection_by_id gets the Azure CrossConnection associated to an
OESS Endpoint's C<cloud_connection_id>.
=cut
sub get_connection_by_id {
my $connections = shift;
my $id = shift;
Expand All @@ -51,87 +54,41 @@ sub get_connection_by_id {
return undef;
}

sub update_oess_vrf {
my $vrf = shift;
my $client = shift;
my %params;
$params{'skip_cloud_provisioning'} = 1;
$params{'vrf_id'} = $vrf->{'vrf_id'};
$params{'name'} = $vrf->{'name'};
$params{'workgroup_id'} = $vrf->{'workgroup'}->{'workgroup_id'};
$params{'description'} = $vrf->{'description'};
$params{'prefix_limit'} = $vrf->{'prefix_limit'};
$params{'local_asn'} = $vrf->{'local_asn'};

$params{'endpoint'} = ();
foreach my $ep (@{$vrf->{'endpoints'}}){
my @peerings;
foreach my $p (@{$ep->{'peers'}}){
push(@peerings,{ peer_ip => $p->{'peer_ip'},
asn => $p->{'peer_asn'},
md5_key => $p->{'md5_key'},
local_ip => $p->{'local_ip'}});
}
push(@{$params{'endpoint'}},encode_json({ interface => $ep->{'interface'}->{'name'},
node => $ep->{'node'}->{'name'},
tag => $ep->{'tag'},
bandwidth => $ep->{'bandwidth'},
inner_tag => $ep->{'inner_tag'},
peers => \@peerings}));


}

my $res = $client->provision(%params);
warn Dumper($res);
}

sub reconcile_oess_vrfs {
my $config = shift;
my $vrfs = shift;
=head2 reconcile_oess_endpoints
reconcile_oess_endpoints looks up the bandwidth as defined via the
Azure ExpressRoute portal and ensures that OESS has the same value.
=cut
sub reconcile_oess_endpoints {
my $db = shift;
my $endpoints = shift;
my $azure_connections = shift;
my $client = shift;

foreach my $vrf (@$vrfs) {
my $update_needed = 0;
foreach my $endpoint (@{$vrf->{endpoints}}) {
my $connection_id = $endpoint->{interface}->{cloud_interconnect_id};
next if ( !defined( $connection_id ) );
my $azure_connection = get_connection_by_id($azure_connections, $connection_id);
next if(!defined($azure_connection));

# For now, just ensure the bandwidth is synced:
my $cloud_bandwidth = $azure_connection->{properties}->{bandwidthInMbps};
if (!$cloud_bandwidth || $endpoint->{bandwidth} eq $cloud_bandwidth) {
next;
}
$endpoint->{bandwidth} = $cloud_bandwidth;
$update_needed = 1;

foreach my $endpoint (@$endpoints) {
my $azure_connection = get_connection_by_id(
$azure_connections,
$endpoint->{cloud_connection_id}
);
next if (!defined $azure_connection);

my $cloud_bandwidth = $azure_connection->{properties}->{bandwidthInMbps};
if (!$cloud_bandwidth || $endpoint->{bandwidth} eq $cloud_bandwidth) {
next;
}

if ($update_needed) {
update_oess_vrf($vrf, $client);
}
}
}
my $ep = new OESS::Endpoint(db => $db, model => $endpoint);
$ep->bandwidth($cloud_bandwidth);

sub fetch_workgroup_id_from_name {
my $client = shift;
my $config = shift;
my $workgroup_name = shift;
$client->set_url( $config->base_url() . "/services/data.cgi");
my $res = $client->get_workgroups();
my $workgroups = $res->{'results'};
foreach my $wg (@$workgroups){
if($wg->{'name'} eq $workgroup_name){
return $wg->{'workgroup_id'};
my $error = $ep->update_db;
if (defined $error) {
warn $error;
}
}
return undef;
}

sub fetch_azure_cloud_account_configs{
my $client = shift;
my $config = shift;
my @results = ();

Expand All @@ -150,20 +107,4 @@ sub fetch_azure_cloud_account_configs{
return @results;
}

sub connect_to_ws {
my $config = shift;

my $creds = $config->get_cloud_config();
my $client = GRNOC::WebService::Client->new(
url => $config->base_url() . "services/vrf.cgi",
uid => $creds->{'user'},
passwd => $creds->{'password'},
realm => $creds->{'realm'},
debug => 0,
timeout => 120
) or die "Cannot connect to webservice";

return $client;
}

main();
2 changes: 1 addition & 1 deletion frontend/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME= oess-frontend
VERSION = 2.0.7
VERSION = 2.0.8

rpm: dist
rpmbuild -ta dist/$(NAME)-$(VERSION).tar.gz
Expand Down
6 changes: 3 additions & 3 deletions frontend/oess-frontend.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: oess-frontend
Version: 2.0.7
Version: 2.0.8
Release: 1%{?dist}
Summary: The OESS webservices and user interface

Expand All @@ -13,14 +13,14 @@ BuildRequires: perl
BuildRequires: python >= 2.6, python-libs >= 2.6
BuildRequires: python-simplejson

Requires: oess-core >= 2.0.7
Requires: oess-core >= 2.0.8
Requires: yui
Requires: httpd, mod_ssl
Requires: nddi-tiles
Requires: perl-Crypt-SSLeay
Requires: xmlsec1, xmlsec1-openssl

Requires: perl-OESS >= 2.0.7
Requires: perl-OESS >= 2.0.8

Requires: perl(strict), perl(warnings)
Requires: perl(AnyEvent)
Expand Down
85 changes: 68 additions & 17 deletions frontend/webservice/admin/admin.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ use GRNOC::WebService;
use OESS::Database;
use OESS::DB;
use OESS::DB::ACL;
use OESS::DB::Interface;
use OESS::DB::Link;

use OESS::ACL;
use OESS::Endpoint;
Expand Down Expand Up @@ -2314,30 +2316,73 @@ sub deny_link {

sub decom_link {
my ($method, $args) = @_;
my ($user, $err) = authorization(admin => 1, read_only => 0);
if (defined $err) {
return send_json($err);

my ($user, $error) = authorization(admin => 1, read_only => 0);
if (defined $error) {
return send_json($error);
}

my $results = {};
my $terror = $db2->start_transaction;
if (defined $terror) {
$method->set_error("$terror");
return;
}

my $link_id = $args->{'link_id'}{'value'};
my ($link, $lerror) = OESS::DB::Link::fetch(db => $db2, link_id => $args->{link_id}->{value});
if (defined $lerror) {
$method->set_error("$lerror");
return;
}
if ($link->{link_state} eq 'decom' || $link->{link_state} eq 'available') {
$method->set_error("Link has already been decom'd or hasn't yet been approved.");
$db2->rollback;
return;
}

my $result = $db->decom_link( link_id => $link_id );
my $link_state;
if ($link->{status} eq 'down') {
# Set role of associated interfaces to unknown.
my $ok1 = OESS::DB::Interface::update(db => $db2, interface => {
interface_id => $link->{interface_a_id},
role => 'unknown'
});
my $ok2 = OESS::DB::Interface::update(db => $db2, interface => {
interface_id => $link->{interface_z_id},
role => 'unknown'
});
if (!$ok1 || !$ok2) {
$method->set_error("Couldn't update link endpoints.");
$db2->rollback;
return;
}

if ( !defined $result ) {
$results->{'results'} = [
{
"error" => $db->get_error(),
"success" => 0
}
];
# Set link_state to 'decom'.
$link_state = 'decom';
} else {
$results->{'results'} = [ { "success" => 1 } ];
# Set link_state to 'available'; This resets the link to the
# discovered / unapproved state.
$link_state = 'available';
}

my ($ok, $err) = OESS::DB::Link::update(
db => $db2,
link => {
link_id => $link->{link_id},
link_state => $link_state,
interface_a_id => $link->{interface_a_id},
interface_z_id => $link->{interface_z_id},
ip_a => $link->{ip_a},
ip_z => $link->{ip_z}
}
);
if (defined $err) {
$method->set_error($err);
$db2->rollback;
return;
}

return $results;
$db2->commit;
return { results => [{ success => 1 }] };
}

sub get_pending_links {
Expand Down Expand Up @@ -2455,7 +2500,7 @@ sub add_mpls_switch{
if (defined $err) {
return send_json($err);
}

my $name = $args->{'name'}{'value'};
my $short_name = $args->{'short_name'}{'value'};
my $ip_address = $args->{'ip_address'}{'value'};
Expand All @@ -2465,6 +2510,12 @@ sub add_mpls_switch{
my $vendor = $args->{'vendor'}{'value'};
my $model = $args->{'model'}{'value'};
my $sw_ver = $args->{'sw_ver'}{'value'};

if ($ip_address !~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/) {
$method->set_error("ip_address $ip_address is an invalid IPv4 Address.");
return;
}

require OESS::RabbitMQ::Client;
my $mq = OESS::RabbitMQ::Client->new( topic => 'OF.FWDCTL.RPC',
timeout => 60 );
Expand Down
Loading

0 comments on commit e0748f8

Please sign in to comment.