-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from nVitius/autoscaling
AutoScaling
- Loading branch information
Showing
8 changed files
with
384 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
Command/Aws/AutoScaling/CreateLaunchConfigurationCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
130
Command/Aws/AutoScaling/UpdateAutoScalingGroupCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.