vagrant-profitbricks 1.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/README.md +326 -174
  4. data/Rakefile +4 -2
  5. data/Vagrantfile +18 -13
  6. data/example_box/Vagrantfile +9 -0
  7. data/example_box/profitbricks.box +0 -0
  8. data/lib/vagrant-profitbricks.rb +12 -11
  9. data/lib/vagrant-profitbricks/action.rb +79 -40
  10. data/lib/vagrant-profitbricks/action/connect_profitbricks.rb +14 -12
  11. data/lib/vagrant-profitbricks/action/create_server.rb +74 -67
  12. data/lib/vagrant-profitbricks/action/delete_server.rb +33 -13
  13. data/lib/vagrant-profitbricks/action/is_created.rb +3 -1
  14. data/lib/vagrant-profitbricks/action/list_flavors.rb +5 -3
  15. data/lib/vagrant-profitbricks/action/list_images.rb +6 -4
  16. data/lib/vagrant-profitbricks/action/message_already_created.rb +4 -2
  17. data/lib/vagrant-profitbricks/action/message_not_created.rb +4 -2
  18. data/lib/vagrant-profitbricks/action/read_ssh_info.rb +10 -16
  19. data/lib/vagrant-profitbricks/action/read_state.rb +19 -12
  20. data/lib/vagrant-profitbricks/action/reboot_server.rb +45 -0
  21. data/lib/vagrant-profitbricks/action/run_init_script.rb +5 -3
  22. data/lib/vagrant-profitbricks/action/start_server.rb +50 -0
  23. data/lib/vagrant-profitbricks/action/stop_server.rb +51 -0
  24. data/lib/vagrant-profitbricks/command/datacenters.rb +34 -0
  25. data/lib/vagrant-profitbricks/command/flavors.rb +19 -6
  26. data/lib/vagrant-profitbricks/command/images.rb +21 -20
  27. data/lib/vagrant-profitbricks/command/locations.rb +34 -0
  28. data/lib/vagrant-profitbricks/command/root.rb +28 -23
  29. data/lib/vagrant-profitbricks/command/servers.rb +7 -4
  30. data/lib/vagrant-profitbricks/command/snapshots.rb +34 -0
  31. data/lib/vagrant-profitbricks/command/utils.rb +27 -0
  32. data/lib/vagrant-profitbricks/config.rb +44 -39
  33. data/lib/vagrant-profitbricks/errors.rb +14 -5
  34. data/lib/vagrant-profitbricks/plugin.rb +13 -11
  35. data/lib/vagrant-profitbricks/provider.rb +8 -6
  36. data/lib/vagrant-profitbricks/version.rb +3 -1
  37. data/locales/en.yml +28 -7
  38. data/spec/spec_helper.rb +4 -2
  39. data/spec/vagrant-profitbricks/config_spec.rb +65 -96
  40. data/vagrant-profitbricks.gemspec +17 -14
  41. metadata +42 -47
  42. data/Appraisals +0 -35
  43. data/CHANGELOG.md +0 -3
  44. data/RELEASE.md +0 -15
  45. data/bootstrap.cmd +0 -16
  46. data/features/provision.feature +0 -36
  47. data/features/steps/sdk_steps.rb +0 -13
  48. data/features/steps/server_steps.rb +0 -25
  49. data/features/support/env.rb +0 -35
  50. data/features/support/fog_mock.rb +0 -17
  51. data/features/vagrant-profitbricks.feature +0 -66
  52. data/lib/vagrant-profitbricks/action/create_image.rb +0 -53
  53. data/lib/vagrant-profitbricks/action/list_keypairs.rb +0 -20
  54. data/lib/vagrant-profitbricks/action/list_networks.rb +0 -20
  55. data/lib/vagrant-profitbricks/action/list_servers.rb +0 -21
  56. data/lib/vagrant-profitbricks/command/create_image.rb +0 -21
  57. data/lib/vagrant-profitbricks/command/keypairs.rb +0 -21
  58. data/lib/vagrant-profitbricks/command/list_images.rb +0 -21
  59. data/lib/vagrant-profitbricks/command/networks.rb +0 -21
  60. data/spec/vagrant-profitbricks/actions/list_flavors_spec.rb +0 -48
  61. data/spec/vagrant-profitbricks/actions/list_images_spec.rb +0 -48
@@ -1,43 +1,63 @@
1
- require "log4r"
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
2
4
 
3
5
  module VagrantPlugins
4
6
  module ProfitBricks
5
7
  module Action
6
8
  # This deletes the running server, if there is one.
7
9
  class DeleteServer
8
- def initialize(app, env)
10
+ def initialize(app, _env)
9
11
  @app = app
