Overview
  • Namespace
  • Class

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Collection
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Log
      • Resource
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Collection
      • Resource
    • Identity
      • Constants
      • Resource
    • Image
      • Enum
      • Resource
        • JsonPatch
        • Schema
    • LoadBalancer
      • Collection
      • Enum
      • Resource
    • Networking
      • Resource
    • ObjectStore
      • Constants
      • Exception
      • Resource
      • Upload
    • Orchestration
      • Resource
    • Queues
      • Collection
      • Exception
      • Resource
    • Volume
      • Resource

Classes

  • OpenCloud\Volume\Resource\Snapshot
  • OpenCloud\Volume\Resource\Volume
  • OpenCloud\Volume\Resource\VolumeType
  1 <?php
  2 /**
  3  * Copyright 2012-2014 Rackspace US, Inc.
  4  *
  5  * Licensed under the Apache License, Version 2.0 (the "License");
  6  * you may not use this file except in compliance with the License.
  7  * You may obtain a copy of the License at
  8  *
  9  * http://www.apache.org/licenses/LICENSE-2.0
 10  *
 11  * Unless required by applicable law or agreed to in writing, software
 12  * distributed under the License is distributed on an "AS IS" BASIS,
 13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  * See the License for the specific language governing permissions and
 15  * limitations under the License.
 16  */
 17 
 18 namespace OpenCloud\Orchestration\Resource;
 19 
 20 use OpenCloud\Common\Resource\PersistentResource;
 21 
 22 /**
 23  * Class that represents a stack.
 24  * @see http://developer.openstack.org/api-ref-orchestration-v1.html#stacks
 25  *
 26  * @package OpenCloud\Orchestration\Resource
 27  */
 28 class Stack extends PersistentResource
 29 {
 30     protected static $url_resource = 'stacks';
 31     protected static $json_name = 'stack';
 32 
 33     protected $id;
 34     protected $parentStack; // Named so because the Base class has a $parent member.
 35     protected $disableRollback;
 36     protected $description;
 37     protected $parameters;
 38     protected $environment;
 39     protected $files;
 40     protected $name;
 41     protected $status;
 42     protected $statusReason;
 43     protected $outputs;
 44     protected $creationTime;
 45     protected $updatedTime;
 46     protected $timeoutMins;
 47     protected $templateUrl;
 48     protected $template;
 49     protected $adoptStackData;
 50     protected $links;
 51 
 52     protected $aliases = array(
 53         'parent'              => 'parentStack',
 54         'disable_rollback'    => 'disableRollback',
 55         'stack_name'          => 'name',
 56         'stack_status'        => 'status',
 57         'stack_status_reason' => 'statusReason',
 58         'creation_time'       => 'creationTime',
 59         'updated_time'        => 'updatedTime',
 60         'timeout_mins'        => 'timeoutMins',
 61         'template_url'        => 'templateUrl',
 62         'adopt_stack_data'    => 'adoptStackData'
 63     );
 64 
 65     protected $createKeys = array(
 66         'name',
 67         'templateUrl',
 68         'template',
 69         'environment',
 70         'files',
 71         'parameters',
 72         'timeoutMins',
 73         'adoptStackData'
 74     );
 75 
 76     protected $updateKeys = array(
 77         'templateUrl',
 78         'template',
 79         'environment',
 80         'files',
 81         'parameters',
 82         'timeoutMins'
 83     );
 84 
 85     protected function createJson()
 86     {
 87         $createJson = parent::createJson();
 88         return $createJson->{self::$json_name};
 89     }
 90 
 91     protected function updateJson($params = array())
 92     {
 93         $updateJson = parent::updateJson($params);
 94         return $updateJson->{self::$json_name};
 95     }
 96 
 97     /**
 98      * Creates a new stack by adopting resources from an abandoned stack
 99      *
100      * @param array $params Adopt stack parameters
101      * @return Guzzle\Http\Message\Response
102      */
103     public function adopt($params)
104     {
105         // Validate that required parameters are provided
106         $requiredParameterName = 'adoptStackData';
107         if (!array_key_exists($requiredParameterName, $params)) {
108             throw new \InvalidArgumentException($requiredParameterName . ' is a required option');
109         }
110 
111         return $this->create($params);
112     }
113 
114     /**
115      * Previews the stack without actually creating it
116      *
117      * @param array $params Preview stack parameters
118      * @return Guzzle\Http\Message\Response
119      */
120     public function preview($params = array())
121     {
122         // set parameters
123         if (!empty($params)) {
124             $this->populate($params, false);
125         }
126 
127         // construct the JSON
128         $json = json_encode($this->createJson());
129         $this->checkJsonError();
130 
131         $previewUrl = $this->previewUrl();
132         $response = $this->getClient()->post($previewUrl, self::getJsonHeader(), $json)->send();
133         
134         $decoded = $this->parseResponse($response);
135         $this->populate($decoded);
136 
137         return $response;
138     }
139 
140     /**
141      * Abandons the stack and returns abandoned stack data.
142      *
143      * @return string Abandoned stack data (which could be passed to the adopt stack operation as adoptStackData).
144      */
145     public function abandon()
146     {
147         $abandonUrl = $this->abandonUrl();
148         $response = $this->getClient()->delete($abandonUrl)->send();
149         return $response->getBody(true);
150     }
151 
152     /**
153      * Returns a Resource object associated with this Stack
154      *
155      * @param string $name Stack resource name
156      * @return Resource object
157      */
158     public function getResource($name)
159     {
160         return $this->getService()->resource('Resource', $name, $this);
161     }
162 
163     /**
164      * Returns a list of Resources associated with this Stack
165      *
166      * @param array $params
167      * @return \OpenCloud\Common\Collection\PaginatedIterator
168      */
169     public function listResources(array $params = array())
170     {
171         $url = clone $this->getUrl();
172         $url->addPath(Resource::resourceName())->setQuery($params);
173 
174         return $this->getService()->resourceList('Resource', $url, $this);
175     }
176 
177     /**
178      * Returns a list of Events associated with this Stack
179      *
180      * @param array $params
181      * @return \OpenCloud\Common\Collection\PaginatedIterator
182      */
183     public function listEvents(array $params = array())
184     {
185         $url = clone $this->getUrl();
186         $url->addPath(Event::resourceName())->setQuery($params);
187 
188         return $this->getService()->resourceList('Event', $url, $this);
189     }
190 
191     /**
192      * Iterator use only
193      */
194     public function event($id)
195     {
196         return $this->getService()->resource('Event', $id, $this);
197     }
198 
199     /**
200      * Returns the template for this stack.
201      *
202      * @return String template
203      */
204     public function getStackTemplate()
205     {
206         $url = clone $this->getUrl();
207         $url->addPath('template');
208 
209         $response = $this->getClient()->get($url)->send();
210         return $response->getBody(true);
211     }
212 
213     protected function previewUrl()
214     {
215         $url = clone $this->getParent()->getUrl();
216         $url->addPath(self::resourceName());
217         $url->addPath('preview');
218 
219         return $url;
220     }
221 
222     protected function abandonUrl()
223     {
224         $url = clone $this->getUrl();
225         $url->addPath('abandon');
226 
227         return $url;
228     }
229 
230     protected function primaryKeyField()
231     {
232         return 'name';
233     }
234 }
235 
API documentation generated by ApiGen