Skip to content

Commit

Permalink
Add Uniter API upward compatibility for NetworkInfo endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
externalreality committed Dec 15, 2017
1 parent 9c19de7 commit 0b0e557
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
17 changes: 17 additions & 0 deletions apiserver/facades/agent/uniter/uniter.go
Expand Up @@ -2189,3 +2189,20 @@ func (u *UniterAPIV4) NetworkInfo(_, _ struct{}) {}

// WatchUnitRelations isn't on the V4 API.
func (u *UniterAPIV4) WatchUnitRelations(_, _ struct{}) {}

func networkInfoResultsToV6(v7Results params.NetworkInfoResults) params.NetworkInfoResultsV6 {
results := make(map[string]params.NetworkInfoResultV6)
for k, v6Result := range v7Results.Results {
results[k] = params.NetworkInfoResultV6{Error: v6Result.Error, Info: v6Result.Info}
}
return params.NetworkInfoResultsV6{Results: results}
}

// Network Info implements UniterAPIV6 version of NetworkInfo by constructing an API V6 compatible result.
func (u *UniterAPIV6) NetworkInfo(args params.NetworkInfoParams) (params.NetworkInfoResultsV6, error) {
v6Results, err := u.UniterAPI.NetworkInfo(args)
if err != nil {
return params.NetworkInfoResultsV6{}, errors.Trace(err)
}
return networkInfoResultsToV6(v6Results), nil
}
13 changes: 12 additions & 1 deletion apiserver/params/network.go
Expand Up @@ -689,7 +689,7 @@ type NetworkInfo struct {
Addresses []InterfaceAddress `json:"addresses"`
}

// NetworkInfoResult holds either and error or a list of NetworkInfos for given binding.
// NetworkInfoResult Adds egress and ingress subnets and changes the `Info` key name in yaml/json serialization to V6.
type NetworkInfoResult struct {
Error *Error `json:"error,omitempty" yaml:"error,omitempty"`
Info []NetworkInfo `json:"bind-addresses,omitempty" yaml:"bind-addresses,omitempty"`
Expand All @@ -702,6 +702,17 @@ type NetworkInfoResults struct {
Results map[string]NetworkInfoResult `json:"results"`
}

// NetworkInfoResultV6 holds either and error or a list of NetworkInfos for given binding.
type NetworkInfoResultV6 struct {
Error *Error `json:"error,omitempty" yaml:"error,omitempty"`
Info []NetworkInfo `json:"network-info" yaml:"info"`
}

// NetworkInfoResults holds a mapping from binding name to NetworkInfoResultV6.
type NetworkInfoResultsV6 struct {
Results map[string]NetworkInfoResultV6 `json:"results"`
}

// NetworkInfoParams holds a name of the unit and list of bindings for which we want to get NetworkInfos.
type NetworkInfoParams struct {
Unit string `json:"unit"`
Expand Down

0 comments on commit 0b0e557

Please sign in to comment.