]>
Commit | Line | Data |
---|---|---|
1c7f4f65 DM |
1 | package PVE::LXCSetup; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
a8e58e9c | 5 | use PVE::Tools; |
1c7f4f65 DM |
6 | |
7 | use PVE::LXCSetup::Debian; | |
a8e58e9c | 8 | use PVE::LXCSetup::Ubuntu; |
c0eae401 | 9 | use PVE::LXCSetup::Redhat; |
1c7f4f65 DM |
10 | |
11 | my $plugins = { | |
12 | debian => 'PVE::LXCSetup::Debian', | |
a8e58e9c | 13 | ubuntu => 'PVE::LXCSetup::Ubuntu', |
c0eae401 | 14 | redhat => 'PVE::LXCSetup::Redhat', |
1c7f4f65 DM |
15 | }; |
16 | ||
bdd4194c | 17 | my $autodetect_type = sub { |
5b4657d0 | 18 | my ($rootdir) = @_; |
a8e58e9c DM |
19 | |
20 | my $lsb_fn = "$rootdir/etc/lsb-release"; | |
21 | if (-f $lsb_fn) { | |
22 | my $data = PVE::Tools::file_get_contents($lsb_fn); | |
23 | if ($data =~ m/^DISTRIB_ID=Ubuntu$/im) { | |
24 | return 'ubuntu'; | |
25 | } | |
26 | } elsif (-f "$rootdir/etc/debian_version") { | |
bdd4194c | 27 | return "debian"; |
c0eae401 DM |
28 | } elsif (-f "$rootdir/etc/redhat-release") { |
29 | return "redhat"; | |
bdd4194c DM |
30 | } |
31 | die "unable to detect OS disribution\n"; | |
32 | }; | |
33 | ||
1c7f4f65 | 34 | sub new { |
5b4657d0 | 35 | my ($class, $conf, $rootdir, $type) = @_; |
1c7f4f65 | 36 | |
5b4657d0 DM |
37 | die "no root directory\n" if !$rootdir || $rootdir eq '/'; |
38 | ||
39 | my $self = bless { conf => $conf, $rootdir => $rootdir}; | |
1c7f4f65 | 40 | |
bdd4194c DM |
41 | if (!defined($type)) { |
42 | # try to autodetect type | |
5b4657d0 | 43 | $type = &$autodetect_type($rootdir); |
bdd4194c DM |
44 | } |
45 | ||
633a7bd8 | 46 | my $plugin_class = $plugins->{$type} || |
1c7f4f65 DM |
47 | "no such OS type '$type'\n"; |
48 | ||
5b4657d0 | 49 | $self->{plugin} = $plugin_class->new($conf, $rootdir); |
633a7bd8 | 50 | |
1c7f4f65 DM |
51 | return $self; |
52 | } | |
53 | ||
142444d5 DM |
54 | sub template_fixup { |
55 | my ($self) = @_; | |
56 | ||
57 | $self->{plugin}->template_fixup($self->{conf}); | |
58 | } | |
59 | ||
1c7f4f65 | 60 | sub setup_network { |
55fa4e09 | 61 | my ($self) = @_; |
1c7f4f65 | 62 | |
55fa4e09 | 63 | $self->{plugin}->setup_network($self->{conf}); |
1c7f4f65 DM |
64 | } |
65 | ||
66 | sub set_hostname { | |
67 | my ($self) = @_; | |
68 | ||
69 | $self->{plugin}->set_hostname($self->{conf}); | |
70 | } | |
71 | ||
c325b32f DM |
72 | sub set_dns { |
73 | my ($self) = @_; | |
74 | ||
75 | $self->{plugin}->set_dns($self->{conf}); | |
76 | } | |
77 | ||
d66768a2 DM |
78 | sub setup_init { |
79 | my ($self) = @_; | |
80 | ||
81 | $self->{plugin}->setup_init($self->{conf}); | |
82 | } | |
83 | ||
168d6b07 DM |
84 | sub set_user_password { |
85 | my ($self, $user, $pw) = @_; | |
86 | ||
87 | $self->{plugin}->set_user_password($self->{conf}, $user, $pw); | |
1c7f4f65 DM |
88 | } |
89 | ||
7ee31468 DM |
90 | sub rewrite_ssh_host_keys { |
91 | my ($self) = @_; | |
92 | ||
93 | $self->{plugin}->rewrite_ssh_host_keys($self->{conf}); | |
94 | } | |
95 | ||
d66768a2 DM |
96 | sub pre_start_hook { |
97 | my ($self) = @_; | |
98 | ||
99 | $self->{plugin}->pre_start_hook($self->{conf}); | |
100 | } | |
101 | ||
102 | sub post_create_hook { | |
168d6b07 | 103 | my ($self, $root_password) = @_; |
1c7f4f65 | 104 | |
168d6b07 | 105 | $self->{plugin}->post_create_hook($self->{conf}, $root_password); |
1c7f4f65 DM |
106 | } |
107 | ||
108 | 1; |