fog / fog-libvirt

libvirt provider for fog
MIT License
16 stars 44 forks source link

Ceph RBD volume creation #54

Closed olifre closed 4 years ago

olifre commented 6 years ago

This has already been proposed in: https://github.com/fog/fog/issues/3285#issuecomment-98696583 a few years ago, but sadly was closed without further comment / reasoning :cry: .

I hope this proposal here will be more successful.

I am right now patching server.xml.erb as follows:

  <devices>
<% args = {}
    File.readlines('/etc/foreman/ceph.conf').each do |line|
      pair = line.strip.split("=")
      key = pair[0]
      value = pair[1]
      args[key] = value
    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 -%>

This works perfectly fine, of course, configuration should be added for those choices (virtio-scsi, writeback, discard). Also, such volumes can not be deleted by fog anymore: https://projects.theforeman.org/issues/12063

plribeiro3000 commented 6 years ago

@olifre Sorry about the original PR. Would you be up to open a PR with this change?

olifre commented 6 years ago

A PR with this change is easy for me, but there are two problems:

I'm unsure how to expose this in a configurable way, my ruby skills are not too extensive, mainly acquired from Ruby template writing...

plribeiro3000 commented 6 years ago

Hmmm. Can we not do it on top of the /etc/foreman/ceph.conf file?

I fell like a Ceph object would make more sense. Or maybe add configuration setters in the main class.

Maybe you can start with a simple PR and we can iterate over it?