Store/restore Server from a dict with credentials
The patch adds two methods to Server class to get a dict with credentials from instance of its class and restore an instance from credentials. LxcProvider requires reconstruction of the Server objects for destruction of resources. blueprint db-resource-track Change-Id: I2f9ca4a1c49477d665ba02ff0736c21a7557e12a
This commit is contained in:
parent
476caf50f2
commit
44773b14e6
@ -34,6 +34,20 @@ class Server(utils.ImmutableMixin):
|
||||
self.ssh = sshutils.SSH(ip, user)
|
||||
super(Server, self).__init__()
|
||||
|
||||
def get_credentials(self):
|
||||
return {
|
||||
'uuid': self.uuid,
|
||||
'ip': self.ip,
|
||||
'user': self.user,
|
||||
'key': self.key,
|
||||
'password': self.password,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_credentials(cls, creds):
|
||||
return cls(creds['uuid'], creds['ip'], creds['user'], creds['key'],
|
||||
password=creds['password'])
|
||||
|
||||
|
||||
class ImageDTO(utils.ImmutableMixin):
|
||||
"""Represent information about created image.
|
||||
|
@ -83,15 +83,24 @@ class ProviderTestCase(test.TestCase):
|
||||
|
||||
|
||||
class ServerTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(ServerTestCase, self).setUp()
|
||||
self.vals = ['uuid', '192.168.1.1', 'admin', 'some_key', 'pwd']
|
||||
self.keys = ['uuid', 'ip', 'user', 'key', 'password']
|
||||
|
||||
def test_init_server_dto(self):
|
||||
vals = ['uuid', '192.168.1.1', 'admin', 'some_key', 'pwd']
|
||||
keys = ['uuid', 'ip', 'user', 'key', 'password']
|
||||
server = serverprovider.Server(*vals)
|
||||
for k, v in dict(zip(keys, vals)).iteritems():
|
||||
server = serverprovider.Server(*self.vals)
|
||||
for k, v in dict(zip(self.keys, self.vals)).iteritems():
|
||||
self.assertEqual(getattr(server, k), v)
|
||||
self.assertIsInstance(server.ssh, sshutils.SSH)
|
||||
|
||||
def test_credentials(self):
|
||||
server_one = serverprovider.Server(*self.vals)
|
||||
creds = server_one.get_credentials()
|
||||
server_two = serverprovider.Server.from_credentials(creds)
|
||||
for k in self.keys:
|
||||
self.assertEqual(getattr(server_one, k), getattr(server_two, k))
|
||||
|
||||
|
||||
class ImageDTOTestCase(test.TestCase):
|
||||
def test_init_image_dto(self):
|
||||
|
Loading…
Reference in New Issue
Block a user