10
- @logger = Log4r::Logger.new("vagrant_profitbricks::action::delete_server")
12
+ @logger = Log4r::Logger.new('vagrant_profitbricks::action::delete_server')
11
13
  end
12
14
 
13
15
  def call(env)
14
16
  compute = env[:profitbricks_compute]
15
17
  server_id = env[:machine].id
18
+ datacenter_id = env[:machine].provider_config.datacenter_id
19
+ config = env[:machine].provider_config
16
20
  server = begin
17
- compute.servers.get(server_id)
21
+ compute.servers.get(datacenter_id, server_id)
18
22
  rescue
19
23
  nil
20
24
  end
21
-
22
25
  if server.nil?
23
26
  @logger.warn "Unable to find server #{server_id}..."
24
27
  env[:ui].warn(I18n.t('vagrant_profitbricks.errors.server_not_found'))
25
28
  env[:machine].id = nil
26
29
  else
27
30
  @logger.info "Deleting server #{server_id}..."
28
- env[:ui].info(I18n.t("vagrant_profitbricks.deleting_server"))
29
-
30
- server.attached_volumes.each do |vol_info|
31
- volume = compute.volumes.get(vol_info['id'])
32
- volume.delete if volume
31
+ env[:ui].info(I18n.t('vagrant_profitbricks.deleting_server'))
32
+
33
+ volumes = compute.list_attached_volumes(datacenter_id, server_id)
34
+ nics = compute.get_all_nic(datacenter_id, server_id)
35
+ if server.delete
36
+ 30.times do |_t|
37
+ begin
38
+ s = compute.servers.get(datacenter_id, server_id)
39
+ rescue Excon::Error::NotFound
40
+ end
41
+ break unless s
42
+ sleep 10
43
+ end
33
44
  end
34
- server.delete
35
- env[:machine].id = nil
36
45
 
46
+ nics.body['items'].each do |nic|
47
+ if nic['properties']['lan'] != config.lan_id
48
+ compute.delete_lan(datacenter_id, nic['properties']['lan'])
49
+ end
50
+ end
51
+
52
+ volumes.body['items'].each do |volume|
53
+ compute.delete_volume(datacenter_id, volume['id'])
54
+ end
55
+
56
+ env[:machine].id = nil
37
57
  @app.call(env)
38
58
  end
39
59
  end
40
60
  end
41
61
  end
42
62
  end
43
- end
63
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module VagrantPlugins
2
4
  module ProfitBricks
3
5
  module Action
4
6
  class IsCreated
5
- def initialize(app, env)
7
+ def initialize(app, _env)
6
8
  @app = app
7
9
  end
8
10
 
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module VagrantPlugins
2
4
  module ProfitBricks
3
5
  module Action
4
6
  class ListFlavors
5
- def initialize(app, env)
7
+ def initialize(app, _env)
6
8
  @app = app
7
9
  end
8
10
 
9
11
  def call(env)
10
12
  compute_service = env[:profitbricks_compute]
11
- env[:ui].info ('%-36s %s' % ['Flavor ID', 'Flavor Name'])
13
+ env[:ui].info format('%-36s %s', 'Flavor ID', 'Flavor Name')
12
14
  compute_service.flavors.sort_by(&:id).each do |flavor|
13
- env[:ui].info ('%-36s %s' % [flavor.id, flavor.name])
15
+ env[:ui].info format('%-36s %s', flavor.id, flavor.name)
14
16
  end
15
17
  @app.call(env)
16
18
  end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module VagrantPlugins
2
4
  module ProfitBricks
3
5
  module Action
4
6
  class ListImages
5
- def initialize(app, env)
7
+ def initialize(app, _env)
6
8
  @app = app
7
9
  end
8
10
 
9
11
  def call(env)
10
12
  compute_service = env[:profitbricks_compute]
11
- env[:ui].info ('%-36s %s' % ['Image ID', 'Image Name'])
12
- compute_service.images.sort_by(&:name).each do |image|
13
- env[:ui].info ('%-36s %s' % [image.id.to_s, image.name])
13
+ env[:ui].info format('%-20s %-20s %s', 'ID', 'Name', 'Location')
14
+ compute_service.images.sort_by(&:name).each do |server|
15
+ env[:ui].info format('%-20s %-20s %s', server.id, server.name, server.location)
14
16
  end
15
17
  @app.call(env)
16
18
  end
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module VagrantPlugins
2
4
  module ProfitBricks
3
5
  module Action
4
6
  class MessageAlreadyCreated
5
- def initialize(app, env)
7
+ def initialize(app, _env)
6
8
  @app = app
7
9
  end
8
10
 
9
11
  def call(env)
