Skip to content

Commit

Permalink
Merge pull request #9 from nVitius/autoscaling
Browse files Browse the repository at this point in the history
AutoScaling
  • Loading branch information
Mauricio Walters committed May 13, 2014
2 parents 3a2624b + b0c3a73 commit cae1add
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 36 deletions.
3 changes: 1 addition & 2 deletions Aws/AbstractAwsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ abstract class AbstractAwsCommand extends ContainerAwareCommand
* Authenticate with AWS and instantiate client
*
* @abstract
* @return Client
*/
abstract protected function getClient();

/**
* Get AWS API credentials from parameters.yml
*
*
* @return array
*/
protected function getCredentials()
Expand Down
51 changes: 51 additions & 0 deletions Aws/AutoScalingCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* Copyright 2014 Underground Elephant
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package aws-cli-bundle
* @copyright (c) 2014 Underground Elephant
* @license Apache License, Version 2.0
*/

namespace Uecode\Bundle\AwsCliBundle\Aws;

use Aws\AutoScaling\AutoScalingClient;

/**
* Authenticates with AWS for use with AutoScaling commands
*
* @author Mauricio Walters <mwalters@undergroundelephant.com>
*/
class AutoScalingCommand extends AbstractAwsCommand
{
/**
* Instantiates a new AutoScaling Client
*
* @return AutoScalingClient
*/
protected function getClient()
{
$credentials = $this->getCredentials();

$client = AutoScalingClient::factory(array(
'key' => $credentials['aws_api_key'],
'secret' => $credentials['aws_api_secret'],
'region' => $credentials['aws_region'],
));

return $client;
}
}
2 changes: 1 addition & 1 deletion Aws/Ec2Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Authenticates with AWS for use with EC2 commands
*
* @author Mauricio Walters <mwalters@undergroundelephant.com>
* @author Mauricio Walters <mwalters@undergroundelephant.com>
*/
class Ec2Command extends AbstractAwsCommand
{
Expand Down
138 changes: 138 additions & 0 deletions Command/Aws/AutoScaling/CreateLaunchConfigurationCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

/**
* Copyright 2014 Underground Elephant
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package aws-cli-bundle
* @copyright (c) 2014 Underground Elephant
* @license Apache License, Version 2.0
*/

namespace Uecode\Bundle\AwsCliBundle\Command\Aws\AutoScaling;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Uecode\Bundle\AwsCliBundle\Aws\AutoScalingCommand;

/**
* Create Launch Configuration Command
*
* @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.AutoScaling.AutoScalingClient.html#_createLaunchConfiguration
* @author Mauricio Walters <mwalters@undergroundelephant.com>
*/
class CreateLaunchConfigurationCommand extends AutoScalingCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
$this
->setName('uecode:aws:autoscaling:createlaunchconfiguration')
->setDescription('Creates a new launch configuration.')
->AddArgument(
'LaunchConfigurationName',
InputArgument::REQUIRED,
'The name of the launch configuration to create'
)
->AddOption(
'ImageId',
null,
InputOption::VALUE_REQUIRED,
'Unique ID of the Amazon Machine Image (AMI) you want to use to launch your EC2 instances'
)
->AddOption(
'KeyName',
null,
InputOption::VALUE_REQUIRED,
'The name of the Amazon EC2 key pair'
)
->AddOption(
'SecurityGroups',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'The security groups with which to associate Amazon EC2 or Amazon VPC instances.'
)
->AddOption(
'UserData',
null,
InputOption::VALUE_REQUIRED,
'The user data to make available to the launched Amazon EC2 instances'
)
->AddOption(
'InstanceId',
null,
InputOption::VALUE_REQUIRED,
'The ID of the Amazon EC2 instance you want to use to create the launch configuration'
)
->AddOption(
'InstanceType',
null,
InputOption::VALUE_REQUIRED,
'The instance type of the Amazon EC2 instance'
)
->AddOption(
'KernelId',
null,
InputOption::VALUE_REQUIRED,
'The ID of the kernel associated with the Amazon EC2 AMI'
)
->AddOption(
'RamdiskId',
null,
InputOption::VALUE_REQUIRED,
'The ID of the RAM disk associated with the Amazon EC2 AMI'
)
->AddOption(
'BlockDeviceMappings',
null,
InputOption::VALUE_REQUIRED,
'A list of mappings that specify how block devices are exposed to the instance. Takes JSON'
)
->AddOption(
'InstanceMonitoring',
null,
InputOption::VALUE_REQUIRED,
'Enables detailed monitoring if it is disabled. true/false'
)
->AddOption(
'SpotPrice',
null,
InputOption::VALUE_REQUIRED,
'The maximum hourly price to be paid for any Spot Instance launched to fulfill the request'
);
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$options = array_merge($input->getArguments(), $input->getOptions());

$options['BlockDeviceMappings'] = json_decode($options['BlockDeviceMappings']);
if ($options['InstanceMonitoring'] == "true") {
$options['InstanceMonitoring'] = ['Enabled' => true];
} else {
unset($options['InstanceMonitoring']);
}

$this->getClient()->createLaunchConfiguration($options);

return self::COMMAND_SUCCESS;
}
}
130 changes: 130 additions & 0 deletions Command/Aws/AutoScaling/UpdateAutoScalingGroupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

