Skip to content

Commit

Permalink
Merge pull request #56 from olifre/ceph-rbd-volumes
Browse files Browse the repository at this point in the history
Add creation of RBD volumes and document it.
  • Loading branch information
strzibny authored Oct 28, 2019
2 parents ca92983 + 59643e5 commit 7709a3b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/fog/libvirt/models/compute/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ Only ssh is supported as the transport for remote URI's. TLS is NOT supported, a
- To check the connection you need to override your libvirt socket location in the URI
- "qemu+ssh://patrick@myserver/system?socket=/var/run/libvirt/libvirt-sock"

## Ceph RBD volumes
To configure Ceph RBD volumes, the file ``/etc/foreman/ceph.conf`` is used.
After adding the authentication key to a libvirt secret, it can be configured as follows:
```
monitor=mon001.example.com,mon002.example.com,mon003.example.com
port=6789
libvirt_ceph_pool=rbd_pool_name
auth_username=libvirt
auth_uuid=uuid_of_libvirt_secret
```
For more recent versions of libvirt which support using the secret by name (`usage` attribute in the `secret` tag),
you can also drop `auth_uuid` and specify `auth_usage` instead. If both are specified, `auth_uuid` will be preferred for maximum compatibility.

## Configuration

The URI can be configured in two ways:
Expand Down
29 changes: 29 additions & 0 deletions lib/fog/libvirt/models/compute/templates/server.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,42 @@
<% 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"] %>'>
<% if args.key?("auth_uuid") -%>
<secret type='ceph' uuid='<%= args["auth_uuid"] %>'/>
<% else -%>
<secret type='ceph' usage='<%= args["auth_usage"] %>'/>
<% end -%>
</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'>
Expand Down
8 changes: 7 additions & 1 deletion lib/fog/libvirt/requests/compute/list_domains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ def domain_display xml
end

def domain_volumes xml
xml_elements(xml, "domain/devices/disk/source", "file")
vols_by_file = xml_elements(xml, "domain/devices/disk/source", "file")
vols_by_name = xml_elements(xml, "domain/devices/disk/source", "name")
vols = []
vols_by_file.zip(vols_by_name).each do |by_file,by_name|
vols.push(by_file.nil? ? by_name : by_file)
end
vols
end

def boot_order xml
Expand Down

0 comments on commit 7709a3b

Please sign in to comment.