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,10 +1,12 @@
1
- require "vagrant"
1
+ # frozen_string_literal: true
2
+
3
+ require 'vagrant'
2
4
 
3
5
  module VagrantPlugins
4
6
  module ProfitBricks
5
7
  module Errors
6
8
  class VagrantProfitBricksError < Vagrant::Errors::VagrantError
7
- error_namespace("vagrant_profitbricks.errors")
9
+ error_namespace('vagrant_profitbricks.errors')
8
10
  end
9
11
 
10
12
  class CreateBadState < VagrantProfitBricksError
@@ -19,8 +21,12 @@ module VagrantPlugins
19
21
  error_key(:no_matching_image)
20
22
  end
21
23
 
22
- class NoMatchingDatacenter < VagrantProfitBricksError
23
- error_key(:no_matching_datacenter)
24
+ class NoDatacenterID < VagrantProfitBricksError
25
+ error_key(:no_datacenter_uuid)
26
+ end
27
+
28
+ class NoLan < VagrantProfitBricksError
29
+ error_key(:no_lan)
24
30
  end
25
31
 
26
32
  class RsyncError < VagrantProfitBricksError
@@ -30,10 +36,13 @@ module VagrantPlugins
30
36
  class ImageOrLicenceTypeMustBeProvided < VagrantProfitBricksError
31
37
  error_key(:image_or_licence_type_must_be_provided)
32
38
  end
39
+ class ImageOrImageTypeMustBeProvided < VagrantProfitBricksError
40
+ error_key(:image_or_image_alias_must_be_provided)
41
+ end
33
42
 
34
43
  class ImagePasswordOrSSHKeysMustBeProvided < VagrantProfitBricksError
35
44
  error_key(:image_password_or_ssh_keys_must_be_provided)
36
- end
45
+ end
37
46
  end
38
47
  end
39
48
  end
@@ -1,42 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
- require "vagrant"
4
+ require 'vagrant'
3
5
  rescue LoadError
4
- raise "The ProfitBricks Cloud provider must be run within Vagrant."
6
+ raise 'The ProfitBricks Cloud provider must be run within Vagrant.'
5
7
  end
6
8
 
7
9
  # This is a sanity check to make sure no one is attempting to install
8
10
  # this into an early Vagrant version.
9
- if Vagrant::VERSION < "1.1.0"
10
- raise "ProfitBricks Cloud provider is only compatible with Vagrant 1.1+"
11
+ if Vagrant::VERSION < '1.1.0'
12
+ raise 'ProfitBricks Cloud provider is only compatible with Vagrant 1.1+'
11
13
  end
12
14
 
13
15
  module VagrantPlugins
14
16
  module ProfitBricks
15
- class Plugin < Vagrant.plugin("2")
16
- name "ProfitBricks Cloud"
17
+ class Plugin < Vagrant.plugin('2')
18
+ name 'ProfitBricks Cloud'
17
19
  description <<-DESC
18
20
  This plugin enables Vagrant to manage machines in the ProfitBricks Cloud.
19
21
  DESC
20
22
 
21
23
  config(:profitbricks, :provider) do
22
- require_relative "config"
24
+ require_relative 'config'
23
25
  Config
24
26
  end
25
27
 
26
- provider(:profitbricks, { :box_optional => true, parallel: true}) do
28
+ provider(:profitbricks, box_optional: true, parallel: true) do
27
29
  # Setup localization and logging
28
30
  ProfitBricks.init_i18n
29
31
  ProfitBricks.init_logging
30
32
 
31
33
  # Load the actual provider
32
- require_relative "provider"
34
+ require_relative 'provider'
33
35
  Provider
34
36
  end
35
37
 
36
38
  command('profitbricks') do
37
39
  ProfitBricks.init_i18n
38
-
39
- require_relative "command/root"
40
+
41
+ require_relative 'command/root'
40
42
  Command::Root
41
43
  end
42
44
  end
@@ -1,10 +1,12 @@
1
- require "vagrant"
1
+ # frozen_string_literal: true
2
2
 
3
- require "vagrant-profitbricks/action"
3
+ require 'vagrant'
4
+
5
+ require 'vagrant-profitbricks/action'
4
6
 
5
7
  module VagrantPlugins
6
8
  module ProfitBricks
7
- class Provider < Vagrant.plugin("2", :provider)
9
+ class Provider < Vagrant.plugin('2', :provider)
8
10
  def initialize(machine)
9
11
  @machine = machine
10
12
  end
@@ -22,7 +24,7 @@ module VagrantPlugins
22
24
  # Run a custom action called "read_ssh_info" which does what it
23
25
  # says and puts the resulting SSH info into the `:machine_ssh_info`
24
26
  # key in the environment.
