opennebula-provider 0.2.4 → 0.3.0

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: 133a2592923c168d7cf6f232ad5f6a0ab4e75944
4
- data.tar.gz: f360bff7b59fe13b08a4ff931e2a27250eb48762
3
+ metadata.gz: 18120f65713e4caff7bf5042be0f6c94ae768e64
4
+ data.tar.gz: c44850849cf4844d1ebb451b3edd3e8ce2f461cf
5
5
  SHA512:
6
- metadata.gz: aaf3d1935c0abe91bb3cf3c3641aa926ecae4a7c8bb1a6f808bff0a22c05f3d7fa8f60222b44baf973f4f73f9b36e514c93b06b1678b8fea3698f3c8f7c8a1b6
7
- data.tar.gz: d48cb67b91f95bd199669b954122ba2c7f2d3520d003439b4478cda08f00f03a178299e35bbc2d608e6977ca32d3390535e6175326010d3f8b5a037c8cb7585f
6
+ metadata.gz: 6f5fdc6707290d15eb51a451e924bc552ce9900fb098b36b1f66db7d392aca80204c5bb69448264ce345f081e98bcdc5be7a4c67dd4d141436fe41790a594284
7
+ data.tar.gz: 50b196264ceec8d7eedb8c861f9dd90da705fd28f566cadc97ed94125ea11b691d2a717ee0f264f7c414991d58a5f385a6b4aab01d9d9658a4f0057040bd114a
@@ -1,25 +1,22 @@
1
- require 'opennebula-provider/helpers/rocci'
2
-
3
1
  module VagrantPlugins
4
2
  module OpenNebulaProvider
5
3
  module Action
6
4
  class CheckState
7
- include Helpers::Rocci
8
-
9
5
  def initialize(app, env)
10
6
  @app = app
11
7
  @logger = Log4r::Logger.new('vagrant::provider::opennebula::check_state')
12
8
  end
13
9
 
14
10
  def call(env)
15
- env[:machine_state] = check_state(env[:rocci], env[:machine])
11
+ env[:machine_state] = check_state(env[:machine])
16
12
  @logger.info I18n.t('opennebula_provider.info.state', state: env[:machine_state])
17
13
  @app.call(env)
18
14
  end
19
15
 
20
- def check_state(rocci, machine)
21
- return :not_created if machine.id.nil?
22
- state = rocci.machine_state(machine.id)
16
+ def check_state(machine)
17
+ return :not_created unless machine.id
18
+ driver = machine.provider.driver
19
+ state = driver.state(machine.id)
23
20
  state.to_sym
24
21
  end
25
22
  end
@@ -9,17 +9,8 @@ module VagrantPlugins
9
9
 
10
10
  def call(env)
11
11
  @logger.info I18n.t('opennebula_provider.info.creating')
12
- result = env[:rocci].compute
13
- env[:machine].id = result
14
- env[:rocci].wait_for_state(env, 'active')
15
- env[:ui].info I18n.t('opennebula_provider.info.waiting_for_sshd')
16
- if !env[:interrupted]
17
- while true
18
- break if env[:interrupted]
19
- break if env[:machine].communicate.ready?
20
- sleep 2
21
- end
22
- end
12
+ driver = env[:machine].provider.driver
13
+ env[:machine].id = driver.create
23
14
  @app.call(env)
24
15
  end
25
16
  end
@@ -9,7 +9,8 @@ module VagrantPlugins
9
9
 
10
10
  def call(env)
11
11
  @logger.info I18n.t('opennebula_provider.info.destroying', machine: env[:machine].id)
12
- env[:rocci].delete(env[:machine].id)
12
+ driver = env[:machine].provider.driver
13
+ driver.delete(env[:machine].id)
13
14
  env[:machine].id = nil
14
15
  @app.call(env)
15
16
  end
@@ -33,6 +33,7 @@ module VagrantPlugins
33
33
  @app.call(env)
34
34
  end
35
35
  end
36
+
36
37
  class MessageNotCreated
37
38
  def initialize(app, env)
38
39
  @app = app
@@ -54,6 +55,17 @@ module VagrantPlugins
54
55
  @app.call(env)
55
56
  end
56
57
  end
58
+
59
+ class MessageHalted
60
+ def initialize(app, env)
61
+ @app = app
62
+ end
63
+
64
+ def call(env)
65
+ env[:ui].info I18n.t('opennebula_provider.info.halted')
66
+ @app.call(env)
67
+ end
68
+ end
57
69
  end
58
70
  end
59
71
  end
@@ -8,14 +8,15 @@ module VagrantPlugins
8
8
  end
9
9
 
10
10
  def call(env)
11
- env[:machine_ssh_info] = read_ssh_info(env[:rocci], env[:machine])
11
+ env[:machine_ssh_info] = read_ssh_info(env[:machine])
12
12
  @app.call(env)
13
13
  end
14
14
 
15
- def read_ssh_info(rocci, machine)
15
+ def read_ssh_info(machine)
16
16
  return nil if machine.id.nil?
17
+ driver = machine.provider.driver
17
18
 
18
- host = rocci.ssh_info(machine.id)
19
+ host = driver.ssh_info(machine.id)
19
20
  { host: host, port: 22 }
20
21
  end
21
22
  end
@@ -8,16 +8,9 @@ module VagrantPlugins
8
8
  end
9
9
 
10
10
  def call(env)
11
- @logger.info I18n.t('opennebula_provider.info.start', machine: env[:machine].id)
12
- env[:rocci].start(env[:machine].id)
13
- env[:ui].info I18n.t('opennebula_provider.info.waiting_for_sshd')
14
- if !env[:interrupted]
15
- while true
16
- break if env[:interrupted]
17
- break if env[:machine].communicate.ready?
18
- sleep 2
19
- end
20
- end
11
+ env[:ui].info I18n.t('opennebula_provider.info.start', machine: env[:machine].id)
12
+ driver = env[:machine].provider.driver
13
+ driver.start(env[:machine].id)
21
14
  @app.call(env)
22
15
  end
23
16
  end
@@ -8,9 +8,9 @@ module VagrantPlugins
8
8
  end
9
9
 
10
10
  def call(env)
11
- @logger.info I18n.t('opennebula_provider.info.stop', machine: env[:machine].id)
12
- env[:rocci].stop(env[:machine].id)
13
- env[:rocci].wait_for_state(env, 'suspended')
11
+ env[:ui].info I18n.t('opennebula_provider.info.halt', machine: env[:machine].id)
12
+ driver = env[:machine].provider.driver
13
+ driver.stop(env[:machine].id)
14
14
  @app.call(env)
15
15
  end
16
16
  end
@@ -1,21 +1,17 @@
1
- require 'opennebula-provider/helpers/rocci'
2
-
3
1
  module VagrantPlugins
4
2
  module OpenNebulaProvider
5
3
  module Action
6
- class ConnectOpenNebula
7
- include Helpers::Rocci
8
-
4
+ class WaitForSSH
9
5
  def initialize(app, env)
10
6
  @app = app
11
- @logger = Log4r::Logger.new('vagrant::provider::opennebula::connect_opennebula')
7
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::wait_for_ssh')
12
8
  end
13
9
 
14
10
  def call(env)
15
- @logger.info('Connecting to OpenNebula')
16
- rocci = rocci(env[:machine].provider_config)
17
- env[:rocci] = rocci
18
-
11
+ env[:ui].info I18n.t('opennebula_provider.info.waiting_for_sshd')
12
+ unless env[:interrupted]
13
+ env[:machine].communicate.ready?
14
+ end
19
15
  @app.call(env)
20
16
  end
21
17
  end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module OpenNebulaProvider
3
+ module Action
4
+ class WaitForState
5
+ def initialize(app, env, state)
6
+ @app = app
7
+ @state = state
8
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::wait_for_state')
9
+ end
10
+
11
+ def call(env)
12
+ driver = env[:machine].provider.driver
13
+ driver.wait_for_state(env, @state)
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,4 @@
1
1
  require_relative 'action/check_state'
