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 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#Policies
## Setup
To interact with the policies of a scaling group, you will need to setup the group object beforehand.
```php
$groupId = 'foobar';
$group = $service->getGroup($groupId);
```
For more information about setting up the `$service` object, please see the userguide tutorial for [Autoscale groups]().
## Get all policies
```php
$policies = $group->getPolicies();
while ($policy = $policies->next()) {
// do something
echo "{$policy->name} {($policy->type)}" . PHP_EOL;
}
```
## Create a new scaling policy
Creating policies is achieved through passing an array to the `create` method.
```php
$policy = new \stdClass;
$policy->name = "NEW NAME";
$policy->change = 1;
$policy->cooldown = 150;
$policy->type = "webhook";
$group->getPolicy()->create(array($policy));
// or even:
$group->getPolicy()->create(array(
(object) array(
'name' => 'NEW NAME',
'change' => 1,
'cooldown' => 150,
'type' => 'webhook'
),
// etc.
));
```
## Get, update and delete a scaling policy
```php
$policyId = 'foobar';
$policy = $group->getPolicy($policyId);
$policy->update(array(
'name' => 'More relevant name'
));
$policy->delete();
```
## Execute a scaling policy
```php
$policy->execute();
```
|