#/bin/bash
export DEBUG=1
export NETCONFPATH=/etc/cni/net.d/
-export CNI_PATH=/home/mcambria/go/src/github.com/containernetworking/cni/bin/
+#export CNI_PATH=/home/mcambria/go/src/github.com/containernetworking/cni/bin/
+export CNI_PATH=/home/mcambria/go2/src/stash.verizon.com/cni/bin
export NETCONFPATH=${NETCONFPATH-/etc/cni/net.d}
export CNI_COMMAND=ADD
export CNI_NETNS=/var/run/netns/mcc-cni-test0
export CNI_CONTAINERID=mcc-cni-test0
-export CNI_ARGS="IP=172.19.99.99"
-export CNI_ARGS+=";UPLINK=cbr0"
+export CNI_ARGS="IP=172.19.99.99;UPLINK=cbr0"
+#export CNI_ARGS="IP=172.19.99.99"
+#export CNI_ARGS+=";UPLINK=cbr0"
export PATH=$CNI_PATH:$PATH
export CNI_IFNAME=eth1
echo $CNI_ARGS
-macvlan </etc/cni/net.d/20-macvlan0.conf
+bin/macvlan < /etc/cni/net.d/20-macvlan0.conf
#/bin/bash
export DEBUG=1
export NETCONFPATH=/etc/cni/net.d/
-export CNI_PATH=/home/mcambria/go/src/github.com/containernetworking/cni/bin/
+#export CNI_PATH=/home/mcambria/go/src/github.com/containernetworking/cni/bin/
+export CNI_PATH=/home/mcambria/go2/src/stash.verizon.com/cni/bin
export NETCONFPATH=${NETCONFPATH-/etc/cni/net.d}
export CNI_COMMAND=DEL
export CNI_NETNS=/var/run/netns/mcc-cni-test0
export CNI_CONTAINERID=mcc-cni-test0
-export CNI_ARGS="IP=172.19.99.99"
-export CNI_ARGS+=";UPLINK=cbr0"
+export CNI_ARGS="IP=172.19.99.99;UPLINK=cbr0"
+#export CNI_ARGS="IP=172.19.99.99"
+#export CNI_ARGS+=";UPLINK=cbr0"
export PATH=$CNI_PATH:$PATH
export CNI_IFNAME=eth1
echo $CNI_ARGS
-macvlan </etc/cni/net.d/20-macvlan0.conf
+bin/macvlan < /etc/cni/net.d/20-macvlan0.conf
"fmt"
"net"
+ "log"
+ "os"
+
"github.com/containernetworking/cni/pkg/types"
)
type IPAMArgs struct {
types.CommonArgs
IP net.IP `json:"ip,omitempty"`
+ UPLINK types.UnmarshallableString `json:"uplink,omitempty"`
+}
+
+/*
+ * Add structs needed to parse labels
+ */
+type Args struct {
+ Mesos Mesos `json:"org.apache.mesos,omitempty"`
+}
+
+type Mesos struct {
+ NetworkInfo NetworkInfo `json:"network_info"`
+}
+
+type NetworkInfo struct {
+ Name string `json:"name"`
+ Labels struct {
+ Labels []struct {
+ Key string `json:"key"`
+ Value string `json:"value"`
+ } `json:"labels,omitempty"`
+ } `json:"labels,omitempty"`
+}
+
+// NetConf describes a network.
+type NetConf struct {
+ CNIVersion string `json:"cniVersion,omitempty"`
+
+ Name string `json:"name,omitempty"`
+ Type string `json:"type,omitempty"`
+ IPAM *IPAMConfig `json:"ipam"`
+ DNS types.DNS `json:"dns"`
+ ARGS *Args `json:"args,omitempty"`
}
type Net struct {
// NewIPAMConfig creates a NetworkConfig from the given network name.
func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, string, error) {
- n := Net{}
+ //n := Net{}
+ n := NetConf{}
if err := json.Unmarshal(bytes, &n); err != nil {
return nil, "", err
}
// Copy net name into IPAM so not to drag Net struct around
n.IPAM.Name = n.Name
+ /*
+ * Example of getting an environment variable supplied to the IPAM plugin
+ */
+ mccval := os.Getenv("MCCVAL")
+ println("mccval is: ", mccval)
+
+ /*
+ * Get values for supplied labels
+ * Ensure that IPAM args (e.g. CNI_ARGS) isn't confused with args passed to CNI itself
+ */
+ labels := map[string]string{}
+
+ if args != "" {
+ if n.ARGS != nil {
+
+ for k, label := range n.ARGS.Mesos.NetworkInfo.Labels.Labels {
+ labels[label.Key] = label.Value
+ println("Map k (for)", k)
+ println("Map k (for)", k, label.Key, label.Value)
+ }
+
+ println("CNI Args: Net Name: ", n.ARGS.Mesos.NetworkInfo.Name)
+ }
+ }
+
+ for key, value := range labels {
+ println("Key:", key, "Value:", value)
+ }
+
+ println("CNI IPAM Name: ", n.IPAM.Name)
+
+ if n.IPAM.Args != nil {
+ var args_ip net.IP
+ if n.IPAM.Args.IP != nil {
+ args_ip = n.IPAM.Args.IP
+ log.Println("IPAM args: n.IPAM.IP is:", args_ip)
+ }
+
+ var uplink types.UnmarshallableString
+ if n.IPAM.Args.UPLINK != "" {
+ uplink = n.IPAM.Args.UPLINK
+ log.Println("IPAM args: n.IPAM.UPLINK is:", uplink)
+ }
+ }
+
+ staticIP, found := labels["StaticIP"]
+ if found {
+ println("StaticIP is: ", staticIP)
+ }
+
+ bull, found := labels["bull"]
+ if !found {
+ println("Hard to believe, but bull not found")
+ } else {
+ println("Found: ", bull)
+ }
+
return n.IPAM, n.CNIVersion, nil
}