vagrant-libvirt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +12 -0
  4. data/LICENSE +22 -0
  5. data/README.md +33 -0
  6. data/Rakefile +7 -0
  7. data/example_box/README.md +14 -0
  8. data/example_box/Vagrantfile +45 -0
  9. data/example_box/metadata.json +5 -0
  10. data/lib/vagrant-libvirt/action/connect_libvirt.rb +72 -0
  11. data/lib/vagrant-libvirt/action/create_domain.rb +62 -0
  12. data/lib/vagrant-libvirt/action/create_domain_volume.rb +58 -0
  13. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +85 -0
  14. data/lib/vagrant-libvirt/action/destroy_domain.rb +28 -0
  15. data/lib/vagrant-libvirt/action/handle_box_image.rb +121 -0
  16. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +49 -0
  17. data/lib/vagrant-libvirt/action/is_created.rb +18 -0
  18. data/lib/vagrant-libvirt/action/message_already_created.rb +16 -0
  19. data/lib/vagrant-libvirt/action/message_not_created.rb +16 -0
  20. data/lib/vagrant-libvirt/action/read_ssh_info.rb +51 -0
  21. data/lib/vagrant-libvirt/action/read_state.rb +38 -0
  22. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +31 -0
  23. data/lib/vagrant-libvirt/action/start_domain.rb +27 -0
  24. data/lib/vagrant-libvirt/action/sync_folders.rb +58 -0
  25. data/lib/vagrant-libvirt/action/timed_provision.rb +21 -0
  26. data/lib/vagrant-libvirt/action/wait_till_up.rb +96 -0
  27. data/lib/vagrant-libvirt/action.rb +94 -0
  28. data/lib/vagrant-libvirt/config.rb +48 -0
  29. data/lib/vagrant-libvirt/errors.rb +90 -0
  30. data/lib/vagrant-libvirt/plugin.rb +77 -0
  31. data/lib/vagrant-libvirt/provider.rb +76 -0
  32. data/lib/vagrant-libvirt/templates/default_storage_pool.xml.erb +13 -0
  33. data/lib/vagrant-libvirt/templates/domain.xml.erb +34 -0
  34. data/lib/vagrant-libvirt/templates/interface.xml.erb +7 -0
  35. data/lib/vagrant-libvirt/templates/volume_snapshot.xml.erb +26 -0
  36. data/lib/vagrant-libvirt/util/collection.rb +22 -0
  37. data/lib/vagrant-libvirt/util/erb_template.rb +21 -0
  38. data/lib/vagrant-libvirt/util/timer.rb +17 -0
  39. data/lib/vagrant-libvirt/util.rb +10 -0
  40. data/lib/vagrant-libvirt/version.rb +5 -0
  41. data/lib/vagrant-libvirt.rb +30 -0
  42. data/locales/en.yml +103 -0
  43. data/vagrant-libvirt.gemspec +23 -0
  44. metadata +127 -0
