Skip to content

Commit

Permalink
feat(storage/nvme): add delete namespace cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <[email protected]>
  • Loading branch information
artek-koltun authored and glimchb committed Nov 28, 2023
1 parent b3e0bce commit 762e61a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cmd/storage-nvme-namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,37 @@ func newCreateNvmeNamespaceCommand() *cobra.Command {

return cmd
}

func newDeleteNvmeNamespaceCommand() *cobra.Command {
name := ""
allowMissing := false
cmd := &cobra.Command{
Use: "namespace",
Aliases: []string{"d"},
Short: "Deletes nvme namespace",
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
addr, err := c.Flags().GetString(addrCmdLineArg)
cobra.CheckErr(err)

timeout, err := c.Flags().GetDuration(timeoutCmdLineArg)
cobra.CheckErr(err)

client, err := storage.New(addr)
cobra.CheckErr(err)

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

err = client.DeleteNvmeNamespace(ctx, name, allowMissing)
cobra.CheckErr(err)
},
}

cmd.Flags().StringVar(&name, "name", "", "name of deleted namespace")
cmd.Flags().BoolVar(&allowMissing, "allowMissing", false, "cmd succeeds if attempts to delete a resource that is not present")

cobra.CheckErr(cmd.MarkFlagRequired("name"))

return cmd
}
1 change: 1 addition & 0 deletions cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func newDeleteNvmeCommand() *cobra.Command {
}

cmd.AddCommand(newDeleteNvmeSubsystemCommand())
cmd.AddCommand(newDeleteNvmeNamespaceCommand())

return cmd
}
Expand Down
23 changes: 23 additions & 0 deletions storage/nvme_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,26 @@ func (c *Client) CreateNvmeNamespace(

return response, err
}

// DeleteNvmeNamespace deletes an nvme namespace
func (c *Client) DeleteNvmeNamespace(
ctx context.Context,
name string,
allowMissing bool,
) error {
conn, connClose, err := c.connector.NewConn()
if err != nil {
return err
}
defer connClose()

client := c.createClient(conn)
_, err = client.DeleteNvmeNamespace(
ctx,
&pb.DeleteNvmeNamespaceRequest{
Name: name,
AllowMissing: allowMissing,
})

return err
}

0 comments on commit 762e61a

Please sign in to comment.