#!/usr/bin/python # mclu (mini cluster) # Copyright (C) 2014 Red Hat Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os import random import sys # Generate libvirt XML. Would be nice to use virt-install here, but # it doesn't work: RHBZ#1095789 def generate_libvirt_xml (vm_name, memory, vcpus, virtio, output): network_model = "virtio" if not virtio: network_model = "e1000" # Give the network a fixed MAC address, otherwise libvirt will # generate a random one on every guest restart. network_mac = "52:54:00:%02x:%02x:%02x" % (random.randint (0, 0xff), random.randint (0, 0xff), random.randint (0, 0xff)) # XXX Quoting, and we should use a real XML generator. xml = """ %s %d %d %d hvm destroy restart restart """ % (vm_name, memory, memory, vcpus, network_mac, network_model) # virtio-scsi or IDE disk: if virtio: xml += """ """ % output else: xml += """ """ % output xml += """ """ return xml