Skip to content
Open
2 changes: 1 addition & 1 deletion cmd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"time"

"github.com/go-openapi/strfmt"
"github.com/metal-stack/metal-go/api/client/audit"

Check failure on line 10 in cmd/audit.go

View workflow job for this annotation

GitHub Actions / build (darwin, arm64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 10 in cmd/audit.go

View workflow job for this annotation

GitHub Actions / build (windows, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 10 in cmd/audit.go

View workflow job for this annotation

GitHub Actions / build (darwin, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 10 in cmd/audit.go

View workflow job for this annotation

GitHub Actions / build (linux, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
Expand All @@ -27,7 +27,7 @@

cmdsConfig := &genericcli.CmdsConfig[any, any, *models.V1AuditResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[any, any, *models.V1AuditResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "audit trace",
Plural: "audit traces",
Description: "show audit traces of the api. feature must be enabled on server-side.",
Expand Down
2 changes: 1 addition & 1 deletion cmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func assertExhaustiveArgs(t *testing.T, args []string, exclude ...string) {
if slices.Contains(exclude, f.Name) {
return
}
require.NoError(t, assertContainsPrefix(args, "--"+f.Name), "please ensure you all available args are used in order to increase coverage or exclude them explicitly")
require.NoError(t, assertContainsPrefix(args, "--"+f.Name), "please ensure all available args are used in order to increase coverage or exclude them explicitly")
})
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/filesystemlayout.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"errors"
"fmt"

fsmodel "github.com/metal-stack/metal-go/api/client/filesystemlayout"

Check failure on line 7 in cmd/filesystemlayout.go

View workflow job for this annotation

GitHub Actions / build (darwin, arm64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 7 in cmd/filesystemlayout.go

View workflow job for this annotation

GitHub Actions / build (windows, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 7 in cmd/filesystemlayout.go

View workflow job for this annotation

GitHub Actions / build (darwin, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 7 in cmd/filesystemlayout.go

View workflow job for this annotation

GitHub Actions / build (linux, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
Expand All @@ -26,7 +26,7 @@

cmdsConfig := &genericcli.CmdsConfig[*models.V1FilesystemLayoutCreateRequest, *models.V1FilesystemLayoutUpdateRequest, *models.V1FilesystemLayoutResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*models.V1FilesystemLayoutCreateRequest, *models.V1FilesystemLayoutUpdateRequest, *models.V1FilesystemLayoutResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "filesystemlayout",
Plural: "filesystemlayouts",
Description: "a filesystemlayout is a specification how the disks in a machine are partitioned, formatted and mounted.",
Expand Down
2 changes: 1 addition & 1 deletion cmd/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"os"
"time"

"github.com/metal-stack/metal-go/api/client/firewall"

Check failure on line 9 in cmd/firewall.go

View workflow job for this annotation

GitHub Actions / build (darwin, arm64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/firewall.go

View workflow job for this annotation

GitHub Actions / build (windows, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/firewall.go

View workflow job for this annotation

GitHub Actions / build (darwin, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/firewall.go

View workflow job for this annotation

GitHub Actions / build (linux, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
Expand All @@ -28,7 +28,7 @@

cmdsConfig := &genericcli.CmdsConfig[*models.V1FirewallCreateRequest, any, *models.V1FirewallResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*models.V1FirewallCreateRequest, any, *models.V1FirewallResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
OnlyCmds: genericcli.OnlyCmds(
genericcli.ListCmd,
genericcli.DescribeCmd,
Expand Down
2 changes: 1 addition & 1 deletion cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"errors"
"fmt"

"github.com/metal-stack/metal-go/api/client/image"

Check failure on line 7 in cmd/image.go

View workflow job for this annotation

GitHub Actions / build (darwin, arm64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 7 in cmd/image.go

View workflow job for this annotation

GitHub Actions / build (windows, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 7 in cmd/image.go

View workflow job for this annotation

GitHub Actions / build (darwin, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 7 in cmd/image.go

View workflow job for this annotation

GitHub Actions / build (linux, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
Expand All @@ -25,7 +25,7 @@

cmdsConfig := &genericcli.CmdsConfig[*models.V1ImageCreateRequest, *models.V1ImageUpdateRequest, *models.V1ImageResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*models.V1ImageCreateRequest, *models.V1ImageUpdateRequest, *models.V1ImageResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "image",
Plural: "images",
Description: "os images available to be installed on machines.",
Expand Down
2 changes: 1 addition & 1 deletion cmd/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"fmt"
"strings"

"github.com/metal-stack/metal-go/api/client/ip"

Check failure on line 8 in cmd/ip.go

View workflow job for this annotation

GitHub Actions / build (darwin, arm64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 8 in cmd/ip.go

View workflow job for this annotation

GitHub Actions / build (windows, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 8 in cmd/ip.go

View workflow job for this annotation

GitHub Actions / build (darwin, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 8 in cmd/ip.go

View workflow job for this annotation

GitHub Actions / build (linux, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist
"github.com/metal-stack/metal-go/api/client/machine"

Check failure on line 9 in cmd/ip.go

View workflow job for this annotation

GitHub Actions / build (darwin, arm64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/ip.go

View workflow job for this annotation

GitHub Actions / build (windows, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/ip.go

View workflow job for this annotation

GitHub Actions / build (darwin, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/ip.go

View workflow job for this annotation

GitHub Actions / build (linux, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
Expand Down Expand Up @@ -34,7 +34,7 @@

cmdsConfig := &genericcli.CmdsConfig[*ipAllocateRequest, *models.V1IPUpdateRequest, *models.V1IPResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*ipAllocateRequest, *models.V1IPUpdateRequest, *models.V1IPResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "ip",
Plural: "ips",
Description: "an ip address can be attached to a machine or firewall such that network traffic can be routed to these servers.",
Expand Down
2 changes: 1 addition & 1 deletion cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func newMachineCmd(c *config) *cobra.Command {

cmdsConfig := &genericcli.CmdsConfig[*models.V1MachineAllocateRequest, *models.V1MachineUpdateRequest, *models.V1MachineResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*models.V1MachineAllocateRequest, *models.V1MachineUpdateRequest, *models.V1MachineResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "machine",
Plural: "machines",
Description: "a machine is a bare metal server provisioned through metal-stack that is intended to run user workload.",
Expand Down
4 changes: 2 additions & 2 deletions cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"slices"

"github.com/metal-stack/metal-go/api/client/network"

Check failure on line 9 in cmd/network.go

View workflow job for this annotation

GitHub Actions / build (darwin, arm64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/network.go

View workflow job for this annotation

GitHub Actions / build (windows, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/network.go

View workflow job for this annotation

GitHub Actions / build (darwin, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist

Check failure on line 9 in cmd/network.go

View workflow job for this annotation

GitHub Actions / build (linux, amd64)

github.com/metal-stack/metal-go@v0.41.2: replacement directory ../metal-go does not exist
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
Expand All @@ -25,12 +25,12 @@
func newNetworkCmd(c *config) *cobra.Command {
w := &networkCmd{
config: c,
childCLI: genericcli.NewGenericCLI[*models.V1NetworkAllocateRequest, any, *models.V1NetworkResponse](networkChildCRUD{config: c}).WithFS(c.fs),
childCLI: genericcli.NewGenericCLI(networkChildCRUD{config: c}).WithFS(c.fs),
}

cmdsConfig := &genericcli.CmdsConfig[*models.V1NetworkCreateRequest, *models.V1NetworkUpdateRequest, *models.V1NetworkResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*models.V1NetworkCreateRequest, *models.V1NetworkUpdateRequest, *models.V1NetworkResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "network",
Plural: "networks",
Description: "networks can be attached to a machine or firewall such that they can communicate with each other.",
Expand Down
74 changes: 72 additions & 2 deletions cmd/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,33 @@ func newPartitionCmd(c *config) *cobra.Command {
DescribePrinter: func() printers.Printer { return c.describePrinter },
ListPrinter: func() printers.Printer { return c.listPrinter },
CreateRequestFromCLI: w.createRequestFromCLI,
UpdateRequestFromCLI: w.updateRequestFromCLI,
CreateCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("id", "", "", "ID of the partition. [required]")
cmd.Flags().StringP("name", "n", "", "Name of the partition. [optional]")
cmd.Flags().StringSlice("labels", []string{}, "add initial labels, must be in the form of key=value, use it like: --labels \"key1=value1,key2=value2\".")
cmd.Flags().StringP("description", "d", "", "Description of the partition. [required]")
cmd.Flags().StringP("mgmtserver", "", "", "management server address in the partition. [required]")
cmd.Flags().StringP("cmdline", "", "", "kernel commandline for the metal-hammer in the partition. [required]")
cmd.Flags().StringP("imageurl", "", "", "initrd for the metal-hammer in the partition. [required]")
cmd.Flags().StringP("kernelurl", "", "", "kernel url for the metal-hammer in the partition. [required]")
cmd.Flags().StringP("dnsservers", "", "", "dns servers for the machines and firewalls in the partition. [optional]")
cmd.Flags().StringP("ntpservers", "", "", "ntp servers for the machines and firewalls in the partition. [optional]")
cmd.Flags().String("waiting-pool-min-size", "", "The minimum size of the waiting machine pool inside the partition (can be a number or percentage, e.g. 50% of the machines should be waiting, the rest will be shutdown). [optional]")
cmd.Flags().String("waiting-pool-max-size", "", "The maximum size of the waiting machine pool inside the partition (can be a number or percentage, e.g. 70% of the machines should be waiting, the rest will be shutdown). [optional]")
},
UpdateCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("name", "n", "", "Name of the partition. [optional]")
cmd.Flags().StringP("description", "d", "", "Description of the partition. [optional]")
cmd.Flags().StringSlice("labels", []string{}, "add initial labels, must be in the form of key=value, use it like: --labels \"key1=value1,key2=value2\".")
cmd.Flags().StringP("mgmtserver", "", "", "management server address in the partition. [optional]")
cmd.Flags().StringP("cmdline", "", "", "kernel commandline for the metal-hammer in the partition. [optional]")
cmd.Flags().StringP("imageurl", "", "", "initrd for the metal-hammer in the partition. [optional]")
cmd.Flags().StringP("kernelurl", "", "", "kernel url for the metal-hammer in the partition. [optional]")
cmd.Flags().StringP("dnsservers", "", "", "dns servers for the machines and firewalls in the partition. [optional]")
cmd.Flags().StringP("ntpservers", "", "", "ntp servers for the machines and firewalls in the partition. [optional]")
cmd.Flags().String("waiting-pool-min-size", "", "The minimum size of the waiting machine pool inside the partition (can be a number or percentage, e.g. 50% of the machines should be waiting, the rest will be shutdown). [optional]")
cmd.Flags().String("waiting-pool-max-size", "", "The maximum size of the waiting machine pool inside the partition (can be a number or percentage, e.g. 70% of the machines should be waiting, the rest will be shutdown). [optional]")
},
}

Expand Down Expand Up @@ -138,6 +155,8 @@ func partitionResponseToCreate(r *models.V1PartitionResponse) *models.V1Partitio
Name: r.Name,
DNSServers: r.DNSServers,
NtpServers: r.NtpServers,
Waitingpoolmaxsize: r.Waitingpoolmaxsize,
Waitingpoolminsize: r.Waitingpoolminsize,
}
}

Expand All @@ -155,6 +174,8 @@ func partitionResponseToUpdate(r *models.V1PartitionResponse) *models.V1Partitio
Labels: r.Labels,
DNSServers: r.DNSServers,
NtpServers: r.NtpServers,
Waitingpoolmaxsize: r.Waitingpoolmaxsize,
Waitingpoolminsize: r.Waitingpoolminsize,
}
}

Expand Down Expand Up @@ -212,9 +233,58 @@ func (c *partitionCmd) createRequestFromCLI() (*models.V1PartitionCreateRequest,
Imageurl: viper.GetString("imageurl"),
Kernelurl: viper.GetString("kernelurl"),
},
DNSServers: dnsServers,
NtpServers: ntpServers,
DNSServers: dnsServers,
NtpServers: ntpServers,
Waitingpoolmaxsize: pointer.Pointer(viper.GetString("waiting-pool-max-size")),
Waitingpoolminsize: pointer.Pointer(viper.GetString("waiting-pool-min-size")),
}

return pcr, nil
}

func (c *partitionCmd) updateRequestFromCLI(args []string) (*models.V1PartitionUpdateRequest, error) {
var (
dnsServers []*models.V1DNSServer
ntpServers []*models.V1NTPServer
)

id, err := genericcli.GetExactlyOneArg(args)
if err != nil {
return nil, err
}

dnsServersArgument := viper.GetStringSlice("dnsservers")
ntpServersArgument := viper.GetStringSlice("ntpservers")

for _, s := range dnsServersArgument {
dnsServers = append(dnsServers, &models.V1DNSServer{IP: pointer.Pointer(s)})
}

for _, s := range ntpServersArgument {
ntpServers = append(ntpServers, &models.V1NTPServer{Address: pointer.Pointer(s)})
}

labels, err := genericcli.LabelsToMap(viper.GetStringSlice("labels"))
if err != nil {
return nil, err
}

pur := &models.V1PartitionUpdateRequest{
ID: &id,
Description: viper.GetString("description"),
Labels: labels,
Name: viper.GetString("name"),
Mgmtserviceaddress: viper.GetString("mgmtserver"),
Bootconfig: &models.V1PartitionBootConfiguration{
Commandline: viper.GetString("cmdline"),
Imageurl: viper.GetString("imageurl"),
Kernelurl: viper.GetString("kernelurl"),
},
DNSServers: dnsServers,
NtpServers: ntpServers,
Waitingpoolmaxsize: pointer.Pointer(viper.GetString("waiting-pool-max-size")),
Waitingpoolminsize: pointer.Pointer(viper.GetString("waiting-pool-min-size")),
}

return pur, nil
}
121 changes: 102 additions & 19 deletions cmd/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/metal-stack/metal-go/api/client/partition"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-go/test/client"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/metal-stack/metal-lib/pkg/testcommon"
"github.com/spf13/afero"
Expand All @@ -22,13 +23,16 @@ var (
Imageurl: "imageurl",
Kernelurl: "kernelurl",
},
Description: "partition 1",
ID: pointer.Pointer("1"),
Mgmtserviceaddress: "mgmt",
Name: "partition-1",
Description: "partition 1",
ID: pointer.Pointer("1"),
Mgmtserviceaddress: "mgmt",
Name: "partition-1",
Privatenetworkprefixlength: 24,
Labels: map[string]string{
"a": "b",
},
Waitingpoolmaxsize: pointer.Pointer("10%"),
Waitingpoolminsize: pointer.Pointer("5%"),
}
partition2 = &models.V1PartitionResponse{
Bootconfig: &models.V1PartitionBootConfiguration{
Expand Down Expand Up @@ -65,13 +69,13 @@ func Test_PartitionCmd_MultiResult(t *testing.T) {
partition2,
},
wantTable: pointer.Pointer(`
ID NAME DESCRIPTION
1 partition-1 partition 1
ID NAME DESCRIPTION MINWAIT MAXWAIT
1 partition-1 partition 1 5% 10%
2 partition-2 partition 2
`),
wantWideTable: pointer.Pointer(`
ID NAME DESCRIPTION LABELS
1 partition-1 partition 1 a=b
ID NAME DESCRIPTION MINWAIT MAXWAIT LABELS
1 partition-1 partition 1 5% 10% a=b
2 partition-2 partition 2
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
Expand All @@ -80,10 +84,10 @@ ID NAME DESCRIPTION LABELS
2 partition-2
`),
wantMarkdown: pointer.Pointer(`
| ID | NAME | DESCRIPTION |
|----|-------------|-------------|
| 1 | partition-1 | partition 1 |
| 2 | partition-2 | partition 2 |
| ID | NAME | DESCRIPTION | MINWAIT | MAXWAIT |
|----|-------------|-------------|---------|---------|
| 1 | partition-1 | partition 1 | 5% | 10% |
| 2 | partition-2 | partition 2 | | |
`),
},
{
Expand Down Expand Up @@ -189,21 +193,21 @@ func Test_PartitionCmd_SingleResult(t *testing.T) {
},
want: partition1,
wantTable: pointer.Pointer(`
ID NAME DESCRIPTION
1 partition-1 partition 1
ID NAME DESCRIPTION MINWAIT MAXWAIT
1 partition-1 partition 1 5% 10%
`),
wantWideTable: pointer.Pointer(`
ID NAME DESCRIPTION LABELS
1 partition-1 partition 1 a=b
ID NAME DESCRIPTION MINWAIT MAXWAIT LABELS
1 partition-1 partition 1 5% 10% a=b
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
1 partition-1
`),
wantMarkdown: pointer.Pointer(`
| ID | NAME | DESCRIPTION |
|----|-------------|-------------|
| 1 | partition-1 | partition 1 |
| ID | NAME | DESCRIPTION | MINWAIT | MAXWAIT |
|----|-------------|-------------|---------|---------|
| 1 | partition-1 | partition 1 | 5% | 10% |
`),
},
{
Expand Down Expand Up @@ -238,13 +242,16 @@ ID NAME DESCRIPTION LABELS
args := []string{"partition", "create",
"--id", *want.ID,
"--name", want.Name,
"--labels", strings.Join(genericcli.MapToLabels(want.Labels), ","),
"--description", want.Description,
"--cmdline", want.Bootconfig.Commandline,
"--kernelurl", want.Bootconfig.Kernelurl,
"--imageurl", want.Bootconfig.Imageurl,
"--mgmtserver", want.Mgmtserviceaddress,
"--dnsservers", strings.Join(dnsServers, ","),
"--ntpservers", strings.Join(ntpServers, ","),
"--waiting-pool-min-size", pointer.SafeDeref(want.Waitingpoolminsize),
"--waiting-pool-max-size", pointer.SafeDeref(want.Waitingpoolmaxsize),
}
assertExhaustiveArgs(t, args, commonExcludedFileArgs()...)
return args
Expand All @@ -259,6 +266,82 @@ ID NAME DESCRIPTION LABELS
},
want: partition1,
},
{
name: "create from file",
cmd: func(want *models.V1PartitionResponse) []string {
return []string{"partition", "create", "-f", "/file.yaml"}
},
fsMocks: func(fs afero.Fs, want *models.V1PartitionResponse) {
require.NoError(t, afero.WriteFile(fs, "/file.yaml", mustMarshal(t, want), 0755))
},
mocks: &client.MetalMockFns{
Partition: func(mock *mock.Mock) {
mock.On("CreatePartition", testcommon.MatchIgnoreContext(t, partition.NewCreatePartitionParams().WithBody(partitionResponseToCreate(partition1))), nil).Return(&partition.CreatePartitionCreated{
Payload: partition1,
}, nil)
},
},
want: partition1,
},
{
name: "update",
cmd: func(want *models.V1PartitionResponse) []string {
var (
dnsServers []string
ntpServers []string
)
for _, dns := range want.DNSServers {
dnsServers = append(dnsServers, *dns.IP)
}

for _, ntp := range want.NtpServers {
ntpServers = append(ntpServers, *ntp.Address)
}

args := []string{"partition", "update", *want.ID,
"--name", want.Name,
"--labels", strings.Join(genericcli.MapToLabels(want.Labels), ","),
"--description", want.Description,
"--mgmtserver", want.Mgmtserviceaddress,
"--cmdline", want.Bootconfig.Commandline,
"--kernelurl", want.Bootconfig.Kernelurl,
"--imageurl", want.Bootconfig.Imageurl,
"--dnsservers", strings.Join(dnsServers, ","),
"--ntpservers", strings.Join(ntpServers, ","),
"--waiting-pool-min-size", pointer.SafeDeref(want.Waitingpoolminsize),
"--waiting-pool-max-size", pointer.SafeDeref(want.Waitingpoolmaxsize),
}
assertExhaustiveArgs(t, args, commonExcludedFileArgs()...)
return args
},
mocks: &client.MetalMockFns{
Partition: func(mock *mock.Mock) {
p := partition1
p.Privatenetworkprefixlength = 0
mock.On("UpdatePartition", testcommon.MatchIgnoreContext(t, partition.NewUpdatePartitionParams().WithBody(partitionResponseToUpdate(p))), nil).Return(&partition.UpdatePartitionOK{
Payload: partition1,
}, nil)
},
},
want: partition1,
},
{
name: "update from file",
cmd: func(want *models.V1PartitionResponse) []string {
return []string{"partition", "update", "-f", "/file.yaml"}
},
fsMocks: func(fs afero.Fs, want *models.V1PartitionResponse) {
require.NoError(t, afero.WriteFile(fs, "/file.yaml", mustMarshal(t, want), 0755))
},
mocks: &client.MetalMockFns{
Partition: func(mock *mock.Mock) {
mock.On("UpdatePartition", testcommon.MatchIgnoreContext(t, partition.NewUpdatePartitionParams().WithBody(partitionResponseToUpdate(partition1))), nil).Return(&partition.UpdatePartitionOK{
Payload: partition1,
}, nil)
},
},
want: partition1,
},
}
for _, tt := range tests {
tt.testCmd(t)
Expand Down
2 changes: 1 addition & 1 deletion cmd/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newSizeCmd(c *config) *cobra.Command {

cmdsConfig := &genericcli.CmdsConfig[*models.V1SizeCreateRequest, *models.V1SizeUpdateRequest, *models.V1SizeResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*models.V1SizeCreateRequest, *models.V1SizeUpdateRequest, *models.V1SizeResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "size",
Plural: "sizes",
Description: "a size matches a machine in terms of cpu cores, ram and storage.",
Expand Down
2 changes: 1 addition & 1 deletion cmd/sizeimageconstraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newSizeImageConstraintCmd(c *config) *cobra.Command {

cmdsConfig := &genericcli.CmdsConfig[*models.V1SizeImageConstraintCreateRequest, *models.V1SizeImageConstraintUpdateRequest, *models.V1SizeImageConstraintResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*models.V1SizeImageConstraintCreateRequest, *models.V1SizeImageConstraintUpdateRequest, *models.V1SizeImageConstraintResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "imageconstraint",
Plural: "imageconstraints",
Description: "if a size has specific requirements regarding the images which must fulfill certain constraints, this can be configured here.",
Expand Down
Loading
Loading