]> git.proxmox.com Git - pve-ha-manager.git/blame - src/PVE/HA/Groups.pm
clean up 'Data::Dumper' usage tree wide
[pve-ha-manager.git] / src / PVE / HA / Groups.pm
CommitLineData
6801c1de
DM
1package PVE::HA::Groups;
2
3use strict;
4use warnings;
5
6801c1de
DM
6use PVE::JSONSchema qw(get_standard_option);
7use PVE::SectionConfig;
a223f4cc 8use PVE::HA::Tools;
6801c1de
DM
9
10use base qw(PVE::SectionConfig);
11
6801c1de
DM
12my $defaultData = {
13 propertyList => {
bc544941
TL
14 type => {
15 description => "Group type.",
16 optional => 1,
17 },
73bede9b
TL
18 group => get_standard_option('pve-ha-group-id',
19 { completion => \&PVE::HA::Tools::complete_group }),
1108ed61 20 nodes => get_standard_option('pve-ha-group-node-list', { optional => 1 }),
6801c1de 21 restricted => {
a2082b28
DM
22 description => "Resources bound to restricted groups may only run on nodes defined by the group.",
23 verbose_description => "Resources bound to restricted groups may only run on nodes defined by the group. The resource will be placed in the stopped state if no group node member is online. Resources on unrestricted groups may run on any cluster node 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 only one member.",
6801c1de
DM
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
43sub type {
44 return 'group';
45}
46
47sub options {
48 return {
1108ed61 49 nodes => { optional => 0 },
6801c1de 50 comment => { optional => 1 },
e941bdc5
DM
51 nofailback => { optional => 1 },
52 restricted => { optional => 1 },
6801c1de
DM
53 };
54}
55
56sub private {
57 return $defaultData;
58}
59
e0a56314
DM
60sub 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)) {
7ae89517 67 if (PVE::HA::Tools::pve_verify_ha_group_node($node)) {
e0a56314
DM
68 $res->{$node} = 1;
69 }
70 }
71
72 return $res;
73 }
74
75 return $value;
76}
77
78sub 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
6801c1de
DM
88sub 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
1021;