Skip to content

Commit

Permalink
Merge pull request jedi4ever#437 from vdemeester/issue_432
Browse files Browse the repository at this point in the history
Pull request for jedi4ever#432
  • Loading branch information
jedi4ever committed Dec 2, 2012
2 parents b766b90 + aae1026 commit 426c481
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 10 deletions.
18 changes: 18 additions & 0 deletions doc/definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,21 @@ Add '.erb' to your files in a definition and they will get rendered (useful for
## Removing a definition

veewee vbox undefine 'myubuntu'

## Provider ``vm_options``

Each provider _can_ take options that are specific to them ; more detail will
be available in each provider documentation but let's have a quick overview.

Veewee::Definition.declare( {
:cpu_count => '1', :memory_size=> '256',
:disk_size => '10140', :disk_format => 'VDI', :disk_variant => 'Standard',
# […]
:postinstall_files => [ "postinstall.sh"],:postinstall_timeout => "10000"
:kvm => { :vm_options => ['network_type' => 'bridge', 'network_bridge_name' => 'brlxc0']}
:virtualbox => { :vm_options => [ 'pae' => 'on', 'ioapic' => 'one'] }
}
)

This box will have ``pae`` and ``ioapic`` enabled on virtualbox, and will use
the ``brlxc0`` bridge on with kvm (on libvirt).
29 changes: 28 additions & 1 deletion doc/kvm.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
NOTE:Virtualbox doesn't like KVM to be enabled

check with
## Prerequires

To check if you're kernel can run kvm :

# kvm_ok or kvm-ok command (on Ubuntu at least)
kvm_ok
# or look for vmx or svm in /proc/cpuinfo
egrep '^flags.*(vmx|svm)' /proc/cpuinfo

The modules needed are the following : kvm, kvm_intel or kvm-amd.

## Define a new box

The workflow to create a box is almost the same as with the Virtualbox
provider (and others).

## Options

There is currently few options supported :

1. **network_type**: the type of network used by this box on libvirt. It could
be either _network_ (for using the default network) or _bridge_.
2. **network_bridge_name**: the name of the bridge. It is used just in case
**network_type** is set to _bridge_.
3. **pool_name**: the _storage_ pool name to be used when creating the box. If
not specified, the default one is used. _Note: it is currently not working
with the current fog version (1.7.0) but should be fixed as soon as the fog
gem is released_.

## Notes

Remove modules:

Expand Down
62 changes: 59 additions & 3 deletions lib/veewee/provider/kvm/box/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/veewee/provider/kvm/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 426c481

Please sign in to comment.