2
- require_relative 'action/connect_opennebula'
3
2
  require_relative 'action/create'
4
3
  require_relative 'action/destroy'
5
4
  require_relative 'action/messages'
@@ -7,6 +6,8 @@ require_relative 'action/read_ssh_info'
7
6
  require_relative 'action/sync_folders'
8
7
  require_relative 'action/start'
9
8
  require_relative 'action/stop'
9
+ require_relative 'action/wait_for_state'
10
+ require_relative 'action/wait_for_ssh'
10
11
 
11
12
  module VagrantPlugins
12
13
  module OpenNebulaProvider
@@ -16,7 +17,6 @@ module VagrantPlugins
16
17
  def self.destroy
17
18
  Vagrant::Action::Builder.new.tap do |b|
18
19
  b.use ConfigValidate
19
- b.use ConnectOpenNebula
20
20
  b.use Call, CheckState do |env, b1|
21
21
  case env[:machine_state]
22
22
  when :active, :error, :suspended, :inactive
@@ -39,7 +39,6 @@ module VagrantPlugins
39
39
  def self.up
40
40
  Vagrant::Action::Builder.new.tap do |b|
41
41
  b.use ConfigValidate
42
- b.use ConnectOpenNebula
43
42
  b.use Call, CheckState do |env, b1|
44
43
  case env[:machine_state]
45
44
  when :active
@@ -49,6 +48,7 @@ module VagrantPlugins
49
48
  when :not_created, :inactive
50
49
  b1.use Create
51
50
  end
51
+ b1.use WaitForState, 'active'
52
52
  end
53
53
  end
54
54
  end
@@ -56,11 +56,11 @@ module VagrantPlugins
56
56
  def self.halt
57
57
  Vagrant::Action::Builder.new.tap do |b|
58
58
  b.use ConfigValidate
59
- b.use ConnectOpenNebula
60
59
  b.use Call, CheckState do |env1, b1|
61
60
  case env1[:machine_state]
62
61
  when :active
63
62
  b1.use Stop
63
+ b1.use WaitForState, 'suspended'
64
64
  when :suspended
65
65
  b1.use MessageAlreadyHalted
66
66
  when :not_created, :inactive
@@ -73,7 +73,6 @@ module VagrantPlugins
73
73
  def self.reload
74
74
  Vagrant::Action::Builder.new.tap do |b|
75
75
  b.use ConfigValidate
76
- b.use ConnectOpenNebula
77
76
  b.use Call, CheckState do |env1, b1|
78
77
  case env1[:machine_state]
79
78
  when :not_created
@@ -90,7 +89,6 @@ module VagrantPlugins
90
89
  def self.check_state
91
90
  Vagrant::Action::Builder.new.tap do |b|
92
91
  b.use ConfigValidate
93
- b.use ConnectOpenNebula
94
92
  b.use CheckState
95
93
  end
96
94
  end
@@ -98,15 +96,23 @@ module VagrantPlugins
98
96
  def self.provision
99
97
  Vagrant::Action::Builder.new.tap do |b|
100
98
  b.use ConfigValidate
101
- b.use Provision
102
- b.use SyncFolders
99
+ b.use Call, CheckState do |env1, b1|
100
+ case env1[:machine_state]
101
+ when :not_created, :inactive
102
+ b1.use MessageNotCreated
103
+ when :suspended
104
+ b1.use MessageHalted
105
+ else
106
+ b1.use Provision
107
+ b1.use SyncFolders
108
+ end
109
+ end
103
110
  end
104
111
  end
105
112
 
106
113
  def self.read_ssh_info
107
114
  Vagrant::Action::Builder.new.tap do |b|
108
115
  b.use ConfigValidate
109
- b.use ConnectOpenNebula
110
116
  b.use ReadSSHInfo
111
117
  end
112
118
  end
@@ -114,7 +120,16 @@ module VagrantPlugins
114
120
  def self.ssh
115
121
  Vagrant::Action::Builder.new.tap do |b|
116
122
  b.use ConfigValidate
