|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | +* Copyright 2014 Underground Elephant |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +* |
| 18 | +* @package aws-cli-bundle |
| 19 | +* @copyright (c) 2014 Underground Elephant |
| 20 | +* @license Apache License, Version 2.0 |
| 21 | +*/ |
| 22 | + |
| 23 | +namespace Uecode\Bundle\AwsCliBundle\Command\Aws\Ec2; |
| 24 | + |
| 25 | +use Symfony\Component\Console\Input\InputArgument; |
| 26 | +use Symfony\Component\Console\Input\InputOption; |
| 27 | +use Symfony\Component\Console\Input\InputInterface; |
| 28 | +use Symfony\Component\Console\Output\OutputInterface; |
| 29 | +use Uecode\Bundle\AwsCliBundle\Aws\Ec2Command; |
| 30 | + |
| 31 | +/** |
| 32 | + * Copy Image command |
| 33 | + * |
| 34 | + * @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.Ec2.Ec2Client.html#_copyImage |
| 35 | + * @author Mauricio Walters <mwalters@undergroundelephant.com> |
| 36 | + */ |
| 37 | +class CopyImageCommand extends Ec2Command |
| 38 | +{ |
| 39 | + /** |
| 40 | + * {@inheritDoc} |
| 41 | + */ |
| 42 | + protected function configure() |
| 43 | + { |
| 44 | + $this |
| 45 | + ->setName('uecode:aws:ec2:copyimage') |
| 46 | + ->setDescription('Initiates the copy of an AMI from the specified source region to the region in which the request was made.') |
| 47 | + ->addArgument('SourceRegion', InputArgument::REQUIRED, 'The name of the region that contains the AMI to copy') |
| 48 | + ->addArgument('SourceImageId', InputArgument::REQUIRED, 'The ID of the AMI to copy') |
| 49 | + ->addArgument('Name', InputArgument::REQUIRED, 'The name of the new AMI in the destination region') |
| 50 | + ->addOption('Description', 'description', InputOption::VALUE_OPTIONAL, 'A description for the new AMI in the destination region') |
| 51 | + ->addOption('ClientToken', 'clienttoken', InputOption::VALUE_OPTIONAL, 'Unique, case-sensitive identifier you provide to ensure the idempotency of the request') |
| 52 | + ->addOption('DryRun', 'dryrun', InputOption::VALUE_NONE, null) |
| 53 | + ->addOption('AmiName', 'aminame', InputOption::VALUE_NONE, 'Use AMI name instead if ID'); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * {@inheritDoc} |
| 58 | + */ |
| 59 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 60 | + { |
| 61 | + $options = array_merge($input->getArguments(), $input->getOptions()); |
| 62 | + |
| 63 | + $client = $this->getClient(); |
| 64 | + |
| 65 | + if ($options['AmiName']) { |
| 66 | + $name = $options['SourceImageId']; |
| 67 | + $image = $client->describeImages(["Filters" => [["Name" => "name", "Values" => [$name]]]]); # TODO if more than one instance is returned, warn the user |
| 68 | + $sourceImageId = $image['Images'][0]['ImageId']; |
| 69 | + $options['SourceImageId'] = $sourceImageId; |
| 70 | + } |
| 71 | + |
| 72 | + $result = $client->copyImage($options); |
| 73 | + } |
| 74 | +} |
0 commit comments