More merge issues addressed
authorMichael Cambria <michael.cambria@verizon.com>
Wed, 15 Feb 2017 14:57:22 +0000 (09:57 -0500)
committerMichael Cambria <michael.cambria@verizon.com>
Wed, 15 Feb 2017 14:57:22 +0000 (09:57 -0500)
20-macvlan0.conf
mcc-manual-add-static-env.sh
mcc-manual-del-static-env.sh
plugins/ipam/vz-local/backend/allocator/config.go
plugins/ipam/vz-local/main.go

index cee25bd..a3f4bf2 100644 (file)
@@ -2,7 +2,7 @@
     "cniVersion": "0.2.0",
     "name": "macvlan0",
     "type": "macvlan",
-    "master": "eth0",
+    "master": "em1",
     "args" : {
       "org.apache.mesos" : {
         "network_info" : {
index 1af3b4f..7a704a9 100755 (executable)
@@ -1,14 +1,16 @@
 #/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 
@@ -19,6 +21,6 @@ export MCCVAL="Jamal Env Value"
 
 echo $CNI_ARGS
 
-macvlan </etc/cni/net.d/20-macvlan0.conf
+bin/macvlan < /etc/cni/net.d/20-macvlan0.conf
 
 
index 23d8459..8c8afa7 100755 (executable)
@@ -1,14 +1,16 @@
 #/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 
@@ -19,6 +21,6 @@ export MCCVAL="Jamal Env Value"
 
 echo $CNI_ARGS
 
-macvlan </etc/cni/net.d/20-macvlan0.conf
+bin/macvlan < /etc/cni/net.d/20-macvlan0.conf
 
 
index d261d0f..bed40fb 100644 (file)
@@ -19,6 +19,9 @@ import (
        "fmt"
        "net"
 
+        "log"
+        "os"
+
        "github.com/containernetworking/cni/pkg/types"
 )
 
@@ -39,6 +42,39 @@ type IPAMConfig struct {
 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 {
@@ -49,7 +85,8 @@ 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
        }
@@ -69,6 +106,63 @@ func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, string, error) {
        // 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
 }
 
index 2f77912..10fbfde 100644 (file)
@@ -15,8 +15,8 @@
 package main
 
 import (
-       "github.com/containernetworking/cni/plugins/ipam/host-local/backend/allocator"
-       "github.com/containernetworking/cni/plugins/ipam/host-local/backend/disk"
+       "github.com/containernetworking/cni/plugins/ipam/vz-local/backend/allocator"
+       "github.com/containernetworking/cni/plugins/ipam/vz-local/backend/disk"
 
        "github.com/containernetworking/cni/pkg/skel"
        "github.com/containernetworking/cni/pkg/types"