Skip to content

Commit 7343c47

Browse files
committed
address todo about returning more than one image on collection
1 parent a492e47 commit 7343c47

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

Aws/AbstractAwsCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
*/
3030
abstract class AbstractAwsCommand extends ContainerAwareCommand
3131
{
32+
const COMMAND_SUCCESS = 0;
33+
const COMMAND_FAILURE = 1;
34+
3235
/**
3336
* Authenticate with AWS and instantiate client
3437
*

Command/Aws/Ec2/DeregisterImageCommand.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
6161
if ($options['AmiName']) {
6262
$name = $options['ImageId'];
6363
$image = $client->describeImages(
64-
["Filters" => [["Name" => "name", "Values" => [$name]]]]
64+
[
65+
"Filters" => [
66+
[
67+
"Name" => "name", "Values" => [$name]
68+
]
69+
]
70+
]
6571
);
66-
$imageId = $image['Images'][0]['ImageId'];
72+
$imageCollection = $image['Images'];
73+
$imageId = $imageCollection[0]['ImageId'];
74+
if (count($imageCollection) > 1) {
75+
$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>');
76+
77+
return self::COMMAND_FAILURE;
78+
}
6779
$options['ImageId'] = $imageId;
6880
}
6981

70-
$result = $client->deregisterImage($options);
82+
$client->deregisterImage($options);
83+
84+
$output->writeln(sprintf('<info>Successfully deregistered image %s.</info>', $options['ImageId']));
85+
86+
return self::COMMAND_SUCCESS;
7187
}
7288
}

0 commit comments

Comments
 (0)