Permalink
Browse files

Issue jedi4ever#432: Handling kvm => :vm_options

Add support for network_type (network default, bridge).
Add (pre)support for volume_pool_name (but there is a bug that is preventing
this to work with fog 1.7.0).
  • Loading branch information...
vdemeester committed Dec 1, 2012
1 parent b766b90 commit eedf44203fe8de1a8b3977a7c489524cf1ffb7a1
Showing with 65 additions and 9 deletions.
  1. +59 −3 lib/veewee/provider/kvm/box/create.rb
  2. +6 −6 lib/veewee/provider/kvm/provider.rb
@@ -16,17 +16,73 @@ def create(options={})
def create_server(options)
#memory_size,cpu_count, volume_size
s=@connection.servers.create(
# verify some stuff before trying to create the server
kvm_options = definition.kvm[:vm_options][0]
# Create the "server"
attributes = {
:name => name,
:memory_size => definition.memory_size.to_i*1024,
:cpus => definition.cpu_count.to_i,
:volume_capacity => "#{definition.disk_size}M",
:domain_type => options['use_emulation'] ? 'qemu': 'kvm',
:network_interface_type => "network",
:iso_file => definition.iso_file,
:arch => definition.os_type_id.end_with?("_64") ? "x86_64" : "i686",
:iso_dir => env.config.veewee.iso_dir
)
}
# Check for network stuff (default, bridge)
check_network(kvm_options, attributes)
# Check for pool (storage)
check_pool(kvm_options, attributes)
s=@connection.servers.create(attributes)
end
# Check the network availability of the defined network for kvm
def check_network(options, attributes)
env.logger.info "Checking network"
if options.nil? or options.empty? or options["network_type"].nil? or options["network_type"] == "network"
check_default_network
attributes[:network_interface_type] = "network"
elsif options["network_type"] == "bridge"
options["network_bridge_name"].nil?
if options["network_bridge_name"].nil?
raise Veewee::Error, "You need to specify a 'network_bridge_name' if you plan to use 'bridge' as network type"
else
attributes[:network_interface_type] = "bridge"
attributes[:network_bridge_name] = "#{options["network_bridge_name"]}"
end
else
raise Veewee::Error, "You specified a 'network_type' that isn't known (#{options["network_type"]})"
end
end
def check_default_network
# Nothing specified, we check for default network
conn = ::Libvirt::open("qemu:///system")
networks=conn.list_networks
if networks.count < 1
raise Veewee::Error, "You need at least one (active) network defined or customize your definition. This needs to be available if you connect to qemu:///system."
end
end
# Check the given pool and append to attributes
# Note: volume_pool_name is not working in fog library version 1.7.0.
# This should be fixed in the next release.
def check_pool(options, attributes)
env.logger.info "Checking pool storage"
if not options.nil? and not options.empty? and not options["pool_name"].nil?
conn = ::Libvirt::open("qemu:///system")
# Checking if the pool exists and if it is active
begin
storage = conn.lookup_storage_pool_by_name(options["pool_name"])
rescue Libvirt::RetrieveError
raise Veewee::Error, "You've specified an non-existent storage pool (#{options["pool_name"]})"
end
if storage.active?
attributes[:volume_pool_name] = options["pool_name"]
else
raise Veewee::Error, "The storage pool '#{options["pool_name"]}' is not started. Start it and restart the creation process"
end
end
end
# Create the volume of a new vm
@@ -32,12 +32,12 @@ def check_requirements
raise Veewee::Error,"You need at least one (active) storage pool defined. This needs to be available if you connect to qemu:///system"
end
env.logger.info "Checking available networks"
networks=conn.list_networks
env.logger.info "Networks: #{networks.join(',')}"
if networks.count < 1
raise Veewee::Error,"You need at least one (active) network defined. This needs to be available if you connect to qemu:///system"
end
#env.logger.info "Checking available networks"
#networks=conn.list_networks
#env.logger.info "Networks: #{networks.join(',')}"
#if networks.count < 1
# raise Veewee::Error,"You need at least one (active) network defined. This needs to be available if you connect to qemu:///system"
#end
# http://www.libvirt.org/html/libvirt-libvirt.html#virGetVersion
# format major * 1,000,000 + minor * 1,000 + release

0 comments on commit eedf442

Please sign in to comment.