Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Improve libvirt support #351

Merged
merged 9 commits into from

2 participants

@ccaum

This pull request improves KVM support by...

  • Using public methods and dropping deprecated methods
  • Improving the way VNC ports are discovered
  • Fixes --postinstall-exclude parameter
  • Improves the way veewee determines the if a VM or volume exists

NOTE: While not required, it is recommended this pull request be merged after this Fog pull request: fog/fog#1069

ccaum added some commits
@ccaum ccaum Use rubygems if available
Previous to this commit, rubygems wasn't being loaded before the
veewee libraries were. This caused dependencies that were installed by
gems to fail.  This commit requires rubygems if it's available on the
sytsem
72b12ad
@ccaum ccaum Remove postinstall files matching exclude regex
Previous to this commit, postinstall files matching the provided exclude
regex were not removed from the postinstall list, but rather were just
prepended with '_'.  This caused an error since the script '_<original
filename>' doesn't exist in the definition.

This commit removes the files from the list of postinstall files if the
filename matches the provided regex
76fd16a
@ccaum ccaum Fix typo
'addres' should have been 'address'
53b148d
@ccaum ccaum Properly format options when doing an scp
Previous to this commit, when printing the scp command to stdout, the
options hash was converted to a string causing all the keys and values
to concat as a single, spaceless, string.

This commit calls Hash#inspect on the hash object to format it
062e977
@ccaum ccaum Replace network from 'nat' to 'network'
Previous to the commit, a new libvirt instance was created with the
'nat' network type.  However, Fog master/HEAD doesn't support this
network type.

This commit changes the network type from 'nat' to 'network', which Fog
supports.
d044969
@ccaum ccaum Use display port provided by Fog
Previous to this commit, the VNC port was determined using the
deprecated vnc_port method in Fog.  This commit uses the display[:port]
method.
cf15ff3
@ccaum ccaum Use public Fog methods to get public IP address
Previous to this commit, the private method #address was called to get
the public IP address of an instance, which caused an exception.  This
commit calls the public #public_ip_address method instead
f81ef66
@ccaum ccaum Properly determine if a volume or instance exists
Preious to this commit, volumes were determined to exist or not by
calling the Volumes#all method the :name parameter to filter only the
volumes that matched the value of :name.  This was not properly
finding the volumes.  This commit uses the #list_volumes method and
calls #find on the array returned.

Likewise for instances
d24641e
@ccaum ccaum Properly retrieve version of libvirt
Previous to this commit, the non-existent LibVirt#libversion method was
called to determine the version of libvirt.  This commit calls the
LibVirt#version method.
332daf6
@jedi4ever jedi4ever merged commit b047eaf into from
@jedi4ever
Owner

awesome thanks man!

@petecheslock petecheslock referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 4, 2012
  1. @ccaum

    Use rubygems if available

    ccaum authored
    Previous to this commit, rubygems wasn't being loaded before the
    veewee libraries were. This caused dependencies that were installed by
    gems to fail.  This commit requires rubygems if it's available on the
    sytsem
  2. @ccaum

    Remove postinstall files matching exclude regex

    ccaum authored
    Previous to this commit, postinstall files matching the provided exclude
    regex were not removed from the postinstall list, but rather were just
    prepended with '_'.  This caused an error since the script '_<original
    filename>' doesn't exist in the definition.
    
    This commit removes the files from the list of postinstall files if the
    filename matches the provided regex
  3. @ccaum

    Fix typo

    ccaum authored
    'addres' should have been 'address'
  4. @ccaum

    Properly format options when doing an scp

    ccaum authored
    Previous to this commit, when printing the scp command to stdout, the
    options hash was converted to a string causing all the keys and values
    to concat as a single, spaceless, string.
    
    This commit calls Hash#inspect on the hash object to format it
  5. @ccaum

    Replace network from 'nat' to 'network'

    ccaum authored
    Previous to the commit, a new libvirt instance was created with the
    'nat' network type.  However, Fog master/HEAD doesn't support this
    network type.
    
    This commit changes the network type from 'nat' to 'network', which Fog
    supports.
  6. @ccaum

    Use display port provided by Fog

    ccaum authored
    Previous to this commit, the VNC port was determined using the
    deprecated vnc_port method in Fog.  This commit uses the display[:port]
    method.
  7. @ccaum

    Use public Fog methods to get public IP address

    ccaum authored
    Previous to this commit, the private method #address was called to get
    the public IP address of an instance, which caused an exception.  This
    commit calls the public #public_ip_address method instead
  8. @ccaum

    Properly determine if a volume or instance exists

    ccaum authored
    Preious to this commit, volumes were determined to exist or not by
    calling the Volumes#all method the :name parameter to filter only the
    volumes that matched the value of :name.  This was not properly
    finding the volumes.  This commit uses the #list_volumes method and
    calls #find on the array returned.
    
    Likewise for instances
  9. @ccaum

    Properly retrieve version of libvirt

    ccaum authored
    Previous to this commit, the non-existent LibVirt#libversion method was
    called to determine the version of libvirt.  This commit calls the
    LibVirt#version method.
