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.
177 lines
3.3 KiB
177 lines
3.3 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(billing_profile_id contact_id);
|
|
|
|
my $opts = {
|
|
type => 'sipaccount',
|
|
status => 'active',
|
|
verbose => 0,
|
|
};
|
|
|
|
# XXX: Remove after mr10.5.
|
|
sub old_option {
|
|
my ($name, $value) = @_;
|
|
my $newname = $name =~ tr/_/-/r;
|
|
$opts->{$name} = $value;
|
|
warn "$0: option --$name is deprecated; use --$newname instead\n";
|
|
}
|
|
|
|
sub parse_option {
|
|
my ($name, $value) = @_;
|
|
$name =~ tr/-/_/;
|
|
$opts->{$name} = $value;
|
|
}
|
|
|
|
GetOptions($opts,
|
|
'help|h' => sub { usage() },
|
|
'billing_profile_id=i' => \&old_option,
|
|
'billing-profile-id=i' => \&parse_option,
|
|
'contact_id=i' => \&old_option,
|
|
'contact-id=i' => \&parse_option,
|
|
'type=s',
|
|
'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 $missing = shift;
|
|
|
|
pod2usage(
|
|
-exitval => $missing ? 1 : 0,
|
|
-verbose => 99,
|
|
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
|
|
-message => $missing ? "Missing parameters: $missing" : '',
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
sub main {
|
|
check_params();
|
|
|
|
my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
|
|
|
|
my $uri = '/api/customers/';
|
|
my %data = map {
|
|
$_ => $opts->{$_}
|
|
} qw(billing_profile_id contact_id type status);
|
|
my $res = $client->request('POST', $uri, \%data);
|
|
print $res->result . "\n";
|
|
|
|
return !$res->is_success;
|
|
}
|
|
|
|
exit main();
|
|
|
|
__END__
|
|
|
|
=head1 NAME
|
|
|
|
ngcp-create-customer - create a customer
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
B<ngcp-create-customer> [I<options>...] I<required-arguments>...
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
B<This program> creates a customer on the NGCP platform.
|
|
|
|
=head1 REQUIRED ARGUMENTS
|
|
|
|
=over 8
|
|
|
|
=item B<--billing-profile-id> I<id>
|
|
|
|
Billing profile id.
|
|
|
|
=item B<--contact-id> I<id>
|
|
|
|
Contact id.
|
|
|
|
=back
|
|
|
|
=head1 OPTIONS
|
|
|
|
=over 8
|
|
|
|
=item B<--type> I<customer-type>
|
|
|
|
Customer can be one of the "sipaccount" or "pbxaccount" type. Defaults to
|
|
"sipaccount".
|
|
|
|
=item B<--verbose>
|
|
|
|
Show additional debug information. Default false.
|
|
|
|
=item B<--help>
|
|
|
|
Print a brief help message.
|
|
|
|
=back
|
|
|
|
=head1 EXIT STATUS
|
|
|
|
=over
|
|
|
|
=item B<0>
|
|
|
|
Command completed successfully.
|
|
|
|
=item B<1>
|
|
|
|
Command failed with errors.
|
|
|
|
=back
|
|
|
|
=head1 SEE ALSO
|
|
|
|
NGCP::API::Client
|
|
|
|
=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) 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
|