Skip to content

Commit 1138f89

Browse files
author
nVitius
committed
Add AutoScaling commands
1 parent 3a2624b commit 1138f89

4 files changed

Lines changed: 317 additions & 0 deletions

File tree

Aws/AutoScalingCommand.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2014 Underground Elephant
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @package aws-cli-bundle
19+
* @copyright (c) 2014 Underground Elephant
20+
* @license Apache License, Version 2.0
21+
*/
22+
23+
namespace Uecode\Bundle\AwsCliBundle\Aws;
24+
25+
use Aws\AutoScaling\AutoScalingClient;
26+
27+
/**
28+
* Authenticates with AWS for use with AutoScaling commands
29+
*
30+
* @author Mauricio Walters <mwalters@undergroundelephant.com>
31+
*/
32+
class AutoScalingCommand extends AbstractAwsCommand
33+
{
34+
/**
35+
* Instantiates a new AutoScaling Client
36+
*
37+
* @return AutoScalingClient
38+
*/
39+
protected function getClient() {
40+
$credentials = $this->getCredentials();
41+
42+
$client = AutoScalingClient::factory(array(
43+
'key' => $credentials['aws_api_key'],
44+
'secret' => $credentials['aws_api_secret'],
45+
'region' => $credentials['aws_region'],
46+
));
47+
48+
return $client;
49+
}
50+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2014 Underground Elephant
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @package aws-cli-bundle
19+
* @copyright (c) 2014 Underground Elephant
20+
* @license Apache License, Version 2.0
21+
*/
22+
23+
namespace Uecode\Bundle\AwsCliBundle\Command\Aws\AutoScaling;
24+
25+
use Symfony\Component\Console\Input\InputArgument;
26+
use Symfony\Component\Console\Input\InputOption;
27+
use Symfony\Component\Console\Input\InputInterface;
28+
use Symfony\Component\Console\Output\OutputInterface;
29+
use Uecode\Bundle\AwsCliBundle\Aws\AutoScalingCommand;
30+
31+
/**
32+
* Create Launch Configuration Command
33+
*
34+
* @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.AutoScaling.AutoScalingClient.html#_createLaunchConfiguration
35+
* @author Mauricio Walters <mwalters@undergroundelephant.com>
36+
*/
37+
class CreateLaunchConfigurationCommand extends AutoScalingCommand
38+
{
39+
/**
40+
* {@inheritDoc}
41+
*/
42+
protected function configure()
43+
{
44+
$this
45+
->setName('uecode:aws:autoscaling:createlaunchconfiguration')
46+
->setDescription('Creates a new launch configuration.')
47+
->AddArgument(
48+
'LaunchConfigurationName',
49+
InputArgument::REQUIRED,
50+
'The name of the launch configuration to create'
51+
)
52+
->AddOption(
53+
'ImageId',
54+
'imageid',
55+
InputOption::VALUE_REQUIRED,
56+
'Unique ID of the Amazon Machine Image (AMI) you want to use to launch your EC2 instances'
57+
)
58+
->AddOption(
59+
'KeyName',
60+
'keyname',
61+
InputOption::VALUE_REQUIRED,
62+
'The name of the Amazon EC2 key pair'
63+
)
64+
->AddOption(
65+
'SecurityGroups',
66+
'securitygroups',
67+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
68+
'The security groups with which to associate Amazon EC2 or Amazon VPC instances.'
69+
)
70+
->AddOption(
71+
'UserData',
72+
'userdata',
73+
InputOption::VALUE_REQUIRED,
74+
'The user data to make available to the launched Amazon EC2 instances'
75+
)
76+
->AddOption(
77+
'InstanceId',
78+
'instanceid',
79+
InputOption::VALUE_REQUIRED,
80+
'The ID of the Amazon EC2 instance you want to use to create the launch configuration'
81+
)
82+
->AddOption(
83+
'InstanceType',
84+
'instancetype',
85+
InputOption::VALUE_REQUIRED,
86+
'The instance type of the Amazon EC2 instance'
87+
)
88+
->AddOption(
89+
'KernelId',
90+
'kernelid',
91+
InputOption::VALUE_REQUIRED,
92+
'The ID of the kernel associated with the Amazon EC2 AMI'
93+
)
94+
->AddOption(
95+
'RamdiskId',
96+
'ramdiskid',
97+
InputOption::VALUE_REQUIRED,
98+
'The ID of the RAM disk associated with the Amazon EC2 AMI'
99+
)
100+
->AddOption(
101+
'BlockDeviceMappings',
102+
'blockdevicemappings',
103+
InputOption::VALUE_REQUIRED,
104+
'A list of mappings that specify how block devices are exposed to the instance. Takes JSON'
105+
)
106+
->AddOption(
107+
'InstanceMonitoring',
108+
'instancemonitoring',
109+
InputOption::VALUE_REQUIRED,
110+
'Enables detailed monitoring if it is disabled. true/false'
111+
)
112+
->AddOption(
113+
'SpotPrice',
114+
'spotprice',
115+
InputOption::VALUE_REQUIRED,
116+
'The maximum hourly price to be paid for any Spot Instance launched to fulfill the request'
117+
);
118+
}
119+
120+
/**
121+
* {@inheritDoc}
122+
*/
123+
protected function execute(InputInterface $input, OutputInterface $output)
124+
{
125+
$options = array_merge($input->getArguments(), $input->getOptions());
126+
127+
$options['BlockDeviceMappings'] = json_decode($options['BlockDeviceMappings']);
128+
if ($options['InstanceMonitoring'] == "true") {
129+
$options['InstanceMonitoring'] = ['Enabled' => true];
130+
} else {
131+
unset($options['InstanceMonitoring']);
132+
}
133+
134+
$this->getClient()->createLaunchConfiguration($options);
135+
136+
return self::COMMAND_SUCCESS;
137+
}
138+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2014 Underground Elephant
5+
*t
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @package aws-cli-bundle
19+
* @copyright (c) 2014 Underground Elephant
20+
* @license Apache License, Version 2.0
21+
*/
22+
23+
namespace Uecode\Bundle\AwsCliBundle\Command\Aws\AutoScaling;
24+
25+
use Symfony\Component\Console\Input\InputArgument;
26+
use Symfony\Component\Console\Input\InputOption;
27+
use Symfony\Component\Console\Input\InputInterface;
28+
use Symfony\Component\Console\Output\OutputInterface;
29+
use Uecode\Bundle\AwsCliBundle\Aws\AutoScalingCommand;
30+
31+
32+
class UpdateAutoScalingGroupCommand extends AutoScalingCommand {
33+
protected function configure()
34+
{
35+
$this
36+
->setName('uecode:aws:autoscaling:updateautoscalinggroup')
37+
->setDescription('Updates the configuration for the specified AutoScalingGroup')
38+
->addArgument(
39+
'AutoScalingGroupName',
40+
InputArgument::REQUIRED,
41+
'The name of the Auto Scaling group'
42+
)
43+
->addOption(
44+
'LaunchConfigurationName',
45+
'launchconfigurationname',
46+
InputOption::VALUE_REQUIRED,
47+
'The name of the launch configuration'
48+
)
49+
->addOption(
50+
'MinSize',
51+
'minsize',
52+
InputOption::VALUE_REQUIRED,
53+
'The minimum size of the Auto Scaling group'
54+
)
55+
->addOption(
56+
'MaxSize',
57+
'maxsize',
58+
InputOption::VALUE_REQUIRED,
59+
'The maximum size of the Auto Scaling group'
60+
)
61+
->addOption(
62+
'DesiredCapacity',
63+
'desiredcapacity',
64+
InputOption::VALUE_REQUIRED,
65+
'The desired capacity for the Auto Scaling group'
66+
)
67+
->addOption(
68+
'DefaultCooldown',
69+
'defaultcooldown',
70+
InputOption::VALUE_REQUIRED,
71+
'The amount of time, in seconds, after a scaling activity completes
72+
before any further scaling activities can start'
73+
)
74+
->addOption(
75+
'AvailabilityZones',
76+
'availabiltyzones',
77+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
78+
'Availability Zones for the group'
79+
)
80+
->addOption(
81+
'HealthCheckType',
82+
'healthchecktype',
83+
InputOption::VALUE_REQUIRED,
84+
'The type of health check for the instances in the Auto Scaling group'
85+
)
86+
->addOption(
87+
'HealthCheckGracePeriod',
88+
'healthcheckgraceperiod',
89+
InputOption::VALUE_REQUIRED,
90+
'The length of time that Auto Scaling waits before checking an instance\'s health status'
91+
)
92+
->addOption(
93+
'PlacementGroup',
94+
'placementgroup',
95+
InputOption::VALUE_REQUIRED,
96+
'The name of the cluster placement group, if applicable'
97+
)
98+
->addOption(
99+
'VPCZoneIdentifier',
100+
'vpczoneidentifier',
101+
InputOption::VALUE_REQUIRED,
102+
'The subnet identifier for the Amazon VPC connection, if applicable.
103+
You can specify several subnets in a comma-separated list'
104+
)
105+
->addOption(
106+
'TerminationPolicies',
107+
'terminationpolicies',
108+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
109+
'A standalone termination policy or a list of termination policies
110+
used to select the instance to terminate'
111+
)
112+
;
113+
}
114+
115+
protected function execute(InputInterface $input, OutputInterface $output)
116+
{
117+
$options = array_merge($input->getArguments(), $input->getOptions());
118+
119+
var_dump($options);
120+
121+
$this->getClient()->updateAutoScalingGroup($options);
122+
123+
return self::COMMAND_SUCCESS;
124+
}
125+
}

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@
1414
},
1515
"require": {
1616
"aws/aws-sdk-php": "2.6.*"
17+
},
18+
"require-dev": {
19+
"symfony/console": "~2.4.0",
20+
"symfony/framework-bundle": "~2.4.0"
1721
}
1822
}

0 commit comments

Comments
 (0)