diff --git a/CHANGELOG.md b/CHANGELOG.md index 3deaadc..71a719e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +6.32.0 +----- +* Added block storage commands. Deprecated big storage methods. + 6.31.0 ----- * Added ssh key support to rescue images diff --git a/composer.json b/composer.json index e128b45..e35b5ba 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "symfony/console": "^5.4", "symfony/finder": "^5.4", "symfony/filesystem": "^5.4", - "transip/transip-api-php": "^6.45", + "transip/transip-api-php": "^6.48", "symfony/yaml": "^5.4" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 3f8eea6..2828a74 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5e0f22c2a148cc455de68312a66f7dc7", + "content-hash": "2101f4d7a708b8ee48184be6bf50aa94", "packages": [ { "name": "clue/stream-filter", @@ -2427,16 +2427,16 @@ }, { "name": "transip/transip-api-php", - "version": "6.45.0", + "version": "6.48.4", "source": { "type": "git", "url": "https://github.com/transip/transip-api-php.git", - "reference": "76011e180720754c8dde0fb8c423d7c332d737ac" + "reference": "36db6bc7722c1d5d5c05c42965290cfbadfb154b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/transip/transip-api-php/zipball/76011e180720754c8dde0fb8c423d7c332d737ac", - "reference": "76011e180720754c8dde0fb8c423d7c332d737ac", + "url": "https://api.github.com/repos/transip/transip-api-php/zipball/36db6bc7722c1d5d5c05c42965290cfbadfb154b", + "reference": "36db6bc7722c1d5d5c05c42965290cfbadfb154b", "shasum": "" }, "require": { @@ -2480,9 +2480,9 @@ "description": "TransIP Rest API Library", "support": { "issues": "https://github.com/transip/transip-api-php/issues", - "source": "https://github.com/transip/transip-api-php/tree/6.45.0" + "source": "https://github.com/transip/transip-api-php/tree/6.48.4" }, - "time": "2023-08-02T14:46:47+00:00" + "time": "2023-10-06T11:25:09+00:00" } ], "packages-dev": [ @@ -3657,5 +3657,5 @@ "platform-overrides": { "php": "7.2.5" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index fdb8dd5..e159692 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Transip\Api\CLI\Command\Setup\Setup; use Transip\Api\CLI\ConsoleOutput\Interfaces\OutputInterface as ConsoleOutputInterface; use Transip\Api\CLI\ConsoleOutput\OutputFactory; @@ -31,6 +32,9 @@ abstract class AbstractCommand extends Command */ private $output; + /** @var SymfonyStyle */ + private $io; + public function __construct(string $name = null) { parent::__construct($name); @@ -90,6 +94,8 @@ protected function initialize(InputInterface $input, OutputInterface $output): v $formatter = $helperSet->get('formatter'); $settings->ensureConfigFileIsReadOnly($formatter, $output); + + $this->io = new SymfonyStyle($input, $output); } $this->input = $input; @@ -114,6 +120,11 @@ protected function output($data): void $this->output->writeln($formattedOutput); } + protected function warning(string $message): void + { + $this->io->getErrorStyle()->warning($message); + } + private function getFormatterFromInput(): ConsoleOutputInterface { $formatType = $this->input->getOption(Field::FORMAT); diff --git a/src/Command/BigStorage/AttachVps.php b/src/Command/BigStorage/AttachVps.php index 516ae07..0ece843 100644 --- a/src/Command/BigStorage/AttachVps.php +++ b/src/Command/BigStorage/AttachVps.php @@ -20,11 +20,12 @@ protected function configure(): void ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC) ->addArgument(Field::VPS_NAME, InputArgument::REQUIRED, 'Name of the vps that the big storage should attach to.') ->addOption(Field::ACTION_WAIT, 'w', InputOption::VALUE_NONE, Field::ACTION_WAIT_DESC) - ->setHelp('This command will attach your big storage to your vps.'); + ->setHelp('This command will attach your big storage to your vps. [deprecated] Use blockstorage:attachvps instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:attachvps instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); $bigStorageVpsName = $input->getArgument(Field::VPS_NAME); $waitForAction = $input->getOption(Field::ACTION_WAIT); diff --git a/src/Command/BigStorage/Backup/GetByBigStorageName.php b/src/Command/BigStorage/Backup/GetByBigStorageName.php index 13fdd79..5614822 100644 --- a/src/Command/BigStorage/Backup/GetByBigStorageName.php +++ b/src/Command/BigStorage/Backup/GetByBigStorageName.php @@ -16,11 +16,12 @@ protected function configure(): void $this->setName('bigstorage:backup:getbybigstoragename') ->setDescription('Get a list of backups for a big storage') ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC) - ->setHelp('This command lists backups for any given big storage.'); + ->setHelp('This command lists backups for any given big storage. [deprecated] Use blockstorage:backup:getbyblockstoragename instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:backup:getbyblockstoragename instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); $vps = $this->getTransipApi()->bigStorageBackups()->getByBigStorageName($bigStorageName); $this->output($vps); diff --git a/src/Command/BigStorage/Backup/Revert.php b/src/Command/BigStorage/Backup/Revert.php index 2792d73..e5c7827 100644 --- a/src/Command/BigStorage/Backup/Revert.php +++ b/src/Command/BigStorage/Backup/Revert.php @@ -21,11 +21,12 @@ protected function configure(): void ->addArgument(Field::BIGSTORAGE_BACKUP_DESTINATION_NAME, InputArgument::OPTIONAL, Field::BIGSTORAGE_BACKUP_DESTINATION_NAME__DESC . Field::OPTIONAL) ->addOption(Field::ACTION_WAIT, 'w', InputOption::VALUE_NONE, Field::ACTION_WAIT_DESC) ->addOption(Field::ACTION_PROGRESS, 'p', InputOption::VALUE_NONE, Field::ACTION_PROGRESS_DESC) - ->setHelp('This command restores a big storage backup.'); + ->setHelp('This command restores a big storage backup. [deprecated] Use blockstorage:backup:revert instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:backup:revert instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); $bigStorageBackupId = $input->getArgument(Field::BIGSTORAGE_BACKUPID); $destinationBigStorageName = $input->getArgument(Field::BIGSTORAGE_BACKUP_DESTINATION_NAME) ?? ''; diff --git a/src/Command/BigStorage/Cancel.php b/src/Command/BigStorage/Cancel.php index 4d510f6..196b7a4 100644 --- a/src/Command/BigStorage/Cancel.php +++ b/src/Command/BigStorage/Cancel.php @@ -18,11 +18,12 @@ protected function configure(): void ->setDescription('Terminate or cancel your big storage') ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC) ->addArgument(Field::CANCELTIME, InputArgument::REQUIRED, Field::CANCELTIME__DESC) - ->setHelp('This command will terminate or cancel your big storage.'); + ->setHelp('This command will terminate or cancel your big storage. [deprecated] Use blockstorage:cancel instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:cancel instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); if (strlen($bigStorageName) < 3) { throw new Exception('Invalid big storage name provided'); diff --git a/src/Command/BigStorage/DetachVps.php b/src/Command/BigStorage/DetachVps.php index f15913f..30ea066 100644 --- a/src/Command/BigStorage/DetachVps.php +++ b/src/Command/BigStorage/DetachVps.php @@ -19,11 +19,12 @@ protected function configure(): void ->setDescription('Detach your big storage to your vps') ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC) ->addOption(Field::ACTION_WAIT, 'w', InputOption::VALUE_NONE, Field::ACTION_WAIT_DESC) - ->setHelp('This command will detach your big storage from your vps.'); + ->setHelp('This command will detach your big storage from your vps. [deprecated] Use blockstorage:detachvps instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:detachvps instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); $waitForAction = $input->getOption(Field::ACTION_WAIT); diff --git a/src/Command/BigStorage/GetAll.php b/src/Command/BigStorage/GetAll.php index 9264cc2..ba83ccd 100644 --- a/src/Command/BigStorage/GetAll.php +++ b/src/Command/BigStorage/GetAll.php @@ -12,10 +12,12 @@ class GetAll extends AbstractCommand protected function configure(): void { $this->setName('bigstorage:getall') - ->setDescription('Get all of your big storages'); + ->setDescription('Get all of your big storages') + ->setHelp('This command will return all your big storages. [deprecated] Use blockstorage:getall instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:getall instead'); $bigStorages = $this->getTransipApi()->bigStorages()->getAll(); $this->output($bigStorages); diff --git a/src/Command/BigStorage/GetByName.php b/src/Command/BigStorage/GetByName.php index 895bdce..d5ccae4 100644 --- a/src/Command/BigStorage/GetByName.php +++ b/src/Command/BigStorage/GetByName.php @@ -14,11 +14,13 @@ protected function configure(): void { $this->setName('bigstorage:getbyname') ->setDescription('Get your big storage by name') - ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC); + ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC) + ->setHelp('This command will return the big storage by name. [deprecated] Use blockstorage:getbyname instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:getbyname instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); $bigStorage = $this->getTransipApi()->bigStorages()->getByName($bigStorageName); diff --git a/src/Command/BigStorage/GetUsage.php b/src/Command/BigStorage/GetUsage.php index 99815c4..5342637 100644 --- a/src/Command/BigStorage/GetUsage.php +++ b/src/Command/BigStorage/GetUsage.php @@ -17,11 +17,12 @@ protected function configure(): void ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC) ->addArgument(Field::BIGSTORAGE_STARTDATE, InputArgument::OPTIONAL, Field::BIGSTORAGE_STARTDATE__DESC . Field::OPTIONAL, 0) ->addArgument(Field::BIGSTORAGE_ENDDATE, InputArgument::OPTIONAL, Field::BIGSTORAGE_ENDDATE__DESC . Field::OPTIONAL, 0) - ->setHelp('This command allows you to retrieve usage statistics of a big storage. Start and end dates cannot be longer than a one month period.'); + ->setHelp('This command allows you to retrieve usage statistics of a big storage. Start and end dates cannot be longer than a one month period. [deprecated] Use blockstorage:getusage instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:getusage instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); $dateTimeStart = $input->getArgument(Field::BIGSTORAGE_STARTDATE); $dateTimeEnd = $input->getArgument(Field::BIGSTORAGE_ENDDATE); diff --git a/src/Command/BigStorage/Order.php b/src/Command/BigStorage/Order.php index e4b2307..eae1e00 100644 --- a/src/Command/BigStorage/Order.php +++ b/src/Command/BigStorage/Order.php @@ -23,11 +23,12 @@ protected function configure(): void ->addArgument(Field::VPS_NAME, InputArgument::OPTIONAL, Field::BIGSTORAGE_VPS_ATTACH__DESC . Field::OPTIONAL) ->addArgument(Field::BIGSTORAGE_DESCRIPTION, InputArgument::OPTIONAL, FIELD::BIGSTORAGE_DESCRIPTION__DESC . Field::OPTIONAL) ->addOption(Field::ACTION_WAIT, 'w', InputOption::VALUE_NONE, Field::ACTION_WAIT_DESC) - ->setHelp('This command allows you to order a new big storage'); + ->setHelp('This command allows you to order a new big storage. [deprecated] Use blockstorage:order instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:order instead'); $bigStorageSize = $input->getArgument(Field::BIGSTORAGE_SIZE); // Default must be true diff --git a/src/Command/BigStorage/SetDescription.php b/src/Command/BigStorage/SetDescription.php index a105e75..0f30613 100644 --- a/src/Command/BigStorage/SetDescription.php +++ b/src/Command/BigStorage/SetDescription.php @@ -16,11 +16,12 @@ protected function configure(): void ->setDescription('Update your big storage description') ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC) ->addArgument(Field::BIGSTORAGE_DESCRIPTION, InputArgument::REQUIRED, Field::BIGSTORAGE_DESCRIPTION__DESC) - ->setHelp('This command will change the description of your big storage'); + ->setHelp('This command will change the description of your big storage. [deprecated] Use blockstorage:setdescription instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:setdescription instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); $bigStorageDescription = $input->getArgument(Field::BIGSTORAGE_DESCRIPTION); diff --git a/src/Command/BigStorage/Upgrade.php b/src/Command/BigStorage/Upgrade.php index db5a6b5..adb43ae 100644 --- a/src/Command/BigStorage/Upgrade.php +++ b/src/Command/BigStorage/Upgrade.php @@ -17,11 +17,12 @@ protected function configure(): void ->addArgument(Field::BIGSTORAGE_NAME, InputArgument::REQUIRED, Field::BIGSTORAGE_NAME__DESC) ->addArgument(Field::BIGSTORAGE_SIZE, InputArgument::REQUIRED, Field::BIGSTORAGE_SIZE__DESC) ->addArgument(Field::BIGSTORAGE_HASOFFSITEBACKUPS, InputArgument::OPTIONAL, 'Whether to add offsite backups. (optional)') - ->setHelp('This command allows you to upgrade a big storage'); + ->setHelp('This command allows you to upgrade a big storage. [deprecated] Use blockstorage:upgrade instead.'); } protected function execute(InputInterface $input, OutputInterface $output): int { + $this->warning('Deprecated: use blockstorage:upgrade instead'); $bigStorageName = $input->getArgument(Field::BIGSTORAGE_NAME); $bigStorageSize = $input->getArgument(Field::BIGSTORAGE_SIZE); diff --git a/src/Command/BlockStorage/AttachVps.php b/src/Command/BlockStorage/AttachVps.php new file mode 100644 index 0000000..3e07abd --- /dev/null +++ b/src/Command/BlockStorage/AttachVps.php @@ -0,0 +1,60 @@ +setName('blockstorage:attachvps') + ->setDescription('Attach your block storage to your vps') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC) + ->addArgument(Field::VPS_NAME, InputArgument::REQUIRED, 'Name of the vps that the block storage should attach to.') + ->addOption(Field::ACTION_WAIT, 'w', InputOption::VALUE_NONE, Field::ACTION_WAIT_DESC) + ->setHelp('This command will attach your block storage to your vps.'); + } + + /** + * @throws ExceptionInterface + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + $blockStorageVpsName = $input->getArgument(Field::VPS_NAME); + $waitForAction = $input->getOption(Field::ACTION_WAIT); + + $blockStorage = $this->getTransipApi()->blockStorages()->getByName($blockStorageName); + $blockStorage->setVpsName($blockStorageVpsName); + + $response = $this->getTransipApi()->blockStorages()->update($blockStorage); + $action = $this->getTransipApi()->actions()->parseActionFromResponse($response); + + if ($action && $waitForAction) { + $app = $this->getApplication(); + + if (!$app) { + return 0; + } + + $command = $app->get('action:pollstatus'); + + $arguments = [ + 'actionUuid' => $action->getUuid() + ]; + + $actionInput = new ArrayInput($arguments); + $command->run($actionInput, $output); + } + + return 0; + } +} diff --git a/src/Command/BlockStorage/Backup/GetByBlockStorageName.php b/src/Command/BlockStorage/Backup/GetByBlockStorageName.php new file mode 100644 index 0000000..2cd04f1 --- /dev/null +++ b/src/Command/BlockStorage/Backup/GetByBlockStorageName.php @@ -0,0 +1,28 @@ +setName('blockstorage:backup:getbyblockstoragename') + ->setDescription('Get a list of backups for a block storage') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC) + ->setHelp('This command lists backups for any given block storage.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + $vps = $this->getTransipApi()->blockStorageBackups()->getByBlockStorageName($blockStorageName); + $this->output($vps); + return 0; + } +} diff --git a/src/Command/BlockStorage/Backup/Revert.php b/src/Command/BlockStorage/Backup/Revert.php new file mode 100644 index 0000000..aefc642 --- /dev/null +++ b/src/Command/BlockStorage/Backup/Revert.php @@ -0,0 +1,69 @@ +setName('blockstorage:backup:revert') + ->setDescription('Restore a blockstorage backup') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC) + ->addArgument(Field::BLOCKSTORAGE_BACKUPID, InputArgument::REQUIRED, Field::BLOCKSTORAGE_BACKUPID__DESC) + ->addArgument(Field::BLOCKSTORAGE_BACKUP_DESTINATION_NAME, InputArgument::OPTIONAL, Field::BLOCKSTORAGE_BACKUP_DESTINATION_NAME__DESC . Field::OPTIONAL) + ->addOption(Field::ACTION_WAIT, 'w', InputOption::VALUE_NONE, Field::ACTION_WAIT_DESC) + ->addOption(Field::ACTION_PROGRESS, 'p', InputOption::VALUE_NONE, Field::ACTION_PROGRESS_DESC) + ->setHelp('This command restores a block storage backup.'); + } + + /** + * @throws ExceptionInterface + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + $blockStorageBackupId = $input->getArgument(Field::BLOCKSTORAGE_BACKUPID); + $destinationBlockStorageName = $input->getArgument(Field::BLOCKSTORAGE_BACKUP_DESTINATION_NAME) ?? ''; + $waitForAction = $input->getOption(Field::ACTION_WAIT); + $showProgress = $input->getOption(Field::ACTION_PROGRESS); + + $response = $this->getTransipApi()->blockStorageBackups()->revertBackup( + $blockStorageName, + $blockStorageBackupId, + $destinationBlockStorageName + ); + + $action = $this->getTransipApi()->actions()->parseActionFromResponse($response); + + if ($action && $waitForAction) { + $app = $this->getApplication(); + if (!$app) { + return 0; + } + + $command = $app->get('action:pollstatus'); + + $arguments = [ + 'actionUuid' => $action->getUuid() + ]; + + if ($showProgress) { + $arguments['--showProgress'] = true; + } + + $actionInput = new ArrayInput($arguments); + $command->run($actionInput, $output); + } + + return 0; + } +} diff --git a/src/Command/BlockStorage/Cancel.php b/src/Command/BlockStorage/Cancel.php new file mode 100644 index 0000000..615f71f --- /dev/null +++ b/src/Command/BlockStorage/Cancel.php @@ -0,0 +1,41 @@ +setName('blockstorage:cancel') + ->setDescription('Terminate or cancel your block storage') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC) + ->addArgument(Field::CANCELTIME, InputArgument::REQUIRED, Field::CANCELTIME__DESC) + ->setHelp('This command will terminate or cancel your block storage.'); + } + + /** + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + if (strlen($blockStorageName) < 3) { + throw new Exception('Invalid block storage name provided'); + } + + $blockStorageCancelTime = $input->getArgument(Field::CANCELTIME); + if (!in_array($blockStorageCancelTime, ['end', 'immediately'])) { + throw new Exception("Incorrect cancellation time provided, the value can only be 'end' or 'immediately'."); + } + + $this->getTransipApi()->blockStorages()->cancel($blockStorageName, $blockStorageCancelTime); + return 0; + } +} diff --git a/src/Command/BlockStorage/DetachVps.php b/src/Command/BlockStorage/DetachVps.php new file mode 100644 index 0000000..b1c70da --- /dev/null +++ b/src/Command/BlockStorage/DetachVps.php @@ -0,0 +1,58 @@ +setName('blockstorage:detachvps') + ->setDescription('Detach your block storage to your vps') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC) + ->addOption(Field::ACTION_WAIT, 'w', InputOption::VALUE_NONE, Field::ACTION_WAIT_DESC) + ->setHelp('This command will detach your block storage from your vps.'); + } + + /** + * @throws ExceptionInterface + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + $waitForAction = $input->getOption(Field::ACTION_WAIT); + + $blockStorage = $this->getTransipApi()->blockStorages()->getByName($blockStorageName); + $blockStorage->setVpsName(''); + + $response = $this->getTransipApi()->blockStorages()->update($blockStorage); + $action = $this->getTransipApi()->actions()->parseActionFromResponse($response); + + if ($action && $waitForAction) { + $app = $this->getApplication(); + + if (!$app) { + return 0; + } + + $command = $app->get('action:pollstatus'); + + $arguments = [ + 'actionUuid' => $action->getUuid() + ]; + + $actionInput = new ArrayInput($arguments); + $command->run($actionInput, $output); + } + + return 0; + } +} diff --git a/src/Command/BlockStorage/GetAll.php b/src/Command/BlockStorage/GetAll.php new file mode 100644 index 0000000..6077f25 --- /dev/null +++ b/src/Command/BlockStorage/GetAll.php @@ -0,0 +1,22 @@ +setName('blockstorage:getall') + ->setDescription('Get all of your block storages'); + } + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorages = $this->getTransipApi()->blockStorages()->getAll(); + $this->output($blockStorages); + return 0; + } +} diff --git a/src/Command/BlockStorage/GetByName.php b/src/Command/BlockStorage/GetByName.php new file mode 100644 index 0000000..80fbcad --- /dev/null +++ b/src/Command/BlockStorage/GetByName.php @@ -0,0 +1,27 @@ +setName('blockstorage:getbyname') + ->setDescription('Get your block storage by name') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + $blockStorage = $this->getTransipApi()->blockStorages()->getByName($blockStorageName); + $this->output($blockStorage); + return 0; + } +} diff --git a/src/Command/BlockStorage/GetUsage.php b/src/Command/BlockStorage/GetUsage.php new file mode 100644 index 0000000..a40eea8 --- /dev/null +++ b/src/Command/BlockStorage/GetUsage.php @@ -0,0 +1,33 @@ +setName('blockstorage:getusage') + ->setDescription('Get your block storage usage i/o statistics') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC) + ->addArgument(Field::BLOCKSTORAGE_STARTDATE, InputArgument::OPTIONAL, Field::BLOCKSTORAGE_STARTDATE__DESC . Field::OPTIONAL, 0) + ->addArgument(Field::BLOCKSTORAGE_ENDDATE, InputArgument::OPTIONAL, Field::BLOCKSTORAGE_ENDDATE__DESC . Field::OPTIONAL, 0) + ->setHelp('This command allows you to retrieve usage statistics of a block storage. Start and end dates cannot be longer than a one month period.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + $dateTimeStart = $input->getArgument(Field::BLOCKSTORAGE_STARTDATE); + $dateTimeEnd = $input->getArgument(Field::BLOCKSTORAGE_ENDDATE); + + $response = $this->getTransipApi()->blockStorageUsage()->getUsageStatistics($blockStorageName, $dateTimeStart, $dateTimeEnd); + $this->output($response); + return 0; + } +} diff --git a/src/Command/BlockStorage/Order.php b/src/Command/BlockStorage/Order.php new file mode 100644 index 0000000..805cd8f --- /dev/null +++ b/src/Command/BlockStorage/Order.php @@ -0,0 +1,73 @@ +setName('blockstorage:order') + ->setDescription('Order a block storage') + ->addArgument(Field::BLOCKSTORAGE_TYPE, InputArgument::REQUIRED, Field::BLOCKSTORAGE_TYPE__DESC) + ->addArgument(Field::BLOCKSTORAGE_SIZE, InputArgument::REQUIRED, Field::BLOCKSTORAGE_SIZE__DESC) + ->addArgument(Field::BLOCKSTORAGE_HASOFFSITEBACKUPS, InputArgument::OPTIONAL, Field::BLOCKSTORAGE_HASOFFSITEBACKUPS__DESC . Field::OPTIONAL) + ->addArgument(Field::AVAILABILITY_ZONE, InputArgument::OPTIONAL, Field::BLOCKSTORAGE_VPS_AVAILABILITY_ZONE__DESC . Field::OPTIONAL) + ->addArgument(Field::VPS_NAME, InputArgument::OPTIONAL, Field::BLOCKSTORAGE_VPS_ATTACH__DESC . Field::OPTIONAL) + ->addArgument(Field::BLOCKSTORAGE_DESCRIPTION, InputArgument::OPTIONAL, FIELD::BLOCKSTORAGE_DESCRIPTION__DESC . Field::OPTIONAL) + ->addOption(Field::ACTION_WAIT, 'w', InputOption::VALUE_NONE, Field::ACTION_WAIT_DESC) + ->setHelp('This command allows you to order a new block storage'); + } + + /** + * @throws ExceptionInterface + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageType = $input->getArgument(Field::BLOCKSTORAGE_TYPE); + $blockStorageSize = $input->getArgument(Field::BLOCKSTORAGE_SIZE); + $blockStorageHasOffSiteBackups = filter_var($input->getArgument(Field::BLOCKSTORAGE_HASOFFSITEBACKUPS) ?? true, FILTER_VALIDATE_BOOLEAN); + $blockStorageAvailabilityZone = $input->getArgument(Field::AVAILABILITY_ZONE) ?? ''; + $blockStorageVpsName = $input->getArgument(Field::VPS_NAME) ?? ''; + $blockStorageDescription = $input->getArgument(Field::BLOCKSTORAGE_DESCRIPTION) ?? ''; + $waitForAction = $input->getOption(Field::ACTION_WAIT); + + $response = $this->getTransipApi()->blockStorages()->order( + $blockStorageType, + $blockStorageSize, + $blockStorageHasOffSiteBackups, + $blockStorageAvailabilityZone, + $blockStorageVpsName, + $blockStorageDescription + ); + + $action = $this->getTransipApi()->actions()->parseActionFromResponse($response); + + if ($action && $waitForAction) { + $app = $this->getApplication(); + + if (!$app) { + return 0; + } + + $command = $app->get('action:pollstatus'); + + $arguments = [ + 'actionUuid' => $action->getUuid() + ]; + + $actionInput = new ArrayInput($arguments); + $command->run($actionInput, $output); + } + + return 0; + } +} diff --git a/src/Command/BlockStorage/SetDescription.php b/src/Command/BlockStorage/SetDescription.php new file mode 100644 index 0000000..a559442 --- /dev/null +++ b/src/Command/BlockStorage/SetDescription.php @@ -0,0 +1,33 @@ +setName('blockstorage:setdescription') + ->setDescription('Update your block storage description') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC) + ->addArgument(Field::BLOCKSTORAGE_DESCRIPTION, InputArgument::REQUIRED, Field::BLOCKSTORAGE_DESCRIPTION__DESC) + ->setHelp('This command will change the description of your block storage'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + $blockStorageDescription = $input->getArgument(Field::BLOCKSTORAGE_DESCRIPTION); + + $blockStorage = $this->getTransipApi()->blockStorages()->getByName($blockStorageName); + $blockStorage->setDescription($blockStorageDescription); + + $this->getTransipApi()->blockStorages()->update($blockStorage); + return 0; + } +} diff --git a/src/Command/BlockStorage/Upgrade.php b/src/Command/BlockStorage/Upgrade.php new file mode 100644 index 0000000..e2e88fe --- /dev/null +++ b/src/Command/BlockStorage/Upgrade.php @@ -0,0 +1,34 @@ +setName('blockstorage:upgrade') + ->setDescription('upgrade your block storage') + ->addArgument(Field::BLOCKSTORAGE_NAME, InputArgument::REQUIRED, Field::BLOCKSTORAGE_NAME__DESC) + ->addArgument(Field::BLOCKSTORAGE_SIZE, InputArgument::REQUIRED, Field::BLOCKSTORAGE_SIZE__DESC) + ->addArgument(Field::BLOCKSTORAGE_HASOFFSITEBACKUPS, InputArgument::OPTIONAL, 'Whether to add offsite backups. (optional)') + ->setHelp('This command allows you to upgrade a block storage'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $blockStorageName = $input->getArgument(Field::BLOCKSTORAGE_NAME); + $blockStorageSize = $input->getArgument(Field::BLOCKSTORAGE_SIZE); + + $hasOffSiteBackupsInput = $input->getArgument(Field::BLOCKSTORAGE_HASOFFSITEBACKUPS); + $blockStorageHasOffSiteBackups = ($hasOffSiteBackupsInput === null) ? null : filter_var($hasOffSiteBackupsInput, FILTER_VALIDATE_BOOLEAN); + + $this->getTransipApi()->blockStorages()->upgrade($blockStorageName, $blockStorageSize, $blockStorageHasOffSiteBackups); + return 0; + } +} diff --git a/src/Command/Field.php b/src/Command/Field.php index e6058ac..e87a2d0 100644 --- a/src/Command/Field.php +++ b/src/Command/Field.php @@ -169,6 +169,27 @@ class Field public const BIGSTORAGE_VPS_ATTACH__DESC = 'The name of the VPS to attach the big storage to'; public const BIGSTORAGE_VPS_AVAILABILITY_ZONE__DESC = 'The name of the availabilityZone where the BigStorage should be created. This parameter can not be used in conjunction with vpsName. If a vpsName is provided as well as an availabilityZone, the zone of the vps is leading'; + public const BLOCKSTORAGE_NAME = 'BlockStorageName'; + public const BLOCKSTORAGE_NAME__DESC = 'The name of the block storage'; + public const BLOCKSTORAGE_TYPE = 'BlockStorageType'; + public const BLOCKSTORAGE_TYPE__DESC = 'The type of the block storage. It can be big-storage or fast-storage.'; + public const BLOCKSTORAGE_SIZE = 'BlockStorageSize'; + public const BLOCKSTORAGE_SIZE__DESC = 'The size of the block storage in KB. Big storages: The minimum size is 2 TiB and storage can be extended with up to maximum of 40 TiB. Make sure to use a multiple of 2 TiB. Note that 2 TiB equals 2147483648 KiB. Fast storages: The minimum size is 10 GiB and storage can be extended with up to maximum of 10000 GiB. Make sure to use a multiple of 10 GiB. Note that 10 GiB equals 10485760 KiB.'; + public const BLOCKSTORAGE_HASOFFSITEBACKUPS = 'BlockStorageHasOffSiteBackups'; + public const BLOCKSTORAGE_HASOFFSITEBACKUPS__DESC = 'Whether to order offsite backups, default is true.'; + public const BLOCKSTORAGE_BACKUPID = 'BlockStorageBackupId'; + public const BLOCKSTORAGE_BACKUPID__DESC = 'ID number of the backup'; + public const BLOCKSTORAGE_BACKUP_DESTINATION_NAME = 'DestinationBlockStorageName'; + public const BLOCKSTORAGE_BACKUP_DESTINATION_NAME__DESC = 'Reverts the backup to this block storage.'; + public const BLOCKSTORAGE_DESCRIPTION = 'BlockStorageDescription'; + public const BLOCKSTORAGE_DESCRIPTION__DESC = 'Description of the block storage'; + public const BLOCKSTORAGE_STARTDATE = 'StartDate'; + public const BLOCKSTORAGE_STARTDATE__DESC = 'Start date in unix timestamp'; + public const BLOCKSTORAGE_ENDDATE = 'EndDate'; + public const BLOCKSTORAGE_ENDDATE__DESC = 'End date in unix timestamp'; + public const BLOCKSTORAGE_VPS_ATTACH__DESC = 'The name of the VPS to attach the block storage to'; + public const BLOCKSTORAGE_VPS_AVAILABILITY_ZONE__DESC = 'The name of the availabilityZone where the BlockStorage should be created. This parameter can not be used in conjunction with vpsName. If a vpsName is provided as well as an availabilityZone, the zone of the vps is leading'; + public const HAIP_NAME = 'HaipName'; public const HAIP_NAME__DESC = 'The name of the HA-IP'; public const HAIP_LOADBALANCING_MODE = 'LoadBalancingMode'; diff --git a/src/Settings/Settings.php b/src/Settings/Settings.php index c95c094..c622820 100644 --- a/src/Settings/Settings.php +++ b/src/Settings/Settings.php @@ -17,7 +17,7 @@ class Settings public const TRANSIP_API_ENDPOINT = 'https://api.transip.nl/v6'; - public const TRANSIP_CLI_VERSION = '6.31.0'; + public const TRANSIP_CLI_VERSION = '6.32.0'; /** * @var string