MT#11501 dialogic api read and hash config

Change-Id: I6adffa64d5ad1fabf6e49b4ac97f22f5e40f3dae
changes/00/1200/3
Gerhard Jungwirth 10 years ago
parent cd3111d665
commit 9bc45cf3f5

@ -89,6 +89,7 @@ my $builder = Local::Module::Build->new(
'Sereal::Encoder' => 0,
'String::MkPasswd' => 0,
'Sipwise::Base' => 0,
'Storable' => 0,
'strict' => 0,
'Template' => 0,
'Template::Plugin::JSON::Escape' => 0,

@ -1,6 +1,5 @@
use strict;
use warnings;
{
package My::Serializer::Custom;
use Moo;
@ -9,7 +8,11 @@ use warnings;
sub _set_serializer {
my $s = Data::Serializer::Raw->new(
serializer => 'XML::Simple',
options => { RootName => 'object' } );
options => {
RootName => 'object',
# KeyAttr => { 'object' => '+classname' },
# ForceArray => ['IPProfile'],
} );
return $s;
}
@ -20,8 +23,10 @@ use warnings;
package NGCP::Panel::Utils::DialogicImg;
use Moo;
use Types::Standard qw(Int HashRef);
use Digest::MD5 qw/md5_hex/;
use HTTP::Tiny;
use Storable qw/freeze/;
use Types::Standard qw(Int HashRef);
with 'Role::REST::Client';
has '+type' => ( default => 'application/xml', is => 'rw' );
@ -456,7 +461,12 @@ sub create_all_sipsip {
$self->_create_indent;
my $resp = $self->create_bn2020;
my @in_schedule = map {
{
name => 'vocoder_profile', options =>
{ PayloadType => $_ },
};
} @{ $settings->{in_codecs} };
my $schedule = [
{name => 'network', options => undef},
{name => 'interface_collection', options => undef},
@ -486,12 +496,7 @@ sub create_all_sipsip {
DigitRelay => 'DTMF Packetized',
Name => 'ngcp_in_profile',
}},
{name => 'vocoder_profile', options => {
PayloadType => 'G711 ulaw',
}},
{name => 'vocoder_profile', options => {
PayloadType => 'G711 alaw',
}},
@in_schedule,
{name => 'sip_profile_collection', options => undef},
{name => 'sip_profile', options => undef},
#{run => 'download_profiles'},
@ -551,12 +556,90 @@ sub create_all_sipsip {
###### OTHER STUFF ######
sub hash_config_sipsip {
my ($self, $config) = @_;
$Storable::canonical = 1;
return md5_hex(freeze $config);
}
sub get_config {
my ($self) = @_;
my $appid = $self->appid;
my $resp = $self->get("/oamp/configuration/objects?appid=$appid");
my $config = {};
if ($resp->code != 200) {
warn "failed to get objects\n";
return $resp;
}
my $classinfo = $self->classinfo;
my $rev_lookup = {};
@{$rev_lookup}{map {$_->{name}} values %{$classinfo}} = keys %{$classinfo};
my $root = $resp->data->{object}[0];
for my $ch (_get_all_children($root)) {
$self->_recursive_get($ch, $rev_lookup);
}
if ($classinfo->{ip_address}{configuredids}[0]) {
($config->{ip1}) = $self->_get_specifics(
'ip_address', $classinfo->{ip_address}{configuredids}[0], ['NIIPAddress']);
}
if ($classinfo->{ip_address}{configuredids}[1]) {
($config->{ip2}) = $self->_get_specifics(
'ip_address', $classinfo->{ip_address}{configuredids}[1], ['NIIPAddress']);
}
if ($classinfo->{external_gateway}{configuredids}[0]) {
($config->{ip_client}) = $self->_get_specifics(
'external_gateway', $classinfo->{external_gateway}{configuredids}[0], ['IPAddress']);
}
if (exists $classinfo->{vocoder_profile}{configuredids}) {
for my $id (@{ $classinfo->{vocoder_profile}{configuredids} }) {
push @{ $config->{in_codecs} }, $self->_get_specifics(
'vocoder_profile', $id, ['PayloadType']);
}
}
return $config;
}
sub _recursive_get {
my ($self, $node, $rev_lookup) = @_;
my $classname = $node->{classname};
my $oname = $rev_lookup->{$classname};
my $oid = $node->{oid};
my $appid = $self->appid;
for my $ch (_get_all_children($node)) {
$self->_recursive_get($ch, $rev_lookup);
}
if ($oname) {
$self->pids->{$oname} = $oid;
push @{ $self->classinfo->{$oname}{configuredids} }, $oid;
}
return;
}
sub _get_specifics {
my ($self, $class, $id, $keys) = @_;
my $appid = $self->appid;
my $classinfo = $self->classinfo->{$class};
my $classname = $classinfo->{name};
my @res;
my $resp = $self->get("/oamp/configuration/objects/$classname/$id?appid=$appid&detaillevel=4");
if ($resp->code != 200) {
warn "failed to get objects\n";
return ();
}
for my $key (@{ $keys }) {
push @res, $resp->data->{property}{$key}{value};
}
return @res;
}
sub _create_indent {
my ($self, @class) = @_;
my $classinfo = $self->classinfo;
@class = keys %{ $classinfo } unless @class;
for my $class (@class) {
next if ($classinfo->{$class}{indent});
next if (exists $classinfo->{$class}{indent});
my $parent = $classinfo->{$class}{parent};
if ($parent eq 'root') {
$classinfo->{$class}{indent} = 0;
@ -608,7 +691,6 @@ sub download_channel_groups {
sub delete_all_bn2020 {
my ($self) = @_;
my $pid = $self->pids->{bn2020};
my $appid = $self->appid;
my $resp = $self->get(
"/oamp/configuration/objects?appid=$appid",

@ -38,12 +38,17 @@ print "LOGGED IN, LOCK OBTAINED ############################\n";
# print_documentation_md($test);
# $resp = $test->get_config;
# p $resp;
# #p $test->classinfo;
# exit;
my $result = $test->create_all_sipsip({
ip1 => '10.15.20.92',
ip2 => '10.15.21.10',
ip_client => '10.15.20.199',
in_codecs => ['G711 ulaw', 'G711 alaw', 'G729', 'AMR'],
out_codecs => ['G711 ulaw', 'G711 alaw', 'G729', 'AMR'], # not yet used
#out_codecs => ['G711 ulaw', 'G711 alaw', 'G729', 'AMR'], # not yet used
},
2,
);
@ -65,7 +70,8 @@ sub print_documentation_md {
for my $o (@{ $options }) {
my ( $name, $displayname, $default, $choices )
= @{$o}{ 'name', 'displayname', 'default', 'choices' };
my $choices_str = $choices && @$choices ? join(", ", map { "`$_`" } @{$choices}) : '';
my $choices_str = $choices && @{$choices}
? join( ", ", map {"`$_`"} @{$choices} ) : '';
if ($default) {
$default = "`$default`";
}

Loading…
Cancel
Save