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;
43 my ($self, $conf) = @_;
45 $self->setup_securetty($conf, qw(lxc/console lxc/tty1 lxc/tty2 lxc/tty3 lxc/tty4));
46 if ($self->{version
} >= 13.2) {
47 $self->setup_container_getty_service();
49 $self->setup_systemd_console($conf);
52 sub setup_container_getty_service
{
54 my $servicefile = '/usr/lib/systemd/system/container-getty@.service';
55 my $raw = $self->ct_file_get_contents($servicefile);
56 if ($raw =~ s
@pts/%I@lxc/tty%I@g) {
57 $self->ct_file_set_contents($servicefile, $raw);
62 my ($self, $conf) = @_;
66 $self->ct_make_path('/etc/sysconfig/network');
68 foreach my $k (keys %$conf) {
69 next if $k !~ m/^net(\d+)$/;
70 my $d = PVE
::LXC
::parse_lxc_network
($conf->{$k});
73 my $filename = "/etc/sysconfig/network/ifcfg-$d->{name}";
74 my $routefile = "/etc/sysconfig/network/ifroute-$d->{name}";
77 my @DHCPMODES = ('static', 'dhcp4', 'dhcp6', 'dhcp');
78 my ($NONE, $DHCP4, $DHCP6, $BOTH) = (0, 1, 2, 3);
83 my $is_configured = 0;
85 if ($d->{ip
} && $d->{ip
} ne 'manual') {
87 if ($d->{ip
} eq 'dhcp') {
90 push @addrs, $d->{ip
};
91 if (defined($d->{gw
})) {
92 if (!PVE
::Network
::is_ip_in_cidr
($d->{gw
}, $d->{ip
}, 4)) {
93 $routes .= "$d->{gw} 0.0.0.0 255.255.255.255 $d->{name}\n";
95 $routes .= "default $d->{gw} 0.0.0.0 $d->{name}\n";
100 if ($d->{ip6
} && $d->{ip6
} ne 'manual') {
102 if ($d->{ip6
} eq 'auto') {
103 # FIXME: Not sure what to do here...
104 } elsif ($d->{ip6
} eq 'dhcp') {
107 push @addrs, $d->{ip6
};
108 if (defined($d->{gw6
})) {
109 if (!PVE
::Network
::is_ip_in_cidr
($d->{gw6
}, $d->{ip6
}, 6)) {
110 $routes .= "$d->{gw6}/128 - - $d->{name}\n";
112 $routes .= "default $d->{gw6} - $d->{name}\n";
118 for my $i (1..@addrs) {
119 $data .= "IPADDR_${i}=$addrs[$i-1]\n";
122 $data .= "IPADDR=$addrs[0]\n";
124 # check for non-manual config with no dhcp and no addresses
125 next if $is_configured && $dhcp == $NONE;
128 $data = "STARTMODE=" . ($is_configured ?
'onboot' : 'manual') . "\n"
129 . "BOOTPROTO=$DHCPMODES[$dhcp]\n"
131 $self->ct_file_set_contents($filename, $data);
133 # To keep user-defined routes in route-$iface we mark ours:
134 my $head = "# --- BEGIN PVE ROUTES ---\n";
135 my $tail = "# --- END PVE ROUTES ---\n";
136 $self->ct_modify_file_head_portion($routefile, $head, $tail, $routes);