vagrant-g5k 0.0.14 → 0.0.15

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: aaeed73b05202f3f4877d8b66401981199f0cafb
4
- data.tar.gz: 91014ed7c211013ce70fb7fc6fa58bd77cd9d336
3
+ metadata.gz: 4bb98de93c858a960bbdbc3918b688c7c053b642
4
+ data.tar.gz: 4f05183a56b167b8bb535e91646e386c4fd58463
5
5
  SHA512:
6
- metadata.gz: 0b0874066b83dfc35b9ff5fed4eedbe9a4746266c43d24f40a1aa5db8ca3821d5b4857b5bc119657f4e727dd4312c0837d881d346f6f346579635ea16653e466
7
- data.tar.gz: 5ad397d2195e17abac2199953ced8b7674823cecec82084fd8dd5f9e5c804b7371cfa53a5287da4a78a077330721c6cf5066454b66ddb1d17a541ae153ed6a4e
6
+ metadata.gz: 4d1dd22b192c8eff2c6a77991ce555bf877b1c6970bd9f43721e960dc473a0f68459a5f699f2456285edf50d3b9a9ca8b5d654c38de130bacf9f11283bfda8dd
7
+ data.tar.gz: f326dc3f70a5b63ced19f3d8562ae8e8b8c72e786e2b498d1e9f6ca8f5e75bb78b7572c11af0496c70976248c37fafc83be867b977d62cba3777738fc73372f7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
+ # 0.0.15
2
+
3
+ * Allow parallel boot
4
+
1
5
  # 0.0.14
2
6
 
3
- * current
7
+ * Add custom oar properties
8
+ * Display the name of the node
4
9
 
5
10
  # 0.0.13
6
11
 
data/Vagrantfile CHANGED
@@ -3,69 +3,52 @@
3
3
  #
4
4
  # Testing purpose only
5
5
  #Vagrant.require_plugin "vagrant-g5k"
6
+ NB_G5K=1
7
+ NB_IGRIDA=1
6
8
 
7
9
  Vagrant.configure(2) do |config|
8
- # box isn't used
9
- config.vm.define "vm" do |my|
10
- my.vm.box = "dummy"
11
- end
10
+ (0..NB_G5K-1).each do |i|
11
+ config.vm.define "vm-g5k-#{i}" do |my|
12
+ my.vm.box = "dummy"
13
+
14
+ my.ssh.username = "root"
15
+ my.ssh.password = ""
16
+
17
+ my.vm.provider "g5k" do |g5k|
18
+ g5k.project_id = "vagrant-g5k"
19
+ g5k.site = "nancy"
20
+ g5k.gateway = "access.grid5000.fr"
21
+ g5k.image = {
22
+ "pool" => "msimonin_rbds",
23
+ "rbd" => "bases/alpine_docker",
24
+ "snapshot" => "parent",
25
+ "id" => "$USER",
26
+ "conf" => "$HOME/.ceph/config",
27
+ "backing" => "snapshot"
28
+ }
29
+ g5k.ports = ['2222-:22']
30
+ end #g5k
31
+ end #vm
32
+ end # each
33
+
34
+
35
+ (0..NB_IGRIDA-1).each do |i|
36
+ config.vm.define "vm-igrida-#{i}" do |my|
37
+ my.vm.box = "dummy"
38
+
39
+ my.vm.provider "g5k" do |g5k|
40
+ g5k.project_id = "vagrant-g5k"
41
+ g5k.site = "igrida-oar-frontend"
42
+ g5k.gateway = "transit.irisa.fr"
43
+ g5k.image = {
44
+ "path" => "/udd/msimonin/precise.qcow2",
45
+ "backing" => "snapshot"
46
+ }
47
+ g5k.ports = ['2222-:22']
48
+ end #g5k
49
+ end # vm
50
+ end # each
12
51
 