This page is out of date. Refresh to see the latest.
View
5 bin/veewee
@@ -1,4 +1,9 @@
#!/usr/bin/env ruby
+begin
+ require 'rubygems'
+rescue LoadError
+end
+
require 'veewee'
env = Veewee::Environment.new
View
4 lib/veewee/provider/core/box/build.rb
@@ -70,7 +70,7 @@ def build(options={})
# This needs to be done after the kickstart:
# As the dhcp request will likely occur just before the kickstart fetch
until !self.ip_address.nil?
- env.logger.info "wait for Ip addres"
+ env.logger.info "wait for Ip address"
sleep 2
end
@@ -119,7 +119,7 @@ def filter_postinstall_files(options)
unless options["postinstall_exclude"].nil?
options["postinstall_exclude"].each do |p|
env.logger.info "Exclude pattern #{p}"
- new_definition.postinstall_files.collect! { |f| f.match(p) ? f.gsub(/^/,"_"): f}
+ new_definition.postinstall_files.reject! { |f| f.match(p) }
end
end
View
2  lib/veewee/provider/core/box/scp.rb
@@ -10,7 +10,7 @@ def scp(localfile,remotefile,options={})
new_options=ssh_options.merge(options)
self.when_ssh_login_works(self.ip_address,new_options) do
begin
- env.logger.info "About to transfer #{localfile} to #{remotefile} to the box #{name} - #{self.ip_address} - #{new_options}"
+ env.logger.info "About to transfer #{localfile} to #{remotefile} to the box #{name} - #{self.ip_address} - #{new_options.inspect}"
self.ssh_transfer_file(self.ip_address,localfile,remotefile,new_options)
rescue RuntimeError => ex
ui.error("Error transfering file #{localfile} failed, possible not enough permissions to write? #{ex}",:prefix => false)
View
4 lib/veewee/provider/kvm/box/create.rb
@@ -21,8 +21,8 @@ def create_server(options)
:memory_size => definition.memory_size.to_i*1024,
:cpus => definition.cpu_count.to_i,
:volume_capacity => "#{definition.disk_size}M",
- :network_interface_type => "nat",
: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
@@ -64,7 +64,7 @@ def add_floppy
# Get the raw xml of the changed document
new_xml=domain_doc.to_xml
- # Undefine the existing domain
+ # Undefine the existing domain
s.undefine
# Re-define the domain
View
6 lib/veewee/provider/kvm/box/helper/console_type.rb
@@ -8,9 +8,9 @@ module Kvm
module BoxCommand
# Type on the console
def console_type(sequence,type_options={})
- vnc_port=@connection.servers.all(:name => name).first.vnc_port
- display_port=vnc_port.to_i - 5900
- ui.success "Sending keystrokes to VNC port :#{display_port} - TCP port: #{vnc_port}"
+ tcp_port=@connection.servers.all(:name => name).first.display[:port]
+ display_port=tcp_port.to_i - 5900
+ ui.success "Sending keystrokes to VNC port :#{display_port} - TCP port: #{tcp_port}"
vnc_type(sequence,"127.0.0.1",display_port)
end
View
2  lib/veewee/provider/kvm/box/helper/ip.rb
@@ -3,7 +3,7 @@ module Provider
module Kvm
module BoxCommand
def ip_address
- ip=@connection.servers.all(:name => "#{name}").first.addresses[:public]
+ ip=@connection.servers.all(:name => "#{name}").first.public_ip_address
return ip.first unless ip.nil?
return ip
end
View
4 lib/veewee/provider/kvm/box/helper/status.rb
@@ -15,11 +15,11 @@ def exists?
end
def exists_volume?
- !@connection.volumes.all(:name => "#{name}.img").nil?
+ @connection.list_volumes.find { |v| v[:name] == "#{name}.img" }
end
def exists_vm?
- !@connection.servers.all(:name => name).nil?
+ @connection.list_domains.find { |d| d[:name] == name }
end
end # End Module
View
2  lib/veewee/provider/kvm/provider.rb
@@ -42,7 +42,7 @@ def check_requirements
# http://www.libvirt.org/html/libvirt-libvirt.html#virGetVersion
# format major * 1,000,000 + minor * 1,000 + release
env.logger.info "Checking libvirt version"
- libvirt_version=conn.libversion
+ libvirt_version=conn.version
if libvirt_version < 8003
raise Veewee::Error,"You need at least libvirt version 0.8.3 or higher "
end
Something went wrong with that request. Please try again.