support QEMU
This commit is contained in:
parent
43cd3c539d
commit
f665da032a
2 changed files with 21 additions and 14 deletions
|
@ -164,20 +164,20 @@ class QEMU:
|
|||
return True
|
||||
|
||||
def create(self, cores, memory, storage, swap, hostname, ipv4, ipv4_gateway, dns1, dns2,
|
||||
password, os_name, os_suite, interface, ssh_key=None):
|
||||
password, os_name, os_suite, interface, vm_id, ssh_key=None):
|
||||
"""
|
||||
функция создания виртуальной машины
|
||||
"""
|
||||
# comm = Common()
|
||||
# comm.load_config()
|
||||
|
||||
self.__prepare(hostname)
|
||||
# self.__prepare(hostname)
|
||||
self.__prepare(vm_id)
|
||||
|
||||
# generate partition file
|
||||
# self.__storage(hostname, storage, swap)
|
||||
|
||||
if ssh_key:
|
||||
self.__ssh_key(hostname, ssh_key)
|
||||
# self.__ssh_key(hostname, ssh_key)
|
||||
self.__ssh_key(vm_id, ssh_key)
|
||||
|
||||
# TODO: move to settings file
|
||||
mirror = "http://ru.archive.ubuntu.com/ubuntu/"
|
||||
|
@ -200,22 +200,23 @@ class QEMU:
|
|||
# "--part=/var/lib/qemu/images/%s/partition" % values['hostname'],
|
||||
"--rootsize=%s" % storage,
|
||||
"--swapsize=%s" % swap,
|
||||
"--templates=/tmp/libvirt/%s/templates/libvirt" % hostname,
|
||||
"--templates=/tmp/libvirt/%s/templates/libvirt" % vm_id,
|
||||
# "--user=administrator",
|
||||
# "--name=administrator",
|
||||
# "--pass=%s" % values['password'],
|
||||
"--rootpass=%s" % password,
|
||||
"--ssh-user-key=/tmp/libvirt/%s/authorized_keys" % hostname,
|
||||
"--ssh-user-key=/tmp/libvirt/%s/authorized_keys" % vm_id,
|
||||
"--addpkg=linux-image-generic",
|
||||
"--addpkg=vim-nox",
|
||||
"--addpkg=nano",
|
||||
"--addpkg=unattended-upgrades",
|
||||
"--addpkg=acpid",
|
||||
"--addpkg=fail2ban",
|
||||
"--firstboot=/tmp/libvirt/%s/boot.sh" % hostname,
|
||||
"--firstboot=/tmp/libvirt/%s/boot.sh" % vm_id,
|
||||
"--mem=%s" % memory,
|
||||
"--cpus=%s" % cores,
|
||||
"--hostname=%s" % hostname,
|
||||
# "--hostname=%s" % hostname,
|
||||
"--hostname=%s" % vm_id,
|
||||
"--bridge=%s" % interface,
|
||||
"--dns=%s" % dns1,
|
||||
"--dns=%s" % dns2,
|
||||
|
|
|
@ -129,6 +129,8 @@ while True:
|
|||
pass
|
||||
nodeclient.task_status_update(task['id'], 2)
|
||||
|
||||
# Virtual machines operations
|
||||
# Create new virtual machine
|
||||
if task.get('task') == 'vm_create':
|
||||
nodeclient.task_status_update(task['id'], 1)
|
||||
vm_id = task['plain']['vm_id']
|
||||
|
@ -138,7 +140,9 @@ while True:
|
|||
qemu.QEMU().create(
|
||||
p['cores'], p['memory'], p['storage'], p['swap'], p['hostname'],
|
||||
p['ipv4'], p['ipv4_gateway'], p['dns1'], p['dns2'], p['password'],
|
||||
p['os_name'], p['os_suite'], settings.get('node', 'interface'), p['ssh_key']
|
||||
p['os_name'], p['os_suite'], settings.get('node', 'interface'),
|
||||
p['vm_id'],
|
||||
p['ssh_key'],
|
||||
)
|
||||
except Exception as e:
|
||||
# TODO: back to origin task status
|
||||
|
@ -146,24 +150,26 @@ while True:
|
|||
pass
|
||||
finally:
|
||||
nodeclient.task_status_update(task['id'], 2)
|
||||
# Start virtual machine
|
||||
if task.get('task') == 'vm_start':
|
||||
nodeclient.task_status_update(task['id'], 1)
|
||||
qemu.QEMU().start(task['plain']['hostname'])
|
||||
qemu.QEMU().start(task['plain']['vm_id'])
|
||||
nodeclient.task_status_update(task['id'], 2)
|
||||
pass
|
||||
# Restart virtual machine
|
||||
if task.get('task') == 'vm_restart':
|
||||
nodeclient.task_status_update(task['id'], 1)
|
||||
qemu.QEMU().restart(task['plain']['hostname'])
|
||||
qemu.QEMU().restart(task['plain']['vm_id'])
|
||||
nodeclient.task_status_update(task['id'], 2)
|
||||
pass
|
||||
if task.get('task') == 'vm_stop':
|
||||
nodeclient.task_status_update(task['id'], 1)
|
||||
qemu.QEMU().stop(task['plain']['hostname'])
|
||||
qemu.QEMU().stop(task['plain']['vm_id'])
|
||||
nodeclient.task_status_update(task['id'], 2)
|
||||
pass
|
||||
if task.get('task') == 'vm_delete':
|
||||
nodeclient.task_status_update(task['id'], 1)
|
||||
qemu.QEMU().delete(task['plain']['hostname'])
|
||||
qemu.QEMU().delete(task['plain']['vm_id'])
|
||||
nodeclient.task_status_update(task['id'], 2)
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue