diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-03-02 11:10:37 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-03-02 19:20:26 +0000 |
commit | edb1609c6121a550a3c882529e44387c217d2b03 (patch) | |
tree | d533567351dd70b8bcffe17174a8edc1fefa199d /libpod/container_ffjson.go | |
parent | 29d650a3799b76b08094b6dc90fe8500c76fa6de (diff) | |
download | podman-edb1609c6121a550a3c882529e44387c217d2b03.tar.gz podman-edb1609c6121a550a3c882529e44387c217d2b03.tar.bz2 podman-edb1609c6121a550a3c882529e44387c217d2b03.zip |
Update DB to hold CNI network information
Replace our old IP and Subnet fields in state with CNI types that
contain a lot more information. Retrieve these structs from the
CNI plugins themselves.
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #440
Approved by: baude
Diffstat (limited to 'libpod/container_ffjson.go')
-rw-r--r-- | libpod/container_ffjson.go | 317 |
1 files changed, 235 insertions, 82 deletions
diff --git a/libpod/container_ffjson.go b/libpod/container_ffjson.go index c34472c1f..d20c7a420 100644 --- a/libpod/container_ffjson.go +++ b/libpod/container_ffjson.go @@ -9,6 +9,8 @@ import ( "encoding/json" "errors" "fmt" + "github.com/containernetworking/cni/pkg/types" + "github.com/containernetworking/cni/pkg/types/current" "github.com/cri-o/ocicni/pkg/ocicni" fflib "github.com/pquerna/ffjson/fflib/v1" "net" @@ -2866,11 +2868,6 @@ func (j *containerState) MarshalJSONBuf(buf fflib.EncodingBuffer) error { fflib.FormatBits2(buf, uint64(j.PID), 10, j.PID < 0) buf.WriteByte(',') } - buf.WriteString(`"ipAddress":`) - fflib.WriteJsonString(buf, string(j.IPAddress)) - buf.WriteString(`,"subnetMask":`) - fflib.WriteJsonString(buf, string(j.SubnetMask)) - buf.WriteByte(',') if len(j.ExecSessions) != 0 { buf.WriteString(`"execSessions":`) /* Falling back. type=map[string]*libpod.ExecSession kind=map */ @@ -2880,6 +2877,68 @@ func (j *containerState) MarshalJSONBuf(buf fflib.EncodingBuffer) error { } buf.WriteByte(',') } + if len(j.IPs) != 0 { + buf.WriteString(`"ipAddresses":`) + if j.IPs != nil { + buf.WriteString(`[`) + for i, v := range j.IPs { + if i != 0 { + buf.WriteString(`,`) + } + + { + + if v == nil { + buf.WriteString("null") + } else { + + obj, err = v.MarshalJSON() + if err != nil { + return err + } + buf.Write(obj) + + } + + } + } + buf.WriteString(`]`) + } else { + buf.WriteString(`null`) + } + buf.WriteByte(',') + } + if len(j.Routes) != 0 { + buf.WriteString(`"routes":`) + if j.Routes != nil { + buf.WriteString(`[`) + for i, v := range j.Routes { + if i != 0 { + buf.WriteString(`,`) + } + + { + + if v == nil { + buf.WriteString("null") + } else { + + obj, err = v.MarshalJSON() + if err != nil { + return err + } + buf.Write(obj) + + } + + } + } + buf.WriteString(`]`) + } else { + buf.WriteString(`null`) + } + buf.WriteByte(',') + } buf.Rewind(1) buf.WriteByte('}') return nil @@ -2909,11 +2968,11 @@ const ( ffjtcontainerStatePID - ffjtcontainerStateIPAddress + ffjtcontainerStateExecSessions - ffjtcontainerStateSubnetMask + ffjtcontainerStateIPs - ffjtcontainerStateExecSessions + ffjtcontainerStateRoutes ) var ffjKeycontainerStateState = []byte("state") @@ -2936,11 +2995,11 @@ var ffjKeycontainerStateOOMKilled = []byte("oomKilled") var ffjKeycontainerStatePID = []byte("pid") -var ffjKeycontainerStateIPAddress = []byte("ipAddress") +var ffjKeycontainerStateExecSessions = []byte("execSessions") -var ffjKeycontainerStateSubnetMask = []byte("subnetMask") +var ffjKeycontainerStateIPs = []byte("ipAddresses") -var ffjKeycontainerStateExecSessions = []byte("execSessions") +var ffjKeycontainerStateRoutes = []byte("routes") // UnmarshalJSON umarshall json - template of ffjson func (j *containerState) UnmarshalJSON(input []byte) error { @@ -3034,8 +3093,8 @@ mainparse: case 'i': - if bytes.Equal(ffjKeycontainerStateIPAddress, kn) { - currentKey = ffjtcontainerStateIPAddress + if bytes.Equal(ffjKeycontainerStateIPs, kn) { + currentKey = ffjtcontainerStateIPs state = fflib.FFParse_want_colon goto mainparse } @@ -3075,6 +3134,11 @@ mainparse: currentKey = ffjtcontainerStateRunDir state = fflib.FFParse_want_colon goto mainparse + + } else if bytes.Equal(ffjKeycontainerStateRoutes, kn) { + currentKey = ffjtcontainerStateRoutes + state = fflib.FFParse_want_colon + goto mainparse } case 's': @@ -3088,29 +3152,24 @@ mainparse: currentKey = ffjtcontainerStateStartedTime state = fflib.FFParse_want_colon goto mainparse - - } else if bytes.Equal(ffjKeycontainerStateSubnetMask, kn) { - currentKey = ffjtcontainerStateSubnetMask - state = fflib.FFParse_want_colon - goto mainparse } } - if fflib.EqualFoldRight(ffjKeycontainerStateExecSessions, kn) { - currentKey = ffjtcontainerStateExecSessions + if fflib.EqualFoldRight(ffjKeycontainerStateRoutes, kn) { + currentKey = ffjtcontainerStateRoutes state = fflib.FFParse_want_colon goto mainparse } - if fflib.EqualFoldRight(ffjKeycontainerStateSubnetMask, kn) { - currentKey = ffjtcontainerStateSubnetMask + if fflib.EqualFoldRight(ffjKeycontainerStateIPs, kn) { + currentKey = ffjtcontainerStateIPs state = fflib.FFParse_want_colon goto mainparse } - if fflib.EqualFoldRight(ffjKeycontainerStateIPAddress, kn) { - currentKey = ffjtcontainerStateIPAddress + if fflib.EqualFoldRight(ffjKeycontainerStateExecSessions, kn) { + currentKey = ffjtcontainerStateExecSessions state = fflib.FFParse_want_colon goto mainparse } @@ -3222,15 +3281,15 @@ mainparse: case ffjtcontainerStatePID: goto handle_PID - case ffjtcontainerStateIPAddress: - goto handle_IPAddress - - case ffjtcontainerStateSubnetMask: - goto handle_SubnetMask - case ffjtcontainerStateExecSessions: goto handle_ExecSessions + case ffjtcontainerStateIPs: + goto handle_IPs + + case ffjtcontainerStateRoutes: + goto handle_Routes + case ffjtcontainerStatenosuchkey: err = fs.SkipField(tok) if err != nil { @@ -3533,58 +3592,6 @@ handle_PID: state = fflib.FFParse_after_value goto mainparse -handle_IPAddress: - - /* handler: j.IPAddress type=string kind=string quoted=false*/ - - { - - { - if tok != fflib.FFTok_string && tok != fflib.FFTok_null { - return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok)) - } - } - - if tok == fflib.FFTok_null { - - } else { - - outBuf := fs.Output.Bytes() - - j.IPAddress = string(string(outBuf)) - - } - } - - state = fflib.FFParse_after_value - goto mainparse - -handle_SubnetMask: - - /* handler: j.SubnetMask type=string kind=string quoted=false*/ - - { - - { - if tok != fflib.FFTok_string && tok != fflib.FFTok_null { - return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok)) - } - } - - if tok == fflib.FFTok_null { - - } else { - - outBuf := fs.Output.Bytes() - - j.SubnetMask = string(string(outBuf)) - - } - } - - state = fflib.FFParse_after_value - goto mainparse - handle_ExecSessions: /* handler: j.ExecSessions type=map[string]*libpod.ExecSession kind=map quoted=false*/ @@ -3690,6 +3697,152 @@ handle_ExecSessions: state = fflib.FFParse_after_value goto mainparse +handle_IPs: + + /* handler: j.IPs type=[]*current.IPConfig kind=slice quoted=false*/ + + { + + { + if tok != fflib.FFTok_left_brace && tok != fflib.FFTok_null { + return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for ", tok)) + } + } + + if tok == fflib.FFTok_null { + j.IPs = nil + } else { + + j.IPs = []*current.IPConfig{} + + wantVal := true + + for { + + var tmpJIPs *current.IPConfig + + tok = fs.Scan() + if tok == fflib.FFTok_error { + goto tokerror + } + if tok == fflib.FFTok_right_brace { + break + } + + if tok == fflib.FFTok_comma { + if wantVal == true { + // TODO(pquerna): this isn't an ideal error message, this handles + // things like [,,,] as an array value. + return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok)) + } + continue + } else { + wantVal = true + } + + /* handler: tmpJIPs type=*current.IPConfig kind=ptr quoted=false*/ + + { + if tok == fflib.FFTok_null { + + } else { + + tbuf, err := fs.CaptureField(tok) + if err != nil { + return fs.WrapErr(err) + } + + err = tmpJIPs.UnmarshalJSON(tbuf) + if err != nil { + return fs.WrapErr(err) + } + } + state = fflib.FFParse_after_value + } + + j.IPs = append(j.IPs, tmpJIPs) + + wantVal = false + } + } + } + + state = fflib.FFParse_after_value + goto mainparse + +handle_Routes: + + /* handler: j.Routes type=[]*types.Route kind=slice quoted=false*/ + + { + + { + if tok != fflib.FFTok_left_brace && tok != fflib.FFTok_null { + return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for ", tok)) + } + } + + if tok == fflib.FFTok_null { + j.Routes = nil + } else { + + j.Routes = []*types.Route{} + + wantVal := true + + for { + + var tmpJRoutes *types.Route + + tok = fs.Scan() + if tok == fflib.FFTok_error { + goto tokerror + } + if tok == fflib.FFTok_right_brace { + break + } + + if tok == fflib.FFTok_comma { + if wantVal == true { + // TODO(pquerna): this isn't an ideal error message, this handles + // things like [,,,] as an array value. + return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok)) + } + continue + } else { + wantVal = true + } + + /* handler: tmpJRoutes type=*types.Route kind=ptr quoted=false*/ + + { + if tok == fflib.FFTok_null { + + } else { + + tbuf, err := fs.CaptureField(tok) + if err != nil { + return fs.WrapErr(err) + } + + err = tmpJRoutes.UnmarshalJSON(tbuf) + if err != nil { + return fs.WrapErr(err) + } + } + state = fflib.FFParse_after_value + } + + j.Routes = append(j.Routes, tmpJRoutes) + + wantVal = false + } + } + } + + state = fflib.FFParse_after_value + goto mainparse + wantedvalue: return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok)) wrongtokenerror: |