# Query
help() unless @ARGV;
-query(@ARGV);
+url_query(@ARGV);
# END
exit 0;
sub ip_routed {
my $ip = shift @_;
- my $rec = _query("/ip/$ip") or exit 1;
+ my $rec = query("/ip/$ip") or exit 1;
my @routed;
if ($rec->{type} =~ /^(failover|dedicated)$/) {
} elsif ($rec->{type} eq 'loadBalancing') {
- my $frontends = _query("/ipLoadbalancing/ip-$ip/frontend") or exit 1;
+ my $frontends = query("/ipLoadbalancing/ip-$ip/frontend") or exit 1;
for my $frontend_id (@$frontends) {
- my $frontend = _query("/ipLoadbalancing/ip-$ip/frontend/$frontend_id") or exit 1;
+ my $frontend = query("/ipLoadbalancing/ip-$ip/frontend/$frontend_id") or exit 1;
next unless $frontend->{defaultBackendId};
- my $farms = _query("/ipLoadbalancing/ip-$ip/".$frontend->{type}."/farm") or exit 1;
+ my $farms = query("/ipLoadbalancing/ip-$ip/".$frontend->{type}."/farm") or exit 1;
for my $farm_id (@$farms) {
- my $servers = _query("/ipLoadbalancing/ip-$ip/".$frontend->{type}."/farm/$farm_id/server") or exit 1;
+ my $servers = query("/ipLoadbalancing/ip-$ip/".$frontend->{type}."/farm/$farm_id/server") or exit 1;
for my $id_server (@$servers) {
- my $server = _query("/ipLoadbalancing/ip-$ip/".$frontend->{type}."/farm/$farm_id/server/$id_server") or exit 1;
+ my $server = query("/ipLoadbalancing/ip-$ip/".$frontend->{type}."/farm/$farm_id/server/$id_server") or exit 1;
push @routed,ip_routed($server->{address});
}
my $localhost = hostname();
- my $rec = _query("/ip/$ip") or exit 1;
+ my $rec = query("/ip/$ip") or exit 1;
my $type = $rec->{type};
$type eq 'failover' or die "$ip $type is not an ip failover!\n";
require Data::Dumper; die Data::Dumper::Dumper([$localhost,$routed,$rec]);
- local $_ = _query("/ip/$ip/move",'POST',{'to' => $localhost});
+ local $_ = query("/ip/$ip/move",'POST',{'to' => $localhost});
print JSON::encode_json($_);
exit;
}
-sub _query {
+sub query {
my ($url,$method,$body) = @_;
exists $ALIASES{$url} and $url = $ALIASES{$url};
return @rows;
}
-sub query {
+sub url_query {
my ($url,@body) = @_;
my $response;
my $method = $Opt{method};
-if (1) {
if ($Opt{rows}) {
- local @_ = _query($url,$method,$body);
+ local @_ = query($url,$method,$body);
print JSON::encode_json(\@_);
} else {
- local $_ = _query($url,$method,$body);
+ local $_ = query($url,$method,$body);
print ref($_) eq '' ? $_ : JSON::encode_json($_);
#print JSON::encode_json(_query($url,$method,$body));
}
exit;
}
- my %aliases = (
- '/server' => '/dedicated/server',
- '/dns' => '/domain/zone',
- );
- exists $aliases{$url} and $url = $aliases{$url};
-
- $response = $Api->rawCall(path=>$url,method=>$method,body=>$body);
- die "$NAME: ERR: ".$response->error() if $response->isFailure();
- $content = $response->content;
-
- return unless defined $content;
-
- if ($Opt{rows}) {
- print "[\n" if @$content>0;
- my $count = 0;
- for my $id (@$content) {
- $id = check_row($url,$id);
- next unless defined $id;
-
- $response = $Api->rawCall(path=>$url.'/'.$id,method=>$Opt{method},body=>{});
- die "$NAME: ERR: ".$response->error() if $response->isFailure();
-
-
- print ',' if $count > 0;
- print JSON::encode_json($response->content)."\n";
- $count++;
- }
- print "]\n" if $count>0;
- return
- }
-
- $content = JSON::encode_json($content) if $content and ref($content) ne '';
- #use Data::Dumper; die Dumper($content);
- print "$content\n";
-}
-
sub sql {
my $preff = 'ovh_';
my @tbs = (