forked from TrueCloudLab/frostfs-node
[#113] cli: add "name" option for "get container" command
* Make get container command filter out the container by attribute name Signed-off-by: Airat Arifullin a.arifullin@yadro.com
This commit is contained in:
parent
7d39fecc6a
commit
01c0c90a86
1 changed files with 31 additions and 16 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||||
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
|
containerSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -16,12 +17,14 @@ import (
|
||||||
const (
|
const (
|
||||||
flagListPrintAttr = "with-attr"
|
flagListPrintAttr = "with-attr"
|
||||||
flagListContainerOwner = "owner"
|
flagListContainerOwner = "owner"
|
||||||
|
flagListName = "name"
|
||||||
)
|
)
|
||||||
|
|
||||||
// flag vars of list command.
|
// flag vars of list command.
|
||||||
var (
|
var (
|
||||||
flagVarListPrintAttr bool
|
flagVarListPrintAttr bool
|
||||||
flagVarListContainerOwner string
|
flagVarListContainerOwner string
|
||||||
|
flagVarListName string
|
||||||
)
|
)
|
||||||
|
|
||||||
var listContainersCmd = &cobra.Command{
|
var listContainersCmd = &cobra.Command{
|
||||||
|
@ -52,24 +55,33 @@ var listContainersCmd = &cobra.Command{
|
||||||
var prmGet internalclient.GetContainerPrm
|
var prmGet internalclient.GetContainerPrm
|
||||||
prmGet.SetClient(cli)
|
prmGet.SetClient(cli)
|
||||||
|
|
||||||
list := res.IDList()
|
containerIDs := res.IDList()
|
||||||
for i := range list {
|
for _, cnrID := range containerIDs {
|
||||||
cmd.Println(list[i].String())
|
if flagVarListName == "" && !flagVarListPrintAttr {
|
||||||
|
cmd.Println(cnrID.String())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
prmGet.SetContainer(cnrID)
|
||||||
|
res, err := internalclient.GetContainer(prmGet)
|
||||||
|
if err != nil {
|
||||||
|
cmd.Printf(" failed to read attributes: %v\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
cnr := res.Container()
|
||||||
|
if cnrName := containerSDK.Name(cnr); flagVarListName != "" && cnrName != flagVarListName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cmd.Println(cnrID.String())
|
||||||
|
|
||||||
if flagVarListPrintAttr {
|
if flagVarListPrintAttr {
|
||||||
prmGet.SetContainer(list[i])
|
cnr.IterateAttributes(func(key, val string) {
|
||||||
|
if !strings.HasPrefix(key, container.SysAttributePrefix) && !strings.HasPrefix(key, container.SysAttributePrefixNeoFS) {
|
||||||
res, err := internalclient.GetContainer(prmGet)
|
// FIXME(@cthulhu-rider): neofs-sdk-go#314 use dedicated method to skip system attributes
|
||||||
if err == nil {
|
cmd.Printf(" %s: %s\n", key, val)
|
||||||
res.Container().IterateAttributes(func(key, val string) {
|
}
|
||||||
if !strings.HasPrefix(key, container.SysAttributePrefix) && !strings.HasPrefix(key, container.SysAttributePrefixNeoFS) {
|
})
|
||||||
// FIXME(@cthulhu-rider): neofs-sdk-go#314 use dedicated method to skip system attributes
|
|
||||||
cmd.Printf(" %s: %s\n", key, val)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
cmd.Printf(" failed to read attributes: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -80,6 +92,9 @@ func initContainerListContainersCmd() {
|
||||||
|
|
||||||
flags := listContainersCmd.Flags()
|
flags := listContainersCmd.Flags()
|
||||||
|
|
||||||
|
flags.StringVar(&flagVarListName, flagListName, "",
|
||||||
|
"List containers by the attribute name",
|
||||||
|
)
|
||||||
flags.StringVar(&flagVarListContainerOwner, flagListContainerOwner, "",
|
flags.StringVar(&flagVarListContainerOwner, flagListContainerOwner, "",
|
||||||
"Owner of containers (omit to use owner from private key)",
|
"Owner of containers (omit to use owner from private key)",
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue