Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added image creation from public lxd server #378

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pylxd/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,32 @@ 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, secret=None,
certificate=None):
"""Copy an image from remote lxd."""
felix-engelmann marked this conversation as resolved.
Show resolved Hide resolved
config = {
'public': public,
'auto_update': auto_update,
'source': {
'type': 'image',
'mode': 'pull',
'server': server,
'protocol': 'lxd',
'fingerprint': fingerprint,
'alias': alias,
'secret': secret,
'certificate': certificate
}
}
if alias is not None:
config["aliases"] = [{'name': 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