vagrant-openstack-plugin-tom 0.12.0

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 (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +11 -0
  4. data/Authors.txt +11 -0
  5. data/CHANGELOG.md +185 -0
  6. data/Gemfile +10 -0
  7. data/LICENSE.txt +23 -0
  8. data/README.md +278 -0
  9. data/Rakefile +21 -0
  10. data/dummy.box +0 -0
  11. data/example_box/README.md +13 -0
  12. data/example_box/metadata.json +3 -0
  13. data/example_vagrant_file +24 -0
  14. data/lib/vagrant-openstack-plugin.rb +53 -0
  15. data/lib/vagrant-openstack-plugin/action.rb +268 -0
  16. data/lib/vagrant-openstack-plugin/action/connect_openstack.rb +90 -0
  17. data/lib/vagrant-openstack-plugin/action/create_network_interfaces.rb +52 -0
  18. data/lib/vagrant-openstack-plugin/action/create_orchestration_stack.rb +97 -0
  19. data/lib/vagrant-openstack-plugin/action/create_server.rb +263 -0
  20. data/lib/vagrant-openstack-plugin/action/delete_orchestration_stack.rb +78 -0
  21. data/lib/vagrant-openstack-plugin/action/delete_server.rb +84 -0
  22. data/lib/vagrant-openstack-plugin/action/hard_reboot_server.rb +27 -0
  23. data/lib/vagrant-openstack-plugin/action/is_created.rb +16 -0
  24. data/lib/vagrant-openstack-plugin/action/is_paused.rb +16 -0
  25. data/lib/vagrant-openstack-plugin/action/is_snapshoting.rb +24 -0
  26. data/lib/vagrant-openstack-plugin/action/is_suspended.rb +16 -0
  27. data/lib/vagrant-openstack-plugin/action/message_already_created.rb +16 -0
  28. data/lib/vagrant-openstack-plugin/action/message_already_paused.rb +16 -0
  29. data/lib/vagrant-openstack-plugin/action/message_already_suspended.rb +16 -0
  30. data/lib/vagrant-openstack-plugin/action/message_not_created.rb +16 -0
  31. data/lib/vagrant-openstack-plugin/action/message_server_running.rb +16 -0
  32. data/lib/vagrant-openstack-plugin/action/message_snapshot_done.rb +16 -0
  33. data/lib/vagrant-openstack-plugin/action/message_snapshot_in_progress.rb +16 -0
  34. data/lib/vagrant-openstack-plugin/action/message_will_not_destroy.rb +16 -0
  35. data/lib/vagrant-openstack-plugin/action/pause_server.rb +27 -0
  36. data/lib/vagrant-openstack-plugin/action/read_ssh_info.rb +103 -0
  37. data/lib/vagrant-openstack-plugin/action/read_state.rb +39 -0
  38. data/lib/vagrant-openstack-plugin/action/reboot_server.rb +27 -0
  39. data/lib/vagrant-openstack-plugin/action/resume_server.rb +31 -0
  40. data/lib/vagrant-openstack-plugin/action/suspend_server.rb +27 -0
  41. data/lib/vagrant-openstack-plugin/action/sync_folders.rb +104 -0
  42. data/lib/vagrant-openstack-plugin/action/take_snapshot.rb +26 -0
  43. data/lib/vagrant-openstack-plugin/action/wait_for_state.rb +39 -0
  44. data/lib/vagrant-openstack-plugin/action/wait_for_task.rb +44 -0
  45. data/lib/vagrant-openstack-plugin/action/warn_networks.rb +19 -0
  46. data/lib/vagrant-openstack-plugin/command.rb +70 -0
  47. data/lib/vagrant-openstack-plugin/command/command_snapshot.rb +43 -0
  48. data/lib/vagrant-openstack-plugin/config.rb +246 -0
  49. data/lib/vagrant-openstack-plugin/errors.rb +71 -0
  50. data/lib/vagrant-openstack-plugin/plugin.rb +45 -0
  51. data/lib/vagrant-openstack-plugin/provider.rb +50 -0
  52. data/lib/vagrant-openstack-plugin/version.rb +5 -0
  53. data/locales/en.yml +154 -0
  54. data/spec/vagrant-openstack-plugin/config_spec.rb +152 -0
  55. data/vagrant-openstack-plugin.gemspec +24 -0
  56. metadata +142 -0
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Immediately sync all stdout so that tools like buildbot can
6
+ # immediately load in the output.
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
12
+
13
+ # This installs the tasks that help with gem creation and
14
+ # publishing.
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ # Install the `spec` task so that we can run tests.
18
+ RSpec::Core::RakeTask.new
19
+
20
+ # Default task is to run the unit tests
21
+ task :default => "spec"
data/dummy.box ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ # Vagrant OpenStack Cloud Example Box
2
+
3
+ Vagrant providers each require a custom provider-specific box format.
4
+ This folder shows the example contents of a box for the `openstack` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf openstack.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for OpenStack. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "openstack"
3
+ }
@@ -0,0 +1,24 @@
1
+ require 'vagrant-openstack-plugin'
2
+
3
+ Vagrant.configure("2") do |config|
4
+ config.vm.box = "dummy"
5
+
6
+ # Make sure the private key from the key pair is provided
7
+ config.ssh.private_key_path = "~/.ssh/openstack_irad_key"
8
+
9
+ config.vm.provider :openstack do |os|
10
+ os.server_name = "thellier-vagrant-test"
11
+ os.username = "thellier1" # e.g. "#{ENV['OS_USERNAME']}"
12
+ os.api_key = "#{ENV['OS_PASSWORD']}" # e.g. "#{ENV['OS_PASSWORD']}"
13
+ os.flavor = /irad.nano/ # Regex or String
14
+ os.image = /CentOS7-nano/ # Regex or String
15
+ os.endpoint = "http://openstack.irad.ng.co.uk:35357/v3/auth/tokens" # e.g. "#{ENV['OS_AUTH_URL']}/tokens"
16
+ os.keypair_name = "openstack-shared-key" # as stored in Nova
17
+ os.ssh_username = "centos" # login for the VM
18
+ os.project_name = "smartdata"
19
+ os.project_domain = "default"
20
+ os.user_domain = "default"
21
+ os.network = "smartdata_network" # optional
22
+ os.metadata = {"key" => "value"} # optional
23
+ end
24
+ end
@@ -0,0 +1,53 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-openstack-plugin/plugin"
4
+
5
+ module VagrantPlugins
6
+ module OpenStack
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-openstack-plugin", __FILE__))
8
+ autoload :Errors, lib_path.join("errors")
9
+
10
+ # This initializes the i18n load path so that the plugin-specific
11
+ # translations work.
12
+ def self.init_i18n
13
+ I18n.load_path << File.expand_path("locales/en.yml", source_root)
14
+ I18n.reload!
15
+ end
16
+
17
+ # This initializes the logging so that our logs are outputted at
18
+ # the same level as Vagrant core logs.
19
+ def self.init_logging
20
+ # Initialize logging
21
+ level = nil
22
+ begin
23
+ level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
24
+ rescue NameError
25
+ # This means that the logging constant wasn't found,
26
+ # which is fine. We just keep `level` as `nil`. But
27
+ # we tell the user.
28
+ level = nil
29
+ end
30
+
31
+ # Some constants, such as "true" resolve to booleans, so the
32
+ # above error checking doesn't catch it. This will check to make
33
+ # sure that the log level is an integer, as Log4r requires.
34
+ level = nil if !level.is_a?(Integer)
35
+
36
+ # Set the logging level on all "vagrant" namespaced
37
+ # logs as long as we have a valid level.
38
+ if level
39
+ logger = Log4r::Logger.new("vagrant_openstack")
40
+ logger.outputters = Log4r::Outputter.stderr
41
+ logger.level = level
42
+ logger = nil
43
+ end
44
+ end
45
+
46
+ # This returns the path to the source of this plugin.
47
+ #
48
+ # @return [Pathname]
49
+ def self.source_root
50
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,268 @@
1
+ require "pathname"
2
+
3
+ require "vagrant/action/builder"
4
+
5
+ module VagrantPlugins
6
+ module OpenStack
7
+ module Action
8
+ # Include the built-in modules so we can use them as top-level things.
9
+ include Vagrant::Action::Builtin
10
+
11
+ # This action is called when `vagrant destroy` is executed.
12
+ def self.action_destroy
13
+ Vagrant::Action::Builder.new.tap do |b|
14
+ b.use ConfigValidate
15
+ b.use Call, DestroyConfirm do |env, b1|
16
+ if env[:result]
17
+ b1.use ConnectOpenStack
18
+ b1.use DeleteServer
19
+ b1.use DeleteOrchestrationStack
20
+ else
21
+ b1.use MessageWillNotDestroy
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ # This action is called to read the SSH info of the machine. The
28
+ # resulting state is expected to be put into the `:machine_ssh_info`
29
+ # key.
30
+ def self.action_read_ssh_info
31
+ Vagrant::Action::Builder.new.tap do |b|
32
+ b.use ConfigValidate
33
+ b.use ConnectOpenStack
34
+ b.use ReadSSHInfo
35
+ end
36
+ end
37
+
38
+ # This action is called to read the state of the machine. The
39
+ # resulting state is expected to be put into the `:machine_state_id`
40
+ # key.
41
+ def self.action_read_state
42
+ Vagrant::Action::Builder.new.tap do |b|
43
+ b.use ConfigValidate
44
+ b.use ConnectOpenStack
45
+ b.use ReadState
46
+ end
47
+ end
48
+
49
+ # This action is called when `vagrant ssh` is executed.
50
+ def self.action_ssh
51
+ Vagrant::Action::Builder.new.tap do |b|
52
+ b.use ConfigValidate
53
+ b.use Call, IsCreated do |env, b1|
54
+ unless env[:result]
55
+ b1.use MessageNotCreated
56
+ next
57
+ end
58
+
59
+ b1.use SSHExec
60
+ end
61
+ end
62
+ end
63
+
64
+ def self.action_ssh_run
65
+ Vagrant::Action::Builder.new.tap do |b|
66
+ b.use ConfigValidate
67
+ b.use Call, IsCreated do |env, b1|
68
+ unless env[:result]
69
+ b1.use MessageNotCreated
70
+ next
71
+ end
72
+
73
+ b1.use SSHRun
74
+ end
75
+ end
76
+ end
77
+
78
+ def self.action_prepare_boot
79
+ Vagrant::Action::Builder.new.tap do |b|
80
+ b.use Provision
81
+ b.use SyncFolders
82
+ b.use SetHostname
83
+ end
84
+ end
85
+
86
+ # This action is called when `vagrant up` is executed.
87
+ def self.action_up
88
+ Vagrant::Action::Builder.new.tap do |b|
89
+ if Vagrant::VERSION < '1.6.0'
90
+ b.use HandleBoxUrl
91
+ else
92
+ b.use HandleBox
93
+ end
94
+ b.use ConfigValidate
95
+ b.use Call, IsCreated do |env, b1|
96
+ unless env[:result]
97
+ b1.use action_prepare_boot
98
+ b1.use ConnectOpenStack
99
+ b1.use CreateOrchestrationStack
100
+ b1.use CreateServer
101
+ b1.use CreateNetworkInterfaces
102
+ else
103
+ b1.use action_resume
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # This action is called when `vagrant provision` is executed.
110
+ def self.action_provision
111
+ Vagrant::Action::Builder.new.tap do |b|
112
+ b.use ConfigValidate
113
+ b.use Call, IsCreated do |env, b1|
114
+ unless env[:result]
115
+ b1.use MessageNotCreated
116
+ next
117
+ end
118
+
119
+ b1.use ConnectOpenStack
120
+ b1.use Provision
121
+ b1.use SyncFolders
122
+ end
123
+ end
124
+ end
125
+
126
+ # This action is called when `vagrant reload` is executed.
127
+ def self.action_reload
128
+ Vagrant::Action::Builder.new.tap do |b|
129
+ b.use ConfigValidate
130
+ b.use ConnectOpenStack
131
+ b.use Call, IsPaused do |env, b1|
132
+ unless env[:result]
133
+ b1.use Call, IsSuspended do |env2, b2|
134
+ b2.use RebootServer
135
+ end
136
+ end
137
+
138
+ b1.use Call, WaitForState, [:active], 120 do |env2, b2|
139
+ unless env2[:result]
140
+ b2.use HardRebootServer
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ # This action is called when `vagrant halt` is executed.
148
+ def self.action_halt
149
+ Vagrant::Action::Builder.new.tap do |b|
150
+ b.use ConfigValidate
151
+ b.use Call, IsCreated do |env, b1|
152
+ unless env[:result]
153
+ b1.use Call, IsSuspended do |env2, b2|
154
+ if env2[:result]
155
+ b1.use MessageAlreadySuspended
156
+ next
157
+ end
158
+ end
159
+ end
160
+
161
+ b1.use ConnectOpenStack
162
+ b1.use PauseServer
163
+ end
164
+ end
165
+ end
166
+
167
+ # This action is called when `vagrant resume` is executed.
168
+ def self.action_resume
169
+ Vagrant::Action::Builder.new.tap do |b|
170
+ b.use ConfigValidate
171
+ b.use Call, IsCreated do |env, b1|
172
+ if env[:result]
173
+ b1.use MessageServerRunning
174
+ next
175
+ end
176
+
177
+ b1.use ConnectOpenStack
178
+ b1.use ResumeServer
179
+ b1.use SyncFolders
180
+ end
181
+ end
182
+ end
183
+
184
+ # This action is called when `vagrant suspend` is executed.
185
+ def self.action_suspend
186
+ Vagrant::Action::Builder.new.tap do |b|
187
+ b.use ConfigValidate
188
+ b.use Call, IsCreated do |env, b1|
189
+ if env[:result]
190
+ b1.use ConnectOpenStack
191
+ b1.use SuspendServer
192
+ else
193
+ b1.use Call, IsPaused do |env2, b2|
194
+ if env2[:result]
195
+ b2.use MessageAlreadyPaused
196
+ else
197
+ b2.use MessageAlreadySuspended
198
+ end
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ def self.action_take_snapshot
206
+ Vagrant::Action::Builder.new.tap do |b|
207
+ b.use ConfigValidate
208
+ b.use Call, IsCreated do |env, b1|
209
+ if env[:result]
210
+ b1.use ConnectOpenStack
211
+ b1.use Call, IsSnapshoting do |env,b2|
212
+ if env[:result]
213
+ b2.use MessageSnapshotInProgress
214
+ else
215
+ b2.use TakeSnapshot
216
+ end
217
+
218
+ b2.use Call, WaitForTask, [nil], 1200 do |env3, b3|
219
+ if env3[:result]
220
+ b3.use MessageSnapshotDone
221
+ end
222
+ end
223
+
224
+
225
+ end
226
+ else
227
+ b1.use MessageNotCreated
228
+ end
229
+ end
230
+ end
231
+ end
232
+
233
+ # The autoload farm
234
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
235
+ autoload :ConnectOpenStack, action_root.join("connect_openstack")
236
+ autoload :CreateServer, action_root.join("create_server")
237
+ autoload :CreateNetworkInterfaces, action_root.join("create_network_interfaces")
238
+ autoload :DeleteServer, action_root.join("delete_server")
239
+ autoload :HardRebootServer, action_root.join("hard_reboot_server")
240
+ autoload :IsCreated, action_root.join("is_created")
241
+ autoload :IsPaused, action_root.join("is_paused")
242
+ autoload :IsSnapshoting, action_root.join("is_snapshoting")
243
+ autoload :IsSuspended, action_root.join("is_suspended")
244
+ autoload :MessageAlreadyCreated, action_root.join("message_already_created")
245
+ autoload :MessageAlreadyPaused, action_root.join("message_already_paused")
246
+ autoload :MessageAlreadySuspended, action_root.join("message_already_suspended")
247
+ autoload :MessageNotCreated, action_root.join("message_not_created")
248
+ autoload :MessageNotSuspended, action_root.join("message_not_suspended")
249
+ autoload :MessageSnapshotDone, action_root.join("message_snapshot_done")
250
+ autoload :MessageSnapshotInProgress, action_root.join("message_snapshot_in_progress")
251
+ autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
252
+ autoload :MessageServerRunning, action_root.join("message_server_running")
253
+ autoload :PauseServer, action_root.join("pause_server")
254
+ autoload :ReadSSHInfo, action_root.join("read_ssh_info")
255
+ autoload :ReadState, action_root.join("read_state")
256
+ autoload :RebootServer, action_root.join("reboot_server")
257
+ autoload :ResumeServer, action_root.join("resume_server")
258
+ autoload :SuspendServer, action_root.join("suspend_server")
259
+ autoload :SyncFolders, action_root.join("sync_folders")
260
+ autoload :TakeSnapshot, action_root.join("take_snapshot")
261
+ autoload :WaitForState, action_root.join("wait_for_state")
262
+ autoload :WaitForTask, action_root.join("wait_for_task")
263
+ autoload :WarnNetworks, action_root.join("warn_networks")
264
+ autoload :CreateOrchestrationStack, action_root.join("create_orchestration_stack")
265
+ autoload :DeleteOrchestrationStack, action_root.join("delete_orchestration_stack")
266
+ end
267
+ end
268
+ end
@@ -0,0 +1,90 @@
1
+ require "fog"
2
+ require "log4r"
3
+
4
+ module VagrantPlugins
5
+ module OpenStack
6
+ module Action
7
+ # This action connects to OpenStack, verifies credentials work, and
8
+ # puts the OpenStack connection object into the `:openstack_compute` key
9
+ # in the environment.
10
+ class ConnectOpenStack
11
+ def initialize(app, env)
12
+ @app = app
13
+ @logger = Log4r::Logger.new("vagrant_openstack::action::connect_openstack")
14
+ end
15
+
16
+ def call(env)
17
+ # Get the configs
18
+ config = env[:machine].provider_config
19
+ api_key = config.api_key
20
+ endpoint = config.endpoint
21
+ username = config.username
22
+ tenant = config.tenant
23
+ region = config.region
24
+ project_name = config.project_name
25
+ project_domain = config.project_domain
26
+ user_domain = config.user_domain
27
+
28
+ # Pass proxy config down into the Fog::Connection object using
29
+ # the `connection_options` hash.
30
+ connection_options = {
31
+ :proxy => config.proxy,
32
+ :ssl_verify_peer => config.ssl_verify_peer
33
+ }
34
+
35
+ # Prepare connection parameters for use with fog service
36
+ # initialization (compute, storage, orchestration, ...).
37
+ env[:fog_openstack_params] = {
38
+ :provider => :openstack,
39
+ :connection_options => connection_options,
40
+ :openstack_username => username,
41
+ :openstack_api_key => api_key,
42
+ :openstack_auth_url => endpoint,
43
+ :openstack_tenant => tenant,
44
+ :openstack_region => region,
45
+ :openstack_project_name => project_name,
46
+ :openstack_project_domain => project_domain,
47
+ :openstack_user_domain => user_domain
48
+ }
49
+
50
+ @logger.info("Connecting to OpenStack...")
51
+ @logger.debug("API connection params: #{connection_options.inspect}")
52
+ env[:openstack_compute] = Fog::Compute.new(
53
+ env[:fog_openstack_params])
54
+
55
+ if config.network || (config.networks && !config.networks.empty?)
56
+ env[:openstack_network] = Fog::Network.new({
57
+ :provider => :openstack,
58
+ :connection_options => connection_options,
59
+ :openstack_username => username,
60
+ :openstack_api_key => api_key,
61
+ :openstack_auth_url => endpoint,
62
+ :openstack_tenant => tenant,
63
+ :openstack_region => region,
64
+ :openstack_project_name => project_name,
65
+ :openstack_project_domain => project_domain,
66
+ :openstack_user_domain => user_domain
67
+ })
68
+ end
69
+
70
+ if config.disks && !config.disks.empty?
71
+ env[:openstack_volume] = Fog::Volume.new({
72
+ :provider => :openstack,
73
+ :connection_options => connection_options,
74
+ :openstack_username => username,
75
+ :openstack_api_key => api_key,
76
+ :openstack_auth_url => endpoint,
77
+ :openstack_tenant => tenant,
78
+ :openstack_region => region,
79
+ :openstack_project_name => project_name,
80
+ :openstack_project_domain => project_domain,
81
+ :openstack_user_domain => user_domain
82
+ })
83
+ end
84
+
85
+ @app.call(env)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end