From 6207a2f261c1c4b74169a47b1c34580d00e642ce Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 26 Nov 2021 20:46:07 +0300 Subject: [PATCH] [#988] cli: Add `subnet` flag to `container create` Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/container.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 5f8c4acf4..8e8b70e15 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -22,6 +22,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/policy" "github.com/nspcc-dev/neofs-sdk-go/session" + subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id" versionSDK "github.com/nspcc-dev/neofs-sdk-go/version" "github.com/spf13/cobra" ) @@ -54,6 +55,7 @@ var ( containerAwait bool containerName string containerNoTimestamp bool + containerSubnet string containerID string @@ -127,6 +129,11 @@ It will be stored in sidechain when inner ring will accepts it.`, placementPolicy, err := parseContainerPolicy(containerPolicy) exitOnErr(cmd, err) + subnetID, err := parseSubnetID(containerSubnet) + exitOnErr(cmd, errf("could not parse subnetID: %w", err)) + + placementPolicy.SetSubnetID(subnetID) + attributes, err := parseAttributes(containerAttributes) exitOnErr(cmd, err) @@ -440,6 +447,7 @@ func initContainerCreateCmd() { flags.BoolVar(&containerAwait, "await", false, "block execution until container is persisted") flags.StringVar(&containerName, "name", "", "container name attribute") flags.BoolVar(&containerNoTimestamp, "disable-timestamp", false, "disable timestamp container attribute") + flags.StringVar(&containerSubnet, "subnet", "", "string representation of container subnetwork") } func initContainerDeleteCmd() { @@ -569,6 +577,16 @@ func prettyPrintContainerList(cmd *cobra.Command, list []*cid.ID) { } } +func parseSubnetID(val string) (sub *subnetid.ID, err error) { + sub = &subnetid.ID{} + + if val != "" { + err = sub.UnmarshalText([]byte(val)) + } + + return +} + func parseContainerPolicy(policyString string) (*netmap.PlacementPolicy, error) { _, err := os.Stat(policyString) // check if `policyString` is a path to file with placement policy if err == nil {