13
- # user to log with inside the vm
14
- config.ssh.username = "root"
15
- # password to use to log inside the vm
16
- config.ssh.password = ""
17
-
18
- config.vm.provider "g5k" do |g5k|
19
- # The project id.
20
- # It is used to generate uniq remote storage for images
21
- # It must be uniq accros all project managed by vagrant.
22
- g5k.project_id = "vagrant-g5k"
23
-
24
- # user name used to connect to g5k
25
- # default to ENV["USER"]
26
- # g5k.username = "john"
27
-
28
- # private key to use
29
- # g5k.private_key = File.join(ENV['HOME'], ".ssh/id_rsa_discovery")
30
-
31
- # site to use
32
- # g5k.site = "igrida-oar-frontend"
33
- g5k.site = "rennes"
34
-
35
- # gateway to use (if needed)
36
- g5k.gateway = "access.grid5000.fr"
37
- # g5k.gateway = "transit.irisa.fr"
38
-
39
- # walltime to use
40
- # g5k.walltime = "02:00:00"
41
-
42
- # image location
43
- #g5k.image = {
44
- # "path" => "/udd/msimonin/precise.qcow2",
45
- # "backing" => "copy"
46
- #}
47
-
48
- # it could be backed by the ceph
49
- g5k.image = {
50
- "pool" => "msimonin_rbds",
51
- "rbd" => "bases/alpine_docker",
52
- "snapshot" => "parent",
53
- "id" => "$USER",
54
- "conf" => "$HOME/.ceph/config",
55
- "backing" => "snapshot"
56
- }
57
-
58
- # ports to expose (at least ssh has to be forwarded)
59
- g5k.ports = ['2222-:22']
60
-
61
- # Custom oar ressource filtering
62
- # This may be specific on the oar ressource declaration
63
- # of the used platform
64
- # g5k.oar = "virtual != 'none'"
65
- end
66
-
67
-
68
-
69
52
  end
70
53
 
71
54
 
@@ -1,31 +1,69 @@
1
1
  require "log4r"
2
2
  require "vagrant-g5k/util/g5k_utils"
3
+ require "vagrant-g5k/driver"
4
+ require 'thread'
5
+
3
6
 
4
7
  module VagrantPlugins
5
8
  module G5K
9
+
10
+ class << self
11
+ attr_accessor :g5k_lock
12
+ attr_accessor :pool
13
+ end
14
+ @g5k_lock = Mutex.new
15
+ @pool = {}
16
+
6
17
  module Action
7
18
  # This action connects to G5K, verifies credentials work, and
8
19
  # puts the G5K connection object into the `:g5k_connection` key
9
20
  # in the environment.
10
21
  class ConnectG5K
22
+
23
+
11
24
  def initialize(app, env)
12
25
  @app = app
13
26
  @logger = Log4r::Logger.new("vagrant_g5k::action::connect_g5k")
14
27
  end
15
28
 
16
29
  def call(env)
17
- # This is a hack to make the connection persistent
18
- # even after environment unload is called
19
- if Connection.instance.nil?
20
- @logger.debug("Creating new connection")
21
- env[:g5k_connection] = Connection.new(env)
22
- else
23
- @logger.debug("Reusing connection")
24
- env[:g5k_connection] = Connection.instance
25
- end
26
-
30
+ driver = _get_driver(env)
31
+ env[:g5k_connection] = Connection.new(env, driver)
27
32
  @app.call(env)
28
33
  end
