The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3937
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) ===
From 8b95369d65b0fb87ff22af3263432b76bbae8f97 Mon Sep 17 00:00:00 2001 From: Alberto Donato <[email protected]> Date: Thu, 12 Oct 2017 16:20:26 +0200 Subject: [PATCH 1/3] lxc/profle: add "profile rename" command Signed-off-by: Alberto Donato <[email protected]> --- lxc/profile.go | 18 ++++++++++++++++++ test/suites/config.sh | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/lxc/profile.go b/lxc/profile.go index fad41668b..a464587a1 100644 --- a/lxc/profile.go +++ b/lxc/profile.go @@ -81,6 +81,9 @@ lxc profile delete [<remote>:]<profile> lxc profile edit [<remote>:]<profile> Edit profile, either by launching external editor or reading STDIN. +lxc profile rename [<remote>:]<profile> <new-name> + Rename a profile. + *Profile assignment* lxc profile assign [<remote>:]<container> <profiles> Replace the current set of profiles for the container by the one provided. @@ -161,6 +164,11 @@ func (c *profileCmd) run(conf *config.Config, args []string) error { return c.doProfileDevice(conf, args) case "edit": return c.doProfileEdit(client, profile) + case "rename": + if len(args) != 3 { + return errArgs + } + return c.doProfileRename(client, profile, args[2]) case "apply", "assign": container := profile switch len(args) { @@ -283,6 +291,16 @@ func (c *profileCmd) doProfileEdit(client lxd.ContainerServer, p string) error { return nil } +func (c *profileCmd) doProfileRename(client lxd.ContainerServer, p string, newName string) error { + err := client.RenameProfile(p, api.ProfilePost{Name: newName}) + if err != nil { + return err + } + + fmt.Printf(i18n.G("Profile %s renamed to %s")+"\n", p, newName) + return nil +} + func (c *profileCmd) doProfileDelete(client lxd.ContainerServer, p string) error { err := client.DeleteProfile(p) if err != nil { diff --git a/test/suites/config.sh b/test/suites/config.sh index f0ecfcf25..2f4e21a59 100644 --- a/test/suites/config.sh +++ b/test/suites/config.sh @@ -150,6 +150,11 @@ test_config_profiles() { lxc profile create unconfined lxc profile set unconfined raw.lxc "lxc.aa_profile=unconfined" lxc profile assign foo onenic,unconfined + # test profile rename + lxc profile create foo + lxc profile rename foo bar + lxc profile list | grep -qv foo # the old name is gone + lxc profile delete bar lxc config device list foo | grep mnt1 lxc config device show foo | grep "/mnt1" From 964f5b4e274d8d23e5a496e41f75116b246498d2 Mon Sep 17 00:00:00 2001 From: Alberto Donato <[email protected]> Date: Thu, 12 Oct 2017 16:28:35 +0200 Subject: [PATCH 2/3] lxc/network: add "network rename" command Signed-off-by: Alberto Donato <[email protected]> --- lxc/network.go | 18 ++++++++++++++++++ test/suites/network.sh | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/lxc/network.go b/lxc/network.go index c17d2b40b..3ef5fd7e8 100644 --- a/lxc/network.go +++ b/lxc/network.go @@ -76,6 +76,9 @@ lxc network delete [<remote>:]<network> lxc network edit [<remote>:]<network> Edit network, either by launching external editor or reading STDIN. +lxc network rename [<remote>:]<network> <new-name> + Rename a network. + lxc network attach [<remote>:]<network> <container> [device name] [interface name] Attach a network interface connecting the network to a specified container. @@ -133,6 +136,11 @@ func (c *networkCmd) run(conf *config.Config, args []string) error { return c.doNetworkDetachProfile(client, network, args[2:]) case "edit": return c.doNetworkEdit(client, network) + case "rename": + if len(args) != 3 { + return errArgs + } + return c.doNetworkRename(client, network, args[2]) case "get": return c.doNetworkGet(client, network, args[2:]) case "set": @@ -434,6 +442,16 @@ func (c *networkCmd) doNetworkEdit(client lxd.ContainerServer, name string) erro return nil } +func (c *networkCmd) doNetworkRename(client lxd.ContainerServer, name string, newName string) error { + err := client.RenameNetwork(name, api.NetworkPost{Name: newName}) + if err != nil { + return err + } + + fmt.Printf(i18n.G("Network %s renamed to %s")+"\n", name, newName) + return nil +} + func (c *networkCmd) doNetworkGet(client lxd.ContainerServer, name string, args []string) error { // we shifted @args so so it should read "<key>" if len(args) != 1 { diff --git a/test/suites/network.sh b/test/suites/network.sh index c13b86332..6a51a9fe0 100644 --- a/test/suites/network.sh +++ b/test/suites/network.sh @@ -19,6 +19,12 @@ test_network() { lxc network show lxdt$$ | grep -q 'description: foo' lxc network delete lxdt$$ + # rename network + lxc network create lxdt$$ + lxc network rename lxdt$$ newnet + lxc network list | grep -qv lxdt$$ # the old name is gone + lxc network delete newnet + # Unconfigured bridge lxc network create lxdt$$ ipv4.address=none ipv6.address=none lxc network delete lxdt$$ From f439ddc90e40a4ab616e22b6e6972e6d5c1d5bca Mon Sep 17 00:00:00 2001 From: Alberto Donato <[email protected]> Date: Thu, 12 Oct 2017 16:40:29 +0200 Subject: [PATCH 3/3] lxc/image: add "image alias rename" command Signed-off-by: Alberto Donato <[email protected]> --- lxc/image.go | 19 +++++++++++++++++++ test/suites/basic.sh | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/lxc/image.go b/lxc/image.go index b88256541..78b90cd33 100644 --- a/lxc/image.go +++ b/lxc/image.go @@ -160,6 +160,9 @@ lxc image edit [<remote>:]<image> lxc image alias create [<remote>:]<alias> <fingerprint> Create a new alias for an existing image. +lxc image alias rename [<remote>:]<alias> <new-name> + Rename an alias. + lxc image alias delete [<remote>:]<alias> Delete an alias. @@ -323,6 +326,22 @@ func (c *imageCmd) doImageAlias(conf *config.Config, args []string) error { alias.Target = args[3] return d.CreateImageAlias(alias) + case "rename": + /* alias rename [<remote>:]<alias> <newname> */ + if len(args) < 4 { + return errArgs + } + remote, alias, err := conf.ParseRemote(args[2]) + if err != nil { + return err + } + + d, err := conf.GetContainerServer(remote) + if err != nil { + return err + } + + return d.RenameImageAlias(alias, api.ImageAliasesEntryPost{Name: args[3]}) case "delete": /* alias delete [<remote>:]<alias> */ if len(args) < 3 { diff --git a/test/suites/basic.sh b/test/suites/basic.sh index cb7d147ae..3d3926656 100644 --- a/test/suites/basic.sh +++ b/test/suites/basic.sh @@ -27,6 +27,11 @@ test_basic_usage() { lxc image alias delete foo lxc image alias delete bar + lxc image alias create foo "${sum}" + lxc image alias rename foo bar + lxc image alias list | grep -qv foo # the old name is gone + lxc image alias delete bar + # Test image list output formats (table & json) lxc image list --format table | grep -q testimage lxc image list --format json \
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
