-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.php
54 lines (46 loc) · 2.02 KB
/
list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
require "functions.php";
function list_protocols($xauthtoken, $region, $accountid) {
$url = "/loadbalancers/protocols";
$response = getlisting($xauthtoken, $region, $accountid, $url);
if ($response["Status"] === "Failure") return $response;
else return $response['protocols'];
}
function list_algorithms($xauthtoken, $region, $accountid) {
$url = "/loadbalancers/algorithms";
$response = getlisting($xauthtoken, $region, $accountid, $url);
if ($response["Status"] === "Failure") return $response;
else return $response['algorithms'];
}
function list_loadbalancers($xauthtoken, $region, $accountid, $deleted=false) {
$url = "/loadbalancers" . ($deleted ? "?status=DELETED" : "");
$response = getlisting($xauthtoken, $region, $accountid, $url);
if ($response["Status"] === "Failure") return $response;
else return $response['loadBalancers'];
}
function list_loadbalancer_details($xauthtoken, $region, $accountid, $id) {
$url = "/loadbalancers/" . $id;
$response = getlisting($xauthtoken, $region, $accountid, $url);
if ($response["Status"] === "Failure") return $response;
else return $response['loadBalancer'];
}
// All of the list functions run almost exactly the same way,
// Took all of the identical pieces and extracted to getlisting
function getlisting($xauthtoken, $region, $accountid, $urlext) {
$headers = array("X-Auth-Token" => "$xauthtoken", "Content-Type" => "application/json", "Accept" => "application/json");
$url = lbaas_url($region, $accountid);
if ( $url == -1 ) return error("Invalid Region: $region");
$url .= $urlext;
$api_response = http_parse_message(http_get($url,array("headers"=>$headers),$info));
/* $info will give request data, $api_response for response info
print "<pre>";
print_r($info);
print_r($api_response);
print "</pre>";
// */
if (ereg("20(.)",$api_response->responseCode,$regs)) {
return json_decode($api_response->body,true);
} else
return error($api_response->responseStatus);
}
?>