]> git.pld-linux.org Git - packages/lxc.git/commitdiff
Release 2. Added lxc_macvlan service, setting up host macvlan interface for lxc...
authorMateusz Korniak <matkor@pld-linux.org>
Wed, 11 Feb 2015 13:16:38 +0000 (14:16 +0100)
committerMateusz Korniak <matkor@pld-linux.org>
Wed, 11 Feb 2015 13:16:38 +0000 (14:16 +0100)
lxc.spec
lxc_macvlan.init [new file with mode: 0755]
lxc_macvlan.sysconfig [new file with mode: 0644]

index a3bb6efc4af45200a00767dd7bf4171ecd82fc94..1c0e53fd9dc5c505cede7a268107a04ef6dd2ba0 100644 (file)
--- a/lxc.spec
+++ b/lxc.spec
@@ -13,13 +13,15 @@ Summary:    Linux Containers userspace tools
 Summary(pl.UTF-8):     Narzędzia do kontenerów linuksowych (LXC)
 Name:          lxc
 Version:       1.0.7
-Release:       1
+Release:       2
 License:       LGPL v2.1+
 Group:         Applications/System
 Source0:       https://www.linuxcontainers.org/downloads/%{name}-%{version}.tar.gz
 # Source0-md5: b48f468a9bef0e4e140dd723f0a65ad0
 Source1:       %{name}-pld.in.sh
 Source2:       %{name}.init
+Source3:       %{name}_macvlan.init
+Source4:       %{name}_macvlan.sysconfig
 Patch1:                %{name}-pld.patch
 URL:           https://www.linuxcontainers.org/
 BuildRequires: autoconf >= 2.50
@@ -155,8 +157,7 @@ cp -p %{SOURCE1} templates/lxc-pld.in
 %install
 rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT{%{configpath},%{configpath}snap,/var/{cache,log}/lxc}  \
-        -d $RPM_BUILD_ROOT/etc/rc.d/init.d
-
+        -d $RPM_BUILD_ROOT/etc/{rc.d/init.d,sysconfig}
 
 %{__make} install \
        SYSTEMD_UNIT_DIR=%{systemdunitdir} \
@@ -175,6 +176,8 @@ install -d $RPM_BUILD_ROOT{%{configpath},%{configpath}snap,/var/{cache,log}/lxc}
 %{__rm} $RPM_BUILD_ROOT%{_datadir}/%{name}/lxc-patch.py
 
 install -p %{SOURCE2} $RPM_BUILD_ROOT/etc/rc.d/init.d/lxc
+install -p %{SOURCE3} $RPM_BUILD_ROOT/etc/rc.d/init.d/lxc_macvlan
+install -p %{SOURCE4} $RPM_BUILD_ROOT/etc/sysconfig/lxc_macvlan
 
 %if %{with python}
 %py3_comp $RPM_BUILD_ROOT%{py3_sitedir}/lxc
@@ -188,8 +191,22 @@ install -p %{SOURCE2} $RPM_BUILD_ROOT/etc/rc.d/init.d/lxc
 rm -rf $RPM_BUILD_ROOT
 
 %post  -p /sbin/ldconfig
+/sbin/chkconfig --add lxc
+/sbin/chkconfig --add lxc_macvlan
+
+# %service lxc restart
+
+%preun
+if [ "$1" = "0" ]; then
+       %service lxc stop
+       /sbin/chkconfig --del lxc
+       %service lxc_macvlan stop
+       /sbin/chkconfig --del lxc_macvlan
+fi
+
 %postun        -p /sbin/ldconfig
 
+
 %files
 %defattr(644,root,root,755)
 %doc AUTHORS CONTRIBUTING MAINTAINERS README  doc/FAQ.txt doc/examples/*.conf
@@ -217,6 +234,8 @@ rm -rf $RPM_BUILD_ROOT
 %attr(755,root,root) %{_libdir}/liblxc.so.*.*.*
 %attr(755,root,root) %ghost %{_libdir}/liblxc.so.1
 %attr(754,root,root) /etc/rc.d/init.d/lxc
+%attr(754,root,root) /etc/rc.d/init.d/lxc_macvlan
+
 %{systemdunitdir}/lxc.service
 %dir %{_libdir}/%{name}
 %dir %{_libdir}/%{name}/rootfs
@@ -226,6 +245,7 @@ rm -rf $RPM_BUILD_ROOT
 %attr(755,root,root) %{_libdir}/%{name}/lxc-user-nic
 %attr(755,root,root) %{_libdir}/%{name}/lxc-autostart-helper
 %dir %{_sysconfdir}/lxc
+%attr(640,root,root) %config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/lxc_macvlan
 %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/lxc/default.conf
 %dir %{_datadir}/%{name}
 %{_datadir}/%{name}/lxc.functions
diff --git a/lxc_macvlan.init b/lxc_macvlan.init
new file mode 100755 (executable)
index 0000000..f2f9b10
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/sh
+#
+# lxc_macvlan Start/Stop LXC MACVLAN interface
+#
+# chkconfig: 345 98 02
+# description: Starts/Stops LXC MACVLAN interface.
+#
+### BEGIN INIT INFO
+# Provides: lxc_macvlan
+# Default-Start: 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start/Stop LXC MACVLAN interface
+# Description: Start/Stop LXC MACVLAN interface
+### END INIT INFO
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Source any configurable options
+test ! -r /etc/sysconfig/lxc_macvlan ||
+        . /etc/sysconfig/lxc_macvlan
+
+# Tests for data provided in /etc/sysconfig/lxc_macvlan
+if [ -z "$MACVLAN_DEV" ]; then 
+    echo "MACVLAN_DEV not set is /etc/sysconfig/lxc_macvlan"
+    exit 6
+fi
+
+if [ -z "$MACVLAN_NAME" ]; then
+    echo "MACVLAN_NAME not set is /etc/sysconfig/lxc_macvlan"
+    exit 6
+fi
+
+if [ -z "$MACVLAN_ADDRESS" ]; then
+    echo "MACVLAN_ADDRESS not set is /etc/sysconfig/lxc_macvlan"
+    exit 6
+fi
+
+# If not defined MACVLAN_HWADDRESS, calculate it from MACVLAN_ADDRESS
+if [ -z "$MACVLAN_HWADDRESS" ]; then 
+    MACVLAN_HWADDRESS=`echo $MACVLAN_ADDRESS | awk -F "/" '{print $1}' | awk -F "." '{ printf "00:16:3e:%x:%x:%x\n", $2, $3, $4 }'`
+    echo "MACVLAN_HWADDRESS not set, using calculated from MACVLAN_ADDRESS=${MACVLAN_ADDRESS} value: ${MACVLAN_HWADDRESS}"; 
+fi
+
+
+start() {
+        msg_starting "LXC macvlan interface"
+       ip link add link $MACVLAN_DEV name $MACVLAN_NAME address $MACVLAN_HWADDRESS type macvlan mode bridge
+       ip link set $MACVLAN_NAME up
+       ip address add $MACVLAN_ADDRESS brd + dev $MACVLAN_NAME
+       # TODO: check if works: 
+       #    cat  /sys/class/net/macv0/address                                                                                                                                                                                                        
+       #    00:13:00:00:20:14
+        RETVAL=$?
+       [ $RETVAL -eq 0 ] && ok || fail
+}
+
+stop() {
+        msg_stopping "LXC macvlan interface"
+       ip link set $MACVLAN_NAME down
+       ip link del $MACVLAN_NAME
+        RETVAL=$?
+       [ $RETVAL -eq 0 ] && ok || fail
+}
+
+
+RETVAL=0
+
+# See how we were called.
+case "$1" in
+  start)
+       start
+       ;;
+
+  stop)
+       stop
+       ;;
+  restart|reload|force-reload)
+       stop
+       start
+       ;;
+  status)
+       ;;
+  *)
+
+        msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
+        exit 3
+esac
+
+exit  $RETVAL
diff --git a/lxc_macvlan.sysconfig b/lxc_macvlan.sysconfig
new file mode 100644 (file)
index 0000000..fe7201f
--- /dev/null
@@ -0,0 +1,14 @@
+# LXC MACVLAN device config 
+
+# Logical interface name
+MACVLAN_NAME=macv0
+
+# Physical device name where logcial interfaces will be created
+MACVLAN_DEV=eth0
+
+# Host address in MACVLAN network
+MACVLAN_ADDRESS=10.0.0.1/23
+
+# Optional MAC address, must be unique.
+# If not set, will be calculated to 00:16:3e:xx:xx:xx where last six octets  will be last six octets from MACVLAN_ADDRESS  
+# MACVLAN_HWADDRESS=00:16:3e:00:00:01
This page took 0.163714 seconds and 4 git commands to generate.