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