10
- env[:ui].info(I18n.t("vagrant_profitbricks.already_created"))
12
+ env[:ui].info(I18n.t('vagrant_profitbricks.already_created'))
11
13
  @app.call(env)
12
14
  end
13
15
  end
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module VagrantPlugins
2
4
  module ProfitBricks
3
5
  module Action
4
6
  class MessageNotCreated
5
- def initialize(app, env)
7
+ def initialize(app, _env)
6
8
  @app = app
7
9
  end
8
10
 
9
11
  def call(env)
10
- env[:ui].info(I18n.t("vagrant_profitbricks.not_created"))
12
+ env[:ui].info(I18n.t('vagrant_profitbricks.not_created'))
11
13
  @app.call(env)
12
14
  end
13
15
  end
@@ -1,4 +1,6 @@
1
- require "log4r"
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
2
4
 
3
5
  module VagrantPlugins
4
6
  module ProfitBricks
@@ -6,9 +8,9 @@ module VagrantPlugins
6
8
  # This action reads the SSH info for the machine and puts it into the
7
9
  # `:machine_ssh_info` key in the environment.
8
10
  class ReadSSHInfo
9
- def initialize(app, env)
11
+ def initialize(app, _env)
10
12
  @app = app
11
- @logger = Log4r::Logger.new("vagrant_profitbricks::action::read_ssh_info")
13
+ @logger = Log4r::Logger.new('vagrant_profitbricks::action::read_ssh_info')
12
14
  end
13
15
 
14
16
  def call(env)
@@ -21,7 +23,7 @@ module VagrantPlugins
21
23
  return nil if machine.id.nil?
22
24
 
23
25
  # Find the machine
24
- server = profitbricks.servers.get(machine.id)
26
+ server = profitbricks.servers.get(machine.provider_config.datacenter_id, machine.id)
25
27
  if server.nil?
26
28
  # The machine can't be found
27
29
  @logger.info("Machine couldn't be found, assuming it got destroyed.")
@@ -29,18 +31,10 @@ module VagrantPlugins
29
31
  return nil
30
32
  end
31
33
 
