From 51c1f93306f5e160f0de8f2909cee2aa444bfe14 Mon Sep 17 00:00:00 2001 From: ElNounch Date: Tue, 23 Feb 2016 07:55:24 +0000 Subject: [PATCH] Handle special IPs names in run command / Help documentation lines --- pkg/cli/cmd_create.go | 2 +- pkg/cli/cmd_run.go | 2 +- pkg/commands/create.go | 2 +- pkg/commands/run.go | 13 ++++++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/cli/cmd_create.go b/pkg/cli/cmd_create.go index 3864a54953..12549c22a4 100644 --- a/pkg/cli/cmd_create.go +++ b/pkg/cli/cmd_create.go @@ -30,7 +30,7 @@ func init() { cmdCreate.Flag.StringVar(&createBootscript, []string{"-bootscript"}, "", "Assign a bootscript") cmdCreate.Flag.StringVar(&createEnv, []string{"e", "-env"}, "", "Provide metadata tags passed to initrd (i.e., boot=resue INITRD_DEBUG=1)") cmdCreate.Flag.StringVar(&createVolume, []string{"v", "-volume"}, "", "Attach additional volume (i.e., 50G)") - cmdCreate.Flag.StringVar(&createIPAddress, []string{"-ip-address"}, "", "Assign an IP") + cmdCreate.Flag.StringVar(&createIPAddress, []string{"-ip-address"}, "dynamic", "Assign a reserved public IP, a 'dynamic' one or 'none'") cmdCreate.Flag.BoolVar(&createHelp, []string{"h", "-help"}, false, "Print usage") cmdCreate.Flag.BoolVar(&createTmpSSHKey, []string{"-tmp-ssh-key"}, false, "Access your server without uploading your SSH key to your account") } diff --git a/pkg/cli/cmd_run.go b/pkg/cli/cmd_run.go index 0545220d6b..0b82496ccc 100644 --- a/pkg/cli/cmd_run.go +++ b/pkg/cli/cmd_run.go @@ -38,7 +38,7 @@ func init() { cmdRun.Flag.StringVar(&runCreateVolume, []string{"v", "-volume"}, "", "Attach additional volume (i.e., 50G)") cmdRun.Flag.BoolVar(&runHelpFlag, []string{"h", "-help"}, false, "Print usage") cmdRun.Flag.Int64Var(&runTimeout, []string{"T", "-timeout"}, 0, "Set timeout value to seconds") - cmdRun.Flag.StringVar(&runIPAddress, []string{"-ip-address"}, "", "Assign an IP") + cmdRun.Flag.StringVar(&runIPAddress, []string{"-ip-address"}, "", "Assign a reserved public IP, a 'dynamic' one or 'none' (default to 'none' if gateway specified, 'dynamic' otherwise)") cmdRun.Flag.BoolVar(&runAttachFlag, []string{"a", "-attach"}, false, "Attach to serial console") cmdRun.Flag.BoolVar(&runDetachFlag, []string{"d", "-detach"}, false, "Run server in background and print server ID") cmdRun.Flag.StringVar(&runGateway, []string{"g", "-gateway"}, "", "Use a SSH gateway") diff --git a/pkg/commands/create.go b/pkg/commands/create.go index 34e41c1ead..29d326b425 100644 --- a/pkg/commands/create.go +++ b/pkg/commands/create.go @@ -42,7 +42,7 @@ func RunCreate(ctx CommandContext, args CreateArgs) error { DynamicIPRequired: false, IP: args.IP, } - if args.IP == "" || args.IP == "dynamic" { + if args.IP == "dynamic" || args.IP == "" { config.DynamicIPRequired = true config.IP = "" } else if args.IP == "none" || args.IP == "no" { diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 71a568c5b0..23cd72eb7c 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -157,15 +157,22 @@ func Run(ctx CommandContext, args RunArgs) error { // create IMAGE logrus.Info("Server creation ...") - serverID, err := api.CreateServer(ctx.API, &api.ConfigCreateServer{ + config := api.ConfigCreateServer{ ImageName: args.Image, Name: args.Name, Bootscript: args.Bootscript, Env: env, AdditionalVolumes: volume, - DynamicIPRequired: args.Gateway == "", + DynamicIPRequired: false, IP: args.IP, - }) + } + if args.IP == "dynamic" || (args.IP == "" && args.Gateway == "") { + config.DynamicIPRequired = true + config.IP = "" + } else if args.IP == "none" || args.IP == "no" || (args.IP == "" && args.Gateway != "") { + config.IP = "" + } + serverID, err := api.CreateServer(ctx.API, &config) if err != nil { return fmt.Errorf("failed to create server: %v", err) }