Skip to content

Commit

Permalink
FixResourcesCode() (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
haim-kermany authored Oct 6, 2024
1 parent 829e09d commit e96642a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 0 additions & 3 deletions pkg/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ package collector

import (
"fmt"

nsx "github.com/np-guard/vmware-analyzer/pkg/model/generated"
)

const (
Expand Down Expand Up @@ -37,7 +35,6 @@ type serverData struct {
func CollectResources(nsxServer, userName, password string) (*ResourcesContainerModel, error) {
server := serverData{nsxServer, userName, password}
res := NewResourcesContainerModel()
nsx.FixResourcesCode()
err := collectResultList(server, virtualMachineQuery, &res.VirtualMachineList)
if err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions pkg/collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ func TestCollectResources(t *testing.T) {
for _, e := range s.ServiceEntries {
_, err := e.ToConnection()
if err != nil {
t.Errorf("fail to create rule service entry error = %v", err)
return
if !strings.Contains(err.Error(), "protocol ICMPv6 of ICMPTypeServiceEntry") {
t.Errorf("fail to create rule service entry error = %v", err)
return
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/collector/resources_container_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package collector
import (
"encoding/json"
"slices"

nsx "github.com/np-guard/vmware-analyzer/pkg/model/generated"
)

// ResourcesContainerModel defines the model of a container for all resource types we can collect
Expand All @@ -28,6 +30,7 @@ type DomainResources struct {

// NewResourcesContainerModel creates an empty resources container
func NewResourcesContainerModel() *ResourcesContainerModel {
nsx.FixResourcesCode()
return &ResourcesContainerModel{}
}

Expand All @@ -38,9 +41,9 @@ func (resources *ResourcesContainerModel) ToJSONString() (string, error) {
}

func FromJSONString(b []byte) (*ResourcesContainerModel, error) {
var resources ResourcesContainerModel
err := json.Unmarshal(b, &resources)
return &resources, err
resources := NewResourcesContainerModel()
err := json.Unmarshal(b, resources)
return resources, err
}

func (resources *DomainResources) GetGroup(query string) *Group {
Expand Down

0 comments on commit e96642a

Please sign in to comment.