]> git.proxmox.com Git - pve-installer.git/blame - Proxmox/Install/Config.pm
switch "maxvz" over to central config
[pve-installer.git] / Proxmox / Install / Config.pm
CommitLineData
390889ab
TL
1package Proxmox::Install::Config;
2
3use strict;
4use warnings;
5
6use Carp;
7use JSON qw(from_json to_json);
8
9use Proxmox::Install::ISOEnv;
10
11my sub init_cfg {
12 return {
13 # installer behavior related
14 autoreboot => 1,
15
16 # disk and filesystem related
17 filesys => 'ext4',
18 hdsize => undef,
19 swapsize => undef,
20 maxroot => undef,
21 minfree => undef,
22 maxvz => undef,
23 };
24}
25
26# merge a $new hash into the current config, with $new taking precedence
27sub merge {
28 my ($new) = @_;
29
30 my $current = get();
31
32 for my $k (sort keys $new->%*) { # first check all
33 croak "unknown key '$k'" if !exists($current->{$k})
34 }
35 $current->{$_} = $new->{$_} for sort keys $new->%*; # then merge
36
37 return $current;
38}
39
40my $_cfg = undef; # NOTE: global singleton
41sub get {
42 my ($k) = @_;
43 $_cfg = init_cfg() if !defined($_cfg);
44 return defined($k) ? $_cfg->{$k} : $_cfg;
45}
46
47sub set_key {
48 my ($k, $v) = @_;
49 my $cfg = get();
50 croak "unknown key '$k'" if !exists($cfg->{$k});
51 $cfg->{$k} = $v;
52}
53
54sub parse_kernel_cmdline {
55 my $cfg = get();
56
57 my $cmdline = Proxmox::Install::RunEnv::get('kernel_cmdline');
58
59 if ($cmdline =~ m/\s(ext4|xfs)(\s.*)?$/) {
60 $cfg->{filesys} = $1;
61 }
62
63 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
64 $cfg->{hdsize} = $1;
65 }
66
67 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
68 $cfg->{swapsize} = $1;
69 }
70
71 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
72 $cfg->{maxroot} = $1;
73 }
74
75 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
76 $cfg->{minfree} = $1;
77 }
78
79 my $iso_env = Proxmox::Install::ISOEnv::get();
80 if ($iso_env->{product} eq 'pve') {
81 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
82 $cfg->{maxvz} = $1;
83 }
84 }
85
86 return $cfg;
87}
88
0a3ac982
TL
89sub set_autoreboot { set_key('autoreboot', $_[0]); }
90sub get_autoreboot { return get('autoreboot'); }
91
cd1a45ad
TL
92sub set_filesys { set_key('filesys', $_[0]); }
93sub get_filesys { return get('filesys'); }
94
a8a14c4d
TL
95sub set_hdsize { set_key('hdsize', $_[0]); }
96sub get_hdsize { return get('hdsize'); }
97
ef41b049
TL
98sub set_swapsize { set_key('swapsize', $_[0]); }
99sub get_swapsize { return get('swapsize'); }
100
b4ab3f19
TL
101sub set_maxroot { set_key('maxroot', $_[0]); }
102sub get_maxroot { return get('maxroot'); }
103
35e7bf16
TL
104sub set_minfree { set_key('minfree', $_[0]); }
105sub get_minfree { return get('minfree'); }
106
140f2e85
TL
107sub set_maxvz { set_key('maxvz', $_[0]); }
108sub get_maxvz { return get('maxvz'); }
109
390889ab 1101;