34
+
35
+ # get a session object to use to connect to the oar scheduler
36
+ # this connection is share for all actions on the same vm
37
+ def _get_driver(env)
38
+ provider_config = env[:machine].provider_config
39
+ gateway = provider_config.gateway
40
+ site = provider_config.site
41
+ username = provider_config.username
42
+ private_key = provider_config.private_key
43
+ #key = "#{env[:machine].name}"
44
+ key = "#{gateway}-#{site}-#{username}"
45
+ options = {
46
+ :forward_agent => true
47
+ }
48
+ options[:keys] = [private_key] if !private_key.nil?
49
+ VagrantPlugins::G5K.g5k_lock.synchronize {
50
+ if VagrantPlugins::G5K.pool[key].nil?
51
+ @logger.debug "Creating a new session object for #{key}"
52
+ if gateway.nil?
53
+ @logger.debug("connecting with #{username} on site #{site}")
54
+ session = Net::SSH.start(site, username, options)
55
+ else
56
+ @logger.debug("connecting with #{username} on site #{site} through #{gateway} with options #{options}")
57
+ gateway = Net::SSH::Gateway.new(gateway, username, options)
58
+ session = gateway.ssh(site, username, options)
59
+ end
60
+ VagrantPlugins::G5K.pool[key] = VagrantPlugins::G5K::Driver.new(session, Mutex.new)
61
+ else
62
+ @logger.debug "Reusing existing session for #{key}"
63
+ end
64
+ }
65
+ return VagrantPlugins::G5K.pool[key]
66
+ end
29
67
  end
30
68
  end
31
69
  end
@@ -0,0 +1,58 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module G5K
5
+ class Driver
6
+ def initialize(session, lock)
7
+ @logger = Log4r::Logger.new("vagrant::g5k::driver")
8
+ @lock = lock
9
+ @session = session
10
+ end
11
+
12
+ def exec(cmd)
13
+ @logger.debug("Executing #{cmd}")
14
+ stdout = ""
15
+ stderr = ""
16
+ exit_code = 0
17
+ @lock.synchronize{
18
+ @session.open_channel do |channel|
19
+ channel.exec(cmd) do |ch, success|
20
+ abort "could not execute command" unless success
21
+
22
+ channel.on_data do |c, data|
23
+ stdout << data.chomp
24
+ end
25
+
26
+ channel.on_extended_data do |c, type, data|
27
+ stderr << data.chomp
28
+ end
29
+
30
+ channel.on_request("exit-status") do |c,data|
31
+ exit_code = data.read_long
32
+ end
33
+
34
+ channel.on_close do |c|
35
+ end
36
+ end
37
+ end
38
+ @session.loop
39
+ if exit_code != 0
40
+ @logger.error(:stderr => stderr, :code => exit_code)
41
+ raise VagrantPlugins::G5K::Errors::CommandError
42
+ end
43
+ @logger.debug("Returning #{stdout}")
44
+ }
45
+ stdout
46
+
47
+ end
48
+
49
+ def upload(src, dst)
50
+ @lock.synchronize {
51
+ @session.scp.upload!(src, dst)
52
+ }
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+
@@ -24,7 +24,7 @@ module VagrantPlugins
24
24
  Config
25
25
  end
26
26
 
27
- provider(:g5k) do
27
+ provider(:g5k, parallel: true) do
28
28
  # Setup logging and i18n
29
29
  setup_logging
30
30
  setup_i18n
@@ -2,6 +2,7 @@ require 'net/ssh/multi'
2
2
  require 'net/scp'
3
3
  require 'json'
4
4
  require 'digest'
5
+ require 'thread'
5
6
 
6
7
  require 'vagrant/util/retryable'
7
8
 
@@ -35,20 +36,11 @@ module VagrantPlugins
35
36
 
36
37
  attr_accessor :node
37
38
 
38
- attr_accessor :pool
39
-
40
39
  attr_accessor :ports
41
40
 
42
41
  attr_accessor :oar
43
-
44
- @@instance = nil
45
-
46
- def self.instance
47
- @@instance
48
- end
49
-
50
-
51
- def initialize(env)
42
+
43
+ def initialize(env, driver)
52
44
  # provider specific config
53
45
  @provider_config = env[:machine].provider_config
54
46
  @username = @provider_config.username
@@ -66,23 +58,13 @@ module VagrantPlugins
66
58
  @ui = env[:ui]
