]>
git.proxmox.com Git - pve-container.git/blob - src/PVE/LXC/Setup/SUSE.pm
b7753780b0d2d8facb997239a45639ab55a59d07
1 package PVE
::LXC
::Setup
::SUSE
;
6 use PVE
::LXC
::Setup
::Base
;
8 use base
qw(PVE::LXC::Setup::Base);
11 my ($class, $conf, $rootdir) = @_;
13 my $release = eval { -f
"$rootdir/etc/SuSE-release"
14 ? PVE
::Tools
::file_get_contents
("$rootdir/etc/SuSE-release")
15 : PVE
::Tools
::file_get_contents
("$rootdir/etc/SuSE-brand") };
16 die "unable to read version info\n" if $@;
20 # Fixme: not sure whether the minor part is optional.
21 if ($release =~ m/^\s*VERSION\s*=\s*(\d+)(?:\.(\d+))?\s*$/m) {
23 # 13.2 needs an updated AppArmor profile (in lxc *after* 2.0.0.beta2)
24 if ($1 != 13 || ($2//0) > 2) {
25 die "unsupported suse release '$version'\n";
28 die "unrecognized suse release";
31 my $self = { conf
=> $conf, rootdir
=> $rootdir, version
=> $version };
33 $conf->{ostype
} = 'opensuse';
35 return bless $self, $class;
39 my ($self, $conf) = @_;
41 $self->setup_securetty($conf);
45 my ($self, $conf) = @_;
47 if ($self->{version
} >= 13.2) {
48 $self->setup_container_getty_service($conf);
50 $self->setup_systemd_console($conf);
54 my ($self, $conf) = @_;
58 $self->ct_make_path('/etc/sysconfig/network');
60 foreach my $k (keys %$conf) {
61 next if $k !~ m/^net(\d+)$/;
62 my $d = PVE
::LXC
::Config-
>parse_lxc_network($conf->{$k});
65 my $filename = "/etc/sysconfig/network/ifcfg-$d->{name}";
66 my $routefile = "/etc/sysconfig/network/ifroute-$d->{name}";
69 my @DHCPMODES = ('static', 'dhcp4', 'dhcp6', 'dhcp');
70 my ($NONE, $DHCP4, $DHCP6, $BOTH) = (0, 1, 2, 3);
75 my $is_configured = 0;
77 if ($d->{ip
} && $d->{ip
} ne 'manual') {
79 if ($d->{ip
} eq 'dhcp') {
82 push @addrs, $d->{ip
};
83 if (defined($d->{gw
})) {
84 if (!PVE
::Network
::is_ip_in_cidr
($d->{gw
}, $d->{ip
}, 4)) {
85 $routes .= "$d->{gw} 0.0.0.0 255.255.255.255 $d->{name}\n";
87 $routes .= "default $d->{gw} 0.0.0.0 $d->{name}\n";
92 if ($d->{ip6
} && $d->{ip6
} ne 'manual') {
94 if ($d->{ip6
} eq 'auto') {
95 # FIXME: Not sure what to do here...
96 } elsif ($d->{ip6
} eq 'dhcp') {
99 push @addrs, $d->{ip6
};
100 if (defined($d->{gw6
})) {
101 if (!PVE
::Network
::is_ip_in_cidr
($d->{gw6
}, $d->{ip6
}, 6) &&
102 !PVE
::Network
::is_ip_in_cidr
($d->{gw6
}, 'fe80::/10', 6)) {
103 $routes .= "$d->{gw6}/128 - - $d->{name}\n";
105 $routes .= "default $d->{gw6} - $d->{name}\n";
111 for my $i (1..@addrs) {
112 $data .= "IPADDR_${i}=$addrs[$i-1]\n";
115 $data .= "IPADDR=$addrs[0]\n";
117 # check for non-manual config with no dhcp and no addresses
118 next if $is_configured && $dhcp == $NONE;
121 $data = "STARTMODE=" . ($is_configured ?
'onboot' : 'manual') . "\n"
122 . "BOOTPROTO=$DHCPMODES[$dhcp]\n"
124 $self->ct_file_set_contents($filename, $data);
126 # To keep user-defined routes in route-$iface we mark ours:
127 $self->ct_modify_file($routefile, $routes, delete => 1, prepend
=> 1);