2016-12-01 05:00:08 +03:00
|
|
|
// Copyright Microsoft Corp.
|
|
|
|
// All rights reserved.
|
|
|
|
|
|
|
|
package cni
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NetworkConfig represents the Azure CNI plugin's network configuration.
|
|
|
|
type NetworkConfig struct {
|
|
|
|
CniVersion string `json:"cniVersion"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
2016-12-02 00:29:23 +03:00
|
|
|
Bridge string `json:"bridge,omitempty"`
|
|
|
|
IfName string `json:"ifName,omitempty"`
|
2016-12-01 05:00:08 +03:00
|
|
|
Ipam struct {
|
|
|
|
Type string `json:"type"`
|
2016-12-02 00:29:23 +03:00
|
|
|
AddrSpace string `json:"addressSpace,omitempty"`
|
|
|
|
Subnet string `json:"subnet,omitempty"`
|
|
|
|
Address string `json:"ipAddress,omitempty"`
|
2016-12-01 05:00:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseNetworkConfig unmarshals network configuration from bytes.
|
|
|
|
func ParseNetworkConfig(b []byte) (*NetworkConfig, error) {
|
|
|
|
nwCfg := NetworkConfig{}
|
|
|
|
|
|
|
|
err := json.Unmarshal(b, &nwCfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &nwCfg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize marshals a network configuration to bytes.
|
|
|
|
func (nwcfg *NetworkConfig) Serialize() []byte {
|
|
|
|
bytes, _ := json.Marshal(nwcfg)
|
|
|
|
return bytes
|
|
|
|
}
|