<commit_before><domain type='<%= domain_type %>'>
  <name><%= name %></name>
  <memory><%= memory_size %></memory>
  <vcpu><%= cpus %></vcpu>
  <os>
    <type arch='<%= arch %>'><%= os_type %></type>
<% boot_order.each do |dev| -%>
    <boot dev='<%= dev %>'/>
<% end -%>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
<% if !cpu.empty? -%>
<% if cpu[:mode] -%>
  <cpu mode='<%= cpu[:mode] %>'>
<% else -%>
  <cpu>
<% end -%>
<%
  fallback = 'allow'
  model = ''
  if cpu[:model]
    fallback = cpu[:model][:fallback] if cpu[:model][:fallback]
    model    = cpu[:model][:name]     if cpu[:model][:name]
  end
-%>
    <model fallback='<%= fallback %>'><%= model %></model>
  </cpu>
<% end -%>
  <clock offset='utc'/>
  <devices>
<% args = {}
   if File.file?('/etc/foreman/ceph.conf')
     File.readlines('/etc/foreman/ceph.conf').each do |line|
       pair = line.strip.split("=")
       key = pair[0]
       value = pair[1]
       args[key] = value
     end
   end
%>
<% volumes.each do |vol| -%>
  <% if vol.pool_name.include? args["libvirt_ceph_pool"]  %>
    <disk type='network' device='disk'>
      <driver name='qemu' type='<%= vol.format_type %>' cache='writeback' discard='unmap'/>
      <source protocol='rbd' name='<%= vol.path %>'>
        <% args["monitor"].split(",").each do |mon| %>
        <host name='<%= mon %>' port='<%= args["port"] %>'/>
        <% end %>
      </source>
      <auth username='<%= args["auth_username"] %>'>
        <secret type='ceph' uuid='<%= args["auth_uuid"] %>'/>
      </auth>
      <target dev='sd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='scsi'/>
    </disk>
  <% else %>
    <disk type='file' device='disk'>
      <driver name='qemu' type='<%= vol.format_type %>'/>
      <source file='<%= vol.path %>'/>
      <%# we need to ensure a unique target dev -%>
      <target dev='vd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='virtio'/>
    </disk>
  <% end %>
<% end -%>
<% if iso_file -%>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='<%= "#{iso_dir}/#{iso_file}" %>'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
<% end -%>
<% nics.each do |nic| -%>
    <interface type='<%= nic.type %>'>
      <source <%= nic.type == 'bridge' ? "bridge='#{nic.bridge}'" : "network='#{nic.network}'" %> />
      <model type='<%= nic.model %>'/>
    </interface>
<% end -%>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target port='0'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
<%
display_type = display[:type]

if display[:port].empty?
  display_port = display[:port]
  autoport = 'no'
else
  display_port = '-1'
  autoport = 'yes'
end

unless display[:listen].empty?
  display_listen = "listen='#{display[:listen]}'"
end

unless display[:password].empty?
  display_password = "passwd='#{display[:password]}'"
end
-%>
    <graphics type='<%= display_type %>' port='<%= display_port %>' autoport='<%= autoport %>' <%= display_listen %> <%= display_password %> />
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
    </video>
  </devices>
</domain>
<commit_msg>Clarify logic of Ceph RBD creation.<commit_after><domain type='<%= domain_type %>'>
  <name><%= name %></name>
  <memory><%= memory_size %></memory>
  <vcpu><%= cpus %></vcpu>
  <os>
    <type arch='<%= arch %>'><%= os_type %></type>
<% boot_order.each do |dev| -%>
    <boot dev='<%= dev %>'/>
<% end -%>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
<% if !cpu.empty? -%>
<% if cpu[:mode] -%>
  <cpu mode='<%= cpu[:mode] %>'>
<% else -%>
  <cpu>
<% end -%>
<%
  fallback = 'allow'
  model = ''
  if cpu[:model]
    fallback = cpu[:model][:fallback] if cpu[:model][:fallback]
    model    = cpu[:model][:name]     if cpu[:model][:name]
  end
-%>
    <model fallback='<%= fallback %>'><%= model %></model>
  </cpu>
<% end -%>
  <clock offset='utc'/>
  <devices>
<% args = {}
   if File.file?('/etc/foreman/ceph.conf')
     File.readlines('/etc/foreman/ceph.conf').each do |line|
       pair = line.strip.split("=")
       key = pair[0]
       value = pair[1]
       args[key] = value
     end
   end
%>
<% volumes.each do |vol| -%>
  <% if File.file?('/etc/foreman/ceph.conf') && vol.pool_name.include?(args["libvirt_ceph_pool"]) %>
    <disk type='network' device='disk'>
      <driver name='qemu' type='<%= vol.format_type %>' cache='writeback' discard='unmap'/>
      <source protocol='rbd' name='<%= vol.path %>'>
        <% args["monitor"].split(",").each do |mon| %>
        <host name='<%= mon %>' port='<%= args["port"] %>'/>
        <% end %>
      </source>
      <auth username='<%= args["auth_username"] %>'>
        <secret type='ceph' uuid='<%= args["auth_uuid"] %>'/>
      </auth>
      <target dev='sd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='scsi'/>
    </disk>
  <% else %>
    <disk type='file' device='disk'>
      <driver name='qemu' type='<%= vol.format_type %>'/>
      <source file='<%= vol.path %>'/>
      <%# we need to ensure a unique target dev -%>
      <target dev='vd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='virtio'/>
    </disk>
  <% end %>
<% end -%>
<% if iso_file -%>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='<%= "#{iso_dir}/#{iso_file}" %>'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
<% end -%>
<% nics.each do |nic| -%>
    <interface type='<%= nic.type %>'>
      <source <%= nic.type == 'bridge' ? "bridge='#{nic.bridge}'" : "network='#{nic.network}'" %> />
      <model type='<%= nic.model %>'/>
    </interface>
<% end -%>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target port='0'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
<%
display_type = display[:type]

if display[:port].empty?
  display_port = display[:port]
  autoport = 'no'
else
  display_port = '-1'
  autoport = 'yes'
end

unless display[:listen].empty?
  display_listen = "listen='#{display[:listen]}'"
end

unless display[:password].empty?
  display_password = "passwd='#{display[:password]}'"
end
-%>
    <graphics type='<%= display_type %>' port='<%= display_port %>' autoport='<%= autoport %>' <%= display_listen %> <%= display_password %> />
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
    </video>
  </devices>
</domain>

{'fraction_non_alphanumeric': 0.25726832222895213, 'fraction_numerical': 0.004239854633555421, 'mean_word_length': 3.097394540942928, 'pattern_counts': {'":': 0, '<': 233, '<?xml version=': 0, '>': 233, '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': '6342058', 'n_tokens_mistral': 2601, 'n_tokens_neox': 2484, 'n_words': 493}