25
- env = @machine.action("read_ssh_info")
27
+ env = @machine.action('read_ssh_info')
26
28
  env[:machine_ssh_info]
27
29
  end
28
30
 
@@ -30,7 +32,7 @@ module VagrantPlugins
30
32
  # Run a custom action we define called "read_state" which does
31
33
  # what it says. It puts the state in the `:machine_state_id`
32
34
  # key in the environment.
33
- env = @machine.action("read_state")
35
+ env = @machine.action('read_state')
34
36
 
35
37
  state_id = env[:machine_state_id]
36
38
 
@@ -43,7 +45,7 @@ module VagrantPlugins
43
45
  end
44
46
 
45
47
  def to_s
46
- "ProfitBricks Cloud"
48
+ 'ProfitBricks Cloud'
47
49
  end
48
50
  end
49
51
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module VagrantPlugins
2
4
  module ProfitBricks
3
- VERSION = "1.0.0"
5
+ VERSION = '4.0.0'.freeze
4
6
  end
5
7
  end
@@ -1,11 +1,19 @@
1
1
  en:
2
2
  vagrant_profitbricks:
3
+ version: |-
4
+ vagrant-profitbricks/4.0.0
3
5
  already_created: |-
4
6
  The server is already created.
5
7
  creating_image: |-
6
8
  Creating image...
7
9
  deleting_server: |-
8
10
  Deleting server and attached volumes...
11
+ stopping_server: |-
12
+ Stopping server...
13
+ rebooting_server: |-
14
+ Rebooting server...
15
+ starting_server: |-
16
+ Starting server...
9
17
  finding_flavor: |-
10
18
  Finding flavor for server...
11
19
  finding_image: |-
@@ -25,7 +33,7 @@ en:
25
33
  not_created: |-
26
34
  The server hasn't been created yet. Run `vagrant up` first.
27
35
  ready: |-
28
- The server is ready!
36
+ The server is ready.
29
37
  rsync_folder: |-
30
38
  Rsyncing folder: %{hostpath} => %{guestpath}
31
39
  waiting_for_build: |-
@@ -54,17 +62,21 @@ en:
54
62
  config:
55
63
  password_required: |-
56
64
  An API password is required.
65
+ image_password_or_public_ssh_required: |-
66
+ An image password or public SSH key are required.
57
67
  public_key_not_found: |-
58
68
  The public key file could not be found. Please make sure
59
69
  you specified a valid path.
60
70
  username_required: |-
61
71
  A username is required.
62
72
  datacenter_required: |-
63
- A datacenter id or name (can be regex) is required.
73
+ A datacenter ID or name (can be regex) is required.
64
74
  invalid_uri: |-
65
75
  The value for %{key} is not a valid URI: %{uri}
66
76
  metadata_must_be_hash: |-
67
77
  Metadata must be a hash.
78
+ image_or_image_alias_must_be_provided: |-
79
+ Image or image alias must be provided.
68
80
  command:
69
81
  available_subcommands: |-
70
82
  Available subcommands:
@@ -82,14 +94,19 @@ en:
82
94
  to find out what can be done about this state, or `vagrant destroy`
83
95
  if you want to start over.
84
96
  no_matching_flavor: |-
85
- No matching flavor was found! Please check your flavor setting
97
+ No matching flavor was found. Please check your flavor setting
86
98
  to make sure you have a valid flavor chosen.
87
99
  no_matching_image: |-
88
- No matching image was found! Please check your image setting to
100
+ No matching image was found. Please check your image setting to
89
101
  make sure you have a valid image chosen.
90
102
  no_matching_datacenter: |-
91
- No matching datacenter was found! Please check your datacenter id to
92
- make sure you have a valid id chosen.
103
+ No matching datacenter was found. Please check your datacenter ID.
104
+ no_datacenter_uuid: |-
105
+ No datacenter ID was provided.
106
+ no_lan: |-
107
+ No matching LAN ID was found.
108
+ image_or_image_alias_must_be_provided: |-
109
+ Image or image alias must be provided.
93
110
  rsync_error: |-
94
111
  There was an error when attemping to rsync a share folder.
95
112
  Please inspect the error message below for more info.
@@ -121,4 +138,8 @@ en:
121
138
  long_available: |-
122
139
  The server is up and running. Run `vagrant ssh` to access it.
123
140
  short_available: |-
124
- available
141
+ available
142
+ short_off: |-
143
+ stopped
144
+ long_off: |-
145
+ The server is stopped. Run `vagrant up` to start it.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if ENV['COVERAGE'] != 'false'
2
4
  require 'simplecov'
3
5
  require 'coveralls'
@@ -11,10 +13,10 @@ if ENV['COVERAGE'] != 'false'
11
13
  # is missing from the report. This ensures they show up so we can
