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
@@ -0,0 +1,84 @@
1
+ require 'vagrant/util/retryable'
2
+ require 'timeout'
3
+
4
+ require "log4r"
5
+
6
+ module VagrantPlugins
7
+ module OpenStack
8
+ module Action
9
+ # This deletes the running server, if there is one.
10
+ class DeleteServer
11
+ include Vagrant::Util::Retryable
12
+
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new("vagrant_openstack::action::delete_server")
16
+ end
17
+
18
+ def call(env)
19
+ machine = env[:machine]
20
+ id = machine.id || (env[:openstack_compute].servers.all( :name => machine.name ).length == 1 and
21
+ env[:openstack_compute].servers.all( :name => machine.name ).first.id)
22
+
23
+ if id
24
+ env[:ui].info(I18n.t("vagrant_openstack.deleting_server"))
25
+
26
+ # TODO: Validate the fact that we get a server back from the API.
27
+ server = env[:openstack_compute].servers.get(id)
28
+ if server
29
+ # get volumes before destroying server
30
+ volumes = server.volume_attachments
31
+
32
+ ip = server.floating_ip_address
33
+
34
+ retryable(:on => Timeout::Error, :tries => 20) do
35
+ # If we're interrupted don't worry about waiting
36
+ next if env[:interrupted]
37
+
38
+ begin
39
+ server.destroy if server
40
+ status = Timeout::timeout(10) {
41
+ while server.reload
42
+ sleep(1)
43
+ end
44
+ }
45
+ rescue RuntimeError => e
46
+ # If we don't have an error about a state transition, then
47
+ # we just move on.
48
+ raise if e.message !~ /should have transitioned/
49
+ raise Errors::ServerNotDestroyed
50
+ rescue Fog::Compute::OpenStack::NotFound
51
+ # If we don't have a server anymore we should be done here just continue on
52
+ end
53
+ end
54
+
55
+ if machine.provider_config.floating_ip_pool && machine.provider_config.floating_ip == ":auto"
56
+ address = env[:openstack_compute].list_all_addresses.body["floating_ips"].find{|i| i["ip"] == ip}
57
+ if address
58
+ env[:openstack_compute].release_address(address["id"])
59
+ end
60
+ end
61
+
62
+ env[:ui].info(I18n.t("vagrant_openstack.deleting_volumes"))
63
+ volumes.each do |compute_volume|
64
+ volume = env[:openstack_volume].volumes.get(compute_volume["id"])
65
+ if volume
66
+ env[:ui].info("Deleting volume: #{volume.display_name}")
67
+ begin
68
+ volume.destroy
69
+ rescue Excon::Errors::Error => e
70
+ raise Errors::VolumeBadState, :volume => volume.display_name, :state => e.message
71
+ end
72
+ end
73
+ end
74
+ end
75
+ else
76
+ env[:ui].info(I18n.t("vagrant_openstack.not_created"))
77
+ end
78
+
79
+ @app.call(env)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,27 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module OpenStack
5
+ module Action
6
+ # This hard reboots a running server, if there is one.
7
+ class HardRebootServer
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant_openstack::action::hard_reboot_server")
11
+ end
12
+
13
+ def call(env)
14
+ if env[:machine].id
15
+ env[:ui].info(I18n.t("vagrant_openstack.hard_rebooting_server"))
16
+
17
+ # TODO: Validate the fact that we get a server back from the API.
18
+ server = env[:openstack_compute].servers.get(env[:machine].id)
19
+ server.reboot('HARD')
20
+ end
21
+
22
+ @app.call(env)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class IsCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:result] = env[:machine].state.id == :active
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class IsPaused
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:result] = env[:machine].state.id == :paused
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class IsSnapshoting
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env[:machine].id
11
+ infos = env[:openstack_compute].get_server_details(env[:machine].id)
12
+ task = infos.body['server']['OS-EXT-STS:task_state']
13
+ if task == 'image_snapshot' || task == 'image_pending_upload'
14
+ env[:result] = true
15
+ else
16
+ env[:result] = false
17
+ end
18
+ end
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class IsSuspended
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:result] = env[:machine].state.id == :suspended
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class MessageAlreadyCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_openstack.already_created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class MessageAlreadyPaused
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_openstack.already_paused"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class MessageAlreadySuspended
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_openstack.already_suspended"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class MessageNotCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_openstack.not_created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class MessageServerRunning
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_openstack.server_running", name: env[:machine].name))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class MessageSnapshotDone
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_openstack.snapshot_done"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class MessageSnapshotInProgress
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_openstack.snapshot_in_progress"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module OpenStack
3
+ module Action
4
+ class MessageWillNotDestroy
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_openstack.will_not_destroy", name: env[:machine].name))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module OpenStack
5
+ module Action
6
+ # This pauses a running server, if there is one.
7
+ class PauseServer
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant_openstack::action::pause_server")
11
+ end
12
+
13
+ def call(env)
14
+ if env[:machine].id
15
+ env[:ui].info(I18n.t("vagrant_openstack.pausing_server"))
16
+
17
+ # TODO: Validate the fact that we get a server back from the API.
18
+ server = env[:openstack_compute].servers.get(env[:machine].id)
19
+ env[:openstack_compute].pause_server(server.id)
20
+ end
21
+
22
+ @app.call(env)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,103 @@
1
+ require "log4r"
2
+ require "ipaddr"
3
+
4
+ module VagrantPlugins
5
+ module OpenStack
6
+ module Action
7
+ # This action reads the SSH info for the machine and puts it into the
8
+ # `:machine_ssh_info` key in the environment.
9
+ class ReadSSHInfo
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_openstack::action::read_ssh_info")
13
+ end
14
+
15
+ def call(env)
16
+ env[:machine_ssh_info] = read_ssh_info(env[:openstack_compute], env[:machine], env[:floating_ip])
17
+
18
+ @app.call(env)
19
+ end
20
+
21
+ def read_ssh_info(openstack, machine, floating_ip)
22
+ id = machine.id || openstack.servers.all( :name => machine.name ).first.id rescue nil
23
+ return nil if id.nil?
24
+ server = openstack.servers.get(id)
25
+ if server.nil?
26
+ # The machine can't be found
27
+ @logger.info("Machine couldn't be found, assuming it got destroyed.")
28
+ machine.id = nil
29
+ return nil
30
+ end
31
+
32
+ config = machine.provider_config
33
+
34
+ # Print a list of the available networks
35
+ server.addresses.each do |network_name, network_info|
36
+ @logger.debug("OpenStack Network Name: #{network_name}")
37
+ end
38
+
39
+ if config.network
40
+ host = server.addresses[config.network].last['addr'] rescue nil
41
+ else
42
+ if config.address_id.to_sym == :floating_ip
43
+ host = floating_ip
44
+ else
45
+ host = server.addresses[config.address_id].last['addr'] rescue nil
46
+ end
47
+ end
48
+
49
+ # If host is still nil, try to find the IP address another way
50
+ if host.nil?
51
+ @logger.debug("Was unable to determine what network to use. Trying to find a valid IP to use.")
52
+ if server.public_ip_addresses.length > 0
53
+ @logger.debug("Public IP addresses available: #{server.public_ip_addresses}")
54
+ if floating_ip
55
+ if server.public_ip_addresses.include?(floating_ip)
56
+ @logger.debug("Using the floating IP defined in Vagrantfile.")
57
+ host = machine.floating_ip
58
+ else
59
+ @logger.debug("The floating IP that was specified is not available to this instance.")
60
+ raise Errors::FloatingIPNotValid
61
+ end
62
+ else
63
+ host = server.public_ip_address
64
+ @logger.debug("Using the first available public IP address: #{host}.")
65
+ end
66
+ elsif server.private_ip_addresses.length > 0
67
+ @logger.debug("Private IP addresses available: #{server.private_ip_addresses}")
68
+ if config.ssh_ip_family.nil?
69
+ host = server.private_ip_address
70
+ @logger.debug("Using the first available private IP address: #{host}.")
71
+ else
72
+ for ip in server.private_ip_addresses
73
+ addr = IPAddr.new ip
74
+ if addr.send("#{config.ssh_ip_family}?".to_sym)
75
+ host = ip.to_s
76
+ @logger.debug("Using the first available #{config.ssh_ip_family} IP address: #{host}.")
77
+ break
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ # If host got this far and is still nil/empty, raise an error or
85
+ # else vagrant will try connecting to localhost which will never
86
+ # make sense in this scenario
87
+ if host.nil? or host.empty?
88
+ @logger.debug("No valid SSH host could be found.")
89
+ raise Errors::SSHNoValidHost
90
+ end
91
+
92
+ # Read the DNS info
93
+ return {
94
+ # Usually there should only be one public IP
95
+ :host => host,
96
+ :port => 22,
97
+ :username => config.ssh_username
98
+ }
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end