vagrant-proxmox 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52d86a90fe57dfe5b5e6e301b57308feb678e868
4
- data.tar.gz: 3372e88c27a4fd155bccc466d851109eecf6ef92
3
+ metadata.gz: 2147dcafed88c358a388e15bff90b58f468b95ad
4
+ data.tar.gz: 60f3c2c0c6045353dec19188ddaa164fd1dc99d4
5
5
  SHA512:
6
- metadata.gz: 911850cd404dffe56562c95c6e1fc293ba7771cb618339f9be5d8bda7ba3e30c956e3d180156e0d9b0dda7751737439fd4e0b782c871936fe32dfc3e02efe161
7
- data.tar.gz: 8ddd8000896e351c5b1da84fa7b218a54ce71bb1405657437db61991097d97a5fb3c0cad5eaa01a0288163f781fac14b3205663557162e94fbec0a2a9b84ab72
6
+ metadata.gz: 09c263224795ea1f5bb85e10f3795c83d5351a339fc5c998879540e817397c19c6bb323e38abda26b96f2b079f0f8d4a924e54f1a45dfeb7b7ffe10d25604dd7
7
+ data.tar.gz: 563fcab8eba3640b08477576d4a1d7cf7209ebd99d1ea6edc624a509ebd6d8dce149ea575d33fc0b33b24ca494b837cbfacc5cfbda87b7ff6c6fbd0d4dd5809d
@@ -1,23 +1,31 @@
1
1
  module VagrantPlugins
2
- module Proxmox
3
- module Action
2
+ module Proxmox
3
+ module Action
4
4
 
5
- # This action reads the state of a Proxmox virtual machine and stores it
6
- # in env[:machine_state_id].
7
- class SelectNode < ProxmoxAction
5
+ # This action reads the state of a Proxmox virtual machine and stores it
6
+ # in env[:machine_state_id].
7
+ class SelectNode < ProxmoxAction
8
8
 
9
- def initialize app, env
10
- @app = app
11
- @logger = Log4r::Logger.new 'vagrant_proxmox::action::select_node'
12
- end
9
+ def initialize app, env
10
+ @app = app
11
+ @logger = Log4r::Logger.new 'vagrant_proxmox::action::select_node'
12
+ end
13
13
 
14
- def call env
15
- env[:proxmox_selected_node] = env[:proxmox_nodes].sample
16
- next_action env
17
- end
14
+ def call env
15
+ if env[:machine].provider_config.selected_node != Config::UNSET_VALUE
16
+ if env[:proxmox_nodes].include?(env[:machine].provider_config.selected_node)
17
+ env[:proxmox_selected_node] = env[:machine].provider_config.selected_node
18
+ else
19
+ raise Errors::InvalidNodeError, node: env[:machine].provider_config.selected_node
20
+ end
21
+ else
22
+ env[:proxmox_selected_node] = env[:proxmox_nodes].sample
23
+ end
24
+ next_action env
25
+ end
18
26
 
19
- end
27
+ end
20
28
 
21
- end
22
- end
29
+ end
30
+ end
23
31
  end
@@ -7,6 +7,11 @@ module VagrantPlugins
7
7
  # @return [String]
8
8
  attr_accessor :endpoint
9
9
 
10
+ # The Proxmox preferred cluster node
11
+ #
12
+ # @return [String]
13
+ attr_accessor :selected_node
14
+
10
15
  # The Proxmox user name
11
16
  #
12
17
  # @return [String]
@@ -94,6 +99,7 @@ module VagrantPlugins
94
99
 
95
100
  def initialize
96
101
  @endpoint = UNSET_VALUE
102
+ @selected_node = UNSET_VALUE
97
103
  @user_name = UNSET_VALUE
98
104
  @password = UNSET_VALUE
99
105
  @vm_type = UNSET_VALUE
@@ -116,6 +122,7 @@ module VagrantPlugins
116
122
  # This is the hook that is called to finalize the object before it is put into use.
