Skip to content

Commit

Permalink
Merge pull request #5 from cordoval/5-cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
Mauricio Walters committed May 6, 2014
2 parents 62f4fb3 + 370d214 commit 3a2624b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 64 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor
/composer.lock
3 changes: 2 additions & 1 deletion Aws/AbstractAwsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@

/**
* @author Mauricio Walters <mwalters@undergroundelephant.com>
* @abstract
*/
abstract class AbstractAwsCommand extends ContainerAwareCommand
{
const COMMAND_SUCCESS = 0;
const COMMAND_FAILURE = 1;

/**
* Authenticate with AWS and instantiate client
Expand Down
14 changes: 7 additions & 7 deletions Aws/Ec2Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ protected function getClient()
{
$credentials = $this->getCredentials();

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

return $client;
return Ec2Client::factory(
array(
'key' => $credentials['aws_api_key'],
'secret' => $credentials['aws_api_secret'],
'region' => $credentials['aws_region'],
)
);
}
}
28 changes: 23 additions & 5 deletions Command/Aws/Ec2/CopyImageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ protected function configure()
->addOption('Description', 'description', InputOption::VALUE_OPTIONAL, 'A description for the new AMI in the destination region')
->addOption('ClientToken', 'clienttoken', InputOption::VALUE_OPTIONAL, 'Unique, case-sensitive identifier you provide to ensure the idempotency of the request')
->addOption('DryRun', 'dryrun', InputOption::VALUE_NONE, null)
->addOption('AmiName', 'aminame', InputOption::VALUE_NONE, 'Use AMI name instead if ID');
->addOption('AmiName', 'aminame', InputOption::VALUE_NONE, 'Use AMI name instead of ID')
;
}

/**
Expand All @@ -64,12 +65,29 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($options['AmiName']) {
$name = $options['SourceImageId'];
$image = $client->describeImages(["Filters" => [["Name" => "name", "Values" => [$name]]]]); # TODO if more than one instance is returned, warn the user
$sourceImageId = $image['Images'][0]['ImageId'];
$options['SourceImageId'] = $sourceImageId;
$image = $client->describeImages(
[
"Filters" => [
[
"Name" => "name",
"Values" => [$name]
]
]
]
);
$imageCollection = $image['Images'];
if (count($imageCollection) > 1) {
$output->writeln('<error>Know that the AMI name provided matched more than one image. Please be more specific to avoid copying the wrong image.</error>');

return self::COMMAND_FAILURE;
}

$options['SourceImageId'] = $imageCollection[0]['ImageId'];
}

$result = $client->copyImage($options);
$output->writeln($result->get('ImageId'));
$output->writeln(sprintf('<info>Successfully copied image %s.</info>', $result->get('ImageId')));

return self::COMMAND_SUCCESS;
}
}
10 changes: 6 additions & 4 deletions Command/Aws/Ec2/CreateImageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ protected function configure()
->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('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);
->addOption('DryRun', 'dryrun', InputOption::VALUE_NONE, null)
;
}

/**
Expand All @@ -62,8 +63,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$options['BlockDeviceMappings'] = json_decode($options['BlockDeviceMappings']);

$client = $this->getClient();

$result = $client->createImage($options);
$output->writeln($result->get('ImageId'));
$output->writeln('AMI Image created with id '.$result->get('ImageId'));

return self::COMMAND_SUCCESS;
}
}
26 changes: 22 additions & 4 deletions Command/Aws/Ec2/DeregisterImageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,29 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($options['AmiName']) {
$name = $options['ImageId'];
$image = $client->describeImages(["Filters" => [["Name" => "name", "Values" => [$name]]]]); # TODO if more than one instance is returned, warn the user
$imageId = $image['Images'][0]['ImageId'];
$options['ImageId'] = $imageId;
$image = $client->describeImages(
[
"Filters" => [
[
"Name" => "name", "Values" => [$name]
]
]
]
);
$imageCollection = $image['Images'];
if (count($imageCollection) > 1) {
$output->writeln('<error>Know that the AMI name provided matched more than one image. Please be more specific to avoid deregistering the wrong image.</error>');

return self::COMMAND_FAILURE;
}

$options['ImageId'] = $imageCollection[0]['ImageId'];
}

$result = $client->deregisterImage($options);
$client->deregisterImage($options);

$output->writeln(sprintf('<info>Successfully deregistered image %s.</info>', $options['ImageId']));

return self::COMMAND_SUCCESS;
}
}
29 changes: 0 additions & 29 deletions DependencyInjection/Configuration.php

This file was deleted.

9 changes: 2 additions & 7 deletions DependencyInjection/UecodeAwsCliExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Uecode\Bundle\AwsCliBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration
Expand All @@ -19,10 +19,5 @@ class UecodeAwsCliExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
7 changes: 0 additions & 7 deletions Resources/config/services.yml

This file was deleted.

0 comments on commit 3a2624b

Please sign in to comment.