|
|
@ -59,6 +59,7 @@ class LilikContainer(object): |
|
|
|
A generic lxc container manipulation object based on python-lxc |
|
|
|
""" |
|
|
|
def __init__(self, module): |
|
|
|
self.module = module |
|
|
|
self.state = module.params['state'] |
|
|
|
self.name = module.params['name'] |
|
|
|
self.template = module.params['template'] |
|
|
@ -66,7 +67,7 @@ class LilikContainer(object): |
|
|
|
self.lvname = module.params['lv_name'] |
|
|
|
self.vgname = module.params['vg_name'] |
|
|
|
self.fstype = module.params['fs_type'] |
|
|
|
self.fssize = module.params['fssize'] |
|
|
|
self.fssize = module.params['fs_size'] |
|
|
|
|
|
|
|
def create_container(self): |
|
|
|
""" |
|
|
@ -78,15 +79,21 @@ class LilikContainer(object): |
|
|
|
'lvname': self.lvname, |
|
|
|
'vgname': self.vgname, |
|
|
|
'fstype': self.fstype, |
|
|
|
'fssize': self.fssize |
|
|
|
'fssize': self.fssize, |
|
|
|
'bdev' : self.backing_store, |
|
|
|
} |
|
|
|
try: |
|
|
|
import lxc |
|
|
|
except ImportError: |
|
|
|
self.module.fail_json(changed=False, msg='Error importing lxc') |
|
|
|
|
|
|
|
container = lxc.Container(name = self.name) |
|
|
|
|
|
|
|
# TODO: python2-lxc does not like bdevtype but python-lxc does |
|
|
|
return container.create( |
|
|
|
template = self.template, |
|
|
|
args = container_options, |
|
|
|
bdevtype=self.backing_store |
|
|
|
# bdevtype = self.backing_store |
|
|
|
) |
|
|
|
|
|
|
|
def main(): |
|
|
@ -95,7 +102,8 @@ def main(): |
|
|
|
argument_spec = dict( |
|
|
|
backing_store = dict( |
|
|
|
default='dir', |
|
|
|
choices=['dir', 'lvm', 'loop', 'btrsf', 'overlayfs', 'zfs', type='str'], |
|
|
|
choices=['dir', 'lvm', 'loop', 'btrsf', 'overlayfs', 'zfs',], |
|
|
|
type='str', |
|
|
|
), |
|
|
|
container_command = dict( |
|
|
|
type='str', |
|
|
@ -188,10 +196,11 @@ def main(): |
|
|
|
try: |
|
|
|
new_container = container.create_container() |
|
|
|
module.exit_json(changed=True) |
|
|
|
except Exception: |
|
|
|
except Exception as e: |
|
|
|
module.fail_json( |
|
|
|
changed=False, |
|
|
|
msg='An excption was raised while creating the container' |
|
|
|
msg='An excption was raised while creating the container', |
|
|
|
exception_message=str(e), |
|
|
|
) |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|