/**
* Copyright 2014 Underground Elephant
*t
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package aws-cli-bundle
* @copyright (c) 2014 Underground Elephant
* @license Apache License, Version 2.0
*/

namespace Uecode\Bundle\AwsCliBundle\Command\Aws\AutoScaling;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Uecode\Bundle\AwsCliBundle\Aws\AutoScalingCommand;

/**
* Update AutoScaling Group Command
*
* @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.AutoScaling.AutoScalingClient.html#_updateAutoScalingGroup
* @author Mauricio Walters <mwalters@undergroundelephant.com>
*/
class UpdateAutoScalingGroupCommand extends AutoScalingCommand {
protected function configure()
{
$this
->setName('uecode:aws:autoscaling:updateautoscalinggroup')
->setDescription('Updates the configuration for the specified AutoScalingGroup')
->addArgument(
'AutoScalingGroupName',
InputArgument::REQUIRED,
'The name of the Auto Scaling group'
)
->addOption(
'LaunchConfigurationName',
null,
InputOption::VALUE_REQUIRED,
'The name of the launch configuration'
)
->addOption(
'MinSize',
null,
InputOption::VALUE_REQUIRED,
'The minimum size of the Auto Scaling group'
)
->addOption(
'MaxSize',
null,
InputOption::VALUE_REQUIRED,
'The maximum size of the Auto Scaling group'
)
->addOption(
'DesiredCapacity',
null,
InputOption::VALUE_REQUIRED,
'The desired capacity for the Auto Scaling group'
)
->addOption(
'DefaultCooldown',
null,
InputOption::VALUE_REQUIRED,
'The amount of time, in seconds, after a scaling activity completes
before any further scaling activities can start'
)
->addOption(
'AvailabilityZones',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Availability Zones for the group'
)
->addOption(
'HealthCheckType',
null,
InputOption::VALUE_REQUIRED,
'The type of health check for the instances in the Auto Scaling group'
)
->addOption(
'HealthCheckGracePeriod',
null,
InputOption::VALUE_REQUIRED,
'The length of time that Auto Scaling waits before checking an instance\'s health status'
)
->addOption(
'PlacementGroup',
null,
InputOption::VALUE_REQUIRED,
'The name of the cluster placement group, if applicable'
)
->addOption(
'VPCZoneIdentifier',
null,
InputOption::VALUE_REQUIRED,
'The subnet identifier for the Amazon VPC connection, if applicable.
You can specify several subnets in a comma-separated list'
)
->addOption(
'TerminationPolicies',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'A standalone termination policy or a list of termination policies
used to select the instance to terminate'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$options = array_merge($input->getArguments(), $input->getOptions());

var_dump($options);

$this->getClient()->updateAutoScalingGroup($options);

return self::COMMAND_SUCCESS;
}
}
Loading

0 comments on commit cae1add

Please sign in to comment.