MT#11501 dialogic API network configuration

option to pass parameters, handle pids automatically in API

Change-Id: Ia8c327ec7377a1a787e7d758f00e682c4c1f1ca8
changes/95/1195/2
Gerhard Jungwirth 10 years ago
parent 37a9021788
commit 188d5195fa

@ -32,13 +32,19 @@ package NGCP::Panel::Utils::DialogicImg;
use strict;
use warnings;
use Moo;
use Types::Standard qw(Int);
use Types::Standard qw(Int HashRef);
use HTTP::Tiny;
with 'Role::REST::Client'; # TODO: dependency
has '+type' => ( default => 'application/xml', is => 'rw' );
has '+serializer_class' => ( is => 'rw', default => sub {'My::Serializer::Plain'} );
has 'appid' => ( is => 'rw', isa => Int, default => 0 );
has 'pids' => (is => 'rw', isa => HashRef, default => sub {return {
bn2020 => 10001, # defaults (should be overwritten)
network => 10002,
interface_collection => 10003,
interface => 10004,
};});
sub login {
my ( $self, $username, $password ) = @_;
@ -71,35 +77,130 @@ sub create_bn2020 {
. $self->appid,
$data
);
if ($resp->code == 200) {
$self->pids->{bn2020} = $resp->data->{oid};
}
return $resp;
}
sub create_network {
my ($self) = @_;
my $data = $self->objects->{bn2020};
my $pid = $self->pids->{bn2020};
my $appid = $self->appid;
my $resp = $self->get(
'/oamp/configuration/objects/NetworkInterfaces/NULL?pid=10001&appid='
. $self->appid,
"/oamp/configuration/objects/NetworkInterfaces/NULL?pid=$pid&appid=$appid",
);
return $resp if ($resp->code != 200);
my $new_resp = $self->_build_response_data($resp->data);
my $new_resp = $self->_build_response_data($resp->data, $pid);
$resp = $self->post(
'/oamp/configuration/objects/NetworkInterfaces/NULL?pid=10001&appid='
. $self->appid,
"/oamp/configuration/objects/NetworkInterfaces/NULL?pid=$pid&appid=$appid",
$new_resp,
);
if ($resp->code == 200) {
$self->pids->{network} = $resp->data->{oid};
}
return $resp;
}
sub create_interface_collection {
my ($self) = @_;
my $data = $self->objects->{bn2020};
my $pid = $self->pids->{network};
my $appid = $self->appid;
my $resp = $self->get(
"/oamp/configuration/objects/NetworkLogicalInterfaces/NULL?detaillevel=4&pid=$pid&appid=$appid",
);
if ($resp->code != 200) {
warn "Failed to fetch resource\n";
return $resp;
}
my $new_resp = $self->_build_response_data($resp->data, $pid);
$resp = $self->post(
"/oamp/configuration/objects/NetworkLogicalInterfaces/NULL?pid=$pid&appid=$appid",
$new_resp,
);
if ($resp->code == 200) {
$self->pids->{interface_collection} = $resp->data->{oid};
}
return $resp;
}
sub create_interface {
my ($self) = @_;
my $data = $self->objects->{bn2020};
my $pid = $self->pids->{interface_collection};
my $appid = $self->appid;
my $resp = $self->get(
"/oamp/configuration/objects/NetworkLogicalInterface/NULL?detaillevel=4&pid=$pid&appid=$appid",
);
if ($resp->code != 200) {
warn "Failed to fetch resource\n";
return $resp;
}
my $new_resp = $self->_build_response_data($resp->data, $pid);
$resp = $self->post(
"/oamp/configuration/objects/NetworkLogicalInterface/NULL?pid=$pid&appid=$appid",
$new_resp,
);
if ($resp->code == 200) {
if ($resp->data->{property}{Interface}{value} eq "Control") {
$self->pids->{interface_control} = $resp->data->{oid};
} elsif ($resp->data->{property}{Interface}{value} eq "Data A") {
$self->pids->{interface_dataa} = $resp->data->{oid};
}
$self->pids->{interface} = $resp->data->{oid};
}
return $resp;
}
#TODO: only supports ipv4 now
sub create_ip_address {
my ($self, $options) = @_;
if (defined $options->{NIIPAddress} && ! defined $options->{NIIPGateway} ) {
$options->{NIIPGateway} = $options->{NIIPAddress} =~ s/\.[0-9]+$/.1/r;
}
my $data = $self->objects->{bn2020};
my $pid = $self->pids->{interface};
my $appid = $self->appid;
my $resp = $self->get(
"/oamp/configuration/objects/NetworkInterface/NULL?detaillevel=4&pid=$pid&appid=$appid",
);
if ($resp->code != 200) {
warn "Failed to fetch resource\n";
return $resp;
}
my $new_resp = $self->_build_response_data($resp->data, $pid, $options);
$resp = $self->post(
"/oamp/configuration/objects/NetworkInterface/NULL?pid=$pid&appid=$appid",
$new_resp,
);
if ($resp->code == 200) {
$self->pids->{interface} = $resp->data->{oid};
}
return $resp;
}
sub _build_response_data {
my ($self, $req) = @_;
my ($self, $req, $pid, $options) = @_;
my $resp = {
pid => 10001,
pid => $pid,
property => {},
};
for my $p(keys %{ $req->{property} }) {
next if "_state_" eq $p;
next if $req->{property}{$p}{visible} eq "__NULL__"; # TODO: that's SwitchOver
next if ($req->{property}{$p}{readonly} eq "True") &&
($req->{property}{$p}{visible} eq "true");
$resp->{property}{$p} = {configuredvalue => $req->{property}{$p}{value}};
if (defined $options->{$p}) {
$resp->{property}{$p}{configuredvalue} = $options->{$p};
}
}
return $resp;
}

@ -11,9 +11,9 @@ my $test = NGCP::Panel::Utils::DialogicImg->new(
server => 'https://10.15.20.150',
clientattrs => {
timeout => 5,
SSL_options => {
SSL_version => 'SSLv23:!SSLv2:!SSLv3:!TLSv1_1:!TLSv1_2',
},
# SSL_options => {
# SSL_version => 'SSLv23:!SSLv2:!SSLv3:!TLSv1_1:!TLSv1_2',
# },
},
);
@ -46,15 +46,43 @@ print "LOGGED IN, LOCK OBTAINED ############################\n";
# #p $resp->data;
$resp = $test->create_bn2020;
p $resp;
p $resp->code;
#p $resp->data;
print "CREATE NETWORK ###################################\n";
$resp = $test->create_network;
p $resp;
p $resp->data;
p $resp->code;
#p $resp->data;
print "CREATE INTERFACE COLLECTION ###################################\n";
$resp = $test->create_interface_collection;
p $resp->code;
#p $resp->data;
print "CREATE INTERFACE ###################################\n";
$resp = $test->create_interface; # Control by default
p $resp->code;
#p $resp->data;
$resp = $test->create_ip_address({
NIIPAddress => '10.2.3.4',
NIIPPhy => 'Services',
});
p $resp->code;
#p $resp->data;
$resp = $test->create_interface; # DataA
p $resp->code;
#p $resp->data;
$resp = $test->create_ip_address({NIIPAddress => '10.6.7.8',
NIIPPhy => 'Media 0'});
p $resp->code;
#p $resp->data;
sub try_parse_file {

Loading…
Cancel
Save