Skip to content

Instantly share code, notes, and snippets.

@jalev
Created February 18, 2013 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalev/4974972 to your computer and use it in GitHub Desktop.
Save jalev/4974972 to your computer and use it in GitHub Desktop.
Creating a storage pool via template
require 'libvirt'
conn = Libvirt::open("qemu+ssh://root@rupert.provisioning.io/system")
name = "ruby_test"
path = "/vmstore"
template = File.read("#{File.dirname __FILE__}/../../templates/pools/file_storage.xml.erb")
=> "<pool type='dir'>\n <name><%= name %></name>\n <target>\n <path><%= path %></path>\n <permissions>\n <mode>0700</mode>\n <owner>-1</owner>\n <group>-1</group>\n </permissions>\n </target>\n</pool>\n"
xml = ERB.new(template, nil, '-').result(binding)
=> "<pool type='dir'>\n <name>test_pool</name>\n <target>\n <path>/vmstore</path>\n <permissions>\n <mode>0700</mode>\n <owner>-1</owner>\n <group>-1</group>\n </permissions>\n </target>\n</pool>\n"
conn.define_storage_pool_xml(xml)
=> #<Libvirt::StoragePool:0x00000001458840>
pool = conn.lookup_storage_pool_by_name("test_pool")
=> #<Libvirt::StoragePool:0x00000001436240>
pool.info
=> #<Libvirt::StoragePoolInfo:0x00000001418a10 @state=0, @capacity=0, @allocation=0, @available=0>
pool.build
pool.create
=> #<Libvirt::StoragePoolInfo:0x000000013a9728 @state=2, @capacity=20637937664, @allocation=5976141824, @available=14661795840>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment