[pve-devel] [PATCH v2 pve-ha-manager 1/5] Add 'service is ha managed' check

Dietmar Maurer dietmar at proxmox.com
Mon Oct 12 18:10:30 CEST 2015


That code looks quite similar to vm_is_ha_managed(). Is it possible to 
improve code reuse?

On 10/12/2015 03:04 PM, Thomas Lamprecht wrote:
> add a check for a given $sid if it's managed by the ha stack
>
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
>   src/PVE/HA/Config.pm | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
>
> diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
> index 0a6dfa5..d6d974d 100644
> --- a/src/PVE/HA/Config.pm
> +++ b/src/PVE/HA/Config.pm
> @@ -174,4 +174,20 @@ sub vm_is_ha_managed {
>       return undef;
>   }
>   
> +sub service_is_ha_managed {
> +    my ($sid, $has_state, $noerr) = @_;
> +
> +    my $conf = cfs_read_file($ha_resources_config);
> +
> +    if (my $vm = $conf->{ids}->{$sid}) {
> +	return 1 if !defined($has_state);
> +
> +	$vm->{state} = 'enabled' if !defined($vm->{state});
> +	return 1 if $vm->{state} eq $has_state;
> +    }
> +
> +    die "resource '$sid' is not HA managed\n" if !$noerr;
> +
> +    return undef;
> +}
>   1;





More information about the pve-devel mailing list