This commit is contained in:
Vyacheslav Anzhiganov 2016-09-14 17:36:23 +03:00
parent 69ba93c824
commit 88cd0cd767

View file

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