|
|
|
|
@ -198,7 +198,14 @@ EXAMPLES = '''
|
|
|
|
|
ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
|
|
|
|
|
|
|
|
|
|
# Create new container automatically selecting the next available vmid.
|
|
|
|
|
- proxmox: node='uk-mc02' api_user='root@pam' api_password='1q2w3e' api_host='node1' password='123456' hostname='example.org' ostemplate='local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
|
|
|
|
|
- proxmox:
|
|
|
|
|
node: 'uk-mc02'
|
|
|
|
|
api_user: 'root@pam'
|
|
|
|
|
api_password: '1q2w3e'
|
|
|
|
|
api_host: 'node1'
|
|
|
|
|
password: '123456'
|
|
|
|
|
hostname: 'example.org'
|
|
|
|
|
ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
|
|
|
|
|
|
|
|
|
|
# Create new container with minimal options with force(it will rewrite existing container)
|
|
|
|
|
- proxmox:
|
|
|
|
|
@ -354,13 +361,13 @@ def create_instance(module, proxmox, vmid, node, disk, storage, cpus, memory, sw
|
|
|
|
|
taskid = getattr(proxmox_node, VZ_TYPE).create(vmid=vmid, storage=storage, memory=memory, swap=swap, **kwargs)
|
|
|
|
|
|
|
|
|
|
while timeout:
|
|
|
|
|
if ( proxmox_node.tasks(taskid).status.get()['status'] == 'stopped'
|
|
|
|
|
and proxmox_node.tasks(taskid).status.get()['exitstatus'] == 'OK' ):
|
|
|
|
|
if (proxmox_node.tasks(taskid).status.get()['status'] == 'stopped' and
|
|
|
|
|
proxmox_node.tasks(taskid).status.get()['exitstatus'] == 'OK'):
|
|
|
|
|
return True
|
|
|
|
|
timeout = timeout - 1
|
|
|
|
|
if timeout == 0:
|
|
|
|
|
module.fail_json(msg='Reached timeout while waiting for creating VM. Last line in task before timeout: %s'
|
|
|
|
|
% proxmox_node.tasks(taskid).log.get()[:1])
|
|
|
|
|
module.fail_json(msg='Reached timeout while waiting for creating VM. Last line in task before timeout: %s' %
|
|
|
|
|
proxmox_node.tasks(taskid).log.get()[:1])
|
|
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
return False
|
|
|
|
|
@ -368,13 +375,13 @@ def create_instance(module, proxmox, vmid, node, disk, storage, cpus, memory, sw
|
|
|
|
|
def start_instance(module, proxmox, vm, vmid, timeout):
|
|
|
|
|
taskid = getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.start.post()
|
|
|
|
|
while timeout:
|
|
|
|
|
if ( proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped'
|
|
|
|
|
and proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK' ):
|
|
|
|
|
if (proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped' and
|
|
|
|
|
proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK'):
|
|
|
|
|
return True
|
|
|
|
|
timeout = timeout - 1
|
|
|
|
|
if timeout == 0:
|
|
|
|
|
module.fail_json(msg='Reached timeout while waiting for starting VM. Last line in task before timeout: %s'
|
|
|
|
|
% proxmox.nodes(vm[0]['node']).tasks(taskid).log.get()[:1])
|
|
|
|
|
module.fail_json(msg='Reached timeout while waiting for starting VM. Last line in task before timeout: %s' %
|
|
|
|
|
proxmox.nodes(vm[0]['node']).tasks(taskid).log.get()[:1])
|
|
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
return False
|
|
|
|
|
@ -385,13 +392,13 @@ def stop_instance(module, proxmox, vm, vmid, timeout, force):
|
|
|
|
|
else:
|
|
|
|
|
taskid = getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.shutdown.post()
|
|
|
|
|
while timeout:
|
|
|
|
|
if ( proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped'
|
|
|
|
|
and proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK' ):
|
|
|
|
|
if (proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped' and
|
|
|
|
|
proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK'):
|
|
|
|
|
return True
|
|
|
|
|
timeout = timeout - 1
|
|
|
|
|
if timeout == 0:
|
|
|
|
|
module.fail_json(msg='Reached timeout while waiting for stopping VM. Last line in task before timeout: %s'
|
|
|
|
|
% proxmox_node.tasks(taskid).log.get()[:1])
|
|
|
|
|
module.fail_json(msg='Reached timeout while waiting for stopping VM. Last line in task before timeout: %s' %
|
|
|
|
|
proxmox_node.tasks(taskid).log.get()[:1])
|
|
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
return False
|
|
|
|
|
@ -399,13 +406,13 @@ def stop_instance(module, proxmox, vm, vmid, timeout, force):
|
|
|
|
|
def umount_instance(module, proxmox, vm, vmid, timeout):
|
|
|
|
|
taskid = getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.umount.post()
|
|
|
|
|
while timeout:
|
|
|
|
|
if ( proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped'
|
|
|
|
|
and proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK' ):
|
|
|
|
|
if (proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped' and
|
|
|
|
|
proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK'):
|
|
|
|
|
return True
|
|
|
|
|
timeout = timeout - 1
|
|
|
|
|
if timeout == 0:
|
|
|
|
|
module.fail_json(msg='Reached timeout while waiting for unmounting VM. Last line in task before timeout: %s'
|
|
|
|
|
% proxmox_node.tasks(taskid).log.get()[:1])
|
|
|
|
|
module.fail_json(msg='Reached timeout while waiting for unmounting VM. Last line in task before timeout: %s' %
|
|
|
|
|
proxmox_node.tasks(taskid).log.get()[:1])
|
|
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
return False
|
|
|
|
|
@ -562,8 +569,8 @@ def main():
|
|
|
|
|
vm = get_instance(proxmox, vmid)
|
|
|
|
|
if not vm:
|
|
|
|
|
module.fail_json(msg='VM with vmid = %s not exists in cluster' % vmid)
|
|
|
|
|
if ( getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.current.get()['status'] == 'stopped'
|
|
|
|
|
or getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.current.get()['status'] == 'mounted' ):
|
|
|
|
|
if (getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.current.get()['status'] == 'stopped' or
|
|
|
|
|
getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.current.get()['status'] == 'mounted'):
|
|
|
|
|
module.exit_json(changed=False, msg="VM %s is not running" % vmid)
|
|
|
|
|
|
|
|
|
|
if (stop_instance(module, proxmox, vm, vmid, timeout, force = module.params['force']) and
|
|
|
|
|
@ -586,8 +593,8 @@ def main():
|
|
|
|
|
|
|
|
|
|
taskid = getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE).delete(vmid)
|
|
|
|
|
while timeout:
|
|
|
|
|
if ( proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped'
|
|
|
|
|
and proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK' ):
|
|
|
|
|
if (proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped' and
|
|
|
|
|
proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK'):
|
|
|
|
|
module.exit_json(changed=True, msg="VM %s removed" % vmid)
|
|
|
|
|
timeout = timeout - 1
|
|
|
|
|
if timeout == 0:
|
|
|
|
|
|