@@ -0,0 +1,76 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module Libvirt
5
+
6
+ # This is the base class for a provider for the V2 API. A provider
7
+ # is responsible for creating compute resources to match the
8
+ # needs of a Vagrant-configured system.
9
+ class Provider < Vagrant.plugin('2', :provider)
10
+ def initialize(machine)
11
+ @machine = machine
12
+ end
13
+
14
+ # This should return an action callable for the given name.
15
+ def action(name)
16
+ # Attempt to get the action method from the Action class if it
17
+ # exists, otherwise return nil to show that we don't support the
18
+ # given action.
19
+ action_method = "action_#{name}"
20
+ return Action.send(action_method) if Action.respond_to?(action_method)
21
+ nil
22
+ end
23
+
24
+ # This method is called if the underying machine ID changes. Providers
25
+ # can use this method to load in new data for the actual backing
26
+ # machine or to realize that the machine is now gone (the ID can
27
+ # become `nil`).
28
+ def machine_id_changed
29
+ end
30
+
31
+ # This should return a hash of information that explains how to
32
+ # SSH into the machine. If the machine is not at a point where
33
+ # SSH is even possible, then `nil` should be returned.
34
+ def ssh_info
35
+ # Run a custom action called "read_ssh_info" which does what it says
36
+ # and puts the resulting SSH info into the `:machine_ssh_info` key in
37
+ # the environment.
38
+ #
39
+ # Ssh info has following format..
40
+ #
41
+ #{
42
+ # :host => "1.2.3.4",
43
+ # :port => "22",
44
+ # :username => "mitchellh",
45
+ # :private_key_path => "/path/to/my/key"
46
+ #}
47
+ env = @machine.action("read_ssh_info")
48
+ env[:machine_ssh_info]
49
+ end
50
+
51
+ # This should return the state of the machine within this provider.
52
+ # The state must be an instance of {MachineState}.
53
+ def state
54
+ # Run a custom action we define called "read_state" which does
55
+ # what it says. It puts the state in the `:machine_state_id`
56
+ # key in the environment.
57
+ env = @machine.action("read_state")
58
+
59
+ state_id = env[:machine_state_id]
60
+
61
+ # Get the short and long description
62
+ short = I18n.t("vagrant_libvirt.states.short_#{state_id}")
63
+ long = I18n.t("vagrant_libvirt.states.long_#{state_id}")
64
+
65
+ # Return the MachineState object
66
+ Vagrant::MachineState.new(state_id, short, long)
67
+ end
68
+
69
+ def to_s
70
+ id = @machine.id.nil? ? "new" : @machine.id
71
+ "Libvirt (#{id})"
72
+ end
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1,13 @@
1
+ <pool type='dir'>
2
+ <name>default</name>
3
+ <source>
4
+ </source>
5
+ <target>
6
+ <path>/var/lib/libvirt/images</path>
7
+ <permissions>
8
+ <mode>0755</mode>
9
+ <owner>-1</owner>
10
+ <group>-1</group>
11
+ </permissions>
12
+ </target>
13
+ </pool>
@@ -0,0 +1,34 @@
1
+ <domain type='<%= @domain_type %>'>
2
+ <name><%= @name %></name>
3
+ <memory><%= @memory_size %></memory>
4
+ <vcpu><%= @cpus %></vcpu>
5
+ <os>
6
+ <type arch='x86_64'>hvm</type>
7
+ <boot dev='hd'/>
8
+ </os>
9
+ <features>
10
+ <acpi/>
11
+ <apic/>
12
+ <pae/>
13
+ </features>
14
+ <clock offset='utc'/>
15
+ <devices>
16
+ <disk type='file' device='disk'>
17
+ <driver name='qemu' type='qcow2'/>
18
+ <source file='<%= @domain_volume_path %>'/>
19
+ <%# we need to ensure a unique target dev -%>
20
+ <target dev='vda' bus='virtio'/>
21
+ </disk>
22
+ <serial type='pty'>
23
+ <target port='0'/>
24
+ </serial>
25
+ <console type='pty'>
26
+ <target port='0'/>
27
+ </console>
28
+ <input type='mouse' bus='ps2'/>
29
+ <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
30
+ <video>
31
+ <model type='cirrus' vram='9216' heads='1'/>
32
+ </video>
33
+ </devices>
34
+ </domain>
@@ -0,0 +1,7 @@
1
+ <interface type='network'>
2
+ <source network='<%= @network_name %>'/>
3
+ <target dev='vnet<%= @iface_number %>'/>
4
+ <alias name='net<%= @iface_number %>'/>
5
+ <model type='virtio'/>
6
+ </interface>
7
+
@@ -0,0 +1,26 @@
1
+ <volume>
2
+ <name><%= @name %></name>
3
+ <capacity unit="G"><%= @capacity %></capacity>
4
+
5
+ <target>
6
+ <format type='qcow2'/>
7
+ <permissions>
8
+ <owner>0</owner>
9
+ <group>0</group>
10
+ <mode>0600</mode>
11
+ <label>virt_image_t</label>
12
+ </permissions>
13
+ </target>
14
+
15
+ <backingStore>
16
+ <path><%= @backing_file %></path>
17
+ <format type='qcow2'/>
18
+ <permissions>
19
+ <owner>0</owner>
20
+ <group>0</group>
21
+ <mode>0600</mode>
22
+ <label>virt_image_t</label>
23
+ </permissions>
24
+ </backingStore>
25
+ </volume>
26
+
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module Libvirt
3
+ module Util
4
+ module Collection
5
+
6
+ # This method finds a matching _thing_ in a collection of
7
+ # _things_. This works matching if the ID or NAME equals to
8
+ # `name`. Or, if `name` is a regexp, a partial match is chosen
9
+ # as well.
10
+ def self.find_matching(collection, name)
11
+ collection.each do |single|
12
+ return single if single.name == name
13
+ end
14
+
15
+ nil
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,21 @@
1
+ require 'erb'
2
+
3
+ module VagrantPlugins
4
+ module Libvirt
5
+ module Util
6
+ module ErbTemplate
7
+
8
+ # Taken from fog source.
9
+ def to_xml template_name = nil
10
+ erb = template_name || self.class.to_s.split("::").last.downcase
11
+ path = File.join(File.dirname(__FILE__), "..", "templates",
12
+ "#{erb}.xml.erb")
13
+ template = File.read(path)
14
+ ERB.new(template, nil, '-').result(binding)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,17 @@
1
+ module VagrantPlugins
2
+ module Libvirt
3
+ module Util
4
+ class Timer
5
+ # A basic utility method that times the execution of the given
6
+ # block and returns it.
7
+ def self.time
8
+ start_time = Time.now.to_f
9
+ yield
10
+ end_time = Time.now.to_f
11
+
12
+ end_time - start_time
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module VagrantPlugins
2
+ module Libvirt
3
+ module Util
4
+ autoload :ErbTemplate, 'vagrant-libvirt/util/erb_template'
5
+ autoload :Collection, 'vagrant-libvirt/util/collection'
6
+ autoload :Timer, 'vagrant-libvirt/util/timer'
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Libvirt
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'pathname'
2
+ require 'vagrant-libvirt/plugin'
3
+
4
+ module VagrantPlugins
5
+ module Libvirt
6
+ lib_path = Pathname.new(File.expand_path("../vagrant-libvirt", __FILE__))
7
+ autoload :Action, lib_path.join("action")
8
+ autoload :Errors, lib_path.join("errors")
9
+ autoload :Util, lib_path.join("util")
10
+
11
+ # Hold connection handler so there is no need to connect more times than
12
+ # one. This can be annoying when there are more machines to create, or when
13
+ # doing state action first and then some other.
14
+ #
15
+ # TODO Don't sure if this is the best solution
16
+ @@libvirt_connection = nil
17
+ def self.libvirt_connection
18
+ @@libvirt_connection
19
+ end
20
+
21
+ def self.libvirt_connection=(conn)
22
+ @@libvirt_connection = conn
23
+ end
24
+
25
+ def self.source_root
26
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
27
+ end
28
+ end
29
+ end
30
+
data/locales/en.yml ADDED
@@ -0,0 +1,103 @@
1
+ en:
2
+ vagrant_libvirt:
3
+ already_created: |-
4
+ The machine is already created.
5
+ not_created: |-
6
+ Machine is not created. Please run `vagrant up` first.
7
+ finding_volume: |-
8
+ Checking if volume is available.
9
+ creating_domain: |-
10
+ Creating machine with the following settings...
11
+ uploading_volume: |-
12
+ Uploading base box image as volume into libvirt storage...
13
+ creating_domain_volume: |-
14
+ Creating image (snapshot of base box volume).
15
+ removing_domain_volume: |-
16
+ Removing image (snapshot of base box volume).
17
+ starting_domain: |-
18
+ Starting machine.
19
+ terminating: |-
20
+ Removing machine...
21
+ poweroff_domain: |-
22
+ Poweroff machine.
23
+ destroy_domain: |-
24
+ Removing machine...
25
+ waiting_for_ready: |-
26
+ Waiting for machine to become "ready"...
27
+ waiting_for_ip: |-
28
+ Waiting for machine to get an IP address...
29
+ waiting_for_ssh: |-
30
+ Waiting for SSH to become available...
31
+ booted: |-
32
+ Machine is booted.
33
+ rsync_folder: |-
34
+ Rsyncing folder: %{hostpath} => %{guestpath}
35
+ ready: |-
36
+ Machine is booted and ready for use!
37
+
38
+ errors:
39
+ fog_error: |-
40
+ There was an error talking to Libvirt. The error message is shown
41
+ below:
42
+
43
+ %{message}
44
+ no_matching_volume: |-
45
+ No matching volume was found! Please check your volume setting
46
+ to make sure you have a valid volume chosen.
47
+ no_storage_pool: |-
48
+ No usable storage pool found! Please check if storage pool is
49
+ created and available.
50
+ no_box_volume: |-
51
+ Volume for box image is missing in storage pools. Try to run vagrant
52
+ again, or check if storage volume is accessible.
53
+ domain_volume_exists: |-
54
+ Volume for domain is already created. Please run 'vagrant destroy' first.
55
+ no_domain_volume: |-
56
+ Volume for domain is missing. Try to run 'vagrant up' again.
57
+ interface_slot_not_available: |-
58
+ Interface adapter number is already in use. Please specify other adapter
59
+ number.
60
+ rsync_error: |-
61
+ There was an error when attemping to rsync a share folder.
62
+ Please inspect the error message below for more info.
63
+
64
+ Host path: %{hostpath}
65
+ Guest path: %{guestpath}
66
+ Error: %{stderr}
67
+ no_box_virtual_size: |-
68
+ No image virtual size specified for box.
69
+ no_box_format: |-
70
+ No image format specified for box.
71
+ wrong_box_format: |-
72
+ Wrong image format specified for box.
73
+ fog_libvirt_connection_error: |-
74
+ Error while connecting to libvirt: %{error_message}
75
+ fog_create_volume_error: |-
76
+ Error while creating a storage pool volume: %{error_message}
77
+ fog_create_domain_volume_error: |-
78
+ Error while creating volume for domain: %{error_message}
79
+ fog_create_server_error: |-
80
+ Error while creating domain: %{error_message}
81
+ domain_name_exists: |-
82
+ Name of domain about to create is already taken. Please try to run
83
+ `vagrant up` command again.
84
+ creating_storage_pool_error: |-
85
+ There was error while creating libvirt storage pool: %{error_message}
86
+ image_upload_error: |-
87
+ Error while uploading image to storage pool: %{error_message}
88
+ no_domain_error: |-
89
+ No domain found. %{error_message}
90
+ attach_device_error: |-
91
+ Error while attaching new device to domain. %{error_message}
92
+
93
+ states:
94
+ short_not_created: |-
95
+ not created
96
+ long_not_created: |-
97
+ The Libvirt domain is not created. Run `vagrant up` to create it.
98
+
99
+ short_running: |-
100
+ running
101
+ long_running: |-
102
+ The Libvirt domain is running. To stop this machine, you can run
103
+ `vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/vagrant-libvirt/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Lukas Stanek"]
6
+ gem.email = ["ls@elostech.cz"]
7
+ gem.description = %q{Vagrant provider for libvirt.}
8
+ gem.summary = %q{Vagrant provider for libvirt.}
9
+ gem.homepage = "http://www.vagrantup.com"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "vagrant-libvirt"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = VagrantPlugins::Libvirt::VERSION
17
+
18
+ gem.add_runtime_dependency "fog", "~> 1.10.0"
19
+ gem.add_runtime_dependency "ruby-libvirt", "~> 0.4.0"
20
+
21
+ gem.add_development_dependency "rake"
22
+ end
23
+
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-libvirt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lukas Stanek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fog
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-libvirt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Vagrant provider for libvirt.
56
+ email:
57
+ - ls@elostech.cz
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - example_box/README.md
68
+ - example_box/Vagrantfile
69
+ - example_box/metadata.json
70
+ - lib/vagrant-libvirt.rb
71
+ - lib/vagrant-libvirt/action.rb
72
+ - lib/vagrant-libvirt/action/connect_libvirt.rb
73
+ - lib/vagrant-libvirt/action/create_domain.rb
74
+ - lib/vagrant-libvirt/action/create_domain_volume.rb
75
+ - lib/vagrant-libvirt/action/create_network_interfaces.rb
76
+ - lib/vagrant-libvirt/action/destroy_domain.rb
77
+ - lib/vagrant-libvirt/action/handle_box_image.rb
78
+ - lib/vagrant-libvirt/action/handle_storage_pool.rb
79
+ - lib/vagrant-libvirt/action/is_created.rb
80
+ - lib/vagrant-libvirt/action/message_already_created.rb
81
+ - lib/vagrant-libvirt/action/message_not_created.rb
82
+ - lib/vagrant-libvirt/action/read_ssh_info.rb
83
+ - lib/vagrant-libvirt/action/read_state.rb
84
+ - lib/vagrant-libvirt/action/set_name_of_domain.rb
85
+ - lib/vagrant-libvirt/action/start_domain.rb
86
+ - lib/vagrant-libvirt/action/sync_folders.rb
87
+ - lib/vagrant-libvirt/action/timed_provision.rb
88
+ - lib/vagrant-libvirt/action/wait_till_up.rb
89
+ - lib/vagrant-libvirt/config.rb
90
+ - lib/vagrant-libvirt/errors.rb
91
+ - lib/vagrant-libvirt/plugin.rb
92
+ - lib/vagrant-libvirt/provider.rb
93
+ - lib/vagrant-libvirt/templates/default_storage_pool.xml.erb
94
+ - lib/vagrant-libvirt/templates/domain.xml.erb
95
+ - lib/vagrant-libvirt/templates/interface.xml.erb
96
+ - lib/vagrant-libvirt/templates/volume_snapshot.xml.erb
97
+ - lib/vagrant-libvirt/util.rb
98
+ - lib/vagrant-libvirt/util/collection.rb
99
+ - lib/vagrant-libvirt/util/erb_template.rb
100
+ - lib/vagrant-libvirt/util/timer.rb
101
+ - lib/vagrant-libvirt/version.rb
102
+ - locales/en.yml
103
+ - vagrant-libvirt.gemspec
104
+ homepage: http://www.vagrantup.com
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Vagrant provider for libvirt.
127
+ test_files: []