fog-libvirt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTORS.md +23 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +29 -0
  6. data/Rakefile +122 -0
  7. data/fog-libvirt.gemspec +49 -0
  8. data/lib/fog/bin/libvirt.rb +58 -0
  9. data/lib/fog/libvirt/compute.rb +136 -0
  10. data/lib/fog/libvirt/models/compute/README.md +76 -0
  11. data/lib/fog/libvirt/models/compute/interface.rb +25 -0
  12. data/lib/fog/libvirt/models/compute/interfaces.rb +20 -0
  13. data/lib/fog/libvirt/models/compute/network.rb +29 -0
  14. data/lib/fog/libvirt/models/compute/networks.rb +20 -0
  15. data/lib/fog/libvirt/models/compute/nic.rb +50 -0
  16. data/lib/fog/libvirt/models/compute/nics.rb +12 -0
  17. data/lib/fog/libvirt/models/compute/node.rb +29 -0
  18. data/lib/fog/libvirt/models/compute/nodes.rb +20 -0
  19. data/lib/fog/libvirt/models/compute/pool.rb +84 -0
  20. data/lib/fog/libvirt/models/compute/pools.rb +20 -0
  21. data/lib/fog/libvirt/models/compute/server.rb +401 -0
  22. data/lib/fog/libvirt/models/compute/servers.rb +21 -0
  23. data/lib/fog/libvirt/models/compute/templates/network.xml.erb +6 -0
  24. data/lib/fog/libvirt/models/compute/templates/pool.xml.erb +6 -0
  25. data/lib/fog/libvirt/models/compute/templates/server.xml.erb +54 -0
  26. data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +26 -0
  27. data/lib/fog/libvirt/models/compute/util/uri.rb +138 -0
  28. data/lib/fog/libvirt/models/compute/util/util.rb +32 -0
  29. data/lib/fog/libvirt/models/compute/volume.rb +122 -0
  30. data/lib/fog/libvirt/models/compute/volumes.rb +20 -0
  31. data/lib/fog/libvirt/requests/compute/clone_volume.rb +18 -0
  32. data/lib/fog/libvirt/requests/compute/create_domain.rb +17 -0
  33. data/lib/fog/libvirt/requests/compute/create_volume.rb +16 -0
  34. data/lib/fog/libvirt/requests/compute/define_domain.rb +17 -0
  35. data/lib/fog/libvirt/requests/compute/define_pool.rb +16 -0
  36. data/lib/fog/libvirt/requests/compute/destroy_interface.rb +18 -0
  37. data/lib/fog/libvirt/requests/compute/destroy_network.rb +17 -0
  38. data/lib/fog/libvirt/requests/compute/get_node_info.rb +37 -0
  39. data/lib/fog/libvirt/requests/compute/list_domains.rb +105 -0
  40. data/lib/fog/libvirt/requests/compute/list_interfaces.rb +57 -0
  41. data/lib/fog/libvirt/requests/compute/list_networks.rb +55 -0
  42. data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +19 -0
  43. data/lib/fog/libvirt/requests/compute/list_pools.rb +71 -0
  44. data/lib/fog/libvirt/requests/compute/list_volumes.rb +88 -0
  45. data/lib/fog/libvirt/requests/compute/mock_files/domain.xml +40 -0
  46. data/lib/fog/libvirt/requests/compute/pool_action.rb +19 -0
  47. data/lib/fog/libvirt/requests/compute/update_display.rb +31 -0
  48. data/lib/fog/libvirt/requests/compute/vm_action.rb +19 -0
  49. data/lib/fog/libvirt/requests/compute/volume_action.rb +18 -0
  50. data/lib/fog/libvirt/version.rb +5 -0
  51. data/lib/fog/libvirt.rb +18 -0
  52. data/tests/helper.rb +17 -0
  53. data/tests/helpers/formats_helper.rb +98 -0
  54. data/tests/helpers/formats_helper_tests.rb +110 -0
  55. data/tests/helpers/mock_helper.rb +14 -0
  56. data/tests/helpers/succeeds_helper.rb +9 -0
  57. data/tests/libvirt/compute_tests.rb +17 -0
  58. data/tests/libvirt/models/compute/interface_tests.rb +27 -0
  59. data/tests/libvirt/models/compute/interfaces_tests.rb +14 -0
  60. data/tests/libvirt/models/compute/network_tests.rb +27 -0
  61. data/tests/libvirt/models/compute/networks_tests.rb +13 -0
  62. data/tests/libvirt/models/compute/nic_tests.rb +31 -0
  63. data/tests/libvirt/models/compute/nics_tests.rb +10 -0
  64. data/tests/libvirt/models/compute/pool_tests.rb +27 -0
  65. data/tests/libvirt/models/compute/pools_tests.rb +13 -0
  66. data/tests/libvirt/models/compute/server_tests.rb +58 -0
  67. data/tests/libvirt/models/compute/servers_tests.rb +14 -0
  68. data/tests/libvirt/models/compute/volume_tests.rb +38 -0
  69. data/tests/libvirt/models/compute/volumes_tests.rb +14 -0
  70. data/tests/libvirt/requests/compute/create_domain_tests.rb +21 -0
  71. data/tests/libvirt/requests/compute/define_domain_tests.rb +11 -0
  72. data/tests/libvirt/requests/compute/update_display.rb +13 -0
  73. metadata +355 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16a2da13c5fbd9d2c90b771de515227de201df13
