[lxc-devel] [pylxd/master] Add rename support to Profile (fixes #148)
rockstar on Github
lxc-bot at linuxcontainers.org
Tue Jun 28 00:33:41 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 302 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160628/4322eee9/attachment.bin>
-------------- next part --------------
From 150fa7ce01ddabf9a9c1c587100c628edc54475b Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Mon, 27 Jun 2016 18:32:42 -0600
Subject: [PATCH] Add rename support to Profile (fixes #148)
---
pylxd/profile.py | 10 ++++++----
pylxd/tests/mock_lxd.py | 7 ++++++-
pylxd/tests/test_profile.py | 7 ++++---
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/pylxd/profile.py b/pylxd/profile.py
index 1bcc0e0..e04e075 100644
--- a/pylxd/profile.py
+++ b/pylxd/profile.py
@@ -21,7 +21,7 @@ class Profile(mixin.Marshallable):
__slots__ = [
'_client',
'config', 'devices', 'name'
- ]
+ ]
@classmethod
def get(cls, client, name):
@@ -77,10 +77,12 @@ def update(self):
self._client.api.profiles[self.name].put(json=marshalled)
- def rename(self, new):
+ def rename(self, new_name):
"""Rename the profile."""
- raise NotImplementedError(
- 'LXD does not currently support renaming profiles')
+ self._client.api.profiles[
+ self.name].post(json={'name': new_name})
+
+ return Profile.get(self._client, new_name)
def delete(self):
"""Delete a profile."""
diff --git a/pylxd/tests/mock_lxd.py b/pylxd/tests/mock_lxd.py
index 8f5d531..a33878f 100644
--- a/pylxd/tests/mock_lxd.py
+++ b/pylxd/tests/mock_lxd.py
@@ -376,7 +376,7 @@ def profile_GET(request, context):
{
'text': profile_GET,
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/profiles/(an-profile|an-new-profile)$',
+ 'url': r'^http://pylxd.test/1.0/profiles/(an-profile|an-new-profile|an-renamed-profile)$', # NOQA
},
{
'text': json.dumps({'type': 'sync'}),
@@ -384,6 +384,11 @@ def profile_GET(request, context):
'url': r'^http://pylxd.test/1.0/profiles/(an-profile|an-new-profile)$',
},
{
+ 'text': json.dumps({'type': 'sync'}),
+ 'method': 'POST',
+ 'url': r'^http://pylxd.test/1.0/profiles/(an-profile|an-new-profile)$',
+ },
+ {
'text': profile_DELETE,
'method': 'DELETE',
'url': r'^http://pylxd.test/1.0/profiles/(an-profile|an-new-profile)$',
diff --git a/pylxd/tests/test_profile.py b/pylxd/tests/test_profile.py
index d964ec7..bf61c6d 100644
--- a/pylxd/tests/test_profile.py
+++ b/pylxd/tests/test_profile.py
@@ -65,11 +65,12 @@ def test_create(self):
self.assertEqual('an-new-profile', an_profile.name)
def test_rename(self):
- """Profiles cannot yet be renamed."""
+ """A profile is renamed."""
an_profile = profile.Profile.get(self.client, 'an-profile')
- self.assertRaises(
- NotImplementedError, an_profile.rename, 'an-renamed-profile')
+ an_renamed_profile = an_profile.rename('an-renamed-profile')
+
+ self.assertEqual('an-renamed-profile', an_renamed_profile.name)
def test_create_failed(self):
"""CreateFailed is raised when errors occur."""
More information about the lxc-devel
mailing list