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.
179 lines
3.7 KiB
179 lines
3.7 KiB
#!/usr/bin/perl
|
|
use strict;
|
|
use warnings;
|
|
use Config::Tiny;
|
|
use English;
|
|
use Getopt::Long;
|
|
use JSON qw();
|
|
use LWP::UserAgent;
|
|
use Pod::Usage;
|
|
|
|
my $config = Config::Tiny->read('/etc/default/ngcp-api');
|
|
my $opts = {
|
|
reseller_id => 1,
|
|
host => '127.0.0.1',
|
|
port => 1443,
|
|
auth_user => 'administrator',
|
|
auth_pwd => 'administrator',
|
|
verbose => 0
|
|
};
|
|
|
|
if ($config) {
|
|
$opts->{host} = $config->{_}->{NGCP_API_IP};
|
|
$opts->{port} = $config->{_}->{NGCP_API_PORT};
|
|
}
|
|
|
|
GetOptions( $opts,
|
|
"help|h" => sub { pod2usage(-exitval =>0); },
|
|
"reseller_id=i",
|
|
"host=s",
|
|
"port=i",
|
|
"auth_user=s",
|
|
"auth_pwd=s",
|
|
"verbose",
|
|
"man" => sub { pod2usage(-exitval => 0, -verbose => 2); }
|
|
) or pod2usage(2);
|
|
|
|
die pod2usage(-exitval => 1, -message => "No domain") unless ($#ARGV == 0);
|
|
|
|
sub main {
|
|
my $domain = shift;
|
|
my $urlbase = 'https://'.$opts->{host}.':'.$opts->{port};
|
|
my $data = {
|
|
domain => $domain,
|
|
reseller_id => $opts->{reseller_id}
|
|
};
|
|
my $ua = LWP::UserAgent->new();
|
|
# set to 0 if using a self-signed certificate
|
|
$ua->ssl_opts(verify_hostname => 0);
|
|
$ua->credentials($opts->{host}.':'.$opts->{port}, 'api_admin_http',
|
|
$opts->{auth_user}, $opts->{auth_pwd});
|
|
# debug!!
|
|
if($opts->{verbose}) {
|
|
$ua->show_progress(1);
|
|
$ua->add_handler("request_send", sub { shift->dump; return });
|
|
$ua->add_handler("response_done", sub { shift->dump; return });
|
|
}
|
|
|
|
my $res = do_request($ua, $urlbase, $data);
|
|
if($res->is_success) {
|
|
print $res->status_line . ' ' . $res->header('Location') . "\n";
|
|
} else {
|
|
die $res->as_string;
|
|
}
|
|
return;
|
|
}
|
|
|
|
sub do_request {
|
|
my $ua = shift;
|
|
my $urlbase = shift;
|
|
my $data = shift;
|
|
|
|
my $req = HTTP::Request->new('POST', $urlbase."/api/domains/");
|
|
$req->header('Content-Type' => 'application/json');
|
|
$req->header('Prefer' => 'return=representation');
|
|
$req->content(JSON::to_json($data));
|
|
|
|
return $ua->request($req);
|
|
}
|
|
|
|
main($ARGV[0]);
|
|
|
|
__END__
|
|
=head1 NAME
|
|
|
|
ngcp-create_domain - create a domain on NGCP
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
ngcp-create_domain [options] domain
|
|
|
|
=head1 OPTIONS
|
|
|
|
=over 8
|
|
|
|
=item B<-help>
|
|
|
|
Print a brief help message and exits.
|
|
|
|
=item B<-reseller_id>
|
|
|
|
The reseller id to assign this domain to. Defaults to 1.
|
|
|
|
=item B<-auth_user>
|
|
|
|
Authentication username . Defaults to 'administrator'.
|
|
|
|
=item B<-auth_pwd>
|
|
|
|
Authentication password . Defaults to 'administrator'.
|
|
|
|
=item B<-host>
|
|
|
|
Host where the send queries. Defaults to '127.0.0.1'.
|
|
|
|
=item B<-port>
|
|
|
|
Port where the send queries. Defaults to 1443.
|
|
|
|
=item B<-verbose>
|
|
|
|
See debug information. Default false.
|
|
|
|
=back
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
B<This program> will create a domain at NGCP.
|
|
|
|
=head1 USAGE
|
|
|
|
ngcp-create_domain -host 1.2.3.4 -reseller_id 4 test.example.org
|
|
|
|
=head1 REQUIRED ARGUMENTS
|
|
|
|
B<domain> to be created
|
|
|
|
=head1 EXIT STATUS
|
|
|
|
Exit code 0 means that everything should have went fine otherwise error.
|
|
|
|
=head1 DIAGNOSTICS
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
/etc/default/ngcp-api for default values
|
|
|
|
=head1 DEPENDENCIES
|
|
|
|
ngcp-create_domain relies on a bunch of Perl modules, all of them specified as
|
|
dependencies through the ngcp-ossbss-clients-perl 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
|
|
|
|
Copyright (c) 2015 Sipwise GmbH, Austria.
|
|
All rights reserved. You may not copy, distribute
|
|
or modify without prior written permission from
|
|
Sipwise GmbH, Austria.
|
|
|
|
=head1 LICENSE AND COPYRIGHT
|
|
|
|
Copyright (c) 2015 Sipwise GmbH, Austria.
|
|
You should have received a copy of the licence terms together with the
|
|
software.
|
|
|
|
=cut
|