Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

KVM Provider

- improved checking of network and storage pool during creation of servers
- replaced not properly implemented KVM options with one option for the network name and one for the storage pool name
- replaced all occurrences of direct libvirt usage with fog.io in create
- improved documentation to reflect the changes above
  • Loading branch information...
commit de8b1a72725ef6dd788be8a1f758ebeab93145ca 1 parent 48e613d
@ffeldhaus authored
View
53 doc/kvm.md
@@ -4,6 +4,9 @@ NOTE: Virtualbox doesn't like KVM to be enabled
## Prerequisites
+Depending on your operating system you may need to install packages for kvm,
+qemu and libvirt.
+
To check if your kernel can run kvm :
# kvm_ok or kvm-ok command (on Ubuntu at least)
@@ -11,10 +14,12 @@ To check if your kernel can run kvm :
# 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.
+The kernel modules needed are the following : kvm, kvm_intel or kvm-amd.
+
+### Storage Pool
-You need to have at least one storage pool defined in libvirt. You can check all
-available storage pools with
+You need to have at least one storage pool defined in libvirt where your VM
+images will be stored. You can check all available storage pools with
virsh pool-list
@@ -33,13 +38,16 @@ VM images in the directory /var/lib/libvirt/images with
EOF
virsh pool-create /tmp/pool.xml
+### Network
+
You need to have at least one network defined. You can check all available
networks with
virsh net-list
-If there is no default network, consult the documentation of your operating
-system to find out how to creat it.
+If there is no network, consult the documentation of your operating
+system to find out how to creat it. More information can also be found in the
+[libvirt documentation](http://libvirt.org/formatdomain.html#elementsNICS).
If you are using libvirt with a URI different than the default `qemu:///system`,
you need to create a config file for fog.io. If your libvirt endpoint is
@@ -49,9 +57,18 @@ file with
cat > ~/.fog << EOF
:default:
:libvirt_uri: qemu+ssh://cloud@myhost.com/system
+ EOF
+
+For more information have a look at the
+[libvirt documentation](http://libvirt.org/drvqemu.html#uris).
## Using VeeWee
+You can always get help by using the the built in help with every command.
+e.g. for the build command use
+
+ veewee kvm help build
+
List available templates
veewee kvm templates
@@ -62,25 +79,13 @@ Use one of the listed templates to define a new box e.g. with
Build the box using KVM / Quemu (this will take a while)
- veewee build 'My Ubuntu 12.10 box'
+ veewee kvm build 'My Ubuntu 12.10 box'
-You may want to use the VNC console (e.g. through virt-manager) to monitor /
-check the build process.
-
-## Options
-
-There is currently few options supported :
+You can specify the name of the storage pool and the network to be used when
+building a VM. Use the options`--pool-name` and `--network-name` with the built
+command:
-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.
+ veewee kvm build 'My Ubuntu 12.10 box' --pool-name virtimages --network-name default
-## Notes
-
-Remove modules:
-
- rmmod kvm_intel
- rmmod kvm
+You may want to use the VNC console (e.g. through virt-manager) to monitor /
+check the build process.
View
2  lib/veewee/command/kvm.rb
@@ -11,6 +11,8 @@ class Kvm< Veewee::Command::GroupBase
method_option :postinstall_include, :type => :array, :default => [], :aliases => "-i", :desc => "ruby regexp of postinstall filenames to additionally include"
method_option :postinstall_exclude, :type => :array, :default => [], :aliases => "-e", :desc => "ruby regexp of postinstall filenames to exclude"
method_option :use_emulation, :type => :boolean , :default => false, :desc => "Use QEMU emulation"
+ method_option :pool_name, :type => :string, :default => nil, :desc => "Name of the libvirt storage pool to be used"
+ method_option :network_name, :type => :string, :default => "default", :desc => "Name of the libvirt network to be used"
def build(box_name)
venv=Veewee::Environment.new(options)
venv.ui=env.ui
View
83 lib/veewee/provider/kvm/box/create.rb
@@ -17,9 +17,24 @@ def create(options={})
end
def create_server(options)
- #memory_size,cpu_count, volume_size
- # verify some stuff before trying to create the server
- kvm_options = definition.kvm[:vm_options][0]
+
+ # set volume pool name to user specified volume pool and fall back to first available volume pool
+ if options["pool_name"]
+ raise Veewee::Error, "Specified storage pool #{options["pool_name"]} does not exist" if @connection.pools.select { |pool| pool.name == options["pool_name"] }.empty?
+ volume_pool_name = options["pool_name"]
+ end
+ volume_pool_name ||= @connection.pools.first.name
+ env.logger.info "Using storage pool #{volume_pool_name}"
+
+ # set network name to user specified network and fall back to default network or first available network
+ if options["network_name"]
+ raise Veewee::Error, "Specified network #{options["network_name"]} does not exist" if @connection.networks.select { |net| net.name == options["network_name"] }.empty?
+ network_name = options["network_name"]
+ end
+ network_name ||= "default" unless @connection.networks.select { |net| net.name == 'default' }.empty?
+ network_name ||= @connection.networks.first.name
+ env.logger.info "Using network #{network_name}"
+
# Create the "server"
attributes = {
:name => name,
@@ -29,62 +44,12 @@ def create_server(options)
:domain_type => options['use_emulation'] ? 'qemu' : 'kvm',
:iso_file => definition.iso_file,
:arch => definition.os_type_id.end_with?("_64") ? "x86_64" : "i686",
- :iso_dir => env.config.veewee.iso_dir
+ :iso_dir => env.config.veewee.iso_dir,
+ :volume_pool_name => volume_pool_name,
+ :network_nat_network => network_name
}
- # 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
+ @connection.servers.create(attributes)
end
# Create the volume of a new vm
@@ -95,7 +60,7 @@ def create_volume(options)
def add_floppy
env.logger.info 'Adding floppy disk'
# Get a raw libvirt connection
- conn = ::Libvirt::open("qemu:///system")
+ conn = @connection.client
# Retrieve the domain
domain=conn.lookup_domain_by_name(name)
@@ -133,7 +98,7 @@ def add_floppy
def add_virtio_drivers
env.logger.info 'Adding virtio drivers for windows system to the virtual machine'
# Get a raw libvirt connection
- conn = ::Libvirt::open("qemu:///system")
+ conn = @connection.client
# Retrieve the domain
domain=conn.lookup_domain_by_name(name)
Please sign in to comment.
Something went wrong with that request. Please try again.