Skip to content

Commit

Permalink
added image creation from public lxd server
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Engelmann <[email protected]>
  • Loading branch information
felix-engelmann committed Oct 17, 2019
1 parent f79a8fe commit 27dfe23
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pylxd/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ def create_from_simplestreams(cls, client, server, alias,

return client.images.get(op.metadata['fingerprint'])

@classmethod
def create_from_image(cls, client, server, fingerprint=None, alias=None, public=False, auto_update=False):
"""Copy an image from remote lxd."""
config = {
'public': public,
'auto_update': auto_update,
'source': {
'type': 'image',
'mode': 'pull',
'server': server,
'protocol': 'lxd',
'fingerprint': fingerprint,
'alias': alias
}
}

op = _image_create_from_config(client, config, wait=True)

return client.images.get(op.metadata['fingerprint'])

@classmethod
def create_from_url(cls, client, url,
public=False, auto_update=False):
Expand Down
11 changes: 11 additions & 0 deletions pylxd/tests/models/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ def test_create_from_simplestreams(self):
image.fingerprint
)

def test_create_from_image(self):
"""Try to create an image from image at public lxd."""
image = self.client.images.create_from_image(
'https://images.nlogn.org:8443',
alias='debian/8'
)
self.assertEqual(
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
image.fingerprint
)

def test_create_from_url(self):
"""Try to create an image from an URL."""
image = self.client.images.create_from_url(
Expand Down

0 comments on commit 27dfe23

Please sign in to comment.