On 9/30/19 9:22 AM, Fabian Ebner wrote:
> Signed-off-by: Fabian Ebner <f.eb...@proxmox.com>
> ---
>  src/PVE/API2/HA/Resources.pm | 37 ++++++++++++++++++++++++++++++++++++
>  src/PVE/CLI/ha_manager.pm    |  2 ++
>  2 files changed, 39 insertions(+)

besides the nit^Wfact that the commit subject should read
"Add stop command to the API and CLI", not sure if this is required?

Couldn't we just have a common helper somewhere and then the
qm stop or pct stop just calls that (indirectly?).

Just need to rethink concepts for this one, code itself looks OK.

> 
> diff --git a/src/PVE/API2/HA/Resources.pm b/src/PVE/API2/HA/Resources.pm
> index 2b62ee8..ecc5f0c 100644
> --- a/src/PVE/API2/HA/Resources.pm
> +++ b/src/PVE/API2/HA/Resources.pm
> @@ -353,4 +353,41 @@ __PACKAGE__->register_method ({
>       return undef;
>      }});
>  
> +__PACKAGE__->register_method ({
> +    name => 'stop',
> +    protected => 1,
> +    path => '{sid}/stop',
> +    method => 'POST',
> +    description => "Request the service to be stopped.",
> +    permissions => {
> +     check => ['perm', '/', [ 'Sys.Console' ]],
> +    },
> +    parameters => {
> +     additionalProperties => 0,
> +     properties => {
> +         sid => get_standard_option('pve-ha-resource-or-vm-id',
> +                                   { completion => 
> \&PVE::HA::Tools::complete_sid }),
> +         timeout => {
> +             description => "Timeout in seconds. If set to 0 a hard stop 
> will be performed.",
> +             type => 'integer',
> +             minimum => 0,
> +             optional => 1,
> +         },
> +     },
> +    },
> +    returns => { type => 'null' },
> +    code => sub {
> +     my ($param) = @_;
> +
> +     my ($sid, $type, $name) = 
> PVE::HA::Config::parse_sid(extract_param($param, 'sid'));
> +
> +     PVE::HA::Config::service_is_ha_managed($sid);
> +
> +     check_service_state($sid);
> +
> +     PVE::HA::Config::queue_crm_commands("stop $sid $param->{timeout}");
> +
> +     return undef;
> +    }});
> +
>  1;
> diff --git a/src/PVE/CLI/ha_manager.pm b/src/PVE/CLI/ha_manager.pm
> index 5ce4c30..c9d4e7f 100644
> --- a/src/PVE/CLI/ha_manager.pm
> +++ b/src/PVE/CLI/ha_manager.pm
> @@ -114,6 +114,8 @@ our $cmddef = {
>      migrate => [ "PVE::API2::HA::Resources", 'migrate', ['sid', 'node'] ],
>      relocate => [ "PVE::API2::HA::Resources", 'relocate', ['sid', 'node'] ],
>  
> +    stop => [ "PVE::API2::HA::Resources", 'stop', ['sid', 'timeout'] ],
> +
>  };
>  
>  1;
> 


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to