Merge branch 'develop' into 'master'

Develop

fix issue #5 

See merge request !1
This commit is contained in:
Vyacheslav Anzhiganov 2016-09-14 17:39:41 +03:00
commit 85310a69a7
2 changed files with 16 additions and 18 deletions

View file

@ -125,40 +125,38 @@ class QEMU:
def __prepare(self, hostname): def __prepare(self, hostname):
# Create directory for new VM # Create directory for new VM
# os.popen('mkdir -p /tmp/libvirt/%s/templates/libvirt' % hostname, "r") # os.popen('mkdir -p /tmp/libvirt/%s/templates/libvirt' % hostname, "r")
subprocess.Popen([ subprocess.Popen(
# 'mkdir', '-p', '/var/lib/libvirt/images/%s/templates/qemu' % hostname [
'mkdir', '-p', '/tmp/libvirt/%s/templates/libvirt' % hostname 'mkdir', '-p', '/var/lib/libvirt/images/%s/templates/qemu' % hostname
], ],
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Copy tempaltes # Copy tempaltes
subprocess.Popen([ subprocess.Popen([
'cp', '/etc/vmbuilder/libvirt/*', '/tmp/libvirt/%s/templates/libvirt' % hostname], 'cp', '/etc/vmbuilder/libvirt/*', '/var/lib/libvirt/images/%s/templates/libvirt' % hostname],
stdout=subprocess.PIPE, stderr=subprocess.PIPE stdout=subprocess.PIPE, stderr=subprocess.PIPE
) )
# os.popen("cp /etc/vmbuilder/libvirt/* /tmp/libvirt/%s/templates/libvirt" % hostname)
# os.popen("cp vm/firstboot.sh /var/lib/qemu/images/%s/boot.sh" % hostname, "r") os.popen("cp /etc/sws/cloud/firstboot.sh /var/lib/libvirt/images/%s/boot.sh" % hostname, "r")
os.popen("cp /etc/sws/cloud/firstboot.sh /tmp/libvirt/%s/boot.sh" % hostname, "r")
return True return True
def __storage(self, hostname, storage, swap=0): def __storage(self, hostname, storage, swap=0):
# generate partition file # generate partition file
# Open new data file # Open new data file
# f = open("/var/lib/qemu/images/%s/partition" % hostname, "w") f = open("/var/lib/libvirt/images/%s/partition" % hostname, "w")
f = open("/tmp/libvirt/%s/partition" % hostname, "w")
f.write("root %s\n" % storage) f.write("root %s\n" % storage)
if swap > 0: if swap > 0:
# f.write("---\n" % swap) f.write("---\n" % swap)
f.write("swap %s\n" % swap) f.write("swap %s\n" % swap)
f.close() f.close()
return True return True
def __ssh_key(self, hostname, sshkey): def __ssh_key(self, hostname, sshkey):
f = open("/tmp/libvirt/%s/authorized_keys" % hostname, "w") f = open("/var/lib/libvirt/images/%s/authorized_keys" % hostname, "w")
f.write(sshkey) if sshkey:
f.write(sshkey)
f.close() f.close()
return True return True
@ -183,7 +181,7 @@ class QEMU:
c = [ c = [
"cd", "cd",
"/var/lib/libvirt/images;", "/var/lib/libvirt/images/%s;" % vm_id,
"/usr/bin/vmbuilder", "/usr/bin/vmbuilder",
"kvm", "kvm",
os_name, os_name,
@ -199,22 +197,22 @@ class QEMU:
# "--part=/var/lib/qemu/images/%s/partition" % values['hostname'], # "--part=/var/lib/qemu/images/%s/partition" % values['hostname'],
"--rootsize=%s" % storage, "--rootsize=%s" % storage,
"--swapsize=%s" % swap, "--swapsize=%s" % swap,
"--templates=/tmp/libvirt/%s/templates/libvirt" % vm_id, "--templates=/var/lib/libvirt/images/%s/templates/libvirt" % vm_id,
# USER # USER
"--user=administrator", "--user=administrator",
"--name=administrator", "--name=administrator",
"--pass=%s" % password, "--pass=%s" % password,
"--ssh-user-key=/tmp/libvirt/%s/authorized_keys" % vm_id, "--ssh-user-key=/var/lib/libvirt/images/%s/authorized_keys" % vm_id,
# "--lock-user", # "--lock-user",
"--rootpass=%s" % password, "--rootpass=%s" % password,
"--ssh-key=/tmp/libvirt/%s/authorized_keys" % vm_id, "--ssh-key=/var/lib/libvirt/images/%s/authorized_keys" % vm_id,
"--addpkg=linux-image-generic", "--addpkg=linux-image-generic",
"--addpkg=vim-nox", "--addpkg=vim-nox",
# "--addpkg=nano", # "--addpkg=nano",
"--addpkg=unattended-upgrades", "--addpkg=unattended-upgrades",
"--addpkg=acpid", "--addpkg=acpid",
# "--addpkg=fail2ban", # "--addpkg=fail2ban",
"--firstboot=/tmp/libvirt/%s/boot.sh" % vm_id, "--firstboot=/var/lib/libvirt/images/%s/boot.sh" % vm_id,
"--mem=%s" % memory, "--mem=%s" % memory,
"--cpus=%s" % cores, "--cpus=%s" % cores,
# "--hostname=%s" % hostname, # "--hostname=%s" % hostname,

View file

@ -4,7 +4,7 @@ from setuptools import setup
setup( setup(
name='SWSCloudNode', name='SWSCloudNode',
version='3.1.6', version='3.1.7',
author='Vyacheslav Anzhiganov', author='Vyacheslav Anzhiganov',
author_email='vanzhiganov@ya.ru', author_email='vanzhiganov@ya.ru',
packages=[ packages=[