]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Groups.pm
clean up 'Data::Dumper' usage tree wide
[pve-ha-manager.git] / src / PVE / HA / Groups.pm
1 package PVE::HA::Groups;
2
3 use strict;
4 use warnings;
5
6 use PVE::JSONSchema qw(get_standard_option);
7 use PVE::SectionConfig;
8 use PVE::HA::Tools;
9
10 use base qw(PVE::SectionConfig);
11
12 my $defaultData = {
13 propertyList => {
14 type => {
15 description => "Group type.",
16 optional => 1,
17 },
18 group => get_standard_option('pve-ha-group-id',
19 { completion => \&PVE::HA::Tools::complete_group }),
20 nodes => get_standard_option('pve-ha-group-node-list', { optional => 1 }),
21 restricted => {
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.",
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::HA::Tools::pve_verify_ha_group_node($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;