From f665da032a7db71a8dd1e9002734a24cc46bdf33 Mon Sep 17 00:00:00 2001 From: vanzhiganov Date: Sat, 21 May 2016 14:25:53 +0000 Subject: [PATCH] support QEMU --- SWSCloudNode/qemu/__init__.py | 19 ++++++++++--------- cloud_node_agent.py | 16 +++++++++++----- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/SWSCloudNode/qemu/__init__.py b/SWSCloudNode/qemu/__init__.py index d32627d..458c6d4 100644 --- a/SWSCloudNode/qemu/__init__.py +++ b/SWSCloudNode/qemu/__init__.py @@ -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, diff --git a/cloud_node_agent.py b/cloud_node_agent.py index 3283a05..217efb4 100644 --- a/cloud_node_agent.py +++ b/cloud_node_agent.py @@ -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