Skip to content

Commit

Permalink
Fix netplugin start scripts and documents
Browse files Browse the repository at this point in the history
The netplugin starting scripts and README files need to be updated
according to the netplugin CLI refactoring.

Signed-off-by: Wei Tie <wtie@cisco.com>
  • Loading branch information
tiewei committed Nov 21, 2017
1 parent 1cf82e9 commit 1e9c1ca
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 81 deletions.
64 changes: 37 additions & 27 deletions install/HowtoSetupContiv.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Download tarball for the version you want to try.
- `netplugin` and `netmaster` are main binaries which are part of contiv networking.
- `netctl` is command line utinlity you will need to talk to netmaster.

## How to start netmaster ?
## How to start netmaster ?

We recommend starting netmaster on master node in your master slave architecture. You can start netmaster in HA mode and appropriate netmaster node will handle all the queries from end user.
We recommend starting netmaster on master node in your master slave architecture. You can start netmaster in HA mode and appropriate netmaster node will handle all the queries from end user.

```
netmaster --help
Expand All @@ -30,41 +30,51 @@ Usage: netmaster [OPTION]...
prints current version
```

## How to start netplugin ?
## How to start netplugin ?

You start netplugin on each node in your cluster.

```
netplugin --help
Usage of netplugin:
-cluster-store string
state store url (default "etcd://127.0.0.1:2379")
-config string
plugin configuration. Use '-' to read configuration from stdin
-ctrl-ip string
Local ip address to be used for control communication
-debug
Show debugging information generated by netplugin
-host-label string
label used to identify endpoints homed for this host, default is host name. If -config flag is used then host-label must be specified in the the configuration passed. (default "aci-testbed-swarm-1")
-json-log
Format logs as JSON
-plugin-mode string
plugin mode docker|kubernetes (default "docker")
-syslog string
Log to syslog at proto://ip:port -- use 'kernel' to log via kernel syslog
-version
Show version
-vlan-if string
VLAN uplink interface
-vtep-ip string
My VTEP ip address
NAME:
netplugin - Contiv netplugin service
USAGE:
netplugin [global options] command [command options] [arguments...]
VERSION:
Version: <netplugin-version>
GitCommit: <netplugin-commit-sha>
BuildTime: <netplugin-build-time>
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--consul-endpoints value, --consul value set netplugin consul endpoints [$CONTIV_NETPLUGIN_CONSUL_ENDPOINTS]
--ctrl-ip value set netplugin control ip for control plane communication (default: <current-ip-address>) [$CONTIV_NETPLUGIN_CONTROL_IP]
--etcd-endpoints value, --etcd value set netplugin etcd endpoints [$CONTIV_NETPLUGIN_ETCD_ENDPOINTS]
--fwdmode value, --forward-mode value set netplugin forwarding network mode, options: [bridge, routing] [$CONTIV_NETPLUGIN_NET_MODE]
--host value, --host-label value set netplugin host to identify itself (default: "8994bb27e5fb") [$CONTIV_NETPLUGIN_HOST]
--log-level value set netplugin log level, options: [DEBUG, INFO, WARN, ERROR] (default: "INFO") [$CONTIV_NETPLUGIN_LOG_LEVEL]
--mode value, --plugin-mode value set netplugin mode, options: [docker, kubernetes, swarm-mode] [$CONTIV_NETPLUGIN_MODE]
--netmode value, --network-mode value set netplugin network mode, options: [vlan, vxlan] [$CONTIV_NETPLUGIN_NET_MODE]
--syslog-url value set netplugin syslog url in format protocol://ip:port (default: "udp://127.0.0.1:514") [$CONTIV_NETPLUGIN_SYSLOG_URL]
--use-json-log, --json-log set netplugin log format to json [$CONTIV_NETPLUGIN_USE_JSON_LOG]
--use-syslog, --syslog set netplugin send log to syslog or not [$CONTIV_NETPLUGIN_USE_SYSLOG]
--vlan-uplinks value, --vlan-if value set netplugin uplink interfaces [$CONTIV_NETPLUGIN_VLAN_UPLINKS]
--vtep-ip value set netplugin vtep ip for vxlan communication (default: <current-ip-address>) [$CONTIV_NETPLUGIN_VTEP_IP]
--vxlan-port value set netplugin VXLAN port (default: 4789) [$CONTIV_NETPLUGIN_VXLAN_PORT]
--help, -h show help
--version, -v print the version
```

