github.com/blixtra/rkt@v0.8.1-0.20160204105720-ab0d1add1a43/stage1/init/kvm.go (about) 1 // Copyright 2014 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //+build linux 16 17 package main 18 19 import ( 20 "errors" 21 "path/filepath" 22 23 "github.com/appc/spec/schema/types" 24 25 "github.com/coreos/rkt/common" 26 "github.com/coreos/rkt/networking" 27 stage1commontypes "github.com/coreos/rkt/stage1/common/types" 28 stage1initcommon "github.com/coreos/rkt/stage1/init/common" 29 "github.com/coreos/rkt/stage1/init/kvm" 30 "github.com/hashicorp/errwrap" 31 ) 32 33 // KvmPodToSystemd generates systemd unit files for a pod according to the manifest and network configuration 34 func KvmPodToSystemd(p *stage1commontypes.Pod, n *networking.Networking) error { 35 podRoot := common.Stage1RootfsPath(p.Root) 36 37 // networking 38 netDescriptions := kvm.GetNetworkDescriptions(n) 39 if err := kvm.GenerateNetworkInterfaceUnits(filepath.Join(podRoot, stage1initcommon.UnitsDir), netDescriptions); err != nil { 40 return errwrap.Wrap(errors.New("failed to transform networking to units"), err) 41 } 42 43 // volumes 44 // prepare all applications names to become dependency for mount units 45 // all host-shared folder has to become available before applications starts 46 appNames := []types.ACName{} 47 for _, runtimeApp := range p.Manifest.Apps { 48 appNames = append(appNames, runtimeApp.Name) 49 } 50 // mount host volumes through some remote file system e.g. 9p to /mnt/volumeName location 51 // order is important here: PodToSystemHostMountUnits prepares folders that are checked by each appToSystemdMountUnits later 52 if err := stage1initcommon.PodToSystemdHostMountUnits(podRoot, p.Manifest.Volumes, appNames, stage1initcommon.UnitsDir); err != nil { 53 return errwrap.Wrap(errors.New("failed to transform pod volumes into mount units"), err) 54 } 55 56 return nil 57 }