From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 43DF9A8AE for ; Wed, 27 Apr 2022 17:34:32 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 30B3828874 for ; Wed, 27 Apr 2022 17:34:02 +0200 (CEST) Received: from bastionodiso.odiso.net (bastionodiso.odiso.net [185.151.191.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 43C90287DE for ; Wed, 27 Apr 2022 17:33:53 +0200 (CEST) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id C5BF2159BC; Wed, 27 Apr 2022 17:33:52 +0200 (CEST) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id C4BF9DE5EB; Wed, 27 Apr 2022 17:33:52 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Wed, 27 Apr 2022 17:33:49 +0200 Message-Id: <20220427153351.1773666-7-aderumier@odiso.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220427153351.1773666-1-aderumier@odiso.com> References: <20220427153351.1773666-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.108 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% HEADER_FROM_DIFFERENT_DOMAINS 0.248 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.001 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH pve-ha-manager 6/8] add resources group X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Apr 2022 15:34:32 -0000 --- debian/pve-ha-manager.install | 1 + src/PVE/HA/Config.pm | 22 +++++++++ src/PVE/HA/Env.pm | 6 +++ src/PVE/HA/Env/PVE2.pm | 6 +++ src/PVE/HA/Makefile | 2 +- src/PVE/HA/Manager.pm | 1 + src/PVE/HA/ResourcesGroups.pm | 90 +++++++++++++++++++++++++++++++++++ src/PVE/HA/Sim/Env.pm | 8 ++++ src/PVE/HA/Sim/Hardware.pm | 15 ++++++ src/PVE/HA/Tools.pm | 6 +++ 10 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 src/PVE/HA/ResourcesGroups.pm diff --git a/debian/pve-ha-manager.install b/debian/pve-ha-manager.install index 3bc7cc8..a4486eb 100644 --- a/debian/pve-ha-manager.install +++ b/debian/pve-ha-manager.install @@ -35,6 +35,7 @@ /usr/share/perl5/PVE/HA/Manager.pm /usr/share/perl5/PVE/HA/NodeStatus.pm /usr/share/perl5/PVE/HA/Resources.pm +/usr/share/perl5/PVE/HA/ResourcesGroups.pm /usr/share/perl5/PVE/HA/Resources/PVECT.pm /usr/share/perl5/PVE/HA/Resources/PVEVM.pm /usr/share/perl5/PVE/HA/Tools.pm diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm index 993b456..f9805d2 100644 --- a/src/PVE/HA/Config.pm +++ b/src/PVE/HA/Config.pm @@ -6,11 +6,13 @@ use JSON; use PVE::HA::Tools; use PVE::HA::Groups; +use PVE::HA::ResourcesGroups; use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file); use PVE::HA::Resources; my $manager_status_filename = "ha/manager_status"; my $ha_groups_config = "ha/groups.cfg"; +my $ha_resources_groups_config = "ha/resources_groups.cfg"; my $ha_resources_config = "ha/resources.cfg"; my $crm_commands_filename = "ha/crm_commands"; my $ha_fence_config = "ha/fence.cfg"; @@ -21,6 +23,9 @@ cfs_register_file($crm_commands_filename, cfs_register_file($ha_groups_config, sub { PVE::HA::Groups->parse_config(@_); }, sub { PVE::HA::Groups->write_config(@_); }); +cfs_register_file($ha_resources_groups_config, + sub { PVE::HA::ResourceGroups->parse_config(@_); }, + sub { PVE::HA::ResourceGroups->write_config(@_); }); cfs_register_file($ha_resources_config, sub { PVE::HA::Resources->parse_config(@_); }, sub { PVE::HA::Resources->write_config(@_); }); @@ -78,6 +83,12 @@ sub parse_groups_config { return PVE::HA::Groups->parse_config($filename, $raw); } +sub parse_resources_roups_config { + my ($filename, $raw) = @_; + + return PVE::HA::Resources_Groups->parse_config($filename, $raw); +} + sub parse_resources_config { my ($filename, $raw) = @_; @@ -200,6 +211,17 @@ sub write_group_config { cfs_write_file($ha_groups_config, $cfg); } +sub read_resources_group_config { + + return cfs_read_file($ha_resources_groups_config); +} + +sub write_resources_group_config { + my ($cfg) = @_; + + cfs_write_file($ha_resources_groups_config, $cfg); +} + sub write_resources_config { my ($cfg) = @_; diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm index 757c5e0..0c917e5 100644 --- a/src/PVE/HA/Env.pm +++ b/src/PVE/HA/Env.pm @@ -130,6 +130,12 @@ sub read_group_config { return $self->{plug}->read_group_config(); } +sub read_resources_groups_config { + my ($self) = @_; + + return $self->{plug}->read_resources_groups_config(); +} + # this should return a hash containing info # what nodes are members and online. sub get_node_info { diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm index ee97559..6e0a55f 100644 --- a/src/PVE/HA/Env/PVE2.pm +++ b/src/PVE/HA/Env/PVE2.pm @@ -189,6 +189,12 @@ sub read_group_config { return PVE::HA::Config::read_group_config(); } +sub read_resources_group_config { + my ($self) = @_; + + return PVE::HA::Config::read_resources_groups_config(); +} + # this should return a hash containing info # what nodes are members and online. sub get_node_info { diff --git a/src/PVE/HA/Makefile b/src/PVE/HA/Makefile index a548c86..bafc7c0 100644 --- a/src/PVE/HA/Makefile +++ b/src/PVE/HA/Makefile @@ -1,5 +1,5 @@ SIM_SOURCES=CRM.pm Env.pm Groups.pm Resources.pm LRM.pm Manager.pm \ - NodeStatus.pm Tools.pm FenceConfig.pm Fence.pm + NodeStatus.pm Tools.pm FenceConfig.pm Fence.pm ResourcesGroups.pm SOURCES=${SIM_SOURCES} Config.pm diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm index 6fa866a..4e318bd 100644 --- a/src/PVE/HA/Manager.pm +++ b/src/PVE/HA/Manager.pm @@ -371,6 +371,7 @@ sub manage { my $sc = $haenv->read_service_config(); $self->{groups} = $haenv->read_group_config(); # update + $self->{vmgroups} = $haenv->read_vmgroup_config(); # compute new service status diff --git a/src/PVE/HA/ResourcesGroups.pm b/src/PVE/HA/ResourcesGroups.pm new file mode 100644 index 0000000..10f97a6 --- /dev/null +++ b/src/PVE/HA/ResourcesGroups.pm @@ -0,0 +1,90 @@ +package PVE::HA::ResourcesGroups; + +use strict; +use warnings; + +use PVE::JSONSchema qw(get_standard_option); +use PVE::SectionConfig; +use PVE::HA::Tools; + +use base qw(PVE::SectionConfig); + +my $defaultData = { + propertyList => { + type => { + description => "Group type.", + optional => 1, + }, + group => get_standard_option('pve-ha-group-id', + { completion => \&PVE::HA::Tools::complete_group }), + resources => get_standard_option('pve-ha-resource-id-list'), + affinity => { + description => "group or separate vms on same host", + type => 'string', + optional => 1, + enum => ['group', 'separate'], + }, + }, +}; + +sub type { + return 'resourcegroup'; +} + +sub options { + return { + resources => { optional => 0 }, + affinity => { optional => 1 }, + }; +} + +sub private { + return $defaultData; +} + +sub decode_value { + my ($class, $type, $key, $value) = @_; + + if ($key eq 'resources') { + my $res = {}; + + foreach my $resource (PVE::Tools::split_list($value)) { + if (PVE::HA::Tools::pve_verify_ha_resource_id($resource)) { + $res->{$resource} = 1; + } + } + + return $res; + } + + return $value; +} + +sub encode_value { + my ($class, $type, $key, $value) = @_; + + if ($key eq 'resources') { + return join(',', keys(%$value)); + } + + return $value; +} + +sub parse_section_header { + my ($class, $line) = @_; + + if ($line =~ m/^(\S+):\s*(\S+)\s*$/) { + my ($type, $group) = (lc($1), $2); + my $errmsg = undef; # set if you want to skip whole section + eval { PVE::JSONSchema::pve_verify_configid($group); }; + $errmsg = $@ if $@; + my $config = {}; # to return additional attributes + return ($type, $group, $errmsg, $config); + } + return undef; +} + +__PACKAGE__->register(); +__PACKAGE__->init(); + +1; diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm index b286708..c3c541b 100644 --- a/src/PVE/HA/Sim/Env.pm +++ b/src/PVE/HA/Sim/Env.pm @@ -253,6 +253,14 @@ sub read_group_config { return $self->{hardware}->read_group_config(); } +sub read_resources_groups_config { + my ($self) = @_; + + $assert_cfs_can_rw->($self); + + return $self->{hardware}->read_resources_groups_config(); +} + # this is normally only allowed by the master to recover a _fenced_ service sub steal_service { my ($self, $sid, $current_node, $new_node) = @_; diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm index 3c3622b..70c2031 100644 --- a/src/PVE/HA/Sim/Hardware.pm +++ b/src/PVE/HA/Sim/Hardware.pm @@ -18,6 +18,7 @@ use POSIX qw(strftime EINTR); use PVE::HA::FenceConfig; use PVE::HA::Groups; +use PVE::HA::ResourcesGroups; my $watchdog_timeout = 60; @@ -397,6 +398,16 @@ sub read_group_config { return PVE::HA::Groups->parse_config($filename, $raw); } +sub read_resources_groups_config { + my ($self) = @_; + + my $filename = "$self->{statusdir}/resources_groups"; + my $raw = ''; + $raw = PVE::Tools::file_get_contents($filename) if -f $filename; + + return PVE::HA::ResourcesGroups->parse_config($filename, $raw); +} + sub read_service_status { my ($self, $node) = @_; @@ -455,6 +466,10 @@ sub new { PVE::Tools::file_set_contents("$statusdir/groups", $default_group_config); } + if (-f "$testdir/resources_groups") { + copy("$testdir/resources_groups", "$statusdir/resources_groups"); + } + if (-f "$testdir/service_config") { copy("$testdir/service_config", "$statusdir/service_config"); } else { diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm index 1a88351..5b9823a 100644 --- a/src/PVE/HA/Tools.pm +++ b/src/PVE/HA/Tools.pm @@ -44,6 +44,12 @@ PVE::JSONSchema::register_standard_option('pve-ha-resource-id', { type => 'string', format => 'pve-ha-resource-id', }); +PVE::JSONSchema::register_standard_option('pve-ha-resource-id-list', { + description => "List of resources", + type => 'string', format => 'pve-ha-resource-id-list', + typetext => '{,}*', +}); + PVE::JSONSchema::register_format('pve-ha-resource-or-vm-id', \&pve_verify_ha_resource_or_vm_id); sub pve_verify_ha_resource_or_vm_id { my ($sid, $noerr) = @_; -- 2.30.2