You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
3.6 KiB
173 lines
3.6 KiB
#!/usr/bin/perl
|
|
use strict;
|
|
use warnings;
|
|
use English;
|
|
use Getopt::Long;
|
|
use Pod::Usage;
|
|
use NGCP::API::Client;
|
|
use Readonly;
|
|
|
|
Readonly my @required => qw(domain);
|
|
|
|
my $opts = {
|
|
domain => $ARGV[0],
|
|
skip_xmpp => 0,
|
|
skip_sip => 0,
|
|
verbose => 0,
|
|
};
|
|
|
|
GetOptions( $opts,
|
|
"help|h" => \&usage,
|
|
"domain=s",
|
|
"skip_xmpp",
|
|
"skip_sip",
|
|
"verbose",
|
|
) or usage();
|
|
|
|
sub check_params {
|
|
my @missing;
|
|
foreach my $param (@required) {
|
|
push @missing, $param unless $opts->{$param};
|
|
}
|
|
usage(join(' ', @missing)) if scalar @missing;
|
|
return;
|
|
}
|
|
|
|
sub usage {
|
|
my $msg = shift;
|
|
pod2usage(-exitval => $msg ? 1 : 0,
|
|
-verbose => 99,
|
|
-sections => [ qw(NAME OPTIONS USAGE) ],
|
|
-message => $msg
|
|
? $msg =~ /not found/i
|
|
? $msg
|
|
: "Missing parameters: $msg"
|
|
: '',
|
|
);
|
|
return;
|
|
}
|
|
|
|
sub main {
|
|
check_params();
|
|
my $uri = '/api/domains/';
|
|
my %data = map { "_".$_."_reload" => $opts->{$_} } qw(skip_xmpp skip_sip);
|
|
my $client = new NGCP::API::Client;
|
|
$client->set_verbose($opts->{verbose});
|
|
# domain_id
|
|
my $dom = $client->request("GET", "/api/domains/?domain=".$opts->{domain});
|
|
if ($dom->as_hash->{total_count} == 1) {
|
|
my $dom_id = $dom->as_hash->{_embedded}->{'ngcp:domains'}->{id};
|
|
usage("Domain not found") unless $dom_id;
|
|
$uri .= $dom_id;
|
|
} else {
|
|
usage("Domain not found");
|
|
}
|
|
my $res = $client->request("DELETE", $uri, \%data);
|
|
print $res->result."\n";
|
|
|
|
exit !$res->is_success;
|
|
|
|
return;
|
|
}
|
|
|
|
main();
|
|
|
|
exit 0;
|
|
|
|
__END__
|
|
|
|
=head1 NAME
|
|
|
|
ngcp-delete_domain - delete an NGCP domain
|
|
|
|
=head1 OPTIONS
|
|
|
|
=over 8
|
|
|
|
=item B<-help>
|
|
|
|
Print a brief help message.
|
|
|
|
=item B<-skip_sip>
|
|
|
|
Skip reloading SIP services. If true, changes will not be effective immedeately
|
|
until the respective service is restarted or properly notified. Default false.
|
|
|
|
=item B<-skip_xmpp>
|
|
|
|
Skip reloading XMPP services. If true, changes will not be effective immedeately
|
|
until the respective service is restarted or properly notified. Default false.
|
|
|
|
=item B<-verbose>
|
|
|
|
Show additional debug information. Default false.
|
|
|
|
=back
|
|
|
|
=head1 USAGE
|
|
|
|
ngcp-delete_domain [options]
|
|
|
|
ngcp-delete_domain --domain example.org
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
B<This program> deletes a domain on the NGCP platform.
|
|
|
|
=head1 REQUIRED ARGUMENTS
|
|
|
|
=over 8
|
|
|
|
=item B<-domain>
|
|
|
|
=back
|
|
|
|
=head1 EXIT STATUS
|
|
|
|
Exit code 0 means everything is ok otherwise 1.
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
=head1 DIAGNOSTICS
|
|
|
|
=head1 SEE ALSO
|
|
|
|
NGCP::API::Client
|
|
|
|
=head1 DEPENDENCIES
|
|
|
|
ngcp-delete_domain relies on a bunch of Perl modules, all of them specified as
|
|
dependencies through the Debian package.
|
|
|
|
=head1 INCOMPATIBILITIES
|
|
|
|
No known at this time.
|
|
|
|
=head1 BUGS AND LIMITATIONS
|
|
|
|
Please report problems you notice to the Sipwise
|
|
Development Team <support@sipwise.com>.
|
|
|
|
=head1 AUTHOR
|
|
|
|
Victor Seva <vseva@sipwise.com>
|
|
|
|
=head1 LICENSE AND COPYRIGHT
|
|
|
|
Copyright (C) 2016 Sipwise GmbH, Austria
|
|
|
|
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
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
=cut
|