for example we can start netplugin in following manner :
```
For example:
netplugin -plugin-mode docker -vlan-if eno33559296 -vtep-ip 10.193.246.2 -ctrl-ip 10.193.246.2
netplugin --plugin-mode docker --vlan-if eno33559296 --vtep-ip 10.193.246.2 --ctrl-ip 10.193.246.2
where,
eno33559296 = Data interface of the node on which this netplugin is running
10.193.246.2 = Control IP of my node
Expand Down
12 changes: 6 additions & 6 deletions install/v2plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ docker plugin install contiv/v2plugin:<version-tag> iflist=<data ifs used for vl
docker swarm join-token worker -q
# on worker nodes, use the token to join swarm
docker swarm join --token SWMTKN-1-4qgg20vkzhc3jhc765k5x0coyriggkdvw1t7fmbiimqguagqr7-8um9goip0d03yqmmrb4c4fh1j 192.168.2.10:2377
```
docker swarm join --token SWMTKN-1-4qgg20vkzhc3jhc765k5x0coyriggkdvw1t7fmbiimqguagqr7-8um9goip0d03yqmmrb4c4fh1j 192.168.2.10:2377
```
3. Install contiv v2plugin
```
# on swarm manager node install plugin with 'master' role
Expand All @@ -90,9 +90,9 @@ docker plugin install contiv/v2plugin:<version-tag> iflist=<data ifs used for vl
# bootup logs are in /var/log/contiv/plugin_bootup.log
# netplugin, netmaster and ovs logs are also in /var/log/contiv/
```
5. Docker workflow
5. Docker workflow

5.1 Create docker network and start docker services
5.1 Create docker network and start docker services

This workflow doesn't support multi-tenancy and policy
```
Expand Down Expand Up @@ -126,8 +126,8 @@ docker plugin install contiv/v2plugin:<version-tag> iflist=<data ifs used for vl
```

## Contiv plugin workflow (legacy docker mode)
v2plugin can also run in legacy mode by setting the plugin_mode to docker explicitly when installing the plugin
1. Etcd cluster should be brought up on the hosts on localhost:2379.
v2plugin can also run in legacy mode by setting the plugin_mode to docker explicitly when installing the plugin
1. Etcd cluster should be brought up on the hosts on localhost:2379.
2. Install contiv v2plugin
```
docker plugin install contiv/v2plugin:<version-tag> plugin-mode=docker iflist=<data ifs used for vlan networks> fwd_mode=<bridge/routing>
Expand Down
17 changes: 12 additions & 5 deletions install/v2plugin/startcontiv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ if [ $iflist == "" ]; then
echo "iflist is empty. Host interface(s) should be specified to use vlan mode" >> $BOOTUP_LOGFILE
fi
if [ $ctrl_ip != "none" ]; then
ctrl_ip_cfg="-ctrl-ip=$ctrl_ip"
ctrl_ip_cfg="--ctrl-ip=$ctrl_ip"
fi
if [ $vtep_ip != "none" ]; then
vtep_ip_cfg="-vtep-ip=$vtep_ip"
vtep_ip_cfg="--vtep-ip=$vtep_ip"
fi
if [ $listen_url != ":9999" ]; then
listen_url_cfg="-listen-url=$listen_url"
Expand All @@ -39,9 +39,16 @@ if [ $control_url != ":9999" ]; then
control_url_cfg="-control-url=$control_url"
fi
if [ $vxlan_port != "4789" ]; then
vxlan_port_cfg="-vxlan-port=$vxlan_port"
vxlan_port_cfg="--vxlan-port=$vxlan_port"
fi

