Skip to content

Commit 370d214

Browse files
committed
adjustments various
1 parent 7343c47 commit 370d214

4 files changed

Lines changed: 37 additions & 18 deletions

File tree

Aws/Ec2Command.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ protected function getClient()
4040
{
4141
$credentials = $this->getCredentials();
4242

43-
$client = Ec2Client::factory(array(
44-
'key' => $credentials['aws_api_key'],
45-
'secret' => $credentials['aws_api_secret'],
46-
'region' => $credentials['aws_region'],
47-
));
48-
49-
return $client;
43+
return Ec2Client::factory(
44+
array(
45+
'key' => $credentials['aws_api_key'],
46+
'secret' => $credentials['aws_api_secret'],
47+
'region' => $credentials['aws_region'],
48+
)
49+
);
5050
}
5151
}

Command/Aws/Ec2/CopyImageCommand.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function configure()
5050
->addOption('Description', 'description', InputOption::VALUE_OPTIONAL, 'A description for the new AMI in the destination region')
5151
->addOption('ClientToken', 'clienttoken', InputOption::VALUE_OPTIONAL, 'Unique, case-sensitive identifier you provide to ensure the idempotency of the request')
5252
->addOption('DryRun', 'dryrun', InputOption::VALUE_NONE, null)
53-
->addOption('AmiName', 'aminame', InputOption::VALUE_NONE, 'Use AMI name instead if ID')
53+
->addOption('AmiName', 'aminame', InputOption::VALUE_NONE, 'Use AMI name instead of ID')
5454
;
5555
}
5656

@@ -65,12 +65,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
6565

6666
if ($options['AmiName']) {
6767
$name = $options['SourceImageId'];
68-
$image = $client->describeImages(["Filters" => [["Name" => "name", "Values" => [$name]]]]); # TODO if more than one instance is returned, warn the user
69-
$sourceImageId = $image['Images'][0]['ImageId'];
70-
$options['SourceImageId'] = $sourceImageId;
68+
$image = $client->describeImages(
69+
[
70+
"Filters" => [
71+
[
72+
"Name" => "name",
73+
"Values" => [$name]
74+
]
75+
]
76+
]
77+
);
78+
$imageCollection = $image['Images'];
79+
if (count($imageCollection) > 1) {
80+
$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>');
81+
82+
return self::COMMAND_FAILURE;
83+
}
84+
85+
$options['SourceImageId'] = $imageCollection[0]['ImageId'];
7186
}
7287

7388
$result = $client->copyImage($options);
74-
$output->writeln($result->get('ImageId'));
89+
$output->writeln(sprintf('<info>Successfully copied image %s.</info>', $result->get('ImageId')));
90+
91+
return self::COMMAND_SUCCESS;
7592
}
7693
}

Command/Aws/Ec2/CreateImageCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ protected function configure()
4747
->addArgument('Name', InputArgument::REQUIRED, 'A name for the new image.')
4848
->addArgument('InstanceId', InputArgument::REQUIRED, 'The ID of the instance')
4949
->addArgument('Description', InputArgument::OPTIONAL, 'A description for the new image.')
50-
->addOption('BlockDeviceMappings', 'mappings', InputOption::VALUE_OPTIONAL, 'Information about one or more block device mappings. Takes JSON')
50+
->addOption('BlockDeviceMappings', 'mappings', InputOption::VALUE_OPTIONAL, 'Information about one or more block device mappings. Takes JSON.')
5151
->addOption('NoReboot', 'noreboot', InputOption::VALUE_NONE, 'Amazon EC2 will not shut down the instance before creating the image. Filesystem integrity is not guaranteed.')
52-
->addOption('DryRun', 'dryrun', InputOption::VALUE_NONE, null);
52+
->addOption('DryRun', 'dryrun', InputOption::VALUE_NONE, null)
53+
;
5354
}
5455

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

6465
$client = $this->getClient();
65-
6666
$result = $client->createImage($options);
67-
$output->writeln($result->get('ImageId'));
67+
$output->writeln('AMI Image created with id '.$result->get('ImageId'));
68+
69+
return self::COMMAND_SUCCESS;
6870
}
6971
}

Command/Aws/Ec2/DeregisterImageCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
7070
]
7171
);
7272
$imageCollection = $image['Images'];
73-
$imageId = $imageCollection[0]['ImageId'];
7473
if (count($imageCollection) > 1) {
7574
$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>');
7675

7776
return self::COMMAND_FAILURE;
7877
}
79-
$options['ImageId'] = $imageId;
78+
79+
$options['ImageId'] = $imageCollection[0]['ImageId'];
8080
}
8181

8282
$client->deregisterImage($options);

0 commit comments

Comments
 (0)