Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional disks, virtio for the network interfaces and block devices. #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions examples/kvm.pp
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# KVM examples, using libvirt provider

class { "kvm-guests": }
class kvm-guests {

virt { "guest-kvm1":
memory => 512,
virt_path => '/home/user/disk0.qcow2',
virt_path => '/tmp/disk0.qcow2',
disk_size => '3',
virt_disks => {"/tmp/disk1.qcow2" => 2, "/tmp/disk2.qcow2" => 3 },
virtio_for_disks => true,
virtio_for_net => true,
#interfaces => ["br1"],
cpus => 2,
ensure => running,
virt_type => 'kvm'

}

# clone from guest-kvm1
virt { guest-kvm2:
clone => 'guest-kvm1'
ensure => running,
virt_type => 'kvm'
}

}
27 changes: 20 additions & 7 deletions lib/puppet/provider/virt/libvirt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def generalargs(bootoninstall)
max_cpus = Facter.value('processorcount')
arguments << ["--vcpus=#{resource[:cpus]},maxvcpus=#{max_cpus}"]

arguments << diskargs
arguments << diskargs << additional_diskargs

if resource[:boot_location]
fail "To use 'boot_location', you need to specify the 'virt_path' parameter." if resource[:virt_path].nil?
Expand All @@ -127,29 +127,42 @@ def diskargs
parameters = ""
parameters = resource[:virt_path] if resource[:virt_path]
parameters.concat("," + resource[:disk_size]) if resource[:disk_size]
parameters.empty? [] : ["--disk", parameters]
parameters.concat(",bus=virtio") if resource[:virtio_for_disks] == :true
parameters.empty? ? [] : ["--disk", parameters]
end

# Additional boot arguments
def additional_diskargs
disks = resource[:virt_disks]
args = []
parameters = ""
parameters.concat(",bus=virtio") if resource[:virtio_for_disks] == :true
disks.each do |key,value|
args << ["--disk=#{key},size=#{value}"+parameters]
end
args
end

# Additional boot arguments #FIXME
def bootargs
debug "Bootargs"

["-x", resource[:kickstart]] if resource[:kickstart] #kickstart support
resource[:kickstart] ? ["-x", resource[:kickstart]] : [] #kickstart support
end

# Creates network arguments for virt-install command
def network
debug "Network paramenters"
network = []
parameters = ""
parameters.concat(",model=virtio") if resource[:virtio_for_net] == :true

iface = resource[:interfaces]
case iface
when nil
network = ["--network", "network=default"]
network = ["--network", "network=default"+parameters]
when "disabled"
network = ["--nonetworks"]
else
iface.each { |iface| network << ["--network","bridge="+iface] if interface?(iface) }
iface.each { |iface| network << ["--network","bridge="+iface+parameters] if interface?(iface) }
end

macs = resource[:macaddrs]
Expand Down
15 changes: 15 additions & 0 deletions lib/puppet/type/virt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,21 @@ def insync?(current)
"size=" + value
end
end
newparam(:virt_disks) do
desc "Additional disks"
end
newparam(:virtio_for_disks) do
desc "Using virtio for block devices"
munge do |value|
@resource.munge_boolean(value)
end
end
newparam(:virtio_for_net) do
desc "Using virtio for network devices"
munge do |value|
@resource.munge_boolean(value)
end
end

newproperty(:quotatime, :parent => VirtNumericParam, :required_features => :disk_quota) do
desc "Sets soft overusage time limit for disk quota (also known as grace period)."
Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

service { $servicename:
ensure => 'running',
ensure => running,
enable => 'true',
}

Expand Down