
This PR adds CNI network plugin to stackube. Usage: 1. CNI network config { "cniVersion": "0.3.1", "name": "net", "type": "kubestack", "kubestack-config": "/etc/kubestack.conf" } 2. /etc/kubestack.conf [Global] auth-url=https://192.168.0.3/identity_admin/v2.0 username=admin password=password tenant-name=admin region=RegionOne ext-net-id=550370a3-4fc2-4494-919d-cae33f5b3de8 [Plugin] plugin-name=ovs integration-bridge=br-int 3. Put stackube command to /opt/cni/bin Change-Id: I3a666aa2b0b90ef5d8e2f065ddda0deb6d0fcd94 Implements: blueprint cni-plugin Signed-off-by: Pengfei Ni <feiskyer@gmail.com> Signed-off-by: mozhuli <21621232@zju.edu.cn>
40 lines
758 B
Go
40 lines
758 B
Go
package util
|
|
|
|
import (
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func absPath(cmd string) (string, error) {
|
|
cmdAbsPath, err := exec.LookPath(cmd)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return cmdAbsPath, nil
|
|
}
|
|
|
|
func buildCommand(cmd string, args ...string) (*exec.Cmd, error) {
|
|
cmdAbsPath, err := absPath(cmd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
command := exec.Command(cmdAbsPath)
|
|
command.Args = append(command.Args, args...)
|
|
return command, nil
|
|
}
|
|
|
|
func RunCommand(cmd string, args ...string) ([]string, error) {
|
|
command, err := buildCommand(cmd, args...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
output, err := command.CombinedOutput()
|
|
if err != nil {
|
|
return []string{string(output)}, err
|
|
}
|
|
return strings.Split(strings.TrimSpace(string(output)), "\n"), nil
|
|
}
|