You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.8 KiB
PHP
92 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cloud;
|
|
|
|
/**
|
|
* Canonical labels for panel-visible cloud jobs and power actions.
|
|
*
|
|
* The engine keeps its own protocol allow-list. This catalog is deliberately
|
|
* limited to the values persisted by the panel so filters and every panel
|
|
* consumer render the same task vocabulary.
|
|
*/
|
|
final class CloudOperationCatalog
|
|
{
|
|
private const KINDS = [
|
|
'create' => '创建实例',
|
|
'action' => '电源操作',
|
|
'reinstall' => '重装系统',
|
|
'rescue' => '救援操作',
|
|
'delete' => '删除实例',
|
|
'network_change' => '更换公网 IP',
|
|
'instance_settings' => '实例设置',
|
|
'snapshot_create' => '创建快照',
|
|
'snapshot_restore' => '恢复快照',
|
|
'snapshot_delete' => '删除快照',
|
|
'firewall_apply' => '应用防火墙',
|
|
'service_suspend' => '到期停用',
|
|
'service_resume' => '恢复服务',
|
|
'network_suspend' => '限制网络',
|
|
'network_resume' => '恢复网络',
|
|
'expiry_delete' => '到期清理',
|
|
];
|
|
|
|
private const POWER_ACTIONS = [
|
|
'start' => '开机',
|
|
'shutdown' => '关机',
|
|
'reboot' => '重启',
|
|
'poweroff' => '强制断电',
|
|
'reset' => '强制重置',
|
|
];
|
|
|
|
/** Return the canonical persisted job kinds and their labels. */
|
|
public static function kinds(): array
|
|
{
|
|
return self::KINDS;
|
|
}
|
|
|
|
/** Return options suitable for an administrator kind filter. */
|
|
public static function kindOptions(): array
|
|
{
|
|
$options = [];
|
|
foreach (self::KINDS as $value => $label) {
|
|
$options[] = ['value' => $value, 'label' => $label];
|
|
}
|
|
return $options;
|
|
}
|
|
|
|
public static function isPowerAction(string $action): bool
|
|
{
|
|
return array_key_exists($action, self::POWER_ACTIONS);
|
|
}
|
|
|
|
public static function kindLabel(?string $kind, ?string $action = null): string
|
|
{
|
|
$kind = (string) $kind;
|
|
if ($kind === 'action' && $action !== null && self::isPowerAction($action)) {
|
|
return self::POWER_ACTIONS[$action];
|
|
}
|
|
return self::KINDS[$kind] ?? '其他任务';
|
|
}
|
|
|
|
public static function actionLabel(?string $action): ?string
|
|
{
|
|
if ($action === null || !self::isPowerAction($action)) {
|
|
return null;
|
|
}
|
|
return self::POWER_ACTIONS[$action];
|
|
}
|
|
|
|
/**
|
|
* Return both raw-action metadata and the final display label. The raw
|
|
* action remains available for clients that need protocol details while
|
|
* kind_label is the one value every panel list should render.
|
|
*/
|
|
public static function labels(?string $kind, ?string $action = null): array
|
|
{
|
|
return [
|
|
'kind_label' => self::kindLabel($kind, $action),
|
|
'action_label' => self::actionLabel($action),
|
|
];
|
|
}
|
|
}
|