117
- b.use SSHExec
123
+ b.use Call, CheckState do |env1, b1|
124
+ case env1[:machine_state]
125
+ when :not_created, :inactive
126
+ b1.use MessageNotCreated
127
+ when :suspended
128
+ b1.use MessageHalted
129
+ else
130
+ b1.use SSHExec
131
+ end
132
+ end
118
133
  end
119
134
  end
120
135
  end
@@ -0,0 +1,56 @@
1
+ require 'opennebula-provider/helpers/rocci'
2
+
3
+ module VagrantPlugins
4
+ module OpenNebulaProvider
5
+ class Driver
6
+ include Vagrant::Util::Retryable
7
+
8
+ def initialize
9
+ @rocci_driver ||= VagrantPlugins::OpenNebulaProvider::Helpers::RocciApi.new
10
+ end
11
+
12
+ def config=(provider_config)
13
+ @rocci_driver.fill_config(provider_config)
14
+ @rocci_driver.connect
15
+ end
16
+
17
+ def state(cid)
18
+ @rocci_driver.machine_state(cid)
19
+ end
20
+
21
+ def create
22
+ @rocci_driver.compute
23
+ end
24
+
25
+ def delete(cid)
26
+ @rocci_driver.delete(cid)
27
+ end
28
+
29
+ def start(cid)
30
+ @rocci_driver.start(cid)
31
+ end
32
+
33
+ def stop(cid)
34
+ @rocci_driver.stop(cid)
35
+ end
36
+
37
+ def ssh_info(cid)
38
+ @rocci_driver.ssh_info(cid)
39
+ end
40
+
41
+ def wait_for_state(env, state)
42
+ retryable(tries: 60, sleep: 2) do
43
+ next if env[:interrupted]
44
+ result = @rocci_driver.machine_state(env[:machine].id)
45
+
46
+ yield result if block_given?
47
+ if result != state
48
+ fail Errors::ComputeError,
49
+ error: "Can not wait when instance will be in '#{state}' status, " \
50
+ "last status is '#{result}'"
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -3,32 +3,33 @@ require 'occi-api'
3
3
  module VagrantPlugins
4
4
  module OpenNebulaProvider
5
5
  module Helpers
6
- module Rocci
7
- def rocci(provider_config)
8
- @rocci ||= RocciApi.new(@machine, provider_config)
9
- end
10
- end
11
-
12
6
  class RocciApi
13
- include Vagrant::Util::Retryable
7
+ def initialize
8
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::helpers::rocciapi')
9
+ end
14
10
 
15
- def initialize(machine, provider_config)
11
+ def fill_config(provider_config)
16
12
  @logger = Log4r::Logger.new('vagrant::provider::opennebula::helpers::rocciapi')
17
13
  @config = provider_config
