713fcf7659
To be able to run the example using the container we need to change our hosts LVM configuration, which was not explained in the docs. This patch adds the explanation as well as a simplified way of running this without touching our own host using Vagrant + libvirt + Ansible.
1.1 KiB
1.1 KiB
Docker example
This Vagrant file deploys a small VM (1GB and 1CPU) with cinderlib in a container and with LVM properly configured to be used by the container.
This makes it really easy to use the containerized version of cinderlib:
$ vagrant up
$ vagrant ssh -c 'sudo docker exec -it cinderlib python'
Once we've run those two commands we are in a Python interpreter shell and can run Python code to use the LVM backend:
import cinderlib as cl
# Initialize the LVM driver
= cl.Backend(volume_driver='cinder.volume.drivers.lvm.LVMVolumeDriver',
lvm ='cinder-volumes',
volume_group='iscsi',
target_protocol='lioadm',
target_helper='lvm_iscsi')
volume_backend_name
# Create a 1GB volume
= lvm.create_volume(1)
vol
# Export, initialize, and do a local attach of the volume
= vol.attach()
attach
print('Volume %s attached to %s' % (vol.id, attach.path))
# Detach it
vol.detach()
# Delete it
vol.delete()