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