TT#116100 bin/create_registrations.pl: use scenario_ids.yml

* IP/port info is already there, no need to split creation/update

Change-Id: I63d080bbc1192af7c7c276eed5fff7ebde95ef75
mr9.5.1
Victor Seva 5 years ago
parent 786a800d64
commit b3219d242d

@ -352,8 +352,6 @@ get_ip() {
port=${scen[3]}
mport=${scen[4]}
foreign_dom=${scen[6]}
registration=${scen[7]}
subscriber=${scen[8]}
done< <(grep "$1" "${SCEN_CHECK_DIR}/scenario.csv")
}
@ -433,14 +431,6 @@ run_sipp() {
echo "$(date) - foreign domain detected... using 5060 port"
port="5060"
fi
if [ "${registration}" == "permanent" ]; then
echo "$(date) - Update permanent reg:${subscriber} ${ip}:${port} info"
if ! "${BIN_DIR}/update_perm_reg.pl" \
-t "${transport}" "${subscriber}" "${ip}" "${port}";
then
error_helper "$(date) - error updating peer info" 15
fi
fi
if [ -f "${SCEN_CHECK_DIR}/${base}_reg.xml" ]; then
echo "$(date) - Register ${base} ${ip}:${port}-${mport}"

@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# Copyright: 2013-2016 Sipwise Development Team <support@sipwise.com>
# Copyright: 2013-2021 Sipwise Development Team <support@sipwise.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -39,16 +39,20 @@ if ($config) {
my $api = Sipwise::API->new($opts);
$opts = $api->opts;
my $del = 0;
my $ids = {};
sub usage {
return "Usage:\n$PROGRAM_NAME registrations.yml\n".
"Options:\n".
" -ids scenario_ids.yml file\n".
" -delete\n".
" -d debug\n".
" -h this help\n";
}
my $help = 0;
my $ids_path;
GetOptions ("h|help" => \$help,
"ids=s" => \$ids_path,
"d|debug" => \$opts->{verbose},
"delete" => \$del)
or die("Error in command line arguments\n".usage());
@ -56,6 +60,14 @@ GetOptions ("h|help" => \$help,
die(usage()) unless (!$help);
die("Error: wrong number of arguments\n".usage()) unless ($#ARGV == 0);
sub key_domain
{
my $domain = shift;
my $key_dom = $domain =~ tr/\./_/r;
return $key_dom =~ tr/\-/_/r;
}
sub delete_regs
{
my $subscriber = shift;
@ -71,6 +83,25 @@ sub delete_regs
return;
}
sub contact
{
my $subscriber = shift;
my $domain = shift;
my $key_dom = key_domain($domain);
foreach my $scen (@{$ids->{scenarios}})
{
foreach my $resp (@{$scen->{responders}})
{
if( $resp->{username} eq $subscriber && $resp->{domain} eq $domain)
{
return "sip:$resp->{ip}:$resp->{port}";
}
}
}
die("can't find ${subscriber}\@${domain} on scenarios\n");
}
sub create_regs
{
my $subscriber = shift;
@ -83,8 +114,9 @@ sub create_regs
foreach my $r (@{$data})
{
$r->{subscriber_id} = $subs_id;
$r->{contact} = contact($subscriber, $domain);
my $id = $api->create_subscriber_registration($r);
print "registration: ${subscriber}[${subs_id}] created [${id}]\n";
print "registration: ${subscriber}[${subs_id}] created as $r->{contact} [${id}]\n";
}
}
else {
@ -126,6 +158,9 @@ sub main {
print "delete registrations\n" unless $opts->{debug};
return do_delete($r);
} else {
die("scenario_ids.yml needed, use -ids option\n") unless defined($ids_path);
print "load ${ids_path}\n" unless $opts->{debug};
$ids = LoadFile($ids_path);
print "create registrations\n" unless $opts->{debug};
return do_create($r);
}

@ -57,6 +57,7 @@ create_voip() {
if [ -f "${SCEN_CHECK_DIR}/registration.yml" ]; then
echo "$(date) - Creating permanent registrations"
"${BIN_DIR}/create_registrations.pl" \
-ids "${SCEN_CHECK_DIR}/scenario_ids.yml" \
"${SCEN_CHECK_DIR}/registration.yml"
fi
}

Loading…
Cancel
Save