1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
8
"github.com/juju/errors"
10
"github.com/juju/juju/apiserver/params"
11
"github.com/juju/juju/storage"
14
// StorageAddCommand implements the status-set command.
15
type StorageAddCommand struct {
18
all map[string]params.StorageConstraints
21
// NewStorageAddCommand makes a jujuc storage-add command.
22
func NewStorageAddCommand(ctx Context) (cmd.Command, error) {
23
return &StorageAddCommand{ctx: ctx}, nil
27
Storage add adds storage instances to unit using provided storage directives.
28
A storage directive consists of a storage name as per charm specification
29
and optional storage COUNT.
31
COUNT is a positive integer indicating how many instances
32
of the storage to create. If unspecified, COUNT defaults to 1.
35
func (s *StorageAddCommand) Info() *cmd.Info {
38
Args: "<charm storage name>[=count] ...",
39
Purpose: "add storage instances",
44
func (s *StorageAddCommand) Init(args []string) error {
46
return errors.New("storage add requires a storage directive")
49
cons, err := storage.ParseConstraintsMap(args, false)
51
return errors.Trace(err)
54
s.all = make(map[string]params.StorageConstraints, len(cons))
55
for k, v := range cons {
56
if v != (storage.Constraints{Count: v.Count}) {
57
return errors.Errorf("only count can be specified for %q", k)
59
s.all[k] = params.StorageConstraints{Count: &v.Count}
64
func (s *StorageAddCommand) Run(ctx *cmd.Context) error {
65
s.ctx.AddUnitStorage(s.all)