From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= Subject: [PATCH 2/2] services: Add openvswitch-service-type. Date: Fri, 27 Jan 2017 21:56:16 +0800 Message-ID: <20170127135616.15017-2-iyzsong@member.fsf.org> References: <20170127135616.15017-1-iyzsong@member.fsf.org> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cX785-0005QY-Rn for guix-devel@gnu.org; Fri, 27 Jan 2017 09:03:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cX782-0002lL-H2 for guix-devel@gnu.org; Fri, 27 Jan 2017 09:03:53 -0500 Received: from lb1.openmailbox.org ([5.79.108.160]:35995) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cX782-0002kx-B6 for guix-devel@gnu.org; Fri, 27 Jan 2017 09:03:50 -0500 In-Reply-To: <20170127135616.15017-1-iyzsong@member.fsf.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org * gnu/services/networking.scm (): New record type. (openvswitch-activation, openvswitch-shepherd-service): New procedures. (openvswitch-service-type): New variable. * doc/guix.texi (Networking Services): Document it. --- doc/guix.texi | 15 +++++++++++ gnu/services/networking.scm | 61 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 7093bf746..8f9973542 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -9093,6 +9093,21 @@ Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6 sockets. @end deffn +@deffn {Scheme Variable} openvswitch-service-type +This is the type of the @uref{http://www.openvswitch.org, Open vSwitch} +service, whose value should be an @code{openvswitch-configuration} +object. +@end deffn + +@deftp {Data Type} openvswitch-configuration +Data type representing the configuration of openvswitch. + +@table @asis +@item @code{package} (default: @var{openvswitch}) +Package object of the Open vSwitch. + +@end table +@end deftp @node X Window @subsubsection X Window diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index f7412ff29..8cc92a31d 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -31,6 +31,7 @@ #:use-module (gnu packages linux) #:use-module (gnu packages tor) #:use-module (gnu packages messaging) + #:use-module (gnu packages networking) #:use-module (gnu packages ntp) #:use-module (gnu packages wicd) #:use-module (gnu packages gnome) @@ -72,7 +73,10 @@ network-manager-service-type connman-service - wpa-supplicant-service-type)) + wpa-supplicant-service-type + + openvswitch-service-type + openvswitch-configuration)) ;;; Commentary: ;;; @@ -811,4 +815,59 @@ configure networking." (service-extension dbus-root-service-type list) (service-extension profile-service-type list))))) + +;;; +;;; Open vSwitch +;;; + +(define-record-type* + openvswitch-configuration make-openvswitch-configuration + openvswitch-configuration? + (package openvswitch-configuration-package + (default openvswitch))) + +(define openvswitch-activation + (match-lambda + (($ package) + (let ((ovsdb-tool (file-append package "/bin/ovsdb-tool"))) + #~(begin + (use-modules (guix build utils)) + (mkdir-p "/var/run/openvswitch") + (mkdir-p "/var/lib/openvswitch") + (let ((conf.db "/var/lib/openvswitch/conf.db")) + (unless (file-exists? conf.db) + (system* #$ovsdb-tool "create" conf.db)))))))) + +(define openvswitch-shepherd-service + (match-lambda + (($ package) + (let ((ovsdb-server (file-append package "/sbin/ovsdb-server")) + (ovs-vswitchd (file-append package "/sbin/ovs-vswitchd"))) + (list + (shepherd-service + (provision '(ovsdb)) + (documentation "Run the Open vSwitch database server.") + (start #~(make-forkexec-constructor + (list #$ovsdb-server + "--remote=punix:/var/run/openvswitch/db.sock"))) + (stop #~(make-kill-destructor))) + (shepherd-service + (provision '(vswitchd)) + (requirement '(ovsdb)) + (documentation "Run the Open vSwitch daemon.") + (start #~(make-forkexec-constructor + (list #$ovs-vswitchd))) + (stop #~(make-kill-destructor)))))))) + +(define openvswitch-service-type + (service-type + (name 'openvswitch) + (extensions + (list (service-extension activation-service-type + openvswitch-activation) + (service-extension profile-service-type + (compose list openvswitch-configuration-package)) + (service-extension shepherd-root-service-type + openvswitch-shepherd-service))))) + ;;; networking.scm ends here -- 2.11.0