diff --git a/Aws/AbstractAwsCommand.php b/Aws/AbstractAwsCommand.php index 63eaac1..c1c0eca 100755 --- a/Aws/AbstractAwsCommand.php +++ b/Aws/AbstractAwsCommand.php @@ -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() diff --git a/Aws/AutoScalingCommand.php b/Aws/AutoScalingCommand.php new file mode 100644 index 0000000..8537518 --- /dev/null +++ b/Aws/AutoScalingCommand.php @@ -0,0 +1,51 @@ + + */ +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; + } +} diff --git a/Aws/Ec2Command.php b/Aws/Ec2Command.php index ba8695d..8b92245 100755 --- a/Aws/Ec2Command.php +++ b/Aws/Ec2Command.php @@ -27,7 +27,7 @@ /** * Authenticates with AWS for use with EC2 commands * - * @author Mauricio Walters + * @author Mauricio Walters */ class Ec2Command extends AbstractAwsCommand { diff --git a/Command/Aws/AutoScaling/CreateLaunchConfigurationCommand.php b/Command/Aws/AutoScaling/CreateLaunchConfigurationCommand.php new file mode 100644 index 0000000..5e43c09 --- /dev/null +++ b/Command/Aws/AutoScaling/CreateLaunchConfigurationCommand.php @@ -0,0 +1,138 @@ + + */ +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; + } +} diff --git a/Command/Aws/AutoScaling/UpdateAutoScalingGroupCommand.php b/Command/Aws/AutoScaling/UpdateAutoScalingGroupCommand.php new file mode 100644 index 0000000..75d0aaa --- /dev/null +++ b/Command/Aws/AutoScaling/UpdateAutoScalingGroupCommand.php @@ -0,0 +1,130 @@ + + */ +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; + } +} diff --git a/Command/Aws/Ec2/CreateImageCommand.php b/Command/Aws/Ec2/CreateImageCommand.php index 9b6b60f..c2ba7ec 100755 --- a/Command/Aws/Ec2/CreateImageCommand.php +++ b/Command/Aws/Ec2/CreateImageCommand.php @@ -1,24 +1,24 @@ + * + * @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.Ec2.Ec2Client.html#_createImage + * @author Mauricio Walters */ class CreateImageCommand extends Ec2Command { @@ -43,14 +43,41 @@ protected function configure() { $this ->setName('uecode:aws:ec2:createimage') - ->setDescription('Creates an Amazon EBS-backed AMI from an Amazon EBS-backed instance that is either running or stopped.') - ->addArgument('Name', InputArgument::REQUIRED, 'A name for the new image.') - ->addArgument('InstanceId', InputArgument::REQUIRED, 'The ID of the instance') - ->addArgument('Description', InputArgument::OPTIONAL, 'A description for the new image.') - ->addOption('BlockDeviceMappings', 'mappings', InputOption::VALUE_OPTIONAL, 'Information about one or more block device mappings. Takes JSON.') - ->addOption('NoReboot', 'noreboot', InputOption::VALUE_NONE, 'Amazon EC2 will not shut down the instance before creating the image. Filesystem integrity is not guaranteed.') - ->addOption('DryRun', 'dryrun', InputOption::VALUE_NONE, null) - ; + ->setDescription('Creates an Amazon EBS-backed AMI from an EBS-backed instance.') + ->addArgument( + 'Name', + InputArgument::REQUIRED, + 'A name for the new image.' + ) + ->addArgument( + 'InstanceId', + InputArgument::REQUIRED, + 'The ID of the instance' + ) + ->addArgument( + 'Description', + InputArgument::OPTIONAL, + 'A description for the new image.' + ) + ->addOption( + 'BlockDeviceMappings', + 'mappings', + InputOption::VALUE_OPTIONAL, + 'Information about one or more block device mappings. Takes JSON.' + ) + ->addOption( + 'NoReboot', + 'noreboot', + InputOption::VALUE_NONE, + 'Amazon EC2 will not shut down the instance before creating the image. + Filesystem integrity is not guaranteed.' + ) + ->addOption( + 'DryRun', + 'dryrun', + InputOption::VALUE_NONE, + null + ); } /** @@ -62,9 +89,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $options['BlockDeviceMappings'] = json_decode($options['BlockDeviceMappings']); - $client = $this->getClient(); - $result = $client->createImage($options); - $output->writeln('AMI Image created with id '.$result->get('ImageId')); + $result = $this->getClient()->createImage($options); + $output->writeln('AMI Image created with id ' . $result->get('ImageId')); return self::COMMAND_SUCCESS; } diff --git a/Command/Aws/Ec2/DeregisterImageCommand.php b/Command/Aws/Ec2/DeregisterImageCommand.php index 2468fa7..a343278 100755 --- a/Command/Aws/Ec2/DeregisterImageCommand.php +++ b/Command/Aws/Ec2/DeregisterImageCommand.php @@ -32,7 +32,7 @@ * Deregister Image command * * @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.Ec2.Ec2Client.html#_deregisterImage - * @author Mauricio Walters + * @author Mauricio Walters */ class DeregisterImageCommand extends Ec2Command { diff --git a/composer.json b/composer.json index 6963282..d8e5bef 100755 --- a/composer.json +++ b/composer.json @@ -14,5 +14,9 @@ }, "require": { "aws/aws-sdk-php": "2.6.*" + }, + "require-dev": { + "symfony/console": "~2.4.0", + "symfony/framework-bundle": "~2.4.0" } }