1
1
Fork 0

macvlan 설정 가능하도록 함

This commit is contained in:
Sangbum Kim 2017-04-24 00:07:11 +09:00
parent c8be99e787
commit 0508524148
3 changed files with 66 additions and 14 deletions

View File

@ -22,17 +22,16 @@ func main(){
renameInterface(link,"eth0")
switch linkInterfaceType {
case "macvlan":
macAddr,_ := net.ParseMAC(getEnv("IF_ADDR"))
renameMacAddress(link,macAddr)
case "ipvlan":
ipAddr,_ := netlink.ParseAddr(getEnv("IP_ADDR"))
gatewayAddr := net.ParseIP(getEnv("GATEWAY_ADDR"))
netlink.AddrAdd(link,ipAddr)
netlink.LinkSetUp(link)
addRoute(gatewayAddr,link)
}
if macAddr,err:= net.ParseMAC(getEnvWithDefault("MAC_ADDR","")) ;err == nil{
renameMacAddress(link,macAddr)
}
if ipAddr,err:= netlink.ParseAddr(getEnvWithDefault("IP_ADDR","")) ; err ==nil{
netlink.AddrAdd(link,ipAddr)
}
netlink.LinkSetUp(link)
if gatewayAddrStr:= getEnvWithDefault("GATEWAY_ADDR","");len(gatewayAddrStr)>0{
addRoute(net.ParseIP(gatewayAddrStr),link)
}
}
func readInitEnviron(){

View File

@ -23,15 +23,39 @@ import (
"github.com/vishvananda/netlink"
)
type cmdList []string
func (i *cmdList) Set(value string) error {
*i = append(*i, value)
return nil
}
func (i *cmdList) String() string {
return ""
}
func (i *cmdList) IsCumulative() bool {
return true
}
func CmdList(s kingpin.Settings) (target *[]string) {
target = new([]string)
s.SetValue((*cmdList)(target))
return
}
var (
app = kingpin.New("octopus-outside", "nspawn Bootstrapper.").Author("Sangbum Kim<sangbumkim@amuz.es>")
verbosePtr = app.Flag("verbose", "Enable verbose mode.").Short('v').Bool()
clearPtr = app.Flag("clear", "clear os environment.").Short('p').Bool()
ifBindTypePtr = app.Flag("if-bind-type", "choose virtual ethernet bind type(ipvlan,macvlan).").Default("ipvlan").Short('b').Enum("ipvlan","macvlan")
macAddrPtr = app.Flag("mac-address", "Specify MAC address of macvlan mode. if not specify, use random.").Short('a').String()
nspawnPathPtr = app.Flag("nspawn-path", "systemd-nspawn location.").Short('s').String()
containerHomePtr = app.Flag("container-home", "container residence path").Default("/container").Short('d').String()
configFileNamePtr = app.Flag("config-file", "config file name").Default("settings.yml").HintOptions("FILENAME").Short('c').String()
nodeNamePtr = app.Arg("nodeName", "nodename to spawn.").Required().String()
bindIfNamePtr = app.Arg("bindInterface", "interface name to bind.").Required().String()
cmdListArgsPtr = CmdList(app.Arg("cmd","execute command rather than boot process"))
)
type mountPoint struct {
@ -40,6 +64,7 @@ type mountPoint struct {
Readonly bool `yaml:"readonly"`
}
func (mp mountPoint) Option(nodePath string) (option string, err error) {
var mountPointPath string
if filepath.IsAbs(mp.Name){
@ -289,10 +314,13 @@ func main() {
_, err := app.Parse(os.Args[1:])
var (
verbose = *verbosePtr
ifBindType = *ifBindTypePtr
macAddr = strings.TrimSpace(*macAddrPtr)
clear = *clearPtr
nodeName = *nodeNamePtr
bindIfName = *bindIfNamePtr
configFileName = *configFileNamePtr
cmdListArgs = *cmdListArgsPtr
nspawnPath string
progress = -1
)
@ -371,13 +399,25 @@ func main() {
fmt.Printf(" - bind interface{%s} : valid\n", bindIfName)
fmt.Printf(" - default routing info : ip %s/%d link %s\n", gw.String(), cidr, linkname)
fmt.Printf(" - node{%s} IP address : %s\n", nodeName, nodeAddr.String())
fmt.Printf(" - bind interface type : %s\n",ifBindType)
}
option := []string{
"--quiet",
"--boot",
"--link-journal=try-host",
"--notify-ready=true"}
option = append(option, fmt.Sprintf("--network-ipvlan=%s", bindIfName))
switch ifBindType {
case "macvlan":
option = append(option, fmt.Sprintf("--network-macvlan=%s", bindIfName))
if len(macAddr)>0{
option = append(option, fmt.Sprintf("--setenv=MAC_ADDR=%s", macAddr))
}
case "ipvlan":
option = append(option, fmt.Sprintf("--network-ipvlan=%s", bindIfName))
default:
panic(errors.New("unknown bind type"))
}
option = append(option, fmt.Sprintf("--setenv=IF_TYPE=%s", ifBindType))
option = append(option, fmt.Sprintf("--setenv=IP_ADDR=%s/%d", nodeAddr.String(), cidr))
option = append(option, fmt.Sprintf("--setenv=GATEWAY_ADDR=%s", gw.String()))
option = append(option, fmt.Sprintf("--machine=%s", nodeName))
@ -390,6 +430,19 @@ func main() {
option = append(option, mountOption)
}
}
if len(cmdListArgs) == 0 {
if verbose {
fmt.Println("startup type: using systemd")
}
option = append(option, "--boot")
}else {
if verbose {
fmt.Println("startup type: using command")
}
for _, cmdArg := range cmdListArgs {
option = append(option, fmt.Sprintf(" %s",cmdArg))
}
}
var env []string
if clear {
env = []string{}

View File

@ -15,7 +15,7 @@ After=dnsmasq.service
After=pdnsd.service
[Service]
ExecStart=/container/octopus-outside %I igb0 -v
ExecStart=/container/octopus-outside %I igb0 -v -b macvlan
KillMode=mixed
Type=notify
RestartForceExitStatus=133