18
- options = {
19
- endpoint: @config.endpoint,
14
+ @options = {
15
+ endpoint: provider_config.endpoint,
20
16
  auth: {
21
- type: @config.auth,
22
- username: @config.username,
23
- password: @config.password
17
+ type: provider_config.auth,
18
+ username: provider_config.username,
19
+ password: provider_config.password
24
20
  }
25
21
  # :log => {
26
22
  # :out => STDERR,
27
23
  # :level => Occi::Api::Log::DEBUG
28
24
  # }
29
25
  }
26
+ end
27
+
28
+ def connect
29
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::helpers::rocciapi')
30
+ @logger.info 'Connect to RocciServer'
30
31
  begin
31
- @rocci = Occi::Api::Client::ClientHttp.new(options)
32
+ @rocci = Occi::Api::Client::ClientHttp.new(@options)
32
33
  rescue Errno::ECONNREFUSED => e
33
34
  raise Errors::ConnectError, error: e
34
35
  rescue Occi::Api::Client::Errors::AuthnError => e
@@ -116,16 +117,6 @@ module VagrantPlugins
116
117
  networkinterface[:address]
117
118
  end
118
119
 
119
- def wait_for_state(env, state)
120
- retryable(tries: 100, sleep: 6) do
121
- next if env[:interrupted]
122
- result = machine_state(env[:machine].id)
123
-
124
- yield result if block_given?
125
- fail Errors::ComputeError, error: 'Not ready' if result != state
126
- end
127
- end
128
-
129
120
  private
130
121
 
131
122
  def action_instance(id, action)
@@ -1,4 +1,5 @@
1
1
  require_relative 'version'
2
+ require_relative 'driver'
2
3
 
3
4
  require 'vagrant'
4
5
 
@@ -7,15 +8,15 @@ module VagrantPlugins
7
8
  class Plugin < Vagrant.plugin('2')
8
9
  name 'opennebula-provider'
9
10
 
10
- provider(:opennebula) do
11
- require_relative 'provider'
12
- Provider
13
- end
14
-
15
11
  config(:opennebula, :provider) do
16
12
  require_relative 'config'
17
13
  Config
18
14
  end
15
+
16
+ provider(:opennebula) do
17
+ require_relative 'provider'
18
+ Provider
19
+ end
19
20
  end
20
21
  end
21
22
  end
@@ -13,16 +13,25 @@ module VagrantPlugins
13
13
  nil
14
14
  end
15
15
 
16
+ def driver
17
+ return @driver if @driver
18
+ @driver = Driver.new
19
+ @driver.config = @machine.provider_config
20
+
21
+ @driver
22
+ end
23
+
16
24
  def ssh_info
17
25
  env = @machine.action('read_ssh_info')
18
26
  env[:machine_ssh_info]
19
27
  end
20
28
 
21
29
  def state
22
- env = @machine.action('check_state')
23
- state = env[:machine_state]
30
+ state = driver.state(@machine.id)
31
+
24
32
  short = I18n.t("opennebula_provider.states.short_#{state}")
25
33
  long = I18n.t("opennebula_provider.states.long_#{state}")
34
+
26
35
  Vagrant::MachineState.new(state, short, long)
27
36
  end
28
37
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module OpenNebulaProvider
3
- VERSION = '0.2.4'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -19,6 +19,12 @@ en:
19
19
  Instance will not be destroyed, declined
20
20
  state: |-
21
21
  Instance state is %{state}
22
+ halt: |-
23
+ Instance is shutdown...
24
+ halted: |-
25
+ Instance is halted
26
+ start: |-
27
+ Starting the instance...
22
28
  waiting_for_sshd: |-
23
29
  Instance is active, waiting for sshd daemon startup...
24
30
  rsyncing: |-
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = VagrantPlugins::OpenNebulaProvider::VERSION
8
8
  spec.authors = ['Cherdancev Evgeni']
9
9
  spec.email = ['cyber@sibnet.ru']
10
- spec.description = %q{OpenNebula provider for Vagrant}
10
+ spec.description = %q(OpenNebula provider for Vagrant)
11
11
  spec.summary = spec.description
12
12
  spec.homepage = ''
13
13
  spec.license = 'MIT'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula-provider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cherdancev Evgeni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: occi-api
@@ -84,7 +84,6 @@ files:
84
84
  - lib/opennebula-provider.rb
85
85
  - lib/opennebula-provider/action.rb
86
86
  - lib/opennebula-provider/action/check_state.rb
87
- - lib/opennebula-provider/action/connect_opennebula.rb
88
87
  - lib/opennebula-provider/action/create.rb
89
88
  - lib/opennebula-provider/action/destroy.rb
90
89
  - lib/opennebula-provider/action/messages.rb
@@ -92,7 +91,10 @@ files:
92
91
  - lib/opennebula-provider/action/start.rb
93
92
  - lib/opennebula-provider/action/stop.rb
94
93
  - lib/opennebula-provider/action/sync_folders.rb
94
+ - lib/opennebula-provider/action/wait_for_ssh.rb
95
+ - lib/opennebula-provider/action/wait_for_state.rb
95
96
  - lib/opennebula-provider/config.rb
97
+ - lib/opennebula-provider/driver.rb
96
98
  - lib/opennebula-provider/errors.rb
97
99
  - lib/opennebula-provider/helpers/rocci.rb
98
100
  - lib/opennebula-provider/plugin.rb