Skip to content

Commit

Permalink
Merge branch 'block-storage-methods' into 'master'
Browse files Browse the repository at this point in the history
Block storage methods

See merge request transip/restapi-cli-client!177
  • Loading branch information
Jordi Donadeu committed Oct 10, 2023
2 parents 9a1eaba + d86f614 commit 89ebf5c
Show file tree
Hide file tree
Showing 28 changed files with 548 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,9 @@ abstract class AbstractCommand extends Command
*/
private $output;

/** @var SymfonyStyle */
private $io;

public function __construct(string $name = null)
{
parent::__construct($name);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/AttachVps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/Backup/GetByBigStorageName.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/Backup/Revert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? '';
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/DetachVps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion src/Command/BigStorage/GetAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/Command/BigStorage/GetByName.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/GetUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/SetDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/Command/BigStorage/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
60 changes: 60 additions & 0 deletions src/Command/BlockStorage/AttachVps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Transip\Api\CLI\Command\BlockStorage;

use Symfony\Component\Console\Exception\ExceptionInterface;
use Transip\Api\CLI\Command\Field;
use Transip\Api\CLI\Command\AbstractCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class AttachVps extends AbstractCommand
{
protected function configure(): void
{
$this->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;
}
}
28 changes: 28 additions & 0 deletions src/Command/BlockStorage/Backup/GetByBlockStorageName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Transip\Api\CLI\Command\BlockStorage\Backup;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Transip\Api\CLI\Command\AbstractCommand;
use Transip\Api\CLI\Command\Field;

class GetByBlockStorageName extends AbstractCommand
{
protected function configure(): void
{
$this->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;
}
}
Loading

0 comments on commit 89ebf5c

Please sign in to comment.