Skip to content

Commit

Permalink
Pqa 1907 Edge BDD: Automation for PEM-5001 - edge host list based on …
Browse files Browse the repository at this point in the history
…tag (#111)

* added func to get edge hosts  using tags

* added edge host filter for PEM-5001

* Update cluster_edge_native.go
  • Loading branch information
MGamya authored Jun 26, 2024
1 parent cfbbb09 commit e41c4ac
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions client/cluster_edge_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"errors"
"fmt"

clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
Expand Down Expand Up @@ -68,6 +69,70 @@ func (h *V1Client) ListEdgeHosts() ([]*models.V1EdgeHostsMetadata, error) {
return items, nil
}

func (h *V1Client) GetEdgeHostsByTags(tags map[string]string) ([]*models.V1EdgeHostsMetadata, error) {
continueToken := ""
var items []*models.V1EdgeHostsMetadata
filter := GetEdgeFilter(nil, tags)
for ok := true; ok; ok = (continueToken != "") {
params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx).
WithBody(&models.V1SearchFilterSummarySpec{
Filter: filter,
Sort: nil,
})
resp, err := h.Client.V1DashboardEdgehostsSearch(params)
if err != nil {
return nil, err
}
continueToken = resp.Payload.Listmeta.Continue
items = append(items, resp.Payload.Items...)
}

return items, nil
}

func GetEdgeFilter(extraFilters []*models.V1SearchFilterItem, tags map[string]string) *models.V1SearchFilterSpec {
filter := &models.V1SearchFilterSpec{
Conjunction: and(),
FilterGroups: []*models.V1SearchFilterGroup{
{
Conjunction: and(),
Filters: []*models.V1SearchFilterItem{},
},
},
}

// Tags filter
if len(tags) > 0 {
var tagValues []string
for key, value := range tags {
tagValues = append(tagValues, fmt.Sprintf("%s:%s", key, value))
}
tagsFilter := &models.V1SearchFilterItem{
Condition: &models.V1SearchFilterCondition{
String: &models.V1SearchFilterStringCondition{
Match: &models.V1SearchFilterStringConditionMatch{
Conjunction: or(),
Values: tagValues,
},
Operator: models.V1SearchFilterStringOperatorEq,
Negation: false,
IgnoreCase: false,
},
},
Property: "tags",
Type: models.V1SearchFilterPropertyTypeString,
}
filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, tagsFilter)
}

// Append extra filters if provided
if extraFilters != nil {
filter.FilterGroups = append(filter.FilterGroups, &models.V1SearchFilterGroup{Conjunction: and(), Filters: extraFilters})
}

return filter
}

func (h *V1Client) CreateClusterEdgeNative(cluster *models.V1SpectroEdgeNativeClusterEntity) (string, error) {
params := clientV1.NewV1SpectroClustersEdgeNativeCreateParamsWithContext(h.ctx).
WithBody(cluster)
Expand Down

0 comments on commit e41c4ac

Please sign in to comment.