Skip to content

Commit 41e07f9

Browse files
committed
Swap bootstrap controller and cloud args
1 parent 12e978b commit 41e07f9

File tree

4 files changed

+93
-80
lines changed

4 files changed

+93
-80
lines changed

cmd/juju/commands/bootstrap.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"bufio"
88
"fmt"
99
"os"
10-
"os/user"
1110
"sort"
1211
"strings"
1312

@@ -97,10 +96,12 @@ Examples:
9796
juju bootstrap
9897
juju bootstrap --clouds
9998
juju bootstrap --regions aws
100-
juju bootstrap joe-us-east1 google
101-
juju bootstrap --config=~/config-rs.yaml joe-syd rackspace
102-
juju bootstrap --config agent-version=1.25.3 joe-us-east-1 aws
103-
juju bootstrap --config bootstrap-timeout=1200 joe-eastus azure
99+
juju bootstrap aws
100+
juju bootstrap aws/us-east-1
101+
juju bootstrap google joe-us-east1
102+
juju bootstrap --config=~/config-rs.yaml rackspace joe-syd
103+
juju bootstrap --config agent-version=1.25.3 aws joe-us-east-1
104+
juju bootstrap --config bootstrap-timeout=1200 azure joe-eastus
104105
105106
See also:
106107
add-credentials
@@ -232,17 +233,16 @@ func (c *bootstrapCommand) Init(args []string) (err error) {
232233
// no args or flags, go interactive.
233234
c.interactive = true
234235
return nil
235-
case 1:
236-
// The user must specify both positional arguments: the controller name,
237-
// and the cloud name (optionally with region specified).
238-
return errors.New("controller name and cloud name are required")
239236
}
240-
c.controllerName = args[0]
241-
c.Cloud = args[1]
237+
c.Cloud = args[0]
242238
if i := strings.IndexRune(c.Cloud, '/'); i > 0 {
243239
c.Cloud, c.Region = c.Cloud[:i], c.Cloud[i+1:]
244240
}
245-
return cmd.CheckEmpty(args[2:])
241+
if len(args) > 1 {
242+
c.controllerName = args[1]
243+
return cmd.CheckEmpty(args[2:])
244+
}
245+
return nil
246246
}
247247

248248
// BootstrapInterface provides bootstrap functionality that Run calls to support cleaner testing.
@@ -470,6 +470,9 @@ func (c *bootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
470470
)
471471
return cmd.ErrSilent
472472
}
473+
if c.controllerName == "" {
474+
c.controllerName = defaultControllerName(c.Cloud, region.Name)
475+
}
473476

474477
controllerModelUUID, err := utils.NewUUID()
475478
if err != nil {
@@ -859,11 +862,7 @@ func (c *bootstrapCommand) runInteractive(ctx *cmd.Context) error {
859862
}
860863
}
861864

862-
var username string
863-
if u, err := user.Current(); err == nil {
864-
username = u.Username
865-
}
866-
defName := defaultControllerName(username, c.Cloud, c.Region, cloud)
865+
defName := defaultControllerName(c.Cloud, c.Region)
867866

868867
c.controllerName, err = queryName(defName, scanner, ctx.Stdout)
869868
if err != nil {

cmd/juju/commands/bootstrap_interactive.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,11 @@ func queryRegion(cloud string, regions []jujucloud.Region, scanner *bufio.Scanne
9191
return regionName, nil
9292
}
9393

94-
func defaultControllerName(username, cloudname, region string, cloud *jujucloud.Cloud) string {
95-
name := cloudname
96-
if len(cloud.Regions) > 1 {
97-
name = region
98-
}
99-
if username == "" {
100-
return name
94+
func defaultControllerName(cloudname, region string) string {
95+
if region == "" {
96+
return cloudname
10197
}
102-
return username + "-" + name
98+
return cloudname + "-" + region
10399
}
104100

105101
func queryName(defName string, scanner *bufio.Scanner, w io.Writer) (string, error) {

cmd/juju/commands/bootstrap_interactive_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (BSInteractSuite) TestInitBuildAgent(c *gc.C) {
4242
func (BSInteractSuite) TestInitArg(c *gc.C) {
4343
cmd := &bootstrapCommand{}
4444
err := jujutesting.InitCommand(cmd, []string{"foo"})
45-
c.Assert(err, gc.ErrorMatches, "controller name and cloud name are required")
45+
c.Assert(err, jc.ErrorIsNil)
4646
c.Assert(cmd.interactive, jc.IsFalse)
4747
}
4848

0 commit comments

Comments
 (0)