From 3a7fbe2c91d1dfbb837cd1ff421287c9c71b4ffc Mon Sep 17 00:00:00 2001 From: tshihad Date: Mon, 6 Dec 2021 01:34:54 -0800 Subject: [PATCH 1/2] Get transport Zone API --- pkg/client/router.go | 30 ++++++++++++++++++++++++++++++ pkg/common/constants.go | 1 + pkg/models/router.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/pkg/client/router.go b/pkg/client/router.go index 0c10786..fdc83a6 100644 --- a/pkg/client/router.go +++ b/pkg/client/router.go @@ -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: routerCompatibleVersion, + 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 +} diff --git a/pkg/common/constants.go b/pkg/common/constants.go index e0ee2b9..5daa6c3 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -37,6 +37,7 @@ const ( NetworkRouterPath = "routers" NetworkRouterTypePath = "network-router-types" NetworkServicePath = "services" + NetworkScopePath = "scopes" ServerPath = "servers" VirtualImagePath = "virtual-images" FolderPath = "folders" diff --git a/pkg/models/router.go b/pkg/models/router.go index 09fec13..e2b5f89 100644 --- a/pkg/models/router.go +++ b/pkg/models/router.go @@ -351,3 +351,34 @@ 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"` + InternalID string `json:"internalId"` + Visibility string `json:"visibility"` + DateCreated string `json:"dateCreated"` + ProviderID string `json:"providerId"` + 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"` + Status string `json:"status"` + Enabled bool `json:"enabled"` + ExternalID string `json:"externalId"` + 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"` +} From 9784a97b77819e7374a3d37a340ac8ca6676de60 Mon Sep 17 00:00:00 2001 From: tshihad Date: Mon, 6 Dec 2021 02:28:44 -0800 Subject: [PATCH 2/2] update model --- pkg/client/router.go | 2 +- pkg/models/router.go | 11 ++++++----- pkg/models/shared_models.go | 10 ++++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pkg/client/router.go b/pkg/client/router.go index fdc83a6..6c4c4da 100644 --- a/pkg/client/router.go +++ b/pkg/client/router.go @@ -449,7 +449,7 @@ func (r *RouterAPIService) GetTransportZones( ) (models.NetworkScope, error) { resp := models.TransportZonesResp{} routerAPI := &api{ - compatibleVersion: routerCompatibleVersion, + compatibleVersion: "5.2.13", method: "GET", path: fmt.Sprintf("%s/%s/%d/%s", consts.NetworksPath, consts.ServerPath, serviceID, consts.NetworkScopePath), diff --git a/pkg/models/router.go b/pkg/models/router.go index e2b5f89..ef2d55e 100644 --- a/pkg/models/router.go +++ b/pkg/models/router.go @@ -358,20 +358,21 @@ type TransportZonesResp struct { } type NetworkScope struct { - ID int `json:"id"` - InternalID string `json:"internalId"` + 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"` + 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"` + Name string `json:"name" tf:"name"` Status string `json:"status"` Enabled bool `json:"enabled"` - ExternalID string `json:"externalId"` + ExternalID string `json:"externalId" tf:"external_id,computed"` Config NetworkScopeConfig `json:"config"` Owner IDModel `json:"owner"` NetworkServer IDModel `json:"networkServer"` diff --git a/pkg/models/shared_models.go b/pkg/models/shared_models.go index 6ec7875..9cea730 100644 --- a/pkg/models/shared_models.go +++ b/pkg/models/shared_models.go @@ -2,6 +2,8 @@ package models +import "encoding/json" + type IDModel struct { ID int `json:"id,omitempty" tf:"id"` } @@ -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"` }