]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Groups.pm
enhance ha-managers' group commands
[pve-ha-manager.git] / src / PVE / HA / Groups.pm
1 package PVE::HA::Groups;
2
3 use strict;
4 use warnings;
5
6 use Data::Dumper;
7 use PVE::JSONSchema qw(get_standard_option);
8 use PVE::SectionConfig;
9 use PVE::HA::Tools;
10
11 use base qw(PVE::SectionConfig);
12
13 my $defaultData = {
14 propertyList => {
15 type => {
16 description => "Group type.",
17 optional => 1,
18 },
19 group => get_standard_option('pve-ha-group-id',
20 { completion => \&PVE::HA::Tools::complete_group }),
21 nodes => get_standard_option('pve-ha-group-node-list', { optional => 1 }),
22 restricted => {
23 description => "Services on unrestricted groups may run on any cluster members if all group members are offline. But they will migrate back as soon as a group member comes online. One can implement a 'preferred node' behavior using an unrestricted group with one member.",
24 type => 'boolean',
25 optional => 1,
26 default => 0,
27 },
28 nofailback => {
29 description => "The CRM tries to run services on the node with the highest priority. If a node with higher priority comes online, the CRM migrates the service to that node. Enabling nofailback prevents that behavior.",
30 type => 'boolean',
31 optional => 1,
32 default => 0,
33 },
34 comment => {
35 description => "Description.",
36 type => 'string',
37 optional => 1,
38 maxLength => 4096,
39 },
40 },
41 };
42
43 sub type {
44 return 'group';
45 }
46
47 sub options {
48 return {
49 nodes => { optional => 0 },
50 comment => { optional => 1 },
51 nofailback => { optional => 1 },
52 restricted => { optional => 1 },
53 };
54 }
55
56 sub private {
57 return $defaultData;
58 }
59
60 sub decode_value {
61 my ($class, $type, $key, $value) = @_;
62
63 if ($key eq 'nodes') {
64 my $res = {};
65
66 foreach my $node (PVE::Tools::split_list($value)) {
67 if (PVE::JSONSchema::pve_verify_node_name($node)) {
68 $res->{$node} = 1;
69 }
70 }
71
72 return $res;
73 }
74
75 return $value;
76 }
77
78 sub encode_value {
79 my ($class, $type, $key, $value) = @_;
80
81 if ($key eq 'nodes') {
82 return join(',', keys(%$value));
83 }
84
85 return $value;
86 }
87
88 sub parse_section_header {
89 my ($class, $line) = @_;
90
91 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
92 my ($type, $group) = (lc($1), $2);
93 my $errmsg = undef; # set if you want to skip whole section
94 eval { PVE::JSONSchema::pve_verify_configid($group); };
95 $errmsg = $@ if $@;
96 my $config = {}; # to return additional attributes
97 return ($type, $group, $errmsg, $config);
98 }
99 return undef;
100 }
101
102 1;