32
- if server.interfaces.empty? || server.internet_access == false
33
- # The machine can't be found
34
- @logger.info("Server has no internet access.")
35
- machine.id = nil
36
- return nil
37
- end
38
-
39
- # Read the DNS info
40
- return {
41
- :host => server.nics[0].ips,
42
- :port => 22,
43
- :username => "root"
34
+ {
35
+ host: server.nics['items'][0]['properties']['ips'][0],
36
+ port: 22,
37
+ username: 'root'
44
38
  }
45
39
  end
46
40
  end
@@ -1,4 +1,6 @@
1
- require "log4r"
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
2
4
 
3
5
  module VagrantPlugins
4
6
  module ProfitBricks
@@ -6,32 +8,37 @@ module VagrantPlugins
6
8
  # This action reads the state of the machine and puts it in the
7
9
  # `:machine_state_id` key in the environment.
8
10
  class ReadState
9
- def initialize(app, env)
11
+ def initialize(app, _env)
10
12
  @app = app
11
- @logger = Log4r::Logger.new("vagrant_profitbricks::action::read_state")
13
+ @logger = Log4r::Logger.new('vagrant_profitbricks::action::read_state')
12
14
  end
13
15
 
14
16
  def call(env)
15
17
  env[:machine_state_id] = read_state(env[:profitbricks_compute], env[:machine])
16
-
17
18
  @app.call(env)
18
19
  end
19
20
 
20
21
  def read_state(profitbricks, machine)
21
22
  return :not_created if machine.id.nil?
22
23
 
23
- # Find the machine
24
- server = profitbricks.servers.get(machine.provider_config.datacenter_id, machine.id)
25
- rescue Excon::Error::NotFound
26
- if server.nil? || server.state == "DELETED"
27
- # The machine can't be found
28
- @logger.info("Machine not found or deleted, assuming it got destroyed.")
29
- machine.id = nil
24
+ server = begin
25
+ profitbricks.servers.get(machine.provider_config.datacenter_id, machine.id)
26
+ rescue
27
+ nil
28
+ end
29
+
30
+ if server.nil?
31
+ @logger.warn 'Unable to find server...'
30
32
  return :not_created
31
33
  end
34
+ if server.state == 'SHUTOFF'
35
+ return :off
36
+ elsif server.state == 'INACTIVE'
37
+ return :off
38
+ end
32
39
 
33
40
  # Return the state
34
- return server.state.downcase.to_sym
41
+ server.state.downcase.to_sym
35
42
  end
36
43
  end
37
44
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module ProfitBricks
5
+ module Action
6
+ class Reboot
7
+ def initialize(app, _env)
8
+ @app = app
9
+ @logger = Log4r::Logger.new('vagrant_profitbricks::action::stopping_server')
10
+ end
11
+
12
+ def call(env)
13
+ compute = env[:profitbricks_compute]
14
+ server_id = env[:machine].id
15
+ datacenter_id = env[:machine].provider_config.datacenter_id
16
+
17
+ server = begin
18
+ compute.servers.get(datacenter_id, server_id)
19
+ rescue
20
+ nil
21
+ end
22
+ if server.nil?
23
+ @logger.warn "Unable to find server #{server_id}..."
24
+ env[:ui].warn(I18n.t('vagrant_profitbricks.errors.server_not_found'))
25
+ env[:machine].id = nil
26
+ else
27
+ @logger.info "Rebooting server #{server_id}..."
28
+ env[:ui].info(I18n.t('vagrant_profitbricks.rebooting_server'))
29
+ end
30
+ if server.reboot
31
+ 30.times do |_t|
32
+ begin
33
+ s = compute.servers.get(datacenter_id, server_id)
34
+ break if s.vm_state == 'RUNNING'
35
+ sleep 10
36
+ end
37
+ end
38
+ end
39
+
40
+ @app.call(env)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,12 +1,14 @@
1
- require "log4r"
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
2
4
 
3
5
  module VagrantPlugins
4
6
  module ProfitBricks
5
7
  module Action
6
8
  class RunInitScript
7
- def initialize(app, env)
9
+ def initialize(app, _env)
8
10
  @app = app
9
- @logger = Log4r::Logger.new("vagrant_profitbricks::action::run_init_script")
11
+ @logger = Log4r::Logger.new('vagrant_profitbricks::action::run_init_script')
10
12
  end
11
13
 
12
14
  def call(env)
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module ProfitBricks
5
+ module Action
6
+ class Start
7
+ def initialize(app, _env)
8
+ @app = app
9
+ @logger = Log4r::Logger.new('vagrant_profitbricks::action::starting_server')
10
+ end
11
+
12
+ def call(env)
13
+ if env[:machine_state] == :not_created
14
+ env[:ui].info(I18n.t('vagrant_profitbricks.not_created'))
15
+ @app.call(env)
16
+ end
17
+
18
+ compute = env[:profitbricks_compute]
19
+ server_id = env[:machine].id
20
+ datacenter_id = env[:machine].provider_config.datacenter_id
21
+
22
+ server = begin
23
+ compute.servers.get(datacenter_id, server_id)
24
+ rescue
25
+ nil
26
+ end
27
+ if server.nil?
28
+ @logger.warn "Unable to find server #{server_id}..."
29
+ env[:ui].warn(I18n.t('vagrant_profitbricks.errors.server_not_found'))
30
+ env[:machine].id = nil
31
+ else
32
+ @logger.info "Starting server #{server_id}..."
33
+ env[:ui].info(I18n.t('vagrant_profitbricks.starting_server'))
34
+ end
35
+ if server.start
36
+ 30.times do |_t|
37
+ begin
38
+ s = compute.servers.get(datacenter_id, server_id)
39
+ break if s.vm_state == 'RUNNING'
40
+ sleep 10
41
+ end
42
+ end
43
+ end
44
+
45
+ @app.call(env)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module ProfitBricks
5
+ module Action
6
+ class Stop
7
+ def initialize(app, _env)
8
+ @app = app
9
+ @logger = Log4r::Logger.new('vagrant_profitbricks::action::stopping_server')
10
+ end
11
+
12
+ def call(env)
13
+ compute = env[:profitbricks_compute]
14
+ server_id = env[:machine].id
15
+ datacenter_id = env[:machine].provider_config.datacenter_id
16
+
17
+ server = begin
18
+ compute.servers.get(datacenter_id, server_id)
19
+ rescue
20
+ nil
21
+ end
22
+
23
+ if server.nil?
24
+ @logger.warn "Unable to find server #{server_id}..."
25
+ env[:ui].warn(I18n.t('vagrant_profitbricks.errors.server_not_found'))
26
+ env[:machine].id = nil
27
+ else
28
+ @logger.info "Stopping server #{server_id}..."
29
+ env[:ui].info(I18n.t('vagrant_profitbricks.stopping_server'))
30
+ end
31
+ stopped = begin
32
+ server.stop
33
+ rescue
34
+ false
35
+ end
36
+ if stopped
37
+ 30.times do |_t|
38
+ begin
39
+ s = compute.servers.get(datacenter_id, server_id)
40
+ break if s.vm_state == 'SHUTOFF'
41
+ sleep 10
42
+ end
43
+ end
44
+ end
45
+
46
+ @app.call(env)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end