vagrant-ganeti 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +12 -0
  3. data/LICENSE +8 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +137 -0
  6. data/Rakefile +23 -0
  7. data/example_box/README.md +13 -0
  8. data/example_box/Vagrantfile +8 -0
  9. data/example_box/ganeti.box +0 -0
  10. data/example_box/metadata.json +3 -0
  11. data/lib/vagrant-plugin-ganeti/action/connect_ganeti.rb +70 -0
  12. data/lib/vagrant-plugin-ganeti/action/is_created.rb +18 -0
  13. data/lib/vagrant-plugin-ganeti/action/is_reachable.rb +18 -0
  14. data/lib/vagrant-plugin-ganeti/action/message_already_created.rb +16 -0
  15. data/lib/vagrant-plugin-ganeti/action/message_not_created.rb +16 -0
  16. data/lib/vagrant-plugin-ganeti/action/message_not_reachable.rb +16 -0
  17. data/lib/vagrant-plugin-ganeti/action/message_will_not_destroy.rb +16 -0
  18. data/lib/vagrant-plugin-ganeti/action/read_ssh_info.rb +32 -0
  19. data/lib/vagrant-plugin-ganeti/action/read_state.rb +84 -0
  20. data/lib/vagrant-plugin-ganeti/action/remove_instance.rb +26 -0
  21. data/lib/vagrant-plugin-ganeti/action/run_instance.rb +76 -0
  22. data/lib/vagrant-plugin-ganeti/action/sync_folders.rb +85 -0
  23. data/lib/vagrant-plugin-ganeti/action/timed_provision.rb +22 -0
  24. data/lib/vagrant-plugin-ganeti/action/unlink_server.rb +30 -0
  25. data/lib/vagrant-plugin-ganeti/action/warn_networks.rb +19 -0
  26. data/lib/vagrant-plugin-ganeti/action.rb +137 -0
  27. data/lib/vagrant-plugin-ganeti/config.rb +308 -0
  28. data/lib/vagrant-plugin-ganeti/errors.rb +19 -0
  29. data/lib/vagrant-plugin-ganeti/plugin.rb +73 -0
  30. data/lib/vagrant-plugin-ganeti/provider.rb +50 -0
  31. data/lib/vagrant-plugin-ganeti/util/ganeti_client.rb +142 -0
  32. data/lib/vagrant-plugin-ganeti/util/timer.rb +17 -0
  33. data/lib/vagrant-plugin-ganeti/version.rb +5 -0
  34. data/lib/vagrant-plugin-ganeti.rb +19 -0
  35. data/locales/en.yml +81 -0
  36. data/vagrant-plugin-ganeti.gemspec +57 -0
  37. metadata +163 -0