4
+ data.tar.gz: 09ea82a8f5f472158821bc8190e07018ba00cf00
5
+ SHA512:
6
+ metadata.gz: feab17cc3360f3b1392e4b634406d2d455ab552737a197c2bc421dd2e3f246d9747b5beb665d47887d8c6111e5eae4c8fe6fa0fc8d18ba309ad3cdfc21643999
7
+ data.tar.gz: 6282c89565f040f88c6ae831a883dd47337eb898cdfaf60547edbd9408c95923cff6c3173c99ba26a3555594978f232f69f090c47b08e968a1cea1f5f7f87f88
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,23 @@
1
+ * Amos Benari <abenari@redhat.com>
2
+ * brookemckim <brooke.mckim@gmail.com>
3
+ * Carl Caum <carl@carlcaum.com>
4
+ * Carlos Sanchez <csanchez@maestrodev.com>
5
+ * David Wittman <david@wittman.com>
6
+ * Dominic Cleal <dcleal@redhat.com>
7
+ * Greg Sutcliffe <gsutclif@redhat.com>
8
+ * James Herdman <james.herdman@me.com>
9
+ * Josef Strzibny <strzibny@strzibny.name>
10
+ * Kevin Menard <nirvdrum@gmail.com>
11
+ * Konstantin Haase <konstantin.mailinglists@googlemail.com>
12
+ * Kyle Rames <kyle.rames@rackspace.com>
13
+ * Lance Ivy <lance@cainlevy.net>
14
+ * Ohad Levy <ohadlevy@redhat.com>
15
+ * Patrick Debois <Patrick.Debois@jedi.be>
16
+ * Paul Thornthwaite <tokengeek@gmail.com>
17
+ * Romain Vrignaud <romain@yakaz.com>
18
+ * Ryan Davies <ryan@ryandavies.co.nz>
19
+ * Sergio Rubio <rubiojr@frameos.org>
20
+ * Shlomi Zadok <shlomi@ben-hanna.com>
21
+ * Steve Smith <github@scsworld.co.uk>
22
+ * Vincent Demeester <vincent+git@demeester.fr>
23
+ * Wesley Beary <geemus@gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development, :test do
4
+ # This is here because gemspec doesn't support require: false
5
+ gem "netrc", :require => false
6
+ gem "octokit", :require => false
7
+ end
8
+
9
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2009-2014 [CONTRIBUTORS.md](https://github.com/fog/fog/blob/master/CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Fog::Libvirt
2
+
3
+ fog-libvirt is a libvirt provider for [fog](https://github.com/fog/fog).
4
+
5
+ [![Build Status](https://secure.travis-ci.org/fog/fog.png?branch=master)](http://travis-ci.org/fog/fog-libvirt)
6
+ [![Dependency Status](https://gemnasium.com/fog/fog.png)](https://gemnasium.com/fog/fog-libvirt)
7
+ [![Code Climate](https://codeclimate.com/github/fog/fog.png)](https://codeclimate.com/github/fog/fog-libvirt)
8
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/fog.png)](http://badge.fury.io/rb/fog-libvirt)
9
+ [![Gittip](http://img.shields.io/gittip/geemus.png)](https://www.gittip.com/geemus/)
10
+
11
+ ## Installation
12
+
13
+ fog-libvirt can be used as a module for fog or installed separately as:
14
+
15
+ ```
16
+ $ sudo gem install fog-libvirt
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ See [README.md](https://github.com/fog/fog-libvirt/blob/master/lib/fog/libvirt/models/compute/README.md).
22
+
23
+ ## Contributing
24
+
25
+ Please refer to [CONTRIBUTING.md](https://github.com/fog/fog/blob/master/CONTRIBUTING.md).
26
+
27
+ ## License
28
+
29
+ Please refer to [LICENSE.md](https://github.com/fog/fog-libvirt/blob/master/LICENSE.md).
data/Rakefile ADDED
@@ -0,0 +1,122 @@
1
+ require 'bundler/setup'
2
+ require 'rake/testtask'
3
+ require 'rubygems'
4
+ require 'rubygems/package_task'
5
+ require 'yard'
6
+ require File.dirname(__FILE__) + '/lib/fog/libvirt'
7
+
8
+ #############################################################################
9
+ #
10
+ # Helper functions
11
+ #
12
+ #############################################################################
13
+
14
+ def name
15
+ @name ||= Dir['*.gemspec'].first.split('.').first
16
+ end
17
+
18
+ def version
19
+ Fog::Libvirt::VERSION
20
+ end
21
+
22
+ def gemspec_file
23
+ "#{name}.gemspec"
24
+ end
25
+
26
+ def gem_file
27
+ "#{name}-#{version}.gem"
28
+ end
29
+
30
+ #############################################################################
31
+ #
32
+ # Standard tasks
33
+ #
34
+ #############################################################################
35
+
36
+ GEM_NAME = "#{name}"
37
+ task :default => :test
38
+
39
+ Rake::TestTask.new do |t|
40
+ end
41
+
42
+ desc 'Run tests'
43
+ task :test do
44
+ mock = ENV['FOG_MOCK'] || 'true'
45
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont tests")
46
+ end
47
+
48
+ desc 'Run mocked tests'
49
+ task :mock do
50
+ sh("export FOG_MOCK=true && bundle exec shindont tests")
51
+ end
52
+
53
+ desc 'Run live tests'
54
+ task :live do
55
+ sh("export FOG_MOCK=false && bundle exec shindont tests")
56
+ end
57
+
58
+ desc "Open an irb session preloaded with this library"
59
+ task :console do
60
+ sh "irb -rubygems -r ./lib/fog/libvirt.rb"
61
+ end
62
+
63
+ #############################################################################
64
+ #
65
+ # Packaging tasks
66
+ #
67
+ #############################################################################
68
+
69
+ task :release => ["release:prepare", "release:publish"]
70
+
71
+ namespace :release do
72
+ task :preflight do
73
+ unless `git branch` =~ /^\* master$/
74
+ puts "You must be on the master branch to release!"
75
+ exit!
76
+ end
77
+ if `git tag` =~ /^\* v#{version}$/
78
+ puts "Tag v#{version} already exists!"
79
+ exit!
80
+ end
81
+ end
82
+
83
+ task :prepare => :preflight do
84
+ Rake::Task[:build].invoke
85
+ sh "gem install pkg/#{name}-#{version}.gem"
86
+ Rake::Task[:git_mark_release].invoke
87
+ end
88
+
89
+ task :publish do
90
+ Rake::Task[:git_push_release].invoke
91
+ Rake::Task[:gem_push].invoke
92
+ end
93
+ end
94
+
95
+ task :git_mark_release do
96
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
97
+ sh "git tag v#{version}"
98
+ end
99
+
100
+ task :git_push_release do
101
+ sh "git push origin master"
102
+ sh "git push origin v#{version}"
103
+ end
104
+
105
+ task :gem_push do
106
+ sh "gem push pkg/#{name}-#{version}.gem"
107
+ end
108
+
109
+ desc "Build #{name}-#{version}.gem"
110
+ task :build do
111
+ sh "mkdir -p pkg"
112
+ sh "gem build #{gemspec_file}"
113
+ sh "mv #{gem_file} pkg"
114
+ end
115
+ task :gem => :build
116
+
117
+ # Include Yard tasks for rake yard
118
+ YARDOC_LOCATION = "doc"
119
+ YARD::Rake::YardocTask.new do |t|
120
+ t.files = ['lib/**/*.rb', "README"]
121
+ t.options = ["--output-dir", YARDOC_LOCATION, "--title", "#{name} #{version}"]
122
+ end
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fog/libvirt/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.specification_version = 2 if s.respond_to? :specification_version=
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+
10
+ s.name = "fog-libvirt"
11
+ s.version = Fog::Libvirt::VERSION
12
+
13
+ s.summary = "Module for the 'fog' gem to support libvirt"
14
+ s.description = "This library can be used as a module for 'fog' or as standalone libvirt provider."
15
+
16
+ s.authors = ["geemus (Wesley Beary)"]
17
+ s.email = "geemus@gmail.com"
18
+ s.homepage = "http://github.com/fog/fog-libvirt"
19
+ s.license = "MIT"
20
+
21
+ s.require_paths = %w[lib]
22
+
23
+ s.rdoc_options = ["--charset=UTF-8"]
24
+ s.extra_rdoc_files = %w[README.md]
25
+
26
+ s.add_dependency("fog-core", "~> 1.27", ">= 1.27.4")
27
+ s.add_dependency("fog-json")
28
+ s.add_dependency("fog-xml", "~> 0.1.1")
29
+ s.add_dependency('ruby-libvirt','~> 0.5.0')
30
+
31
+ # Fedora and derivates need explicit require
32
+ s.add_dependency("json")
33
+
34
+ s.add_development_dependency("minitest")
35
+ s.add_development_dependency("minitest-stub-const")
36
+ s.add_development_dependency("pry")
37
+ s.add_development_dependency("rake")
38
+ s.add_development_dependency("rubocop") if RUBY_VERSION > "1.9"
39
+ s.add_development_dependency("shindo", "~> 0.3.4")
40
+ s.add_development_dependency("simplecov")
41
+ s.add_development_dependency("thor")
42
+ s.add_development_dependency("yard")
43
+ s.add_development_dependency("redcarpet")
44
+
45
+ # Let's not ship dot files and gemfiles
46
+ git_files = `git ls-files`.split("\n")
47
+ s.files = git_files.delete_if{ |f| f =~ /^\..*/ || f =~ /^gemfiles\/*/ }
48
+ s.test_files = `git ls-files -- {spec,tests}/*`.split("\n")
49
+ end
@@ -0,0 +1,58 @@
1
+ module Libvirt # deviates from other bin stuff to accomodate gem
2
+ class << self
3
+ def class_for(key)
4
+ case key
5
+ when :compute
6
+ Fog::Compute::Libvirt
7
+ else
8
+ raise ArgumentError, "Unrecognized service: #{key}"
9
+ end
10
+ end
11
+
12
+ def [](service)
13
+ @@connections ||= Hash.new do |hash, key|
14
+ hash[key] = case key
15
+ when :compute
16
+ Fog::Logger.warning("Libvirt[:compute] is not recommended, use Compute[:libvirt] for portability")
17
+ Fog::Compute.new(:provider => 'Libvirt')
18
+ else
19
+ raise ArgumentError, "Unrecognized service: #{key.inspect}"
20
+ end
21
+ end
22
+ @@connections[service]
23
+ end
24
+
25
+ def available?
26
+ begin
27
+ availability=true unless Gem::Specification::find_by_name("ruby-libvirt").nil?
28
+ rescue Gem::LoadError
29
+ availability=false
30
+ rescue
31
+ availability_gem=Gem.available?("ruby-libvirt")
32
+ end
33
+
34
+ if availability
35
+ for service in services
36
+ for collection in self.class_for(service).collections
37
+ unless self.respond_to?(collection)
38
+ self.class_eval <<-EOS, __FILE__, __LINE__
39
+ def self.#{collection}
40
+ self[:#{service}].#{collection}
41
+ end
42
+ EOS
43
+ end
44
+ end
45
+ end
46
+ end
47
+ availability
48
+ end
49
+
50
+ def collections
51
+ services.map {|service| self[service].collections}.flatten.sort_by {|service| service.to_s}
52
+ end
53
+
54
+ def services
55
+ Fog::Libvirt.services
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,136 @@
1
+ require 'fog/libvirt/models/compute/util/util'
2
+ require 'fog/libvirt/models/compute/util/uri'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Libvirt < Fog::Service
7
+ requires :libvirt_uri
8
+ recognizes :libvirt_username, :libvirt_password
9
+ recognizes :libvirt_ip_command
10
+
11
+ model_path 'fog/libvirt/models/compute'
12
+ model :server
13
+ collection :servers
14
+ model :network
15
+ collection :networks
16
+ model :interface
17
+ collection :interfaces
18
+ model :volume
19
+ collection :volumes
20
+ model :pool
21
+ collection :pools
22
+ model :node
23
+ collection :nodes
24
+ model :nic
25
+ collection :nics
26
+
27
+ request_path 'fog/libvirt/requests/compute'
28
+ request :list_domains
29
+ request :create_domain
30
+ request :define_domain
31
+ request :vm_action
32
+ request :list_pools
33
+ request :list_pool_volumes
34
+ request :define_pool
35
+ request :pool_action
36
+ request :list_volumes
37
+ request :volume_action
38
+ request :create_volume
39
+ request :clone_volume
40
+ request :list_networks
41
+ request :destroy_network
42
+ request :list_interfaces
43
+ request :destroy_interface
44
+ request :get_node_info
45
+ request :update_display
46
+
47
+ module Shared
48
+ include Fog::Compute::LibvirtUtil
49
+ end
50
+
51
+ class Mock
52
+ include Shared
53
+ def initialize(options={})
54
+ # libvirt is part of the gem => ruby-libvirt
55
+ require 'libvirt'
56
+ end
57
+
58
+ private
59
+
60
+ def client
61
+ return @client if defined?(@client)
62
+ end
63
+
64
+ #read mocks xml
65
+ def read_xml(file_name)
66
+ file_path = File.join(File.dirname(__FILE__),"requests","compute","mock_files",file_name)
67
+ File.read(file_path)
68
+ end
69
+ end
70
+
71
+ class Real
72
+ include Shared
73
+ attr_reader :client
74
+ attr_reader :uri
75
+ attr_reader :ip_command
76
+
77
+ def initialize(options={})
78
+ @uri = ::Fog::Compute::LibvirtUtil::URI.new(enhance_uri(options[:libvirt_uri]))
79
+ @ip_command = options[:libvirt_ip_command]
80
+
81
+ # libvirt is part of the gem => ruby-libvirt
82
+ begin
83
+ require 'libvirt'
84
+ rescue LoadError => e
85
+ retry if require('rubygems')
86
+ raise e.message
87
+ end
88
+
89
+ begin
90
+ if options[:libvirt_username] and options[:libvirt_password]
91
+ @client = ::Libvirt::open_auth(uri.uri, [::Libvirt::CRED_AUTHNAME, ::Libvirt::CRED_PASSPHRASE]) do |cred|
92
+ case cred['type']
93
+ when ::Libvirt::CRED_AUTHNAME
94
+ options[:libvirt_username]
95
+ when ::Libvirt::CRED_PASSPHRASE
96
+ options[:libvirt_password]
97
+ end
98
+ end
99
+ else
100
+ @client = ::Libvirt::open(uri.uri)
101
+ end
102
+
103
+ rescue ::Libvirt::ConnectionError
104
+ raise Fog::Errors::Error.new("Error making a connection to libvirt URI #{uri.uri}:\n#{$!}")
105
+ end
106
+ end
107
+
108
+ def terminate
109
+ @client.close if @client and !@client.closed?
110
+ end
111
+
112
+ def enhance_uri(uri)
113
+ require 'cgi'
114
+ append=""
115
+
116
+ # on macosx, chances are we are using libvirt through homebrew
117
+ # the client will default to a socket location based on it's own location (/opt)
118
+ # we conveniently point it to /var/run/libvirt/libvirt-sock
119
+ # if no socket option has been specified explicitly
120
+
121
+ if RUBY_PLATFORM =~ /darwin/
122
+ querystring=::URI.parse(uri).query
123
+ if querystring.nil?
124
+ append="?socket=/var/run/libvirt/libvirt-sock"
125
+ else
126
+ if !::CGI.parse(querystring).key?("socket")
127
+ append="&socket=/var/run/libvirt/libvirt-sock"
128
+ end
129
+ end
130
+ end
131
+ uri+append
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,76 @@
1
+ This model implements the connection with a libvirt URI.
2
+ A libvirt URI can either be local or remote.
3
+
4
+ To learn more on the specific libvirt URI syntax see:
5
+
6
+ - [http://libvirt.org/uri.html](http://libvirt.org/uri.html)
7
+ - [http://libvirt.org/remote.html#Remote_URI_reference](http://libvirt.org/remote.html#Remote_URI_reference)
8
+
9
+ Only ssh is supported as the transport for remote URI's. TLS is NOT supported, as we can't easily login to the server
10
+
11
+ ## Dependencies
12
+
13
+ - the interaction with libvirt is done through the official libvirt gem called 'ruby-libvirt'.
14
+ - be aware that there is another libvirt gem called 'libvirt', which is not compatible
15
+ - If this gem is not installed the models for libvirt will not be available
16
+
17
+ - libvirt needs to be setup so that it can be used
18
+ - for a remote ssh connection this requires to be member of the libvirt group before you can use the libvirt commands
19
+ - verify if you can execute virsh command to see if you have correct access
20
+
21
+ ## Libvirt on Macosx
22
+
23
+ - There is a libvirt client for Macosx, available via homebrew
24
+ - By default this will install things in /usr/local/somewhere
25
+ - This means that also the default locations of the libvirt-socket are assumed to be in /usr/local
26
+ - To check the connection you need to override your libvirt socket location in the URI
27
+ - "qemu+ssh://patrick@myserver/system?socket=/var/run/libvirt/libvirt-sock"
28
+
29
+ ## Configuration
30
+
31
+ The URI can be configured in two ways:
32
+ 1) via the .fog file
33
+ :default
34
+ :libvirt_uri: "qemu+ssh://patrick@myserver/system?socket=/var/run/libvirt/libvirt-sock"
35
+
36
+ 2) you can also pass it during creation :
37
+ f=Fog::Compute.new(:provider => "Libvirt", :libvirt_uri => "qemu+ssh://patrick@myserver/system")
38
+
39
+ ## IP-addresses of guests
40
+ Libvirt does not provide a way to query guests for Ip-addresses.
41
+ The way we solve this problem is by installing arpwatch: this watches an interface for new mac-addresses and ip-addresses requested by DHCP
42
+ We query that logfile for the mac-address and can retrieve the ip-address
43
+
44
+ vi /etc/rsyslog.d/30-arpwatch.conf
45
+ #:msg, contains, "arpwatch:" -/var/log/arpwatch.log
46
+ #& ~
47
+ if $programname =='arpwatch' then /var/log/arpwatch.log
48
+ & ~
49
+
50
+ This log files needs to be readable for the users of libvirt
51
+
52
+ ## SSh-ing into the guests
53
+ Once we have retrieved the ip-address of the guest we can ssh into it. This works great if the URI is local.
54
+ But when the URI is remote our machine can't ssh directly into the guest sometimes (due to NAT or firewall issues)
55
+
56
+ Luckily libvirt over ssh requires netcat to be installed on the libvirt server.
57
+ We use this to proxy our ssh requests to the guest over the ssh connection to the libvirt server.
58
+ Thanks to the requirement that you need ssh login to work to a libvirt server, we can login and tunnel the ssh to the guest.
59
+
60
+ ## Bridge configuration (slowness)
61
+ We had noticed that sometimes it takes about 30 seconds before the server gets a DHCP response from the server.
62
+ In our case it was because the new machine Mac-address was not allowed immediately by the bridge.
63
+ Adding the flag 'bridge_fd 0' solved that problem.
64
+
65
+ /etc/network/interfaces
66
+ auto br0
67
+ iface br0 inet static
68
+ address 10.247.4.13
69
+ netmask 255.255.255.0
70
+ network 10.247.4.0
71
+ broadcast 10.247.4.255
72
+ bridge_ports eth0.4
73
+ bridge_stp on
74
+ bridge_maxwait 0
75
+ bridge_fd 0
76
+
@@ -0,0 +1,25 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Libvirt
6
+ class Interface < Fog::Model
7
+ identity :name
8
+ attribute :mac
9
+ attribute :active
10
+
11
+ def save
12
+ raise Fog::Errors::Error.new('Creating a new interface is not yet implemented. Contributions welcome!')
13
+ end
14
+
15
+ def shutdown
16
+ service.destroy_interface(mac)
17
+ end
18
+
19
+ def active?
20
+ active
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/libvirt/models/compute/interface'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Libvirt
7
+ class Interfaces < Fog::Collection
8
+ model Fog::Compute::Libvirt::Interface
9
+
10
+ def all(filter={})
11
+ load(service.list_interfaces(filter))
12
+ end
13
+
14
+ def get(name)
15
+ self.all(:name => name).first
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ require 'fog/core/model'
2
+ require 'fog/libvirt/models/compute/util/util'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Libvirt
7
+ class Network < Fog::Model
8
+ include Fog::Compute::LibvirtUtil
9
+
10
+ identity :uuid
11
+ attribute :name
12
+ attribute :bridge_name
13
+ attribute :xml
14
+
15
+ def initialize(attributes = {})
16
+ super
17
+ end
18
+
19
+ def save
20
+ raise Fog::Errors::Error.new('Creating a new network is not yet implemented. Contributions welcome!')
21
+ end
22
+
23
+ def shutdown
24
+ service.destroy_network(uuid)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/libvirt/models/compute/network'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Libvirt
7
+ class Networks < Fog::Collection
8
+ model Fog::Compute::Libvirt::Network
9
+
10
+ def all(filter={})
11
+ load(service.list_networks(filter))
12
+ end
13
+
14
+ def get(uuid)
15
+ self.all(:uuid => uuid).first
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Libvirt
6
+ class Nic < Fog::Model
7
+ identity :mac
8
+ attribute :id
9
+ attribute :type
10
+ attribute :network
11
+ attribute :bridge
12
+ attribute :model
13
+
14
+ attr_accessor :server
15
+
16
+ TYPES = ["network", "bridge", "user"]
17
+
18
+ def new?
19
+ mac.nil?
20
+ end
21
+
22
+ def initialize attributes
23
+ super defaults.merge(attributes)
24
+ raise Fog::Errors::Error.new("#{type} is not a supported nic type") if new? && !TYPES.include?(type)
25
+ end
26
+
27
+ def save
28
+ raise Fog::Errors::Error.new('Creating a new nic is not yet implemented. Contributions welcome!')
29
+ #requires :server
30
+ #service.attach_nic(domain , self)
31
+ end
32
+
33
+ def destroy
34
+ raise Fog::Errors::Error.new('Destroying an interface is not yet implemented. Contributions welcome!')
35
+ #requires :server
36
+ ##detach the nic
37
+ #service.detach_nic(domain, mac)
38
+ end
39
+
40
+ private
41
+ def defaults
42
+ {
43
+ :type => "bridge",
44
+ :model => "virtio"
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end