]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Config.pm
1 package PVE
::HA
::Config
;
9 use PVE
::HA
::Resources
;
10 use PVE
::Cluster
qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file);
12 PVE
::HA
::Groups-
>register();
14 PVE
::HA
::Groups-
>init();
16 PVE
::HA
::Resources
::PVEVM-
>register();
17 #PVE::HA::Resources::IPAddr->register();
19 PVE
::HA
::Resources-
>init();
21 my $manager_status_filename = "ha/manager_status";
22 my $ha_groups_config = "ha/groups.cfg";
23 my $ha_resources_config = "ha/resources.cfg";
24 my $crm_commands_filename = "ha/crm_commands";
26 cfs_register_file
($crm_commands_filename,
27 sub { my ($fn, $raw) = @_; return defined($raw) ?
$raw : ''; },
28 sub { my ($fn, $raw) = @_; return $raw; });
29 cfs_register_file
($ha_groups_config,
30 sub { PVE
::HA
::Groups-
>parse_config(@_); },
31 sub { PVE
::HA
::Groups-
>write_config(@_); });
32 cfs_register_file
($ha_resources_config,
33 sub { PVE
::HA
::Resources-
>parse_config(@_); },
34 sub { PVE
::HA
::Resources-
>write_config(@_); });
35 cfs_register_file
($manager_status_filename,
40 my ($filename, $data) = @_;
42 return defined($data) ? decode_json
($data) : {};
46 my ($filename, $data) = @_;
48 return encode_json
($data);
54 die "undefined node" if !defined($node);
56 my $filename = "/etc/pve/nodes/$node/lrm_status";
58 return PVE
::HA
::Tools
::read_json_from_file
($filename, {});
61 sub write_lrm_status
{
62 my ($node, $status_obj) = @_;
64 die "undefined node" if !defined($node);
66 my $filename = "/etc/pve/nodes/$node/lrm_status";
68 PVE
::HA
::Tools
::write_json_to_file
($filename, $status_obj);
71 sub parse_groups_config
{
72 my ($filename, $raw) = @_;
74 return PVE
::HA
::Groups-
>parse_config($filename, $raw);
77 sub parse_resources_config
{
78 my ($filename, $raw) = @_;
80 return PVE
::HA
::Resources-
>parse_config($filename, $raw);
83 sub resources_config_exists
{
85 return (-f
"/etc/pve/$ha_resources_config") ?
1 : 0;
88 sub read_resources_config
{
90 return cfs_read_file
($ha_resources_config);
93 sub read_group_config
{
95 return cfs_read_file
($ha_groups_config);
98 sub write_group_config
{
101 cfs_write_file
($ha_groups_config, $cfg);
104 sub write_resources_config
{
107 cfs_write_file
($ha_resources_config, $cfg);
110 sub read_manager_status
{
113 return cfs_read_file
($manager_status_filename);
116 sub write_manager_status
{
117 my ($status_obj) = @_;
119 cfs_write_file
($manager_status_filename, $status_obj);
123 my ($code, $errmsg) = @_;
125 # fixme: do not use cfs_lock_storage (replace with cfs_lock_ha)
126 my $res = PVE
::Cluster
::cfs_lock_storage
("_ha_crm_commands", undef, $code);
129 $errmsg ?
die "$errmsg: $err" : die $err;
134 sub queue_crm_commands
{
140 my $data = cfs_read_file
($crm_commands_filename);
142 cfs_write_file
($crm_commands_filename, $data);
145 return lock_ha_config
($code);
148 sub read_crm_commands
{
151 my $data = cfs_read_file
($crm_commands_filename);
152 cfs_write_file
($crm_commands_filename, '');
156 return lock_ha_config
($code);
159 sub vm_is_ha_managed
{
162 my $conf = cfs_read_file
($ha_resources_config);
164 my $sid = "vm:$vmid";
166 return defined($conf->{ids
}->{$sid});