<commit_before><domain type='kvm'>
  <name>TESTVM</name>
  <uuid>8961e333-7c09-a545-7ebb-b93b977ea7fb</uuid>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>4</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/var/lib/kvm/TESTVM.img'/>
      <target dev='sda' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>
    <controller type='scsi' index='0' model='virtio-scsi'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller><commit_msg>adding function to handle mac addresses and disk names in kvm template<commit_after><%
import uuid
import os
import random
imgdir = os.getenv("IMGDIR", "/var/lib/kvm/")
slot=1

diskLetter='a'

# increment disk letter
def nextDiskLetter():
    global diskLetter
    diskLetter = chr(ord(disk) + 1)

# init mac calculation 
# Fixed OUI
# random NIC specific first 2 bytes (but common to all interfaces)
# random last byte, incremented for each interface
# this methods limits the number of interfaces to 128
def randomMacInit():
    global lastMac
    global baseMac
    lastMac=random.randint(0x00, 0xef)
    baseMac = [ 0x52, 0x54, 0x00,
            random.randint(0x00, 0x7f),
            random.randint(0x00, 0xff) ]

# get a semi-random mac address
def getMac():
    global lastMac
    global baseMac
    mac = list(baseMac)
    mac.append(lastMac)
    lastMac = lastMac + 1
    return ':'.join(map(lambda x: "%02x" % x, mac))

randomMacInit()

%>\
<domain type='kvm'>
  <name>${host['hostname']}</name>
  <% uuid=uuid.uuid1() %>\
  <uuid>${uuid}</uuid>
  <% memory=str(host['hardware']['ram'] * 1024) %>\
  <memory unit='KiB'>${memory}</memory>
  <currentMemory unit='KiB'>${memory}</currentMemory>
  <% cpus=str(host['hardware']['cpus']) %>\
  <vcpu placement='static'>${cpus}</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
<%counter=0%>\
%for vg in host['partitioning']['volume-groups']:
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='${imgdir}/TESTVM.img'/>
      <target dev='sda' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
%endfor
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>
    <controller type='scsi' index='0' model='virtio-scsi'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
{'fraction_non_alphanumeric': 0.19474778991159647, 'fraction_numerical': 0.04316172646905876, 'mean_word_length': 3.851197982345523, 'pattern_counts': {'":': 0, '<': 106, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1728000', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1449, 'n_words': 286}