@@ -0,0 +1,50 @@
1
+ require "log4r"
2
+ require "vagrant"
3
+
4
+ module VagrantPlugins
5
+ module GANETI
6
+ class Provider < Vagrant.plugin("2", :provider)
7
+ def initialize(machine)
8
+ @machine = machine
9
+ end
10
+
11
+ def action(name)
12
+ # Attempt to get the action method from the Action class if it
13
+ # exists, otherwise return nil to show that we don't support the
14
+ # given action.
15
+ action_method = "action_#{name}"
16
+ return Action.send(action_method) if Action.respond_to?(action_method)
17
+ nil
18
+ end
19
+
20
+ def ssh_info
21
+ # Run a custom action called "read_ssh_info" which does what it
22
+ # says and puts the resulting SSH info into the `:machine_ssh_info`
23
+ # key in the environment.
24
+ env = @machine.action("read_ssh_info")
25
+ env[:machine_ssh_info]
26
+ end
27
+
28
+ def state
29
+ # Run a custom action we define called "read_state" which does
30
+ # what it says. It puts the state in the `:machine_state_id`
31
+ # key in the environment.
32
+ env = @machine.action("read_state")
33
+
34
+ state_id = env[:machine_state_id]
35
+
36
+ # Get the short and long description
37
+ short = I18n.t("vagrant_ganeti.states.short_#{state_id}")
38
+ long = I18n.t("vagrant_ganeti.states.long_#{state_id}")
39
+
40
+ # Return the MachineState object
41
+ Vagrant::MachineState.new(state_id, short, long)
42
+ end
43
+
44
+ def to_s
45
+ id = @machine.id.nil? ? "new" : @machine.id
46
+ "GANETI (#{id})"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,142 @@
1
+ module VagrantPlugins
2
+ module GANETI
3
+ module Util
4
+ class GanetiClient
5
+ attr_accessor :cluster, :rapi_user, :rapi_pass, :version,:info
6
+
7
+ def initialize(cluster, rapi_user, rapi_pass)
8
+ self.cluster = cluster
9
+ self.rapi_user = rapi_user
10
+ self.rapi_pass = rapi_pass
11
+ self.version = self.version_get
12
+ end
13
+
14
+ def set_config(info)
15
+ self.info = info
16
+ end
17
+
18
+ def instance_create( dry_run = 0)
19
+ url = get_url("instances")
20
+ body = info.to_json
21
+ response_body = send_request("POST", url, body)
22
+ return response_body
23
+ end
24
+
25
+ def instance_terminate(dry_run = 0)
26
+ url = get_url("instances/#{info['instance_name']}")
27
+ body = info.to_json
28
+ response_body = send_request("DELETE", url)
29
+ return response_body
30
+ end
31
+
32
+
33
+ def is_job_ready(jobno)
34
+ url = get_url("jobs/#{jobno}")
35
+ response_body = send_request("GET", url)
36
+ if response_body["status"] =="error"
37
+ if response_body["opresult"][0][1][1] == "already_exists"
38
+ return "already_exists"
39
+ else
40
+ return "error"
41
+ end
42
+ else
43
+ response_body["status"]
44
+ end
45
+ end
46
+
47
+ def set_default_iallocator()
48
+ url = get_url("info")
49
+ response_body = send_request("GET", url)
50
+ return response_body["default_iallocator"]
51
+ end
52
+
53
+ def start_instance()
54
+ url = get_url("instances/#{info['instance_name']}/startup")
55
+ response_body = send_request("PUT", url)
56
+
57
+ return response_body
58
+ end
59
+
60
+ def version_get
61
+ url = get_url("version")
62
+ response_body = send_request("GET", url)
63
+
64
+ return response_body
65
+ end
66
+
67
+ def authenticate(rapi_user, rapi_pass)
68
+ basic = Base64.encode64("#{rapi_user}:#{rapi_pass}").strip
69
+ return "Basic #{basic}"
70
+ end
71
+
72
+
73
+ def get_url(path, params = nil)
74
+ param_string = ""
75
+
76
+ if params
77
+ params.each do |key, value|
78
+ if value.kind_of?(Array)
79
+ value.each do |svalue|
80
+ param_string += "#{key}=#{svalue}&"
81
+ end
82
+ else
83
+ param_string += "#{key}=#{value}&"
84
+ end
85
+ end
86
+ end
87
+
88
+ url = (self.version)? "/#{self.version}/#{path}?#{param_string}" : "/#{path}?#{param_string}"
89
+
90
+ return url.chop
91
+ end
92
+
93
+
94
+ def send_request(method, url, body = nil, headers = {})
95
+ uri = URI.parse(cluster)
96
+
97
+ http = Net::HTTP.new(uri.host, uri.port)
98
+ http.use_ssl = true
99
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
100
+ headers['User-Agent'] = 'Ruby Ganeti RAPI Client'
101
+ headers['Content-Type'] = 'application/json'
102
+ headers['Authorization']= authenticate(self.rapi_user, self.rapi_pass)
103
+
104
+ begin
105
+ response = http.send_request(method, url, body, headers)
106
+ # response = http.send_request("GET",url)
107
+ rescue => e
108
+ puts "Error sending request"
109
+ puts "#{e.message}"
110
+
111
+ else
112
+ case response
113
+ when Net::HTTPSuccess
114
+ parse_response(response.body.strip)
115
+ else
116
+ response.instance_eval { class << self; attr_accessor :body_parsed; end }
117
+ begin
118
+ response.body_parsed = parse_response(response.body)
119
+ rescue
120
+ # raises exception corresponding to http error Net::XXX
121
+ puts "#{response.error!}"
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+
128
+ def parse_response(response_body)
129
+ # adding workaround becouse Google seems to operate on 'non-strict' JSON format
130
+ # http://code.google.com/p/ganeti/issues/detail?id=117
131
+ begin
132
+ response_body = JSON.parse(response_body)
133
+ rescue
134
+ response_body = JSON.parse('['+response_body+']').first
135
+ end
136
+
137
+ return response_body
138
+ end
139
+ end #Class GanetiClient
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,17 @@
1
+ module VagrantPlugins
2
+ module GANETI
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,5 @@
1
+ module VagrantPlugins
2
+ module GANETI
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-plugin-ganeti/plugin"
4
+ require "vagrant-plugin-ganeti/util/ganeti_client"
5
+
6
+ module VagrantPlugins
7
+ module GANETI
8
+ lib_path = Pathname.new(File.expand_path("../vagrant-plugin-ganeti", __FILE__))
9
+ autoload :Action, lib_path.join("action")
10
+ autoload :Errors, lib_path.join("errors")
11
+
12
+ # This returns the path to the source of this plugin.
13
+ #
14
+ # @return [Pathname]
15
+ def self.source_root
16
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
17
+ end
18
+ end
19
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,81 @@
1
+ en:
2
+ vagrant_ganeti:
3
+ already_created: |-
4
+ The machine is already created.
5
+ launching_instance: |-
6
+ Launching an instance with the following settings...
7
+ launch_no_keypair: |-
8
+ Warning! You didn't specify a keypair to launch your instance with.
9
+ This can sometimes result in not being able to access your instance.
10
+ launch_vpc_warning: |-
11
+ Warning! You're launching this instance into a VPC without an
12
+ elastic IP. Please verify you're properly connected to a VPN so
13
+ you can access this machine, otherwise Vagrant will not be able
14
+ to SSH into it.
15
+ not_created: |-
16
+ Instance is not created. Please run `vagrant up` first.
17
+ ready: |-
18
+ Machine is booted and ready for use!
19
+ rsync_folder: |-
20
+ Rsyncing folder: %{hostpath} => %{guestpath}
21
+ terminating: |-
22
+ Terminating the instance...
23
+ waiting_for_ready: |-
24
+ Waiting for instance to become "ready"...
25
+ waiting_for_ssh: |-
26
+ Waiting for SSH to become available...
27
+ warn_networks: |-
28
+ Warning! The Ganeti provider doesn't support any of the Vagrant
29
+ high-level network configurations (`config.vm.network`). They
30
+ will be silently ignored.
31
+ will_not_destroy: |-
32
+ The instance '%{name}' will not be destroyed, since the confirmation
33
+ was declined.
34
+
35
+ config:
36
+ username_required: |-
37
+ A valid RAPI username required
38
+ password_required: |-
39
+ A valid RAPI password corresponding to username not found
40
+ os_name_required: |-
41
+ An OS Name must be specified via "os_name"
42
+ host_required: |-
43
+ A host must be specified via "host"
44
+ disks_required: |-
45
+ Disks must be specified via "disks"
46
+ mode_required: |-
47
+ Mode must be specified via "mode"
48
+ instance_name_required: |-
49
+ An Instance name is required via "instance_name"
50
+ disk_template_required: |-
51
+ Disk Template must be specified via "disk_template"
52
+ nics_required: |-
53
+ Network configuration must be specified via "nics"
54
+ pnode_required: |-
55
+ Primary Node must be specified via "pnode"
56
+
57
+ errors:
58
+ instance_ready_timeout: |-
59
+ The instance never became "ready" in Ganeti. The timeout currently
60
+ set waiting for the instance to become ready is %{timeout} seconds.
61
+ Please verify that the machine properly boots. If you need more time
62
+ set the `instance_ready_timeout` configuration on the Ganeti provider.
63
+ rsync_error: |-
64
+ There was an error when attemping to rsync a share folder.
65
+ Please inspect the error message below for more info.
66
+
67
+ Host path: %{hostpath}
68
+ Guest path: %{guestpath}
69
+ Error: %{stderr}
70
+
71
+ states:
72
+ short_not_created: |-
73
+ not created
74
+ long_not_created: |-
75
+ The Ganeti instance is not created. Run `vagrant up` to create it.
76
+
77
+ short_running: |-
78
+ running
79
+ long_running: |-
80
+ The Ganeti instance is running. To stop this machine, you can run
81
+ `vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
@@ -0,0 +1,57 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "vagrant-plugin-ganeti/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "vagrant-ganeti"
6
+ s.version = VagrantPlugins::GANETI::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = "Ahmed Shabib,Lance Albertson"
9
+ s.email = "reachshabib@gmail.com"
10
+ s.homepage = "http://www.vagrantup.com"
11
+ s.summary = "Enables Vagrant to manage machines in Ganeti"
12
+ s.description = "Enables Vagrant to manage machines in Ganeti."
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "vagrant-plugin-ganeti"
16
+
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "rspec-core", "~> 2.12.2"
19
+ s.add_development_dependency "rspec-expectations", "~> 2.12.1"
20
+ s.add_development_dependency "rspec-mocks", "~> 2.12.1"
21
+
22
+ # The following block of code determines the files that should be included
23
+ # in the gem. It does this by reading all the files in the directory where
24
+ # this gemspec is, and parsing out the ignored files from the gitignore.
25
+ # Note that the entire gitignore(5) syntax is not supported, specifically
26
+ # the "!" syntax, but it should mostly work correctly.
27
+ root_path = File.dirname(__FILE__)
28
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
29
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
30
+ gitignore_path = File.join(root_path, ".gitignore")
31
+ gitignore = File.readlines(gitignore_path)
32
+ gitignore.map! { |line| line.chomp.strip }
33
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
34
+
35
+ unignored_files = all_files.reject do |file|
36
+ # Ignore any directories, the gemspec only cares about files
37
+ next true if File.directory?(file)
38
+
39
+ # Ignore any paths that match anything in the gitignore. We do
40
+ # two tests here:
41
+ #
42
+ # - First, test to see if the entire path matches the gitignore.
43
+ # - Second, match if the basename does, this makes it so that things
44
+ # like '.DS_Store' will match sub-directories too (same behavior
45
+ # as git).
46
+ #
47
+ gitignore.any? do |ignore|
48
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
49
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
50
+ end
51
+ end
52
+
53
+ s.files = unignored_files
54
+ s.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
55
+ s.require_path = 'lib'
56
+ end
57
+
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ganeti
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ahmed Shabib,Lance Albertson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-08-31 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec-core
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 59
43
+ segments:
44
+ - 2
45
+ - 12
46
+ - 2
47
+ version: 2.12.2
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec-expectations
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 61
59
+ segments:
60
+ - 2
61
+ - 12
62
+ - 1
63
+ version: 2.12.1
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: rspec-mocks
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 61
75
+ segments:
76
+ - 2
77
+ - 12
78
+ - 1
79
+ version: 2.12.1
80
+ type: :development
81
+ version_requirements: *id004
82
+ description: Enables Vagrant to manage machines in Ganeti.
83
+ email: reachshabib@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - README.md
92
+ - lib/vagrant-plugin-ganeti/util/timer.rb
93
+ - lib/vagrant-plugin-ganeti/util/ganeti_client.rb
94
+ - lib/vagrant-plugin-ganeti/action/message_already_created.rb
95
+ - lib/vagrant-plugin-ganeti/action/message_will_not_destroy.rb
96
+ - lib/vagrant-plugin-ganeti/action/connect_ganeti.rb
97
+ - lib/vagrant-plugin-ganeti/action/unlink_server.rb
98
+ - lib/vagrant-plugin-ganeti/action/remove_instance.rb
99
+ - lib/vagrant-plugin-ganeti/action/is_created.rb
100
+ - lib/vagrant-plugin-ganeti/action/warn_networks.rb
101
+ - lib/vagrant-plugin-ganeti/action/read_state.rb
102
+ - lib/vagrant-plugin-ganeti/action/timed_provision.rb
103
+ - lib/vagrant-plugin-ganeti/action/run_instance.rb
104
+ - lib/vagrant-plugin-ganeti/action/message_not_created.rb
105
+ - lib/vagrant-plugin-ganeti/action/read_ssh_info.rb
106
+ - lib/vagrant-plugin-ganeti/action/is_reachable.rb
107
+ - lib/vagrant-plugin-ganeti/action/sync_folders.rb
108
+ - lib/vagrant-plugin-ganeti/action/message_not_reachable.rb
109
+ - lib/vagrant-plugin-ganeti/config.rb
110
+ - lib/vagrant-plugin-ganeti/version.rb
111
+ - lib/vagrant-plugin-ganeti/action.rb
112
+ - lib/vagrant-plugin-ganeti/errors.rb
113
+ - lib/vagrant-plugin-ganeti/provider.rb
114
+ - lib/vagrant-plugin-ganeti/plugin.rb
115
+ - lib/vagrant-plugin-ganeti.rb
116
+ - Gemfile
117
+ - LICENSE
118
+ - LICENSE.txt
119
+ - example_box/README.md
120
+ - example_box/Vagrantfile
121
+ - example_box/metadata.json
122
+ - example_box/ganeti.box
123
+ - Rakefile
124
+ - locales/en.yml
125
+ - vagrant-plugin-ganeti.gemspec
126
+ - .gitignore
127
+ homepage: http://www.vagrantup.com
128
+ licenses: []
129
+
130
+ post_install_message:
131
+ rdoc_options: []
132
+
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 23
150
+ segments:
151
+ - 1
152
+ - 3
153
+ - 6
154
+ version: 1.3.6
155
+ requirements: []
156
+
157
+ rubyforge_project: vagrant-plugin-ganeti
158
+ rubygems_version: 1.8.15
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: Enables Vagrant to manage machines in Ganeti
162
+ test_files: []
163
+