-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAWSAutoScaler.class.php
executable file
·69 lines (50 loc) · 2.23 KB
/
AWSAutoScaler.class.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once 'AWSSDKforPHP/sdk.class.php';
class AWSAutoScaler extends AmazonAS {
private static $describe_auto_scaling_groups_response = array();
private static $describe_scaling_activities_response = array();
public function __construct($aws, $credentials){
$this->aws = $aws;
return parent::__construct($credentials);
}
public function getInstances(){
$ec2 = $this->aws->getEC2();
$nombres = $this->getName();
$instances = array();
foreach ($nombres as $nombre) {
$instances = array_merge($ec2->getInstances($nombre), $instances);
}
return $instances;
}
public function getName(){
if( !self::$describe_auto_scaling_groups_response ) self::$describe_auto_scaling_groups_response = $this->describe_auto_scaling_groups();
$groups = self::$describe_auto_scaling_groups_response->body->DescribeAutoScalingGroupsResult->AutoScalingGroups->member;
$groupNames = array();
foreach($groups as $group){
$name = (string) $group->AutoScalingGroupName;
$groupNames[] = $name;
}
return $groupNames;
}
public function getCapacity(){
if( !self::$describe_auto_scaling_groups_response ) self::$describe_auto_scaling_groups_response = $this->describe_auto_scaling_groups();
return (int) self::$describe_auto_scaling_groups_response->body->DescribeAutoScalingGroupsResult->AutoScalingGroups->member->DesiredCapacity;
}
public function getDescription(){
$action = self::getLastActivity();
return $action->Description;
}
public function getLastActivity(){
if( !self::$describe_scaling_activities_response ) self::$describe_scaling_activities_response = $this->describe_scaling_activities();
$action = (array) self::$describe_scaling_activities_response->body->DescribeScalingActivitiesResult->Activities->member;
$action['Details'] = json_decode($action['Details']);
$action['class'] = ( $action['StatusCode'] == 'Successful' ) ? 'success' : 'highlight';
return (object) $action;
}
public function __call($function, $arguments){
// vamos a ver sin por ejemplo la funcion getID() tiene una variable correspondiente
$varname = str_replace("get", "", strtolower($function));
if( isset($this->$varname) ) return $this->$varname;
return null;
}
}