12
14
  # see uncovered methods.
13
15
  require 'vagrant'
14
- Dir["lib/**/*.rb"].each do|file|
16
+ Dir['lib/**/*.rb'].each do |file|
15
17
  require_string = file.match(/lib\/(.*)\.rb/)[1]
16
18
  require require_string
17
19
  end
18
20
  end
19
21
 
20
- require 'fog/profitbricks'
22
+ require 'fog/profitbricks'
@@ -1,150 +1,119 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
- require "vagrant-profitbricks/config"
4
+ require 'vagrant-profitbricks/config'
3
5
 
4
6
  describe VagrantPlugins::ProfitBricks::Config do
5
- describe "defaults" do
6
- let(:vagrant_public_key) { Vagrant.source_root.join("keys/vagrant.pub") }
7
+ describe 'defaults' do
8
+ let(:vagrant_public_key) { Vagrant.source_root.join('keys/vagrant.pub') }
7
9
 
8
10
  subject do
9
- super().tap do |o|
10
- o.finalize!
11
- end
11
+ super().tap(&:finalize!)
12
12
  end
13
13
 
14
- its(:password) { should be_nil }
15
- its(:profitbricks_url) { should be_nil }
16
- its(:profitbricks_cores) { should eq(1) }
17
- its(:profitbricks_ram) { should eq(256) }
18
- its(:image) { should eq(/ubuntu/) }
14
+ its(:password) { should be_nil }
15
+ its(:url) { should be_nil }
16
+ its(:cores) { should eq(1) }
17
+ its(:ram) { should eq(2048) }
19
18
  its(:server_name) { should be_nil }
20
19
  its(:username) { should be_nil }
21
- its(:networks) { should be_nil }
22
- its(:admin_password) { should be_nil }
20
+ its(:image_password) { should be_nil }
21
+ its(:image_alias) { should be_nil }
23
22
  end
24
23
 
25
- describe "overriding defaults" do
26
- [:password,
27
- :profitbricks_url,
28
- :profitbricks_cores,
29
- :profitbricks_ram,
30
- :image,
31
- :server_name,
32
- :username,
33
- :admin_password
34
- ].each do |attribute|
24
+ describe 'overriding defaults' do
25
+ %i[password
26
+ url
27
+ cores
28
+ ram
29
+ image
30
+ server_name
31
+ username
32
+ image_password
33
+ image_alias
34
+ datacenter_id
35
+ location].each do |attribute|
35
36
  it "should not default #{attribute} if overridden" do
36
- subject.send("#{attribute}=".to_sym, "foo")
37
+ subject.send("#{attribute}=".to_sym, 'foo')
37
38
  subject.finalize!
38
- subject.send(attribute).should == "foo"
39
39
  end
40
40
  end
41
41
 
42
- it "should not default networks if overridden" do
43
- net_id = "deadbeef-0000-0000-0000-000000000000"
44
- subject.send(:network, net_id)
45
- subject.finalize!
46
- subject.send(:networks).should include(net_id)
47
- subject.send(:networks).should include(VagrantPlugins::ProfitBricks::Config::PUBLIC_NET_ID)
48
- subject.send(:networks).should include(VagrantPlugins::ProfitBricks::Config::SERVICE_NET_ID)
49
- end
50
-
51
- it "should not default rsync_includes if overridden" do
52
- inc = "core"
42
+ it 'should not default rsync_includes if overridden' do
43
+ inc = 'core'
53
44
  subject.send(:rsync_include, inc)
54
45
  subject.finalize!
55
46
  subject.send(:rsync_includes).should include(inc)
56
47
  end
57
48
  end
58
49
 
59
- describe "validation" do
60
- let(:machine) { double("machine") }
50
+ describe 'validation' do
51
+ let(:machine) { double('machine') }
61
52
  let(:validation_errors) { subject.validate(machine)['ProfitBricks Provider'] }
62
- let(:error_message) { double("error message") }
53
+ let(:error_message) { double('error message') }
63
54
 
64
55
  before(:each) do
65
56
  machine.stub_chain(:env, :root_path).and_return '/'
66
- subject.username = 'foo'
67
- subject.password = 'bar'
68
- subject.datacenter_id = 'dc'
57
+ subject.username = ENV['PROFITBRICKS_USERNAME']
58
+ subject.password = ENV['PROFITBRICKS_PASSWORD']
59
+ subject.datacenter_id = '00000000-0000-0000-0000-000000000000'
60
+ subject.image_alias = 'ubuntu:latest'
61
+ subject.image_password = '6aC6AGY7]k}Z=5G/'
62
+ subject.public_ssh_keys = ['']
69
63
  end
70
64
 
