1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: namespace OpenCloud\Autoscale\Resource;
12:
13: use OpenCloud\Common\Exceptions;
14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
32: class Group extends AbstractResource
33: {
34:
35: public $id;
36: public $links;
37: public $groupConfiguration;
38: public $launchConfiguration;
39: public $scalingPolicies;
40: public $name;
41: public $metadata;
42:
43: public $active;
44: public $activeCapacity;
45: public $pendingCapacity;
46: public $desiredCapacity;
47: public $paused;
48:
49: protected static $json_name = 'group';
50: protected static $url_resource = 'groups';
51: protected static $json_collection_name = 'groups';
52:
53: 54: 55:
56: public $createKeys = array(
57: 'groupConfiguration',
58: 'launchConfiguration',
59: 'scalingPolicies'
60: );
61:
62: 63: 64:
65: public $associatedResources = array(
66: 'groupConfiguration' => 'GroupConfiguration',
67: 'launchConfiguration' => 'LaunchConfiguration',
68:
69: );
70:
71: 72: 73:
74: public $associatedCollections = array(
75: 'scalingPolicies' => 'ScalingPolicy'
76: );
77:
78: 79: 80:
81: public function create($params = array())
82: {
83: if (is_string($params)) {
84: $params = json_decode($params);
85: $this->checkJsonError();
86: } elseif (!is_object($params) && !is_array($params)) {
87: throw new Exceptions\InvalidArgumentError(
88: 'You must provide either a string or an array/object'
89: );
90: }
91:
92: $this->populate($params, false);
93:
94: return parent::create();
95: }
96:
97: 98: 99:
100: public function update($params = array())
101: {
102: return $this->noUpdate();
103: }
104:
105: 106: 107: 108: 109: 110: 111: 112: 113:
114: public function getState()
115: {
116: $object = $this->customAction($this->url('state', true));
117:
118: return (!empty($object->group)) ? $object->group : false;
119: }
120:
121: 122: 123: 124: 125:
126: public function getGroupConfig()
127: {
128: if ($this->groupConfiguration instanceof GroupConfiguration) {
129: return $this->groupConfiguration;
130: }
131:
132: $config = $this->getService()->resource('GroupConfiguration');
133: $config->setParent($this);
134: if ($this->id) {
135: $config->refresh(null, $config->url());
136: }
137: return $config;
138: }
139:
140: 141: 142: 143: 144:
145: public function getLaunchConfig()
146: {
147: if ($this->launchConfiguration instanceof LaunchConfiguration) {
148: return $this->launchConfiguration;
149: }
150:
151: $config = $this->getService()->resource('LaunchConfiguration');
152: $config->setParent($this);
153: if ($this->id) {
154: $config->refresh(null, $config->url());
155: }
156: return $config;
157: }
158:
159: 160: 161: 162: 163:
164: public function pause()
165: {
166: return $this->customAction($this->url('pause', true), 'POST');
167: }
168:
169: 170: 171: 172: 173:
174: public function resume()
175: {
176: return $this->customAction($this->url('resume', true), 'POST');
177: }
178:
179: 180: 181: 182: 183:
184: public function getPolicies()
185: {
186: return $this->service()->resourceList('ScalingPolicy', null, $this);
187: }
188:
189: 190: 191: 192: 193: 194:
195: public function getPolicy($id = null)
196: {
197: $config = $this->getService()->resource('ScalingPolicy');
198: $config->setParent($this);
199: if ($id) {
200: $config->populate($id);
201: }
202: return $config;
203: }
204:
205: }