"os"
"github.com/containernetworking/cni/pkg/types"
- // "github.com/containernetworking/cni/ipam/vz-local/custom"
)
// IPAMConfig represents the IP related network configuration.
IPAM *IPAMConfig `json:"ipam"`
DNS types.DNS `json:"dns"`
ARGS *Args `json:"args,omitempty"`
- // ARGS Args `json:"args"`
}
// NewIPAMConfig creates a NetworkConfig from the given network name.
n.IPAM.Name = n.Name
/*
- * Begin
+ * Example of getting an environment variable supplied to the IPAM plugin
*/
- println("Debug Getenv - Start")
-
mccval := os.Getenv("MCCVAL")
println("mccval is: ", mccval)
- println("Debug Getenv- End")
-/*
- * End
- */
/*
- * Begin
+ * Get values for supplied labels
+ * Ensure that IPAM args (e.g. CNI_ARGS) isn't confused with args passed to CNI itself
*/
- println("Debug - Start")
labels := map[string]string{}
- // println("initial:")
- // fmt.Println("Initial Map:", labels)
- // println(":initial")
-
if args != "" {
if n.ARGS != nil {
- println("Bingo")
- //n.IPAM.Args = &IPAMArgs{}
- //n.ARGS.Mesos = &Mesos{}
-
- // fmt.Printf("NetConf Struct type is: ")
- // fmt.Printf("%T ", n)
- // fmt.Printf("NetConf Struct type is: ")
- // fmt.Printf("%+v", n)
- //myargs := &n.Args
- // m := &myargs.Mesos{}
- //fmt.Printf("myargs Struct is: %T = %+v", myargs, myargs)
- //fmt.Printf("Mesos Struct is: %T = %+v", m, m)
-
- //n.ARGS = &Args{}
- //fmt.Printf("Args Struct type is: ")
- //fmt.Printf("T", n.ARGS)
- //fmt.Printf("Args Struct value is: ")
- //fmt.Printf("%+v", n.ARGS)
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("Map (for)", labels)
- // fmt.Println("Map: ", label)
}
- // println("Map (final)", labels)
- //fmt.Println("Final Map (Println)", labels)
- //fmt.Printf("Final Map (Printf) %v", labels)
}
}
- println("Debug - End")
for key, value := range labels {
- // fmt.Println("Key:", key, "Value:", value)
println("Key:", key, "Value:", value)
}
- //fmt.Println("done:", n.ARGS.Mesos.NetworkInfo.Labels.Labels)
if n.ARGS != nil {
- println("done: Net Name: ", n.ARGS.Mesos.NetworkInfo.Name)
- println("done: IPAM Name: ", n.IPAM.Name)
- println("done: Labels2: ", n.ARGS.Mesos.NetworkInfo.Labels.Labels)
+ println("CNI Args: Net Name: ", n.ARGS.Mesos.NetworkInfo.Name)
+ println("CNI Args: IPAM Name: ", n.IPAM.Name)
args_ip := n.IPAM.Args.IP
uplink := n.IPAM.Args.UPLINK
- println("MikeC: n.IPAM.IP is:", args_ip)
- println("MikeC: n.IPAM.UPLINK is:", uplink)
+ println("IPAM args: n.IPAM.IP is:", args_ip)
+ println("IPAM args: n.IPAM.UPLINK is:", uplink)
}
staticIP, found := labels["StaticIP"]
println("Found: ", bull)
}
-/*
- * End
- */
-
return n.IPAM, nil
}
+++ /dev/null
-
-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 vz custom ipam network
-type NetConf struct {
- CNIVersion string `json:"cniVersion,omitempty"`
-
- Name string `json:"name"`
- Type string `json:"type"`
- IPAM struct {
- Type string `json:"type,omitempty"`
- } `json:"ipam,omitempty"`
- DNS DNS `json:"dns"`
- Args Args `json:"args"`
-}
-