From cb832aff0140aa83d2b686e9b74634d2cb04e780 Mon Sep 17 00:00:00 2001 From: Kento Kawakami Date: Thu, 16 Jan 2020 15:49:35 +0900 Subject: [PATCH] Add mounts option for tinet spec This commit is add mounts option for spec file. For example, If I want to mount `pwd` direcotry as follows: ``` nodes: - name: T1 image: slankdev/frr mounts: - "`pwd`:/mnt/test" interfaces: - { name: net0, type: direct, args: T2#net0 } - name: T2 image: slankdev/frr interfaces: - { name: net0, type: direct, args: T1#net0 } ` ``` --- internal/pkg/shell/shell.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/pkg/shell/shell.go b/internal/pkg/shell/shell.go index eebb69f..ca96d30 100644 --- a/internal/pkg/shell/shell.go +++ b/internal/pkg/shell/shell.go @@ -53,6 +53,7 @@ type Node struct { Image string `yaml:"image"` Interfaces []Interface `yaml:"interfaces" mapstructure:"interfaces"` Sysctls []Sysctl `yaml:"sysctls" mapstructure:"sysctls"` + Mounts []string `yaml:"mounts,flow"` } // Interface @@ -367,6 +368,13 @@ func CreateNode(node Node) []string { createNodeCmd += fmt.Sprintf("--sysctl %s ", sysctl.Sysctl) } } + + if len(node.Mounts) != 0 { + for _, mount := range node.Mounts { + createNodeCmd += fmt.Sprintf("-v %s ", mount) + } + } + createNodeCmd += node.Image } else if node.Type == "netns" { createNodeCmd = fmt.Sprintf("ip netns add %s", node.Name) @@ -377,6 +385,13 @@ func CreateNode(node Node) []string { createNodeCmd += fmt.Sprintf("--sysctl %s ", sysctl.Sysctl) } } + + if len(node.Mounts) != 0 { + for _, mount := range node.Mounts { + createNodeCmd += fmt.Sprintf("-v %s ", mount) + } + } + createNodeCmd += node.Image } else { // err := fmt.Errorf("unknown nodetype %s", node.Type)