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

Adding faultset support in sds and getting node/nodepool details #94

Merged
merged 5 commits into from
Jan 22, 2024
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
65 changes: 65 additions & 0 deletions inttests/node_test.go
shenda1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright © 2024 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package inttests

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetNodes(t *testing.T) {
allNodes, err := C.GetAllNodes()
assert.Nil(t, err)
assert.NotNil(t, allNodes)
}

func TestGetNodeByID(t *testing.T) {
allNodes, err := C.GetAllNodes()
assert.Nil(t, err)
assert.NotNil(t, allNodes)

if len(allNodes) > 0 {
node, err := C.GetNodeByID(allNodes[0].RefID)
assert.Nil(t, err)
assert.NotNil(t, node)
}

node, err := C.GetNodeByID(invalidIdentifier)
assert.NotNil(t, err)
assert.Nil(t, node)
}

func TestGetNodeByFilters(t *testing.T) {
allNodes, err := C.GetNodeByFilters("invalid", "invalid")
assert.NotNil(t, err)
assert.Nil(t, allNodes)
}

func TestGetNodePoolByID(t *testing.T) {
nodePool, err := C.GetNodePoolByID(-2)
assert.Nil(t, err)
assert.Equal(t, nodePool.DeviceGroup.GroupName, "")
}

func TestGetNodePoolByName(t *testing.T) {
nodePool, err := C.GetNodePoolByName(invalidIdentifier)
assert.NotNil(t, err)
assert.Nil(t, nodePool)
}

func TestGetAllNodePools(t *testing.T) {
allNodePools, err := C.GetAllNodePools()
assert.Nil(t, err)
assert.NotNil(t, allNodePools)
}
115 changes: 115 additions & 0 deletions node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright © 2024 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package goscaleio

import (
"errors"
"fmt"
"net/http"
"time"

types "github.com/dell/goscaleio/types/v1"
)

// GetNodeByID gets the node details based on ID
func (c *Client) GetNodeByID(id string) (*types.NodeDetails, error) {
defer TimeSpent("GetNodeByID", time.Now())

path := fmt.Sprintf("/Api/V1/ManagedDevice/%v", id)

var node types.NodeDetails
err := c.getJSONWithRetry(http.MethodGet, path, nil, &node)
if err != nil {
return nil, err
}
return &node, nil
}

// GetAllNodes gets all the node details
func (c *Client) GetAllNodes() ([]types.NodeDetails, error) {
defer TimeSpent("GetNodeByID", time.Now())

path := fmt.Sprintf("/Api/V1/ManagedDevice")

var nodes []types.NodeDetails
err := c.getJSONWithRetry(http.MethodGet, path, nil, &nodes)
if err != nil {
return nil, err
}
return nodes, nil
}

// GetNodeByFilters gets the node details based on the provided filter
func (c *Client) GetNodeByFilters(key string, value string) ([]types.NodeDetails, error) {
defer TimeSpent("GetNodeByFilters", time.Now())

path := fmt.Sprintf("/Api/V1/ManagedDevice?filter=eq,%v,%v", key, value)

var nodes []types.NodeDetails
err := c.getJSONWithRetry(http.MethodGet, path, nil, &nodes)
if err != nil {
return nil, err
}

if len(nodes) == 0 {
return nil, errors.New("Couldn't find nodes with the given filter")
}
return nodes, nil
}

// GetNodePoolByID gets the nodepool details based on ID
func (c *Client) GetNodePoolByID(id int) (*types.NodePoolDetails, error) {
defer TimeSpent("GetNodePoolByID", time.Now())

path := fmt.Sprintf("/Api/V1/nodepool/%v", id)

var nodePool types.NodePoolDetails
err := c.getJSONWithRetry(http.MethodGet, path, nil, &nodePool)
if err != nil {
return nil, err
}

return &nodePool, nil
}

// GetNodePoolByName gets the nodepool details based on name
func (c *Client) GetNodePoolByName(name string) (*types.NodePoolDetails, error) {
defer TimeSpent("GetNodePoolByName", time.Now())

nodePools, err := c.GetAllNodePools()
if err != nil {
return nil, err
}

for _, nodePool := range nodePools.NodePoolDetails {
if nodePool.GroupName == name {
return c.GetNodePoolByID(nodePool.GroupSeqID)
}
}
return nil, errors.New("no node pool found with name " + name)
}

// GetAllNodePools gets all the nodepool details
func (c *Client) GetAllNodePools() (*types.NodePoolDetailsFilter, error) {
defer TimeSpent("GetAllNodePools", time.Now())

path := fmt.Sprintf("/Api/V1/nodepool")

var nodePools types.NodePoolDetailsFilter
err := c.getJSONWithRetry(http.MethodGet, path, nil, &nodePools)
if err != nil {
return nil, err
}

return &nodePools, nil
}
Loading
Loading