Skip to content

Commit cae1add

Browse files
author
Mauricio Walters
committed
Merge pull request #9 from nVitius/autoscaling
AutoScaling
2 parents 3a2624b + b0c3a73 commit cae1add

File tree

8 files changed

+384
-36
lines changed

8 files changed

+384
-36
lines changed

Aws/AbstractAwsCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ abstract class AbstractAwsCommand extends ContainerAwareCommand
3636
* Authenticate with AWS and instantiate client
3737
*
3838
* @abstract
39-
* @return Client
4039
*/
4140
abstract protected function getClient();
4241

4342
/**
4443
* Get AWS API credentials from parameters.yml
45-
*
44+
*
4645
* @return array
4746
*/
4847
protected function getCredentials()

Aws/AutoScalingCommand.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
{
41+
$credentials = $this->getCredentials();
42+
43+
$client = AutoScalingClient::factory(array(
44+
'key' => $credentials['aws_api_key'],
45+
'secret' => $credentials['aws_api_secret'],
46+
'region' => $credentials['aws_region'],
47+
));
48+
49+
return $client;
50+
}
51+
}

Aws/Ec2Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* Authenticates with AWS for use with EC2 commands
2929
*
30-
* @author Mauricio Walters <mwalters@undergroundelephant.com>
30+
* @author Mauricio Walters <mwalters@undergroundelephant.com>
3131
*/
3232
class Ec2Command extends AbstractAwsCommand
3333
{
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+
null,
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+
null,
61+
InputOption::VALUE_REQUIRED,
62+
'The name of the Amazon EC2 key pair'
63+
)
64+
->AddOption(
65+
'SecurityGroups',
66+
null,
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+
null,
73+
InputOption::VALUE_REQUIRED,
74+
'The user data to make available to the launched Amazon EC2 instances'
75+
)
76+
->AddOption(
77+
'InstanceId',
78+
null,
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+
null,
85+
InputOption::VALUE_REQUIRED,
86+
'The instance type of the Amazon EC2 instance'
87+
)
88+
->AddOption(
89+
'KernelId',
90+
null,
91+
InputOption::VALUE_REQUIRED,
92+
'The ID of the kernel associated with the Amazon EC2 AMI'
93+
)
94+
->AddOption(
95+
'RamdiskId',
96+
null,
97+
InputOption::VALUE_REQUIRED,
98+
'The ID of the RAM disk associated with the Amazon EC2 AMI'
99+
)
100+
->AddOption(
101+
'BlockDeviceMappings',
102+
null,
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+
null,
109+
InputOption::VALUE_REQUIRED,
110+
'Enables detailed monitoring if it is disabled. true/false'
111+
)
112+
->AddOption(
113+
'SpotPrice',
114+
null,
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: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
* Update AutoScaling Group Command
33+
*
34+
* @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.AutoScaling.AutoScalingClient.html#_updateAutoScalingGroup
35+
* @author Mauricio Walters <mwalters@undergroundelephant.com>
36+
*/
37+
class UpdateAutoScalingGroupCommand extends AutoScalingCommand {
38+
protected function configure()
39+
{
40+
$this
41+
->setName('uecode:aws:autoscaling:updateautoscalinggroup')
42+
->setDescription('Updates the configuration for the specified AutoScalingGroup')
43+
->addArgument(
44+
'AutoScalingGroupName',
45+
InputArgument::REQUIRED,
46+
'The name of the Auto Scaling group'
47+
)
48+
->addOption(
49+
'LaunchConfigurationName',
50+
null,
51+
InputOption::VALUE_REQUIRED,
52+
'The name of the launch configuration'
53+
)
54+
->addOption(
55+
'MinSize',
56+
null,
57+
InputOption::VALUE_REQUIRED,
58+
'The minimum size of the Auto Scaling group'
59+
)
60+
->addOption(
61+
'MaxSize',
62+
null,
63+
InputOption::VALUE_REQUIRED,
64+
'The maximum size of the Auto Scaling group'
65+
)
66+
->addOption(
67+
'DesiredCapacity',
68+
null,
69+
InputOption::VALUE_REQUIRED,
70+
'The desired capacity for the Auto Scaling group'
71+
)
72+
->addOption(
73+
'DefaultCooldown',
74+
null,
75+
InputOption::VALUE_REQUIRED,
76+
'The amount of time, in seconds, after a scaling activity completes
77+
before any further scaling activities can start'
78+
)
79+
->addOption(
80+
'AvailabilityZones',
81+
null,
82+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
83+
'Availability Zones for the group'
84+
)
85+
->addOption(
86+
'HealthCheckType',
87+
null,
88+
InputOption::VALUE_REQUIRED,
89+
'The type of health check for the instances in the Auto Scaling group'
90+
)
91+
->addOption(
92+
'HealthCheckGracePeriod',
93+
null,
94+
InputOption::VALUE_REQUIRED,
95+
'The length of time that Auto Scaling waits before checking an instance\'s health status'
96+
)
97+
->addOption(
98+
'PlacementGroup',
99+
null,
100+
InputOption::VALUE_REQUIRED,
101+
'The name of the cluster placement group, if applicable'
102+
)
103+
->addOption(
104+
'VPCZoneIdentifier',
105+
null,
106+
InputOption::VALUE_REQUIRED,
107+
'The subnet identifier for the Amazon VPC connection, if applicable.
108+
You can specify several subnets in a comma-separated list'
109+
)
110+
->addOption(
111+
'TerminationPolicies',
112+
null,
113+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
114+
'A standalone termination policy or a list of termination policies
115+
used to select the instance to terminate'
116+
)
117+
;
118+
}
119+
120+
protected function execute(InputInterface $input, OutputInterface $output)
121+
{
122+
$options = array_merge($input->getArguments(), $input->getOptions());
123+
124+
var_dump($options);
125+
126+
$this->getClient()->updateAutoScalingGroup($options);
127+
128+
return self::COMMAND_SUCCESS;
129+
}
130+
}

0 commit comments

Comments
 (0)