117
123
  def finalize!
118
124
  @endpoint = nil if @endpoint == UNSET_VALUE
125
+ @selected_node = nil if @endpoint == UNSET_VALUE
119
126
  @user_name = nil if @user_name == UNSET_VALUE
120
127
  @password = nil if @password == UNSET_VALUE
121
128
  @vm_type = nil if @vm_type == UNSET_VALUE
@@ -54,6 +54,10 @@ module VagrantPlugins
54
54
  error_key :ssh_error
55
55
  end
56
56
 
57
+ class InvalidNodeError < VagrantProxmoxError
58
+ error_key :invalid_node_error
59
+ end
60
+
57
61
  end
58
62
  end
59
63
  end
@@ -1,7 +1,7 @@
1
1
  module VagrantPlugins
2
2
  module Proxmox
3
3
 
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
 
6
6
  end
7
7
  end
data/locales/en.yml CHANGED
@@ -71,6 +71,7 @@ en:
71
71
  no_qemu_iso_or_qemu_iso_file_specified_for_vm_type_qemu: "No qemu_iso or qemu_iso_file specified for vm_type=:qemu"
72
72
  no_qemu_os_specified_for_vm_type_qemu: "No qemu_os specified for vm_type=:qemu"
73
73
  no_qemu_disk_size_specified_for_vm_type_qemu: "No qemu_disk_size specified for vm_type=:qemu"
74
+ invalid_node_error: 'Invalid node specified: %{node}'
74
75
  not_created: 'The virtual machine is not created on the server!'
75
76
  rsync_folder: |-
76
77
  Rsyncing folder: %{hostpath} => %{guestpath}
@@ -9,22 +9,46 @@ module VagrantPlugins::Proxmox
9
9
  let(:connection) { Connection.new 'https://proxmox.example.com/api2/json' }
10
10
  let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
11
11
  proxmox_connection: connection, proxmox_nodes: nodes} }
12
- let(:nodes) { ['node1', 'node2'] }
12
+ let(:nodes) { ['node1', 'node2', 'selected_node'] }
13
13
 
14
14
  subject(:action) { described_class.new(-> (_) {}, environment) }
15
15
 
16
16
  describe '#call' do
17
17
 
18
- before do
19
- allow(nodes).to receive(:sample).and_return 'node2'
20
- end
21
-
22
- it_behaves_like 'a proxmox action call'
23
-
24
- it 'randomly selects a node from the list of available nodes' do
25
- action.call env
26
- expect(env[:proxmox_selected_node]).to eq('node2')
27
- end
18
+ it_behaves_like 'a proxmox action call'
19
+
20
+ context "when no selected_node is specified in the configuration" do
21
+ it 'randomly selects a node from the list of available nodes' do
22
+ expect(nodes).to receive(:sample).and_return 'node2'
23
+ action.call env
24
+ expect(env[:proxmox_selected_node]).to eq('node2')
25
+ end
26
+ end
27
+
28
+ context "when a specific node is specified in the configuration" do
29
+
30
+ context "when this node is included in the nodes list" do
31
+ before do
32
+ env[:machine].provider_config.selected_node = 'selected_node'
33
+ end
34
+
35
+ it 'selects the selected_node' do
36
+ expect(nodes).not_to receive(:sample)
37
+ action.call env
38
+ expect(env[:proxmox_selected_node]).to eq('selected_node')
39
+ end
40
+ end
41
+
42
+ context "when this node is not included in the nodes list" do
43
+ before do
44
+ env[:machine].provider_config.selected_node = 'invalid_node'
45
+ end
46
+
47
+ it 'should raise an error' do
48
+ expect { action.call env }.to raise_error Errors::InvalidNodeError
49
+ end
50
+ end
51
+ end
28
52
 
29
53
  end
30
54
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-proxmox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dirk Grappendorf
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-10-08 00:00:00.000000000 Z
13
+ date: 2015-01-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client