[pve-devel] [PATCH v2 ha-manager 1/4] Tools: make PVE::Cluster and HA-Env optional

Dietmar Maurer dietmar at proxmox.com
Sat Oct 6 08:15:14 CEST 2018


looks wrong too me - will do some test next weeks.

> On October 5, 2018 at 8:46 PM Fabian Grünbichler <f.gruenbichler at proxmox.com> wrote:
> 
> 
> since Tools is used by the simulator as well, which does not need
> PVE::Cluster otherwise.
> 
> the bash completion methods are only used by ha-manager's CLI tools, and
> parse_sid is never called with an argument requiring PVE::Cluster by the
> simulation/testing stack.
> 
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
> Note: unchanged
> 
>  src/PVE/HA/Tools.pm | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm
> index 88f775e..fd537b3 100644
> --- a/src/PVE/HA/Tools.pm
> +++ b/src/PVE/HA/Tools.pm
> @@ -3,9 +3,9 @@ package PVE::HA::Tools;
>  use strict;
>  use warnings;
>  use JSON;
> +
>  use PVE::JSONSchema;
>  use PVE::Tools;
> -use PVE::Cluster;
>  use PVE::ProcFSTools;
>  
>  # return codes used in the ha environment
> @@ -84,6 +84,19 @@ PVE::JSONSchema::register_standard_option('pve-ha-group-id', {
>      type => 'string', format => 'pve-configid',
>  });
>  
> +my $have_cluster = 0;
> +eval {
> +    if (! defined $INC{'PVE::Cluster'}) {
> +	require PVE::Cluster;
> +	PVE::Cluster->import();
> +    }
> +    if (! defined $INC{'PVE::HA::Config'}) {
> +	require PVE::HA::Config;
> +	PVE::HA::Env->import();
> +    }
> +    $have_cluster = 1;
> +};
> +
>  sub parse_sid {
>      my ($sid) = @_;
>  
> @@ -91,6 +104,9 @@ sub parse_sid {
>  
>      if ($sid =~ m/^(\d+)$/) {
>  	$name = $1;
> +
> +	die "PVE::Cluster not available!\n" if !$have_cluster;
> +
>  	my $vmlist = PVE::Cluster::get_vmlist();
>  	if (defined($vmlist->{ids}->{$name})) {
>  	    my $vm_type = $vmlist->{ids}->{$name}->{type};
> @@ -128,6 +144,9 @@ sub read_json_from_file {
>  	# workaround for bug #775
>  	if ($filename =~ m|^/etc/pve/|) {
>  	    $filename =~ s|^/etc/pve/+||;
> +
> +	    die "PVE::Cluster not available!\n" if !$have_cluster;
> +
>  	    $raw = PVE::Cluster::get_config($filename);
>  	    die "unable to read file '/etc/pve/$filename'\n" 
>  		if !defined($raw);
> @@ -218,6 +237,7 @@ sub upid_wait {
>  sub complete_sid {
>      my ($cmd, $pname, $cur) = @_;
>  
> +    die "PVE::Cluster not available!\n" if !$have_cluster;
>      my $cfg = PVE::HA::Config::read_resources_config();
>  
>      my $res = [];
> @@ -255,6 +275,7 @@ sub complete_sid {
>  
>  sub complete_enabled_sid {
>  
> +    die "PVE::Cluster not available!\n" if !$have_cluster;
>      my $cfg = PVE::HA::Config::read_resources_config();
>  
>      my $res = [];
> @@ -269,6 +290,7 @@ sub complete_enabled_sid {
>  
>  sub complete_disabled_sid {
>  
> +    die "PVE::Cluster not available!\n" if !$have_cluster;
>      my $cfg = PVE::HA::Config::read_resources_config();
>  
>      my $res = [];
> @@ -284,6 +306,7 @@ sub complete_disabled_sid {
>  sub complete_group {
>      my ($cmd, $pname, $cur) = @_;
>  
> +    die "PVE::Cluster not available!\n" if !$have_cluster;
>      my $cfg = PVE::HA::Config::read_group_config();
>  
>      my $res = [];
> -- 
> 2.19.0
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list