[pve-devel] [PATCH v2 cluster 07/13] move datacenter.cfg to own file

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Nov 11 11:28:01 CET 2019


and inline get_local_migration_ip into 'pvecm mtunnel', since all the
other callers are either wrong or have different requirements.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---

Notes:
    requires versioned breaks on
    - ha-manager
    - libpve-access-control-perl
    - libpve-guest-common-perl
    - libpve-storage-perl
    - pve-container
    - pve-manager
    - qemu-server

 data/PVE/Makefile            |   2 +-
 data/PVE/CLI/pvecm.pm        |  29 +++-
 data/PVE/Cluster.pm          | 252 -----------------------------------
 data/PVE/DataCenterConfig.pm | 236 ++++++++++++++++++++++++++++++++
 debian/control               |   2 +-
 5 files changed, 265 insertions(+), 256 deletions(-)
 create mode 100644 data/PVE/DataCenterConfig.pm

diff --git a/data/PVE/Makefile b/data/PVE/Makefile
index 052a815..d965932 100644
--- a/data/PVE/Makefile
+++ b/data/PVE/Makefile
@@ -11,7 +11,7 @@ PVE_VENDORARCH=${DESTDIR}/${PERL_VENDORARCH}/auto/PVE/IPCC
 PERL_DOC_INC_DIRS:=..
 
 SUBDIRS=Cluster CLI API2
-SOURCES=IPCC.pm Cluster.pm Corosync.pm RRD.pm
+SOURCES=IPCC.pm Cluster.pm Corosync.pm RRD.pm DataCenterConfig.pm
 
 all:
 
diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
index 0fed6cb..d3fde3c 100755
--- a/data/PVE/CLI/pvecm.pm
+++ b/data/PVE/CLI/pvecm.pm
@@ -611,11 +611,36 @@ __PACKAGE__->register_method ({
 	    return undef;
 	}
 
+	my $get_local_migration_ip = sub {
+	    my ($cidr) = @_;
+
+	    if (!defined($cidr)) {
+		my $dc_conf = cfs_read_file('datacenter.cfg');
+		$cidr = $dc_conf->{migration}->{network}
+		if defined($dc_conf->{migration}->{network});
+	    }
+
+	    if (defined($cidr)) {
+		my $ips = PVE::Network::get_local_ip_from_cidr($cidr);
+
+		die "could not get migration ip: no IP address configured on local " .
+		    "node for network '$cidr'\n" if scalar(@$ips) == 0;
+
+		die "could not get migration ip: multiple IP address configured for " .
+		    "network '$cidr'\n" if scalar(@$ips) > 1;
+
+		return @$ips[0];
+	    }
+
+	    return undef;
+	};
+
 	my $network = $param->{migration_network};
 	if ($param->{get_migration_ip}) {
 	    die "cannot use --run-command with --get_migration_ip\n"
 		if $param->{'run-command'};
-	    if (my $ip = PVE::Cluster::get_local_migration_ip($network)) {
+
+	    if (my $ip = $get_local_migration_ip->($network)) {
 		print "ip: '$ip'\n";
 	    } else {
 		print "no ip\n";
@@ -632,7 +657,7 @@ __PACKAGE__->register_method ({
 	    # Get an ip address to listen on, and find a free migration port
 	    my ($ip, $family);
 	    if (defined($network)) {
-		$ip = PVE::Cluster::get_local_migration_ip($network)
+		$ip = $get_local_migration_ip->($network)
 		    or die "failed to get migration IP address to listen on\n";
 		$family = PVE::Tools::get_host_address_family($ip);
 	    } else {
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 5b017e4..2f2daf6 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -726,258 +726,6 @@ sub remote_node_ip {
     return PVE::Network::get_ip_from_hostname($nodename, $noerr);
 }
 
-sub get_local_migration_ip {
-    my ($migration_network, $noerr) = @_;
-
-    my $cidr = $migration_network;
-
-    if (!defined($cidr)) {
-	my $dc_conf = cfs_read_file('datacenter.cfg');
-	$cidr = $dc_conf->{migration}->{network}
-	  if defined($dc_conf->{migration}->{network});
-    }
-
-    if (defined($cidr)) {
-	my $ips = PVE::Network::get_local_ip_from_cidr($cidr);
-
-	die "could not get migration ip: no IP address configured on local " .
-	    "node for network '$cidr'\n" if !$noerr && (scalar(@$ips) == 0);
-
-	die "could not get migration ip: multiple IP address configured for " .
-	    "network '$cidr'\n" if !$noerr && (scalar(@$ips) > 1);
-
-	return @$ips[0];
-    }
-
-    return undef;
-};
-
-
-my $migration_format = {
-    type => {
-	default_key => 1,
-	type => 'string',
-	enum => ['secure', 'insecure'],
-	description => "Migration traffic is encrypted using an SSH tunnel by " .
-	  "default. On secure, completely private networks this can be " .
-	  "disabled to increase performance.",
-	default => 'secure',
-    },
-    network => {
-	optional => 1,
-	type => 'string', format => 'CIDR',
-	format_description => 'CIDR',
-	description => "CIDR of the (sub) network that is used for migration."
-    },
-};
-
-my $ha_format = {
-    shutdown_policy => {
-	type => 'string',
-	enum => ['freeze', 'failover', 'conditional'],
-	description => "The policy for HA services on node shutdown. 'freeze' disables auto-recovery, 'failover' ensures recovery, 'conditional' recovers on poweroff and freezes on reboot. Running HA Services will always get stopped first on shutdown.",
-	verbose_description => "Describes the policy for handling HA services on poweroff or reboot of a node. Freeze will always freeze services which are still located on the node on shutdown, those services won't be recovered by the HA manager. Failover will not mark the services as frozen and thus the services will get recovered to other nodes, if the shutdown node does not come up again quickly (< 1min). 'conditional' chooses automatically depending on the type of shutdown, i.e., on a reboot the service will be frozen but on a poweroff the service will stay as is, and thus get recovered after about 2 minutes.",
-	default => 'conditional',
-    }
-};
-
-PVE::JSONSchema::register_format('mac-prefix', \&pve_verify_mac_prefix);
-sub pve_verify_mac_prefix {
-    my ($mac_prefix, $noerr) = @_;
-
-    if ($mac_prefix !~ m/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i) {
-	return undef if $noerr;
-	die "value is not a valid unicast MAC address prefix\n";
-    }
-    return $mac_prefix;
-}
-
-our $u2f_format = {
-    appid => {
-	type => 'string',
-	description => "U2F AppId URL override. Defaults to the origin.",
-	format_description => 'APPID',
-	optional => 1,
-    },
-    origin => {
-	type => 'string',
-	description => "U2F Origin override. Mostly useful for single nodes with a single URL.",
-	format_description => 'URL',
-	optional => 1,
-    },
-};
-
-my $datacenter_schema = {
-    type => "object",
-    additionalProperties => 0,
-    properties => {
-	keyboard => {
-	    optional => 1,
-	    type => 'string',
-	    description => "Default keybord layout for vnc server.",
-	    enum => PVE::Tools::kvmkeymaplist(),
-	},
-	language => {
-	    optional => 1,
-	    type => 'string',
-	    description => "Default GUI language.",
-	    enum => [
-		'ca',
-		'da',
-		'de',
-		'en',
-		'es',
-		'eu',
-		'fa',
-		'fr',
-		'he',
-		'it',
-		'ja',
-		'nb',
-		'nn',
-		'pl',
-		'pt_BR',
-		'ru',
-		'sl',
-		'sv',
-		'tr',
-		'zh_CN',
-		'zh_TW',
-	    ],
-	},
-	http_proxy => {
-	    optional => 1,
-	    type => 'string',
-	    description => "Specify external http proxy which is used for downloads (example: 'http://username:password\@host:port/')",
-	    pattern => "http://.*",
-	},
-	migration_unsecure => {
-	    optional => 1,
-	    type => 'boolean',
-	    description => "Migration is secure using SSH tunnel by default. " .
-	      "For secure private networks you can disable it to speed up " .
-	      "migration. Deprecated, use the 'migration' property instead!",
-	},
-	migration => {
-	    optional => 1,
-	    type => 'string', format => $migration_format,
-	    description => "For cluster wide migration settings.",
-	},
-	console => {
-	    optional => 1,
-	    type => 'string',
-	    description => "Select the default Console viewer. You can either use the builtin java applet (VNC; deprecated and maps to html5), an external virt-viewer comtatible application (SPICE), an HTML5 based vnc viewer (noVNC), or an HTML5 based console client (xtermjs). If the selected viewer is not available (e.g. SPICE not activated for the VM), the fallback is noVNC.",
-	    enum => ['applet', 'vv', 'html5', 'xtermjs'],
-	},
-	email_from => {
-	    optional => 1,
-	    type => 'string',
-	    format => 'email-opt',
-	    description => "Specify email address to send notification from (default is root@\$hostname)",
-	},
-	max_workers => {
-	    optional => 1,
-	    type => 'integer',
-	    minimum => 1,
-	    description => "Defines how many workers (per node) are maximal started ".
-	      " on actions like 'stopall VMs' or task from the ha-manager.",
-	},
-	fencing => {
-	    optional => 1,
-	    type => 'string',
-	    default => 'watchdog',
-	    enum => [ 'watchdog', 'hardware', 'both' ],
-	    description => "Set the fencing mode of the HA cluster. Hardware mode " .
-	      "needs a valid configuration of fence devices in /etc/pve/ha/fence.cfg." .
-	      " With both all two modes are used." .
-	      "\n\nWARNING: 'hardware' and 'both' are EXPERIMENTAL & WIP",
-	},
-	ha => {
-	    optional => 1,
-	    type => 'string', format => $ha_format,
-	    description => "Cluster wide HA settings.",
-	},
-	mac_prefix => {
-	    optional => 1,
-	    type => 'string',
-	    format => 'mac-prefix',
-	    description => 'Prefix for autogenerated MAC addresses.',
-	},
-	bwlimit => PVE::JSONSchema::get_standard_option('bwlimit'),
-	u2f => {
-	    optional => 1,
-	    type => 'string',
-	    format => $u2f_format,
-	    description => 'u2f',
-	},
-    },
-};
-
-# make schema accessible from outside (for documentation)
-sub get_datacenter_schema { return $datacenter_schema };
-
-sub parse_datacenter_config {
-    my ($filename, $raw) = @_;
-
-    my $res = PVE::JSONSchema::parse_config($datacenter_schema, $filename, $raw // '');
-
-    if (my $migration = $res->{migration}) {
-	$res->{migration} = PVE::JSONSchema::parse_property_string($migration_format, $migration);
-    }
-
-    if (my $ha = $res->{ha}) {
-	$res->{ha} = PVE::JSONSchema::parse_property_string($ha_format, $ha);
-    }
-
-    # for backwards compatibility only, new migration property has precedence
-    if (defined($res->{migration_unsecure})) {
-	if (defined($res->{migration}->{type})) {
-	    warn "deprecated setting 'migration_unsecure' and new 'migration: type' " .
-	      "set at same time! Ignore 'migration_unsecure'\n";
-	} else {
-	    $res->{migration}->{type} = ($res->{migration_unsecure}) ? 'insecure' : 'secure';
-	}
-    }
-
-    # for backwards compatibility only, applet maps to html5
-    if (defined($res->{console}) && $res->{console} eq 'applet') {
-	$res->{console} = 'html5';
-    }
-
-    return $res;
-}
-
-sub write_datacenter_config {
-    my ($filename, $cfg) = @_;
-
-    # map deprecated setting to new one
-    if (defined($cfg->{migration_unsecure}) && !defined($cfg->{migration})) {
-	my $migration_unsecure = delete $cfg->{migration_unsecure};
-	$cfg->{migration}->{type} = ($migration_unsecure) ? 'insecure' : 'secure';
-    }
-
-    # map deprecated applet setting to html5
-    if (defined($cfg->{console}) && $cfg->{console} eq 'applet') {
-	$cfg->{console} = 'html5';
-    }
-
-    if (ref($cfg->{migration})) {
-	my $migration = $cfg->{migration};
-	$cfg->{migration} = PVE::JSONSchema::print_property_string($migration, $migration_format);
-    }
-
-    if (ref($cfg->{ha})) {
-	my $ha = $cfg->{ha};
-	$cfg->{ha} = PVE::JSONSchema::print_property_string($ha, $ha_format);
-    }
-
-    return PVE::JSONSchema::dump_config($datacenter_schema, $filename, $cfg);
-}
-
-cfs_register_file('datacenter.cfg',
-		  \&parse_datacenter_config,
-		  \&write_datacenter_config);
-
 sub get_node_fingerprint {
     my ($node) = @_;
 
diff --git a/data/PVE/DataCenterConfig.pm b/data/PVE/DataCenterConfig.pm
new file mode 100644
index 0000000..5f3f80a
--- /dev/null
+++ b/data/PVE/DataCenterConfig.pm
@@ -0,0 +1,236 @@
+package PVE::DataCenterConfig;
+
+use strict;
+use warnings;
+
+use PVE::JSONSchema;
+use PVE::Tools;
+use PVE::Cluster;
+
+my $migration_format = {
+    type => {
+	default_key => 1,
+	type => 'string',
+	enum => ['secure', 'insecure'],
+	description => "Migration traffic is encrypted using an SSH tunnel by " .
+	  "default. On secure, completely private networks this can be " .
+	  "disabled to increase performance.",
+	default => 'secure',
+    },
+    network => {
+	optional => 1,
+	type => 'string', format => 'CIDR',
+	format_description => 'CIDR',
+	description => "CIDR of the (sub) network that is used for migration."
+    },
+};
+
+my $ha_format = {
+    shutdown_policy => {
+	type => 'string',
+	enum => ['freeze', 'failover', 'conditional'],
+	description => "The policy for HA services on node shutdown. 'freeze' disables auto-recovery, 'failover' ensures recovery, 'conditional' recovers on poweroff and freezes on reboot. Running HA Services will always get stopped first on shutdown.",
+	verbose_description => "Describes the policy for handling HA services on poweroff or reboot of a node. Freeze will always freeze services which are still located on the node on shutdown, those services won't be recovered by the HA manager. Failover will not mark the services as frozen and thus the services will get recovered to other nodes, if the shutdown node does not come up again quickly (< 1min). 'conditional' chooses automatically depending on the type of shutdown, i.e., on a reboot the service will be frozen but on a poweroff the service will stay as is, and thus get recovered after about 2 minutes.",
+	default => 'conditional',
+    }
+};
+
+our $u2f_format = {
+    appid => {
+	type => 'string',
+	description => "U2F AppId URL override. Defaults to the origin.",
+	format_description => 'APPID',
+	optional => 1,
+    },
+    origin => {
+	type => 'string',
+	description => "U2F Origin override. Mostly useful for single nodes with a single URL.",
+	format_description => 'URL',
+	optional => 1,
+    },
+};
+
+
+PVE::JSONSchema::register_format('mac-prefix', \&pve_verify_mac_prefix);
+sub pve_verify_mac_prefix {
+    my ($mac_prefix, $noerr) = @_;
+
+    if ($mac_prefix !~ m/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i) {
+	return undef if $noerr;
+	die "value is not a valid unicast MAC address prefix\n";
+    }
+    return $mac_prefix;
+}
+
+my $datacenter_schema = {
+    type => "object",
+    additionalProperties => 0,
+    properties => {
+	keyboard => {
+	    optional => 1,
+	    type => 'string',
+	    description => "Default keybord layout for vnc server.",
+	    enum => PVE::Tools::kvmkeymaplist(),
+	},
+	language => {
+	    optional => 1,
+	    type => 'string',
+	    description => "Default GUI language.",
+	    enum => [
+		'ca',
+		'da',
+		'de',
+		'en',
+		'es',
+		'eu',
+		'fa',
+		'fr',
+		'he',
+		'it',
+		'ja',
+		'nb',
+		'nn',
+		'pl',
+		'pt_BR',
+		'ru',
+		'sl',
+		'sv',
+		'tr',
+		'zh_CN',
+		'zh_TW',
+	    ],
+	},
+	http_proxy => {
+	    optional => 1,
+	    type => 'string',
+	    description => "Specify external http proxy which is used for downloads (example: 'http://username:password\@host:port/')",
+	    pattern => "http://.*",
+	},
+	migration_unsecure => {
+	    optional => 1,
+	    type => 'boolean',
+	    description => "Migration is secure using SSH tunnel by default. " .
+	      "For secure private networks you can disable it to speed up " .
+	      "migration. Deprecated, use the 'migration' property instead!",
+	},
+	migration => {
+	    optional => 1,
+	    type => 'string', format => $migration_format,
+	    description => "For cluster wide migration settings.",
+	},
+	console => {
+	    optional => 1,
+	    type => 'string',
+	    description => "Select the default Console viewer. You can either use the builtin java applet (VNC; deprecated and maps to html5), an external virt-viewer comtatible application (SPICE), an HTML5 based vnc viewer (noVNC), or an HTML5 based console client (xtermjs). If the selected viewer is not available (e.g. SPICE not activated for the VM), the fallback is noVNC.",
+	    enum => ['applet', 'vv', 'html5', 'xtermjs'],
+	},
+	email_from => {
+	    optional => 1,
+	    type => 'string',
+	    format => 'email-opt',
+	    description => "Specify email address to send notification from (default is root@\$hostname)",
+	},
+	max_workers => {
+	    optional => 1,
+	    type => 'integer',
+	    minimum => 1,
+	    description => "Defines how many workers (per node) are maximal started ".
+	      " on actions like 'stopall VMs' or task from the ha-manager.",
+	},
+	fencing => {
+	    optional => 1,
+	    type => 'string',
+	    default => 'watchdog',
+	    enum => [ 'watchdog', 'hardware', 'both' ],
+	    description => "Set the fencing mode of the HA cluster. Hardware mode " .
+	      "needs a valid configuration of fence devices in /etc/pve/ha/fence.cfg." .
+	      " With both all two modes are used." .
+	      "\n\nWARNING: 'hardware' and 'both' are EXPERIMENTAL & WIP",
+	},
+	ha => {
+	    optional => 1,
+	    type => 'string', format => $ha_format,
+	    description => "Cluster wide HA settings.",
+	},
+	mac_prefix => {
+	    optional => 1,
+	    type => 'string',
+	    format => 'mac-prefix',
+	    description => 'Prefix for autogenerated MAC addresses.',
+	},
+	bwlimit => PVE::JSONSchema::get_standard_option('bwlimit'),
+	u2f => {
+	    optional => 1,
+	    type => 'string',
+	    format => $u2f_format,
+	    description => 'u2f',
+	},
+    },
+};
+
+# make schema accessible from outside (for documentation)
+sub get_datacenter_schema { return $datacenter_schema };
+
+sub parse_datacenter_config {
+    my ($filename, $raw) = @_;
+
+    my $res = PVE::JSONSchema::parse_config($datacenter_schema, $filename, $raw // '');
+
+    if (my $migration = $res->{migration}) {
+	$res->{migration} = PVE::JSONSchema::parse_property_string($migration_format, $migration);
+    }
+
+    if (my $ha = $res->{ha}) {
+	$res->{ha} = PVE::JSONSchema::parse_property_string($ha_format, $ha);
+    }
+
+    # for backwards compatibility only, new migration property has precedence
+    if (defined($res->{migration_unsecure})) {
+	if (defined($res->{migration}->{type})) {
+	    warn "deprecated setting 'migration_unsecure' and new 'migration: type' " .
+	      "set at same time! Ignore 'migration_unsecure'\n";
+	} else {
+	    $res->{migration}->{type} = ($res->{migration_unsecure}) ? 'insecure' : 'secure';
+	}
+    }
+
+    # for backwards compatibility only, applet maps to html5
+    if (defined($res->{console}) && $res->{console} eq 'applet') {
+	$res->{console} = 'html5';
+    }
+
+    return $res;
+}
+
+sub write_datacenter_config {
+    my ($filename, $cfg) = @_;
+
+    # map deprecated setting to new one
+    if (defined($cfg->{migration_unsecure}) && !defined($cfg->{migration})) {
+	my $migration_unsecure = delete $cfg->{migration_unsecure};
+	$cfg->{migration}->{type} = ($migration_unsecure) ? 'insecure' : 'secure';
+    }
+
+    # map deprecated applet setting to html5
+    if (defined($cfg->{console}) && $cfg->{console} eq 'applet') {
+	$cfg->{console} = 'html5';
+    }
+
+    if (ref($cfg->{migration})) {
+	my $migration = $cfg->{migration};
+	$cfg->{migration} = PVE::JSONSchema::print_property_string($migration, $migration_format);
+    }
+
+    if (ref($cfg->{ha})) {
+	my $ha = $cfg->{ha};
+	$cfg->{ha} = PVE::JSONSchema::print_property_string($ha, $ha_format);
+    }
+
+    return PVE::JSONSchema::dump_config($datacenter_schema, $filename, $cfg);
+}
+
+PVE::Cluster::cfs_register_file('datacenter.cfg',
+		  \&parse_datacenter_config,
+		  \&write_datacenter_config);
+
+1;
diff --git a/debian/control b/debian/control
index 1451c2d..c5e6962 100644
--- a/debian/control
+++ b/debian/control
@@ -19,7 +19,7 @@ Build-Depends: check,
                librrds-perl,
                libsqlite3-dev,
                libuuid-perl,
-               pve-doc-generator (>= 5.3-3),
+               pve-doc-generator (>= 6.0-9~),
                rrdcached,
                sqlite3,
 Standards-Version: 4.3.0
-- 
2.20.1





More information about the pve-devel mailing list