update qemu operations

This commit is contained in:
Vyacheslav Anzhiganov 2016-05-19 22:44:19 +00:00
parent f77174de31
commit 43cd3c539d
2 changed files with 18 additions and 2 deletions

View file

@ -220,7 +220,9 @@ class QEMU:
"--dns=%s" % dns1, "--dns=%s" % dns1,
"--dns=%s" % dns2, "--dns=%s" % dns2,
] ]
subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print ' '.join(c)
print ';;;'
print subprocess.call(' '.join(c), shell=True)
# os.popen("cd /var/lib/qemu/images/%(hostname)s;/usr/bin/vmbuilder kvm %(os_name)s --suite=%(os_suite)s --flavour=virtual --arch=amd64 --mirror=%(mirror)s -o --qemu=qemu:///system --ip=%(ip)s --gw=%(gw)s --part=/var/lib/qemu/images/%(hostname)s/partition --templates=templates --user=administrator --name=administrator --pass=%(password)s --addpkg=linux-image-generic --addpkg=vim-nox --addpkg=nano --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/qemu/images/%(hostname)s/boot.sh --mem=%(memory)s --cpus=%(cores)s --hostname=%(hostname)s --bridge=br0" % values) # os.popen("cd /var/lib/qemu/images/%(hostname)s;/usr/bin/vmbuilder kvm %(os_name)s --suite=%(os_suite)s --flavour=virtual --arch=amd64 --mirror=%(mirror)s -o --qemu=qemu:///system --ip=%(ip)s --gw=%(gw)s --part=/var/lib/qemu/images/%(hostname)s/partition --templates=templates --user=administrator --name=administrator --pass=%(password)s --addpkg=linux-image-generic --addpkg=vim-nox --addpkg=nano --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/qemu/images/%(hostname)s/boot.sh --mem=%(memory)s --cpus=%(cores)s --hostname=%(hostname)s --bridge=br0" % values)
return True return True

View file

@ -141,16 +141,30 @@ while True:
p['os_name'], p['os_suite'], settings.get('node', 'interface'), p['ssh_key'] p['os_name'], p['os_suite'], settings.get('node', 'interface'), p['ssh_key']
) )
except Exception as e: except Exception as e:
# TODO: back to origin task status
logging.warning(e) logging.warning(e)
pass pass
nodeclient.task_status_update(task['id'], 2) finally:
nodeclient.task_status_update(task['id'], 2)
if task.get('task') == 'vm_start': if task.get('task') == 'vm_start':
nodeclient.task_status_update(task['id'], 1)
qemu.QEMU().start(task['plain']['hostname'])
nodeclient.task_status_update(task['id'], 2)
pass pass
if task.get('task') == 'vm_restart': if task.get('task') == 'vm_restart':
nodeclient.task_status_update(task['id'], 1)
qemu.QEMU().restart(task['plain']['hostname'])
nodeclient.task_status_update(task['id'], 2)
pass pass
if task.get('task') == 'vm_stop': if task.get('task') == 'vm_stop':
nodeclient.task_status_update(task['id'], 1)
qemu.QEMU().stop(task['plain']['hostname'])
nodeclient.task_status_update(task['id'], 2)
pass pass
if task.get('task') == 'vm_delete': if task.get('task') == 'vm_delete':
nodeclient.task_status_update(task['id'], 1)
qemu.QEMU().delete(task['plain']['hostname'])
nodeclient.task_status_update(task['id'], 2)
pass pass
logging.debug("Application ended") logging.debug("Application ended")