Skip to content

Commit

Permalink
Merge pull request #36 from HewlettPackard/transport
Browse files Browse the repository at this point in the history
Get transport Zone API
  • Loading branch information
gandharvas authored Dec 9, 2021
2 parents 5e14862 + 9784a97 commit 818b72e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
30 changes: 30 additions & 0 deletions pkg/client/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,33 @@ func (r *RouterAPIService) DeleteRouterBgpNeighbor(

return resp, err
}

func (r *RouterAPIService) GetTransportZones(
ctx context.Context,
serviceID int,
transportName string,
) (models.NetworkScope, error) {
resp := models.TransportZonesResp{}
routerAPI := &api{
compatibleVersion: "5.2.13",
method: "GET",
path: fmt.Sprintf("%s/%s/%d/%s",
consts.NetworksPath, consts.ServerPath, serviceID, consts.NetworkScopePath),
client: r.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &resp)
},
}

if err := routerAPI.do(ctx, nil, nil); err != nil {
return models.NetworkScope{}, err
}

for _, t := range resp.NetworkScopes {
if t.Name == transportName {
return t, nil
}
}

return models.NetworkScope{}, nil
}
1 change: 1 addition & 0 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
NetworkRouterPath = "routers"
NetworkRouterTypePath = "network-router-types"
NetworkServicePath = "services"
NetworkScopePath = "scopes"
ServerPath = "servers"
VirtualImagePath = "virtual-images"
FolderPath = "folders"
Expand Down
32 changes: 32 additions & 0 deletions pkg/models/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,35 @@ type NetworkRouterBgpNeighborBody struct {
DateCreated string `json:"dateCreated"`
LastUpdated string `json:"lastUpdated"`
}

type TransportZonesResp struct {
NetworkScopes []NetworkScope `json:"networkScopes"`
Meta Meta `json:"meta"`
}

type NetworkScope struct {
ID int `json:"id" tf:"id,computed"`
ServiceID int `json:"-" tf:"service_id,computed"`
InternalID string `json:"internalId" tf:"internal_id,computed"`
Visibility string `json:"visibility"`
DateCreated string `json:"dateCreated"`
ProviderID string `json:"providerId" tf:"provider_id,computed"`
LastUpdated string `json:"lastUpdated"`
Active bool `json:"active"`
StreamType string `json:"streamType"`
DisplayName string `json:"displayName"`
StatusMessage string `json:"statusMessage,omitempty"`
Name string `json:"name" tf:"name"`
Status string `json:"status"`
Enabled bool `json:"enabled"`
ExternalID string `json:"externalId" tf:"external_id,computed"`
Config NetworkScopeConfig `json:"config"`
Owner IDModel `json:"owner"`
NetworkServer IDModel `json:"networkServer"`
Zone IDModel `json:"zone"`
}

type NetworkScopeConfig struct {
NvdsName string `json:"nvdsName"`
HostMembershipCriteria string `json:"hostMembershipCriteria"`
}
10 changes: 6 additions & 4 deletions pkg/models/shared_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package models

import "encoding/json"

type IDModel struct {
ID int `json:"id,omitempty" tf:"id"`
}
Expand All @@ -19,8 +21,8 @@ type NameModel struct {
}

type Meta struct {
Max int `json:"max"`
Offset int `json:"offset"`
Size int `json:"size"`
Total int `json:"total"`
Max json.Number `json:"max"`
Offset json.Number `json:"offset"`
Size json.Number `json:"size"`
Total json.Number `json:"total"`
}

0 comments on commit 818b72e

Please sign in to comment.