Skip to content

Commit 583a2ae

Browse files
authored
Merge pull request #31 from serverscom/move-kbm-under-hosts-resource
move-kbm-under-hosts-resource
2 parents 7cb54a0 + 18982b4 commit 583a2ae

37 files changed

+559
-1486
lines changed

cmd/base/const.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package base
22

33
const (
4-
ENDPOINT = "https://api.servers.com/v1"
4+
ENDPOINT = "https://api.servers.com/v1"
5+
ErrNoContexts = "no contexts found, log in first: 'srvctl login <context-name>' or, if you don't want to create the context, you may pass SC_TOKEN every time you use srvctl"
56
)

cmd/base/hooks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package base
22

33
import (
4+
"errors"
45
"fmt"
56
"html/template"
67
"os"
@@ -131,7 +132,7 @@ func CheckEmptyContexts(cmdContext *CmdContext) func(cmd *cobra.Command, args []
131132
manager := cmdContext.GetManager()
132133

133134
if len(manager.GetContexts()) == 0 {
134-
return fmt.Errorf("no contexts found, log in first: 'srvctl login <context-name>'")
135+
return errors.New(ErrNoContexts)
135136
}
136137
return nil
137138
}

cmd/entities/hosts/drive-slots.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@ func newListDSDriveSlotsCmd(cmdContext *base.CmdContext) *cobra.Command {
2323
return base.NewListCmd("list-drive-slots <id>", "Dedicated server drive slots", factory, cmdContext, opts)
2424
}
2525

26-
// TODO add list drive slots for KBM after adding KBMDriveSlots in go client
26+
func newListKBMDriveSlotsCmd(cmdContext *base.CmdContext) *cobra.Command {
27+
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.HostDriveSlot] {
28+
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
29+
if len(args) == 0 {
30+
log.Fatal("Missing KBM node ID")
31+
}
32+
id := args[0]
33+
return scClient.Hosts.KubernetesBaremetalNodeDriveSlots(id)
34+
}
35+
36+
opts := base.NewListOptions(
37+
&base.BaseListOptions[serverscom.HostDriveSlot]{},
38+
&base.SearchPatternOption[serverscom.HostDriveSlot]{},
39+
)
40+
41+
return base.NewListCmd("list-drive-slots <id>", "KBM node drive slots", factory, cmdContext, opts...)
42+
}

cmd/entities/hosts/hosts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func NewCmd(cmdContext *base.CmdContext) *cobra.Command {
7171
extraCmds: []func(*base.CmdContext) *cobra.Command{
7272
newUpdateKBMCmd,
7373
newListKBMCmd,
74+
newListKBMNetworksCmd,
75+
newListKBMDriveSlotsCmd,
7476
},
7577
},
7678
{

0 commit comments

Comments
 (0)