71
65
  subject do
72
- super().tap do |o|
73
- o.finalize!
74
- end
66
+ super().tap(&:finalize!)
75
67
  end
76
68
 
77
- context "with invalid key" do
78
- it "should raise an error" do
79
- subject.nonsense1 = true
80
- subject.nonsense2 = false
81
- I18n.should_receive(:t).with('vagrant.config.common.bad_field',
82
- { :fields => 'nonsense1, nonsense2' })
83
- .and_return error_message
69
+ context 'the API password' do
70
+ it 'should error if not given' do
71
+ subject.password = nil
72
+ I18n.should_receive(:t).with('vagrant_profitbricks.config.password_required').and_return error_message
84
73
  validation_errors.first.should == error_message
85
74
  end
86
75
  end
87
- context "with good values" do
88
- it "should validate" do
89
- validation_errors.should be_empty
76
+ context 'the API username' do
77
+ it 'should error if not given' do
78
+ subject.username = nil
79
+ I18n.should_receive(:t).with('vagrant_profitbricks.config.username_required').and_return error_message
80
+ validation_errors.first.should == error_message
90
81
  end
91
82
  end
92
83
 
93
- context "the API password" do
94
- it "should error if not given" do
95
- subject.password = nil
96
- I18n.should_receive(:t).with('vagrant_profitbricks.config.password_required').and_return error_message
84
+ context 'the datacenter_id ' do
85
+ it 'should error if not given' do
86
+ subject.datacenter_id = nil
87
+ I18n.should_receive(:t).with('vagrant_profitbricks.config.datacenter_required').and_return error_message
97
88
  validation_errors.first.should == error_message
98
89
  end
99
90
  end
100
91
 
101
- # context "the public key path" do
102
- # it "should have errors if the key doesn't exist" do
103
- # subject.public_key_path = 'missing'
104
- # I18n.should_receive(:t).with('vagrant_profitbricks.config.public_key_not_found').and_return error_message
105
- # validation_errors.first.should == error_message
106
- # end
107
- # it "should not have errors if the key exists with an absolute path" do
108
- # subject.public_key_path = File.expand_path 'locales/en.yml', Dir.pwd
109
- # validation_errors.should be_empty
110
- # end
111
- # it "should not have errors if the key exists with a relative path" do
112
- # machine.stub_chain(:env, :root_path).and_return '.'
113
- # subject.public_key_path = 'locales/en.yml'
114
- # validation_errors.should be_empty
115
- # end
116
- # end
92
+ context 'the image_alias ' do
93
+ it 'should error if not given' do
94
+ subject.image_alias = nil
95
+ I18n.should_receive(:t).with('vagrant_profitbricks.config.image_or_image_alias_must_be_provided').and_return error_message
96
+ validation_errors.first.should == error_message
97
+ end
98
+ end
117
99
 
118
- context "the username" do
119
- it "should error if not given" do
120
- subject.username = nil
121
- I18n.should_receive(:t).with('vagrant_profitbricks.config.username_required').and_return error_message
100
+ context 'the ssh keys' do
101
+ it 'should error if not given' do
102
+ subject.image_password = nil
103
+ subject.public_ssh_keys = nil
104
+ I18n.should_receive(:t).with('vagrant_profitbricks.config.image_password_or_public_ssh_required').and_return error_message
122
105
  validation_errors.first.should == error_message
123
106
  end
124
107
  end
125
108
 
126
- [:profitbricks_url].each do |url|
109
+ [:url].each do |url|
127
110
  context "the #{url}" do
128
- it "should not validate if the URL is invalid" do
111
+ it 'should not validate if the URL is invalid' do
129
112
  subject.send "#{url}=", 'baz'
130
- I18n.should_receive(:t).with('vagrant_profitbricks.config.invalid_uri', {:key => url, :uri => 'baz'}).and_return error_message
113
+ I18n.should_receive(:t).with('vagrant_profitbricks.config.invalid_uri', key: url, uri: 'baz').and_return error_message
131
114
  validation_errors.first.should == error_message
132
115
  end
133
116
  end
134
117
  end
135
118
  end
136
-
137
- describe "network" do
138
- it "should remove SERVICE_NET_ID if :service_net is detached" do
139
- subject.send(:network, :service_net, :attached => false)
140
- subject.send(:networks).should_not include(VagrantPlugins::ProfitBricks::Config::SERVICE_NET_ID)
141
- end
142
-
143
- it "should not allow duplicate networks" do
144
- net_id = "deadbeef-0000-0000-0000-000000000000"
145
- subject.send(:network, net_id)
146
- subject.send(:network, net_id)
147
- subject.send(:networks).count(net_id).should == 1
148
- end
149
- end
150
119
  end