]>
Commit | Line | Data |
---|---|---|
1c7f4f65 DM |
1 | package PVE::LXCSetup; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::LXCSetup::Debian; | |
7 | ||
8 | my $plugins = { | |
9 | debian => 'PVE::LXCSetup::Debian', | |
10 | }; | |
11 | ||
bdd4194c DM |
12 | my $autodetect_type = sub { |
13 | my ($conf) = @_; | |
14 | ||
15 | my $rootfs = $conf->{'lxc.rootfs'}; | |
16 | if (-f "$rootfs/etc/debian_version") { | |
17 | ||
18 | return "debian"; | |
19 | } | |
20 | die "unable to detect OS disribution\n"; | |
21 | }; | |
22 | ||
1c7f4f65 | 23 | sub new { |
bdd4194c | 24 | my ($class, $conf, $type) = @_; |
1c7f4f65 DM |
25 | |
26 | my $self = bless { conf => $conf }; | |
27 | ||
c325b32f DM |
28 | my $rootfs = $conf->{'lxc.rootfs'}; |
29 | die "unable to find root filesystem\n" if !$rootfs || $rootfs eq '/'; | |
30 | ||
bdd4194c DM |
31 | if (!defined($type)) { |
32 | # try to autodetect type | |
33 | $type = &$autodetect_type($conf); | |
34 | } | |
35 | ||
1c7f4f65 DM |
36 | $self->{plugin} = $plugins->{$type} || |
37 | "no such OS type '$type'\n"; | |
38 | ||
39 | return $self; | |
40 | } | |
41 | ||
42 | sub setup_network { | |
55fa4e09 | 43 | my ($self) = @_; |
1c7f4f65 | 44 | |
55fa4e09 | 45 | $self->{plugin}->setup_network($self->{conf}); |
1c7f4f65 DM |
46 | } |
47 | ||
48 | sub set_hostname { | |
49 | my ($self) = @_; | |
50 | ||
51 | $self->{plugin}->set_hostname($self->{conf}); | |
52 | } | |
53 | ||
c325b32f DM |
54 | sub set_dns { |
55 | my ($self) = @_; | |
56 | ||
57 | $self->{plugin}->set_dns($self->{conf}); | |
58 | } | |
59 | ||
d66768a2 DM |
60 | sub setup_init { |
61 | my ($self) = @_; | |
62 | ||
63 | $self->{plugin}->setup_init($self->{conf}); | |
64 | } | |
65 | ||
168d6b07 DM |
66 | sub set_user_password { |
67 | my ($self, $user, $pw) = @_; | |
68 | ||
69 | $self->{plugin}->set_user_password($self->{conf}, $user, $pw); | |
1c7f4f65 DM |
70 | } |
71 | ||
d66768a2 DM |
72 | sub pre_start_hook { |
73 | my ($self) = @_; | |
74 | ||
75 | $self->{plugin}->pre_start_hook($self->{conf}); | |
76 | } | |
77 | ||
78 | sub post_create_hook { | |
168d6b07 | 79 | my ($self, $root_password) = @_; |
1c7f4f65 | 80 | |
168d6b07 | 81 | $self->{plugin}->post_create_hook($self->{conf}, $root_password); |
1c7f4f65 DM |
82 | } |
83 | ||
84 | 1; |