1 |
joko |
1.1 |
package UML::Config; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
require Exporter; |
7 |
|
|
our @ISA = qw(Exporter); |
8 |
|
|
our @EXPORT = qw( |
9 |
|
|
$DEBUG_STEP |
10 |
|
|
&get_host_cfg |
11 |
|
|
&get_host_basepath |
12 |
|
|
&get_skel_cfg |
13 |
|
|
&vhost_exists |
14 |
|
|
); |
15 |
|
|
|
16 |
|
|
our $DEBUG_STEP = 1; |
17 |
|
|
|
18 |
|
|
my $ns1 = '<put your nameserver here>'; |
19 |
|
|
|
20 |
|
|
my $cfg_main = { |
21 |
|
|
|
22 |
|
|
'main' => { |
23 |
|
|
'path_base' => '/home/uml', |
24 |
|
|
'path_skels' => '/home/uml/skels', |
25 |
|
|
}, |
26 |
|
|
|
27 |
|
|
'default' => { |
28 |
|
|
'ip' => '192.168.20.1', |
29 |
|
|
'netmask' => '255.255.255.0', |
30 |
|
|
'broadcast' => '192.168.20.255', |
31 |
|
|
'device' => 'eth0', |
32 |
|
|
}, |
33 |
|
|
|
34 |
|
|
'skels' => { |
35 |
|
|
'woody-stable' => { |
36 |
|
|
'rootfs' => 'master-rootfs.woody-stable.ext3-20020810', |
37 |
|
|
'datafs' => 'master-datafs.ext3', |
38 |
|
|
'datafs_type' => 'ext3', |
39 |
|
|
}, |
40 |
|
|
}, |
41 |
|
|
|
42 |
|
|
'hosts' => { |
43 |
|
|
|
44 |
|
|
# -------------------------------------------------------- |
45 |
|
|
'test' => { |
46 |
|
|
'mem' => '64M', |
47 |
|
|
'umid' => 'test', |
48 |
|
|
'path_rel' => 'test', |
49 |
|
|
'rootfs' => 'root_fs.woody-stable.ext3', |
50 |
|
|
'rootfs_size' => 600, |
51 |
|
|
'datafs' => 'data_fs.ext3', |
52 |
|
|
'datafs_type' => 'ext3', |
53 |
|
|
'datafs_size' => 50, |
54 |
|
|
'swapfs' => 'swap', |
55 |
|
|
'net' => { |
56 |
|
|
'device' => 'eth0', |
57 |
|
|
'hostname' => 'test', |
58 |
|
|
# put vhost's main ip-address here |
59 |
|
|
'ip' => '192.168.20.50', |
60 |
|
|
'nameserver' => $ns1, |
61 |
|
|
# put vhost's main domain (mydomain.com) here |
62 |
|
|
'domain' => 'localhost', |
63 |
|
|
}, |
64 |
|
|
'bridge' => { |
65 |
|
|
'device' => 'tap50', |
66 |
|
|
'owner' => 'service', |
67 |
|
|
}, |
68 |
|
|
# declare net-configuration of main host here |
69 |
|
|
# deprecated: this would inherit from $cfg->{default} also |
70 |
|
|
'main' => { |
71 |
|
|
'ip' => '192.168.20.1', |
72 |
|
|
'netmask' => '255.255.255.0', |
73 |
|
|
'device' => 'eth0', |
74 |
|
|
}, |
75 |
|
|
}, |
76 |
|
|
# -------------------------------------------------------- |
77 |
|
|
|
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
}; |
81 |
|
|
|
82 |
|
|
# for local pkg |
83 |
|
|
my %cfg = %{$cfg_main}; |
84 |
|
|
|
85 |
|
|
sub get_skel_cfg { |
86 |
|
|
my $skel_name = shift; |
87 |
|
|
if (! exists $cfg{skels}{$skel_name} ) { |
88 |
|
|
die("skel \"$skel_name\" doesn't exist"); |
89 |
|
|
} |
90 |
|
|
return $cfg{skels}{$skel_name}; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
sub get_host_cfg { |
94 |
|
|
my $host_name = shift; |
95 |
|
|
my $vhost = $cfg{'hosts'}{$host_name}; |
96 |
|
|
|
97 |
|
|
# do something like inheritance here |
98 |
|
|
foreach my $key (keys %{$cfg{default}}) { |
99 |
|
|
my $val = $cfg{default}{$key}; |
100 |
|
|
$vhost->{main}{$key} ||= $val; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
return $vhost; |
104 |
|
|
} |
105 |
|
|
sub vhost_exists { |
106 |
|
|
my $vhost_name = shift; |
107 |
|
|
return exists $cfg{hosts}{$vhost_name}; |
108 |
|
|
} |
109 |
|
|
sub get_host_basepath { |
110 |
|
|
my $host_name = shift; |
111 |
|
|
if (!vhost_exists($host_name)) { |
112 |
|
|
die("vhost \"$host_name\" doesn't exist"); |
113 |
|
|
} |
114 |
|
|
return $cfg{'main'}{'path_base'} . '/' . $cfg{'hosts'}{$host_name}{'path_rel'}; |
115 |
|
|
} |
116 |
|
|
sub get_host_rootfs { |
117 |
|
|
my $host_name = shift; |
118 |
|
|
my $host = get_host_cfg($host_name); |
119 |
|
|
return get_host_basepath($host_name) . '/rootfs/' . $host->{'rootfs'}; |
120 |
|
|
} |
121 |
|
|
sub get_host_datafs { |
122 |
|
|
my $host_name = shift; |
123 |
|
|
my $host = get_host_cfg($host_name); |
124 |
|
|
return get_host_basepath($host_name) . '/datafs/' . $host->{'datafs'}; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
sub get_skel_base { |
128 |
|
|
my $skel_name = shift; |
129 |
|
|
return $cfg{'main'}{'path_skels'} . '/' . $skel_name; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
sub get_skel_rootfs_file { |
133 |
|
|
my $skel_name = shift; |
134 |
|
|
return $cfg{'skels'}{$skel_name}{'rootfs'}; |
135 |
|
|
} |
136 |
|
|
sub get_skel_rootfs_path { |
137 |
|
|
my $skel_name = shift; |
138 |
|
|
return $cfg{'main'}{'path_skels'} . '/' . $skel_name . '/' . get_skel_rootfs_file($skel_name); |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
sub get_skel_datafs_file { |
142 |
|
|
my $skel_name = shift; |
143 |
|
|
return $cfg{'skels'}{$skel_name}{'datafs'}; |
144 |
|
|
} |
145 |
|
|
sub get_skel_datafs_path { |
146 |
|
|
my $skel_name = shift; |
147 |
|
|
return $cfg{'main'}{'path_skels'} . '/' . $skel_name . '/' . get_skel_datafs_file($skel_name); |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
1; |