From 876f4ce1fadb9b49f5d54c6f210213221879861b Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Wed, 29 Aug 2018 11:21:21 +0800 Subject: [PATCH] climc: server-rebuild-root support keypair and passwd --- cmd/climc/shell/keypairs.go | 4 ++-- cmd/climc/shell/servers.go | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/climc/shell/keypairs.go b/cmd/climc/shell/keypairs.go index a13ae163a7..d56d2122a2 100644 --- a/cmd/climc/shell/keypairs.go +++ b/cmd/climc/shell/keypairs.go @@ -113,9 +113,9 @@ func init() { if len(args.PublicKey) > 0 { content, e := ioutil.ReadFile(args.PublicKey) if e != nil { - params.Add(jsonutils.NewString(args.PublicKey), "public_Key") + params.Add(jsonutils.NewString(args.PublicKey), "public_key") } else { - params.Add(jsonutils.NewString(string(content)), "public_Key") + params.Add(jsonutils.NewString(string(content)), "public_key") } } else { return fmt.Errorf("no public key provided") diff --git a/cmd/climc/shell/servers.go b/cmd/climc/shell/servers.go index f0d74b5d59..09e610c86f 100644 --- a/cmd/climc/shell/servers.go +++ b/cmd/climc/shell/servers.go @@ -644,14 +644,26 @@ func init() { }) type ServerRebuildRootOptions struct { - SERVER string `help:"Server to rebuild root"` - Image string `help:"New root Image template ID"` + SERVER string `help:"Server to rebuild root"` + AutoStart bool `help:"Auto start server after it is created"` + Image string `help:"New root Image template ID"` + Keypair string `help:"ssh Keypair used for login"` + Password string `help:"Default user password"` } R(&ServerRebuildRootOptions{}, "server-rebuild-root", "Rebuild VM root image with new template", func(s *mcclient.ClientSession, args *ServerRebuildRootOptions) error { params := jsonutils.NewDict() if len(args.Image) > 0 { params.Add(jsonutils.NewString(args.Image), "image_id") } + if args.AutoStart { + params.Add(jsonutils.JSONTrue, "auto_start") + } + if args.Keypair != "" { + params.Add(jsonutils.NewString(args.Keypair), "keypair") + } + if args.Password != "" { + params.Add(jsonutils.NewString(args.Password), "password") + } srv, err := modules.Servers.PerformAction(s, args.SERVER, "rebuild-root", params) if err != nil { return err