67
59
 
68
60
  @logger = Log4r::Logger.new("vagrant::environment")
69
- options = {
70
- :forward_agent => true
71
- }
72
- options[:keys] = [@private_key] if !@private_key.nil?
73
- if @gateway.nil?
74
- @logger.debug("connecting with #{@username} on site #{@site}")
75
- @session = Net::SSH.start(@site, @username, options)
76
- else
77
- @logger.debug("connecting with #{@username} on site #{@site} through #{@gateway}")
78
- gateway = Net::SSH::Gateway.new(@gateway, @username, options)
79
- @session = gateway.ssh(@site, @username, options)
80
- end
81
- @@instance = self
61
+ @driver = driver
62
+
82
63
  end
83
64
 
65
+
84
66
  def create_local_working_dir(env)
85
- @session.exec("mkdir -p #{cwd(env)}")
67
+ exec("mkdir -p #{cwd(env)}")
86
68
  end
87
69
 
88
70
  def cwd(env)
@@ -205,48 +187,18 @@ module VagrantPlugins
205
187
  end
206
188
 
207
189
  def close()
208
- # Terminate the session
209
- @session.close
190
+ # Terminate the driver
191
+ @driver[:session].close
210
192
  end
211
193
 
212
194
 
213
195
 
214
196
  def exec(cmd)
215
- @logger.debug("Executing #{cmd}")
216
- stdout = ""
217
- stderr = ""
218
- exit_code = 0
219
- @session.open_channel do |channel|
220
- channel.exec(cmd) do |ch, success|
221
- abort "could not execute command" unless success
222
-
223
- channel.on_data do |c, data|
224
- stdout << data.chomp
225
- end
226
-
227
- channel.on_extended_data do |c, type, data|
228
- stderr << data.chomp
229
- end
230
-
231
- channel.on_request("exit-status") do |c,data|
232
- exit_code = data.read_long
233
- end
234
-
235
- channel.on_close do |c|
236
- end
237
- end
238
- end
239
- @session.loop
240
- if exit_code != 0
241
- @logger.error(:stderr => stderr, :code => exit_code)
242
- raise VagrantPlugins::G5K::Errors::CommandError
243
- end
244
- @logger.debug("Returning #{stdout}")
245
- stdout
246
- end
197
+ @driver.exec(cmd)
198
+ end
247
199
 
248
200
  def upload(src, dst)
249
- @session.scp.upload!(src, dst)
201
+ @driver.upload(src, dst)
250
202
  end
251
203
 
252
204
  def _generate_drive(env)
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module G5K
3
- VERSION = '0.0.14'
3
+ VERSION = '0.0.15'
4
4
  end
5
5
  end
data/lib/vagrant-g5k.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require "pathname"
2
2
 
3
3
  require "vagrant-g5k/plugin"
4
+ require 'thread'
4
5
 
5
6
  module VagrantPlugins
6
7
  module G5K
8
+
7
9
  lib_path = Pathname.new(File.expand_path("../vagrant-g5k", __FILE__))
8
10
  autoload :Action, lib_path.join("action")
9
11
  autoload :Errors, lib_path.join("errors")
@@ -14,5 +16,6 @@ module VagrantPlugins
14
16
  def self.source_root
15
17
  @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
16
18
  end
19
+
17
20
  end
18
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-g5k
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Simonin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-07 00:00:00.000000000 Z
11
+ date: 2016-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iniparse
@@ -143,6 +143,7 @@ files:
143
143
  - lib/vagrant-g5k/action/run_instance.rb
144
144
  - lib/vagrant-g5k/command.rb
145
145
  - lib/vagrant-g5k/config.rb
146
+ - lib/vagrant-g5k/driver.rb
146
147
  - lib/vagrant-g5k/errors.rb
147
148
  - lib/vagrant-g5k/plugin.rb
148
149
  - lib/vagrant-g5k/provider.rb