Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
language: python
dist: bionic


install:
# Required so `git describe` will definitely find a tag; see
# https://github.com/travis-ci/travis-ci/issues/7422
- git fetch --unshallow

matrix:
fast_finish: true
include:
- name: run-lxd-example
install:
- pip install -r requirements.txt
script:
- sudo apt-get remove --yes --purge lxd lxd-client
- sudo rm -Rf /var/lib/lxd
- sudo snap install lxd
- sudo lxd init --auto
- sudo usermod -a -G lxd $USER
- sg lxd -c "python examples/lxd.py"
- name: run-cloudinit-integration-tests
install:
- pip install -r requirements.txt
- pip install pytest
script:
- sudo apt-get remove --yes --purge lxd lxd-client
- sudo rm -Rf /var/lib/lxd
- sudo snap install lxd
- sudo lxd init --auto
- sudo usermod -a -G lxd $USER
- git clone https://github.com/canonical/cloud-init.git
- cd cloud-init
- sg lxd -c "pytest tests/integration_tests/"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use tox and only run the CI tests we run in cloud-init: that should comfortably exercise most of the pycloudlib functionality we use. Given that I'm going to be pushing a cloud-init commit to make that easier to do, let's leave this as-is and I'll propose a separate change which does that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Except tox might have a hard time using the current pycloudlib rather than cloud-init's default one, so I'll give this further thought.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was exactly why I have not used tox :(

21 changes: 13 additions & 8 deletions examples/lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def snapshot_instance():
instance to the snapshot level.
Finally, launch another instance from the snapshot of the instance.
"""
lxd = pycloudlib.LXD('example-snapshot')
lxd = pycloudlib.LXDContainer('example-snapshot')
inst = lxd.launch(name='pycloudlib-snapshot-base', image_id=RELEASE)

snapshot_name = 'snapshot'
Expand All @@ -43,7 +43,7 @@ def modify_instance():
Once started the instance demonstrates some interactions with the
instance.
"""
lxd = pycloudlib.LXD('example-modify')
lxd = pycloudlib.LXDContainer('example-modify')

inst = lxd.init('pycloudlib-modify-inst', RELEASE)
inst.edit('limits.memory', '3GB')
Expand All @@ -64,7 +64,7 @@ def launch_multiple():
waiting for the instance to start each time. Note that the
wait_for_delete method is not used, as LXD does not do any waiting.
"""
lxd = pycloudlib.LXD('example-multiple')
lxd = pycloudlib.LXDContainer('example-multiple')

instances = []
for num in range(3):
Expand Down Expand Up @@ -97,7 +97,7 @@ def launch_options():

Finally, an instance with custom configurations options.
"""
lxd = pycloudlib.LXD('example-launch')
lxd = pycloudlib.LXDContainer('example-launch')
kvm_profile = textwrap.dedent(
"""\
devices:
Expand Down Expand Up @@ -148,7 +148,10 @@ def launch_options():

def basic_lifecycle():
"""Demonstrate basic set of lifecycle operations with LXD."""
lxd = pycloudlib.LXD('example-basic')
lxd = pycloudlib.LXDContainer('example-basic')
inst = lxd.launch(image_id=RELEASE)
inst.delete()

name = 'pycloudlib-daily'
inst = lxd.launch(name=name, image_id=RELEASE)
inst.console_log()
Expand All @@ -174,7 +177,7 @@ def basic_lifecycle():

def launch_virtual_machine():
"""Demonstrate launching virtual machine scenario."""
lxd = pycloudlib.LXD('example-vm')
lxd = pycloudlib.LXDVirtualMachine('example-vm')

pub_key_path = "lxd-pubkey"
priv_key_path = "lxd-privkey"
Expand All @@ -191,10 +194,12 @@ def launch_virtual_machine():
private_key_path=priv_key_path
)

image_id = lxd.released_image(release=RELEASE, is_vm=True)
image_id = lxd.released_image(release=RELEASE)
image_serial = lxd.image_serial(image_id)
print("Image serial: {}".format(image_serial))
name = 'pycloudlib-vm'
inst = lxd.launch(
name=name, image_id=image_id, is_vm=True)
name=name, image_id=image_id)
print("Is vm: {}".format(inst.is_vm))
result = inst.execute("lsb_release -a")
print(result)
Expand Down
4 changes: 3 additions & 1 deletion pycloudlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pycloudlib.azure.cloud import Azure
from pycloudlib.ec2.cloud import EC2
from pycloudlib.gce.cloud import GCE
from pycloudlib.lxd.cloud import LXD
from pycloudlib.lxd.cloud import LXD, LXDContainer, LXDVirtualMachine
from pycloudlib.kvm.cloud import KVM
from pycloudlib.oci.cloud import OCI

Expand All @@ -15,6 +15,8 @@
'EC2',
'GCE',
'LXD',
'LXDContainer',
'LXDVirtualMachine',
'KVM',
'OCI',
]
Expand Down
Loading