Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get transport Zone API #36

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
}