]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Groups.pm
Groups: correctly set optional flag in propertyList
[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 => { description => "Section type." },
16 group => get_standard_option('pve-ha-group-id',
17 { completion => \&PVE::HA::Tools::complete_group }),
18 nodes => get_standard_option('pve-ha-group-node-list', { optional => 1 }),
19 restricted => {
20 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.",
21 type => 'boolean',
22 optional => 1,
23 default => 0,
24 },
25 nofailback => {
26 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.",
27 type => 'boolean',
28 optional => 1,
29 default => 0,
30 },
31 comment => {
32 description => "Description.",
33 type => 'string',
34 optional => 1,
35 maxLength => 4096,
36 },
37 },
38 };
39
40 sub type {
41 return 'group';
42 }
43
44 sub options {
45 return {
46 nodes => { optional => 0 },
47 comment => { optional => 1 },
48 nofailback => { optional => 1 },
49 restricted => { optional => 1 },
50 };
51 }
52
53 sub private {
54 return $defaultData;
55 }
56
57 sub decode_value {
58 my ($class, $type, $key, $value) = @_;
59
60 if ($key eq 'nodes') {
61 my $res = {};
62
63 foreach my $node (PVE::Tools::split_list($value)) {
64 if (PVE::JSONSchema::pve_verify_node_name($node)) {
65 $res->{$node} = 1;
66 }
67 }
68
69 return $res;
70 }
71
72 return $value;
73 }
74
75 sub encode_value {
76 my ($class, $type, $key, $value) = @_;
77
78 if ($key eq 'nodes') {
79 return join(',', keys(%$value));
80 }
81
82 return $value;
83 }
84
85 sub parse_section_header {
86 my ($class, $line) = @_;
87
88 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
89 my ($type, $group) = (lc($1), $2);
90 my $errmsg = undef; # set if you want to skip whole section
91 eval { PVE::JSONSchema::pve_verify_configid($group); };
92 $errmsg = $@ if $@;
93 my $config = {}; # to return additional attributes
94 return ($type, $group, $errmsg, $config);
95 }
96 return undef;
97 }
98
99 1;