30 use \HPCloud\Transport;
47 $url = sprintf(
'%s/instances/%s', $this->
url, $instanceId);
48 $res = $this->client->doRequest(
$url,
'GET', $this->
headers());
50 $json = json_decode($res->content(), TRUE);
51 return InstanceDetails::newFromJSON($json[
'instance']);
55 $url = $this->
url .
'/instances';
56 $res = $this->client->doRequest(
$url,
'GET', $this->
headers());
57 $json = json_decode($res->content(), TRUE);
60 foreach ($json[
'instances'] as $instance) {
61 $list[] = InstanceDetails::newFromJSON($instance);
87 public function create(
$name, $flavor =
'medium', $typeSpec = NULL) {
91 $flavorObject = $f->getFlavorByName($flavor);
95 if (empty($typeSpec)) {
104 'flavorRef' => $flavorObject->url(),
105 'dbtype' => $typeSpec,
108 $url = $this->
url .
'/instances';
109 $postData = json_encode($json);
111 $length = strlen($postData);
112 $headers = $this->
headers(array(
113 'Accept' =>
'application/json',
114 'Content-Length' => $length,
115 'Content-Type' =>
'application/json',
117 $res = $this->client->doRequest(
$url,
'POST', $headers, $postData);
119 $results = json_decode($res->content(), TRUE);
121 return InstanceDetails::newFromJSON($results[
'instance']);
124 public function delete($instanceId) {
125 $url = sprintf(
'%s/instances/%s', $this->
url, $instanceId);
126 $this->client->doRequest(
$url,
'DELETE', $this->
headers());
131 $url = sprintf(
'%s/instances/%s/restart', $this->
url, $instanceId);
132 $headers = $this->
headers(array(
'Content-Length' =>
'0'));
133 $this->client->doRequest(
$url,
'POST', $headers);
145 $url = sprintf(
'%s/instances/%s/resetpassword', $this->
url, $instanceId);
146 $headers = $this->
headers(array(
'Content-Length' =>
'0'));
147 $res = $this->client->doRequest(
$url,
'POST', $headers);
148 $json = json_decode($res);
150 return $json->password;