if [[ "$cluster_store" =~ ^etcd://.+ ]]; then
store_arg="--etcd-endpoints $(echo $cluster_store | sed s/etcd/http/)"
else
store_arg="--consul-endpoints $(echo $cluster_store | sed s/consul/http/)"
fi
set -e

echo "Loading OVS" >> $BOOTUP_LOGFILE
(modprobe openvswitch) || (echo "Load ovs FAILED!!! " >> $BOOTUP_LOGFILE)

Expand All @@ -66,8 +73,8 @@ set +e

echo "Starting Netplugin " >> $BOOTUP_LOGFILE
while true ; do
echo "/netplugin $dbg_flag -plugin-mode=$plugin_mode $vxlan_port_cfg -vlan-if=$iflist -cluster-store=$cluster_store $ctrl_ip_cfg $vtep_ip_cfg" >> $BOOTUP_LOGFILE
/netplugin $dbg_flag -plugin-mode=$plugin_mode $vxlan_port_cfg -vlan-if=$iflist -cluster-store=$cluster_store $ctrl_ip_cfg $vtep_ip_cfg &> $log_dir/netplugin.log
echo "/netplugin $dbg_flag --plugin-mode=$plugin_mode $vxlan_port_cfg --vlan-if=$iflist $store_arg $ctrl_ip_cfg $vtep_ip_cfg" >> $BOOTUP_LOGFILE
/netplugin $dbg_flag --plugin-mode=$plugin_mode $vxlan_port_cfg --vlan-if=$iflist $store_arg $ctrl_ip_cfg $vtep_ip_cfg &> $log_dir/netplugin.log
echo "CRITICAL : Net Plugin has exited, Respawn in 5" >> $BOOTUP_LOGFILE
mv $log_dir/netplugin.log $log_dir/netplugin.log.lastrun
sleep 5
Expand Down
19 changes: 11 additions & 8 deletions netplugin/netd.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ func initNetPluginConifg(ctx *cli.Context) (plugin.Config, error) {

// 4. validate forward mode
forwardMode := strings.ToLower(ctx.String("fwdmode"))
if (networkMode == "vlan" && forwardMode == "bridge") || forwardMode == "routing" {
logrus.Infof("Using netplugin forwarding mode: %v", forwardMode)
} else if forwardMode == "" {
return plugin.Config{}, fmt.Errorf("netplugin network mode is not set")
} else {
return plugin.Config{}, fmt.Errorf("invalid netplugin forwarding mode: %v", forwardMode)
if forwardMode == "" {
return plugin.Config{}, fmt.Errorf("unknown netplugin forwarding mode: %v", forwardMode)
} else if forwardMode != "bridge" && forwardMode != "routing" {
return plugin.Config{}, fmt.Errorf("netplugin forwarding mode is not set")
} else if networkMode == "vxlan" && forwardMode == "bridge" {
return plugin.Config{}, fmt.Errorf("invalid netplugin forwarding mode: %q (network mode: %q)", forwardMode, networkMode)
}
// vxlan/vlan+routing, vlan+bridge are valid combinations
logrus.Infof("Using netplugin forwarding mode: %v", forwardMode)

// 5. validate and set other optional configs
hostLabel := ctx.String("host")
Expand Down Expand Up @@ -268,7 +270,7 @@ func main() {
cli.StringFlag{
Name: "consul-endpoints, consul",
EnvVar: "CONTIV_NETPLUGIN_CONSUL_ENDPOINTS",
Usage: "a comma-delimited list of netplugin consul endpoints",
Usage: "a comma-delimited list of netplugin consul endpoints, ignored when etcd-endpoints is set",
},
cli.IntFlag{
Name: "vxlan-port",
Expand All @@ -283,11 +285,12 @@ func main() {
},
cli.StringFlag{
Name: "fwdmode, forward-mode",
EnvVar: "CONTIV_NETPLUGIN_NET_MODE",
EnvVar: "CONTIV_NETPLUGIN_FORWARD_MODE",
Usage: "set netplugin forwarding network mode, options: [bridge, routing]",
},
/*
// only ovs is supported
// TODO: turn it on when having more than one backend supported
cli.StringFlag {
Name: "driver, net-driver",
Value: "ovs",
Expand Down
4 changes: 2 additions & 2 deletions netplugin/plugin/netplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func InitGlobalSettings(stateDriver core.StateDriver, inst *core.InstanceInfo) e

// make sure local config matches netmaster config
if inst.FwdMode != "" && inst.FwdMode != gCfg.FwdMode {
err := fmt.Errorf("Netplugin's local forward mode [%v] doesn't match global settings [%v]", inst.FwdMode, gCfg.FwdMode)
err := fmt.Errorf("netplugin's local forward mode %q doesn't match global settings %q", inst.FwdMode, gCfg.FwdMode)
logrus.Errorf(err.Error())
return err
}
Expand All @@ -351,7 +351,7 @@ func InitGlobalSettings(stateDriver core.StateDriver, inst *core.InstanceInfo) e
logrus.Infof("Using forwarding mode: %v", inst.FwdMode)
net, err := netutils.CIDRToMask(gCfg.PvtSubnet)
if err != nil {
err := fmt.Errorf("Error convert private subnet %v from CIDR to mask, error %v", gCfg.PvtSubnet, err.Error())
err := fmt.Errorf("error convert private subnet %v from CIDR to mask, error %v", gCfg.PvtSubnet, err.Error())
logrus.Errorf(err.Error())
return err
}
Expand Down
4 changes: 2 additions & 2 deletions objdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func InitClient(storeName string, storeURLs []string) (API, error) {
plugin := GetPlugin(storeName)
if plugin == nil {
log.Errorf("Invalid DB type %s", storeName)
return nil, errors.New("Unsupported DB type")
return nil, errors.New("unsupported DB type")
}
cl, err := plugin.NewClient(storeURLs)
if err != nil {
Expand All @@ -49,7 +49,7 @@ func NewClient(dbURL string) (API, error) {
parts := strings.Split(dbURL, "://")
if len(parts) < 2 {
log.Errorf("Invalid DB URL format %s", dbURL)
return nil, errors.New("Invalid DB URL")
return nil, errors.New("invalid DB URL")
}
clientName := parts[0]
clientURL := parts[1]
Expand Down
4 changes: 2 additions & 2 deletions scripts/netContain/contivInit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ echo "0.0.0.0 localhost" >>/etc/hosts
export no_proxy="0.0.0.0, $NETMASTER_IP"

if [ not $CONTIV_FWD_MODE == "routing" ]; then
CONTIV_FWD_MODE="bridged"
CONTIV_FWD_MODE="bridge"
fi

/contiv/bin/netplugin -vtep-ip $VTEP_IP -vlan-if $VLAN_IF -fwd-mode $CONTIV_FWD_MODE 2>/var/log/contiv/netplugin.errlog 1>/var/log/contiv/netplugin.log &
/contiv/bin/netplugin --netmode vlan --plugin-mode docker --vtep-ip $VTEP_IP --vlan-if $VLAN_IF --fwdmode $CONTIV_FWD_MODE 2>/var/log/contiv/netplugin.errlog 1>/var/log/contiv/netplugin.log &
6 changes: 3 additions & 3 deletions scripts/netContain/contivRc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RC file for passing or tuning contiv parameters correctly. Please set
# them as necessary and described below.
# them as necessary and described below.

# IF this contiv node needs to run as netmaster, set the following to 1
IS_NETMASTER=0
Expand All @@ -8,7 +8,7 @@ IS_NETMASTER=0
# netplugin process
NETMASTER_IP="172.28.11.253"

# VTEP IP address used for VXLAN encapsulation. This should be one
# VTEP IP address used for VXLAN encapsulation. This should be one
# routable within the contiv cluster
VTEP_IP="172.28.11.252"

Expand All @@ -18,5 +18,5 @@ VTEP_IP="172.28.11.252"
# Also used for BGP when started
VLAN_IF="ens32"

#routing or bridged
#routing or bridge
CONTIV_FWD_MODE="routing"
17 changes: 3 additions & 14 deletions scripts/netContain/scripts/contivNet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ netmaster=false
netplugin=true
debug=""
cleanup=false
cstore_param=""
vtep_ip_param=""
vlan_if_param=""
control_url=":9999"
Expand Down Expand Up @@ -49,9 +48,6 @@ while getopts ":xmp:v:i:c:drl:o:t:" opt; do
c)
cstore=$OPTARG
;;
t)
cstore_type=$OPTARG
;;
p)
plugin=$OPTARG
;;
Expand Down Expand Up @@ -144,20 +140,13 @@ elif [ $netplugin == true ]; then

while true; do
if [ -f /tmp/restart_netplugin ]; then
if [ "$cstore" != "" ]; then
if [ "$cstore_type" = "etcd" ]; then
cstore_param="--etcd-endpoints"
else
cstore_param="--consul-endpoints"
fi
fi
if [ "$vtep_ip" != "" ]; then
vtep_ip_param="-vtep-ip"
vtep_ip_param="--vtep-ip"
fi
if [ "$vlan_if" != "" ]; then
vlan_if_param="-vlan-if"
vlan_if_param="--vlan-if"
fi
/contiv/bin/netplugin $debug $cstore_param $cstore $vtep_ip_param $vtep_ip $vlan_if_param $vlan_if -plugin-mode $plugin || true
/contiv/bin/netplugin $debug $store_arg $vtep_ip_param $vtep_ip $vlan_if_param $vlan_if --plugin-mode $plugin || true
echo "CRITICAL : Netplugin has exited. Trying to respawn in 5s"
fi
sleep 5
Expand Down
2 changes: 1 addition & 1 deletion scripts/python/api/tnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def startNetplugin(self, args=""):
# TODO: determine the fwdmode and netmode
fwd_arg = " --fwdmode bridge "
net_arg = " --netmode vlan "
command = "sudo " + self.binpath + "/netplugin -vlan-if eth2 -vlan-if eth3 " + fwd_arg + fwd_arg + store_args + args + "> /tmp/netplugin.log 2>&1"
command = "sudo " + self.binpath + "/netplugin --vlan-if eth2 --vlan-if eth3 " + fwd_arg + fwd_arg + store_args + args + "> /tmp/netplugin.log 2>&1"
self.npThread = threading.Thread(target=ssh_exec_thread, args=(ssh_object, command))
# npThread.setDaemon(True)
self.npThread.start()
Expand Down
10 changes: 5 additions & 5 deletions state/consulstatedriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ func (d *ConsulStateDriver) Init(instInfo *core.InstanceInfo) error {
var endpoint *url.URL

if instInfo == nil || instInfo.DbURL == "" {
return errors.New("no Consul config found")
return errors.New("no consul config found")
}
endpoint, err = url.Parse(instInfo.DbURL)
if err != nil {
return err
}
if endpoint.Scheme == "consul" {
endpoint.Scheme = "http"
} else if endpoint.Scheme != "http" && endpoint.Scheme != "https" {
return fmt.Errorf("invalid Consul URL scheme %q", endpoint.Scheme)
}
if err != nil {
return err
return fmt.Errorf("invalid consul URL scheme %q", endpoint.Scheme)
}
cfg := api.Config{
Address: endpoint.Host,
Expand Down
4 changes: 2 additions & 2 deletions state/etcdstatedriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (d *EtcdStateDriver) Init(instInfo *core.InstanceInfo) error {
var endpoint *url.URL

if instInfo == nil || instInfo.DbURL == "" {
return errors.New("no Etcd config found")
return errors.New("no etcd config found")
}
endpoint, err = url.Parse(instInfo.DbURL)
if err != nil {
Expand All @@ -65,7 +65,7 @@ func (d *EtcdStateDriver) Init(instInfo *core.InstanceInfo) error {
if endpoint.Scheme == "etcd" {
endpoint.Scheme = "http"
} else if endpoint.Scheme != "http" && endpoint.Scheme != "https" {
return core.Errorf("invalid Etcd URL scheme %q", endpoint.Scheme)
return core.Errorf("invalid etcd URL scheme %q", endpoint.Scheme)
}
// TODO: support multi-endpoints
etcdConfig := client.Config{
Expand Down
2 changes: 1 addition & 1 deletion test/systemtests/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (d *docker) startNetplugin(args string) error {
storeArgs = " --consul-endpoints " + strings.Replace(cStore, "consul", "http", 1) + " "
}

cmd := "sudo " + d.node.suite.basicInfo.BinPath + "/netplugin --netmode " + netMode + " --fwdmode " + fwdMode + " -plugin-mode docker -vlan-if " + d.node.suite.hostInfo.HostDataInterfaces + storeArgs + args + " &> /tmp/netplugin.log"
cmd := "sudo " + d.node.suite.basicInfo.BinPath + "/netplugin --netmode " + netMode + " --fwdmode " + fwdMode + " --plugin-mode docker --vlan-if " + d.node.suite.hostInfo.HostDataInterfaces + storeArgs + args + " &> /tmp/netplugin.log"
logrus.Infof("Starting netplugin on %s with command: %s", d.node.Name(), cmd)
return d.node.tbnode.RunCommandBackground(cmd)
}
Expand Down
2 changes: 1 addition & 1 deletion test/systemtests/k8setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func (k *kubernetes) startNetplugin(args string) error {
}
logrus.Infof("Starting netplugin on %s", k.node.Name())

return k.node.tbnode.RunCommandBackground("sudo " + k.node.suite.basicInfo.BinPath + "/netplugin --netmode " + netMode + " --fwdmode " + fwdMode + " -plugin-mode kubernetes -vlan-if " + k.node.suite.hostInfo.HostDataInterfaces + storeArgs + args + "&> /tmp/netplugin.log")
return k.node.tbnode.RunCommandBackground("sudo " + k.node.suite.basicInfo.BinPath + "/netplugin --netmode " + netMode + " --fwdmode " + fwdMode + " --plugin-mode kubernetes --vlan-if " + k.node.suite.hostInfo.HostDataInterfaces + storeArgs + args + "&> /tmp/netplugin.log")
}

func (k *kubernetes) stopNetplugin() error {
Expand Down
2 changes: 1 addition & 1 deletion test/systemtests/kubeadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (k *kubePod) startNetplugin(args string) error {
}

logrus.Infof("Starting netplugin on %s", k.node.Name())
startNetpluginCmd := k.node.suite.basicInfo.BinPath + `/netplugin --netmode ` + netMode + ` --fwdmode ` + fwdMode + ` -plugin-mode=kubernetes -vlan-if=` + k.node.suite.hostInfo.HostDataInterfaces + storeArgs + args + ` > ` + netpluginLogLocation + ` 2>&1`
startNetpluginCmd := k.node.suite.basicInfo.BinPath + `/netplugin --netmode ` + netMode + ` --fwdmode ` + fwdMode + ` --plugin-mode=kubernetes --vlan-if=` + k.node.suite.hostInfo.HostDataInterfaces + storeArgs + args + ` > ` + netpluginLogLocation + ` 2>&1`

return k.podExecBG(podName, startNetpluginCmd, "kube-system")
}
Expand Down
Loading

0 comments on commit 1e9c1ca

Please sign in to comment.