]>
git.proxmox.com Git - pve-container.git/blob - src/PVE/LXC/Setup/SUSE.pm
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, $os_release) = @_;
13 my $version = $os_release->{VERSION_ID
};
14 my $ostype = $os_release->{ID
};
16 if ($version =~ m/^(\d+)\.(\d+)$/) {
17 my ($major, $minor) = ($1, $2);
20 } elsif ($major == 13 && $minor <= 2) {
22 } elsif ($ostype eq 'sles' && $major == 12) {
23 # OK - shares base with LEAP (42)
24 } elsif ($major == 15) {
25 # OK for SLES and openSUSE Leap, see: https://lwn.net/Articles/720924/
27 die "unsupported suse release '$version'\n";
29 } elsif ($version =~ m/^(\d{4})(\d{2})(\d{2})$/) {
30 my ($year, $month, $day) = ($1, $2, $3);
31 if ($year >= 2017 && $month <= 12 && $day <= 31) {
34 die "unsupported suse tumbleweed release '$version'\n";
37 die "unrecognized suse release";
40 my $self = { conf
=> $conf, rootdir
=> $rootdir, version
=> $version, os_release
=> $os_release };
42 $conf->{ostype
} = 'opensuse';
44 return bless $self, $class;
48 my ($self, $conf) = @_;
50 $self->setup_securetty($conf);
52 # temporary fix for systemd-firstboot
53 $self->ct_file_set_contents('/etc/locale.conf', "LANG=C.utf8") if !$self->ct_file_exists('/etc/locale.conf');
54 $self->ct_symlink('/usr/share/zoneinfo/UTC', '/etc/localtime') if !$self->ct_file_exists('/etc/localtime');
56 $self->remove_lxc_name_from_etc_hosts();
60 my ($self, $conf) = @_;
62 $self->fixup_old_getty();
64 $self->setup_container_getty_service($conf);
68 my ($self, $conf) = @_;
72 $self->ct_make_path('/etc/sysconfig/network');
74 foreach my $k (keys %$conf) {
75 next if $k !~ m/^net(\d+)$/;
76 my $d = PVE
::LXC
::Config-
>parse_lxc_network($conf->{$k});
79 my $filename = "/etc/sysconfig/network/ifcfg-$d->{name}";
80 my $routefile = "/etc/sysconfig/network/ifroute-$d->{name}";
83 my @DHCPMODES = ('static', 'dhcp4', 'dhcp6', 'dhcp');
84 my ($NONE, $DHCP4, $DHCP6, $BOTH) = (0, 1, 2, 3);
89 my $is_configured = 0;
91 if ($d->{ip
} && $d->{ip
} ne 'manual') {
93 if ($d->{ip
} eq 'dhcp') {
96 push @addrs, $d->{ip
};
97 if (defined($d->{gw
})) {
98 if (!PVE
::Network
::is_ip_in_cidr
($d->{gw
}, $d->{ip
}, 4)) {
99 $routes .= "$d->{gw} 0.0.0.0 255.255.255.255 $d->{name}\n";
101 $routes .= "default $d->{gw} 0.0.0.0 $d->{name}\n";
106 if ($d->{ip6
} && $d->{ip6
} ne 'manual') {
108 if ($d->{ip6
} eq 'auto') {
109 # FIXME: Not sure what to do here...
110 } elsif ($d->{ip6
} eq 'dhcp') {
113 push @addrs, $d->{ip6
};
114 if (defined($d->{gw6
})) {
115 if (!PVE
::Network
::is_ip_in_cidr
($d->{gw6
}, $d->{ip6
}, 6) &&
116 !PVE
::Network
::is_ip_in_cidr
($d->{gw6
}, 'fe80::/10', 6)) {
117 $routes .= "$d->{gw6}/128 - - $d->{name}\n";
119 $routes .= "default $d->{gw6} - $d->{name}\n";
125 for my $i (1..@addrs) {
126 $data .= "IPADDR_${i}=$addrs[$i-1]\n";
129 $data .= "IPADDR=$addrs[0]\n";
131 # check for non-manual config with no dhcp and no addresses
132 next if $is_configured && $dhcp == $NONE;
135 $data = "STARTMODE=" . ($is_configured ?
'onboot' : 'manual') . "\n"
136 . "BOOTPROTO=$DHCPMODES[$dhcp]\n"
138 $self->ct_file_set_contents($filename, $data);
140 # To keep user-defined routes in route-$iface we mark ours:
141 $self->ct_modify_file($routefile, $routes, delete => 1, prepend
=> 1);