vagrant-g5k 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +30 -2
  4. data/Vagrantfile +49 -20
  5. data/lib/vagrant-g5k.rb +16 -0
  6. data/lib/vagrant-g5k/action.rb +52 -20
  7. data/lib/vagrant-g5k/action/connect_g5k.rb +3 -8
  8. data/lib/vagrant-g5k/action/create_local_working_dir.rb +1 -1
  9. data/lib/vagrant-g5k/action/get_state.rb +23 -0
  10. data/lib/vagrant-g5k/action/is_created.rb +6 -2
  11. data/lib/vagrant-g5k/action/{message_already_created.rb → message_already_running.rb} +1 -1
  12. data/lib/vagrant-g5k/action/message_not_running.rb +16 -0
  13. data/lib/vagrant-g5k/action/read_ssh_info.rb +16 -14
  14. data/lib/vagrant-g5k/action/read_state.rb +8 -0
  15. data/lib/vagrant-g5k/action/run_instance.rb +1 -0
  16. data/lib/vagrant-g5k/action/wait_instance.rb +18 -0
  17. data/lib/vagrant-g5k/config.rb +7 -3
  18. data/lib/vagrant-g5k/util/g5k_utils.rb +164 -37
  19. data/lib/vagrant-g5k/util/launch_vm_bridge.sh +58 -0
  20. data/lib/vagrant-g5k/version.rb +1 -1
  21. data/vagrant-g5k.gemspec +6 -6
  22. metadata +24 -70
  23. data/Vagrantfile.multisite +0 -37
  24. data/results/.gitignore +0 -2
  25. data/results/README.md +0 -43
  26. data/results/Vagrantfile +0 -126
  27. data/results/ansible.cfg +0 -2
  28. data/results/boilerplate.retry +0 -1
  29. data/results/boilerplate.yml +0 -248
  30. data/results/files/grafana/dashboard.json +0 -4572
  31. data/results/files/grafana/dedicated.json +0 -5486
  32. data/results/files/grafana/haproxy.json +0 -2632
  33. data/results/files/heka/config.json +0 -47
  34. data/results/files/heka/heka-globals.toml +0 -2
  35. data/results/files/heka/lua_decoders/haproxy_log.lua +0 -162
  36. data/results/files/heka/lua_decoders/os_keystone_apache_log.lua +0 -78
  37. data/results/files/heka/lua_decoders/os_mysql_log.lua +0 -56
  38. data/results/files/heka/lua_decoders/os_openstack_log.lua +0 -146
  39. data/results/files/heka/lua_decoders/os_rabbitmq_log.lua +0 -79
  40. data/results/files/kibana/all_objects.json +0 -81
  41. data/results/files/nginx.conf +0 -34
  42. data/results/templates/heka-elasticsearch.toml.j2 +0 -18
  43. data/results/templates/heka-haproxy.toml.j2 +0 -10
  44. data/results/templates/heka-keystone.toml.j2 +0 -14
  45. data/results/templates/heka-mariadb.toml.j2 +0 -14
  46. data/results/templates/heka-openstack.toml.j2 +0 -15
  47. data/results/templates/heka-rabbitmq.toml.j2 +0 -21
  48. data/results/test.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1df4a32a68cbad5242e82101c86660aec6edf0b
4
- data.tar.gz: 2978fdaf2984face9272df254040893082497a7d
3
+ metadata.gz: 36a28bd1d6c3273013c988e54f99f247d6c23b32
4
+ data.tar.gz: 4aae9321d7dfdc633d32c15b0c247e4fedfb017b
5
5
  SHA512:
6
- metadata.gz: 24b08525b133f8f58a185315f8553322b57c1cf16b544634dd3df56695d496a632e073fb5c790cd4a1c0a11a724d5ff9371e40bcb659d0dd3294f35fb47b795a
7
- data.tar.gz: 1229bd98b6478fb89a7d68cb486d6c089b88682a2493558d87d9519bd47a3cdb7e955402ac9d345634d97d53c7b1196b4af95fa641ad471216b738b8db65ae50
6
+ metadata.gz: b2229d27387e2ac38faeb23f29f17d51144cc85aeef103376a4d12786a4e543426bd61f5d5daaddec5606ae07a4b7a94eafa1548abd095bd15ac787773fe4637
7
+ data.tar.gz: a4d7f6930d7aa1b881cf2576f91251a49b191b4d948bac37e797c6531baaa7a5915416b7cd4b58bf38763b91a88580a07bb2dbdf85ba4c63e20a119a5e6ec0d3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.0.17
2
+
3
+ * Add bridged network support
4
+ * Add support for ssh run command (cli : vagrant ssh vm -c "...".)
5
+ * Add generic lockable function
6
+ * Add generic GetState Middleware (destroy can be called even if the VM is
7
+ terminated)
8
+
1
9
  # 0.0.16
2
10
 
3
11
  * Improve stdout (add information on physical node)
data/README.md CHANGED
@@ -39,6 +39,36 @@ to back the disk image of the virtual machines :
39
39
  * `direct`: will use the image directly (you'll need r/w access to the image)
40
40
  * `snapshot`: will let `kvm` create an ephemeral copy on write image.
41
41
 
42
+ ## Note on network configuration
43
+
44
+ Two networking modes are supported :
45
+
46
+ * NAT networking. VMs traffic is NATed to the outside world.
47
+ The outside world can access the VMs on dedicated ports that are mapped in the host of Grid'5000.
48
+ ```
49
+ config.vm.provider "g5k" do |g5k|
50
+ [...]
51
+ g5k.net = {
52
+ "type": "nat",
53
+ "ports": ["2222-:22", "8080-":80]
54
+ }
55
+ end
56
+ ```
57
+
58
+ e.g : Assuming `parapluie-1.rennes.grid5000.fr` hosts the VM. A SSH tunnel from your local machine to `parapluie-1.rennes.grid5000.fr:8080` will be forwarded to the port `80` of the VM.
59
+
60
+ * Bridge networking. VMs are given an IP from a Grid'5000 subnet. They can thus communicate with each others using their IPs.
61
+
62
+ ```
63
+ config.vm.provider "g5k" do |g5k|
64
+ [...]
65
+ g5k.net = {
66
+ "type": "bridge"
67
+ }
68
+ end
69
+ ```
70
+
71
+
42
72
  ## Supported operations
43
73
 
44
74
  * `vagrant destroy`
@@ -64,5 +94,3 @@ You can read[1] for further information on how to configure ceph on grid'5000.
64
94
  ```
65
95
  VAGRANT_LOG=debug VAGRANT_DEFAULT_PROVIDER=g5k bundle exec vagrant up
66
96
  ```
67
-
68
-
data/Vagrantfile CHANGED
@@ -4,20 +4,19 @@
4
4
  # Testing purpose only
5
5
  #Vagrant.require_plugin "vagrant-g5k"
6
6
 
7
- SITES=['rennes']
8
-
9
7
  Vagrant.configure(2) do |config|
10
- SITES.each do |site|
11
- config.vm.define "vm-#{site}" do |my|
12
- my.vm.box = "dummy"
13
8
 
14
- my.ssh.username = "root"
15
- my.ssh.password = ""
9
+ config.vm.provider "g5k" do |g5k|
10
+ # project id must be unique accross all
11
+ # your projects using vagrant-g5k to avoid conflict
12
+ # on vm disks
13
+ g5k.project_id = "vagrant-g5k"
14
+ g5k.site = "rennes"
15
+ g5k.username = ENV["USER"]
16
+ g5k.gateway = "access.grid5000.fr"
17
+ g5k.walltime = "01:00:00"
16
18
 
17
- my.vm.provider "g5k" do |g5k|
18
- g5k.project_id = "vagrant-g5k"
19
- g5k.site = "#{site}"
20
- g5k.gateway = "access.grid5000.fr"
19
+ # Image backed by the ceph cluster
21
20
  # g5k.image = {
22
21
  # "pool" => "msimonin_rbds",
23
22
  # "rbd" => "bases/alpine_docker",
@@ -26,15 +25,45 @@ Vagrant.configure(2) do |config|
26
25
  # "conf" => "$HOME/.ceph/config",
27
26
  # "backing" => "snapshot"
28
27
  # }
29
- g5k.image = {
30
- "path" => "/grid5000/virt-images/alpine_docker.qcow2",
31
- "backing" => "snapshot"
32
- }
33
- g5k.ports = ['2222-:22']
34
- g5k.oar = "virtual != 'none'"
35
- end #g5k
36
- end #vm
37
- end # each
28
+ #
29
+ # Image backed on the frontend filesystem
30
+ g5k.image = {
31
+ "path" => "/grid5000/virt-images/alpine_docker.qcow2",
32
+ "backing" => "snapshot"
33
+ }
34
+
35
+ g5k.net = {
36
+ "type" => "bridge"
37
+ }
38
+ # g5k.net = {
39
+ # "type" => "nat",
40
+ # "ports" => ["2222-:22"]
41
+ # }
42
+
43
+
44
+ # oar selection of resource
45
+ g5k.oar = "virtual != 'none'"
46
+ end #g5k
47
+
48
+ config.vm.define "vm1" do |my|
49
+ my.vm.box = "dummy"
50
+
51
+ my.ssh.username = "root"
52
+ my.ssh.password = ""
53
+
54
+ end #vm
55
+
56
+ config.vm.define "vm2" do |my|
57
+ my.vm.box = "dummy"
58
+
59
+ my.ssh.username = "root"
60
+ my.ssh.password = ""
61
+
62
+ end #vm
63
+ # Repeat block to define another vm
64
+ # config.vm.define "vm2" do |my|
65
+ #
66
+ # end
38
67
 
39
68
  end
40
69
 
data/lib/vagrant-g5k.rb CHANGED
@@ -6,6 +6,15 @@ require 'thread'
6
6
  module VagrantPlugins
7
7
  module G5K
8
8
 
9
+ class << self
10
+ attr_accessor :g5k_lock
11
+ attr_accessor :subnet_lock
12
+ attr_accessor :pool
13
+ end
14
+ @g5k_lock = Mutex.new
15
+ @subnet_lock = Mutex.new
16
+ @pool = {}
17
+
9
18
  lib_path = Pathname.new(File.expand_path("../vagrant-g5k", __FILE__))
10
19
  autoload :Action, lib_path.join("action")
11
20
  autoload :Errors, lib_path.join("errors")
@@ -17,5 +26,12 @@ module VagrantPlugins
17
26
  @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
18
27
  end
19
28
 
29
+ def lockable(opts)
30
+ opts[:lock].synchronize {
31
+ yield
32
+ }
33
+ end
34
+
35
+
20
36
  end
21
37
  end
@@ -36,9 +36,11 @@ module VagrantPlugins
36
36
  def self.action_ssh
37
37
  Vagrant::Action::Builder.new.tap do |b|
38
38
  b.use ConfigValidate
39
- b.use Call, IsCreated do |env, b2|
40
- if !env[:result]
41
- b2.use MessageNotCreated
39
+ # read_state is hook by the call to machine.state.id
40
+ # in GetState Middleware
41
+ b.use Call, GetState do |env, b2|
42
+ if env[:result] != :Running
43
+ b2.use MessageNotRunning
42
44
  next
43
45
  end
44
46
  b2.use SSHExec
@@ -46,16 +48,36 @@ module VagrantPlugins
46
48
  end
47
49
  end
48
50
 
51
+
52
+ # This action is called when vagrant ssh -C "..." is used
53
+ def self.action_ssh_run
54
+ Vagrant::Action::Builder.new.tap do |b|
55
+ b.use ConfigValidate
56
+ b.use Call, GetState do |env, b2|
57
+ if env[:result] != :Running
58
+ b2.use MessageNotRunning
59
+ next
60
+ end
61
+
62
+ b2.use SSHRun
63
+ end
64
+ end
65
+ end
66
+
67
+
49
68
  # This action is called to bring the box up from nothing.
50
69
  def self.action_up
51
70
  Vagrant::Action::Builder.new.tap do |b|
52
71
  b.use ConfigValidate
53
- b.use ConnectG5K
54
- b.use CreateLocalWorkingDir
55
- b.use Call, IsCreated do |env1, b1|
56
- if env1[:result] then
57
- b1.use MessageAlreadyCreated
72
+ b.use Call, GetState do |env1, b1|
73
+ if env1[:result] == :Running then
74
+ b1.use MessageAlreadyRunning
75
+ elsif env1[:result] == :Waiting
76
+ b1.use ConnectG5K
77
+ b1.use WaitInstance
58
78
  else
79
+ b1.use ConnectG5K
80
+ b1.use CreateLocalWorkingDir
59
81
  b1.use RunInstance # launch a new instance
60
82
  end
61
83
  end
@@ -69,13 +91,18 @@ module VagrantPlugins
69
91
  if env[:result]
70
92
  b2.use ConfigValidate
71
93
  b2.use ConnectG5K
72
- b2.use Call, IsCreated do |env2, b3|
73
- if !env2[:result]
94
+ b2.use Call, GetState do |env2, b3|
95
+ if [:Running, :Waiting].include?(env2[:result])
96
+ b3.use DeleteJob
97
+ b3.use DeleteDisk
98
+ next
99
+ elsif env2[:result] == :shutdown
100
+ b3.use DeleteDisk
101
+ next
102
+ else
74
103
  b3.use MessageNotCreated
75
104
  next
76
105
  end
77
- b3.use DeleteJob
78
- b3.use DeleteDisk
79
106
  end
80
107
  else
81
108
  b2.use MessageWillNotDestroy
@@ -89,12 +116,14 @@ module VagrantPlugins
89
116
  Vagrant::Action::Builder.new.tap do |b|
90
117
  b.use ConfigValidate
91
118
  b.use ConnectG5K
92
- b.use Call, IsCreated do |env1, b2|
93
- if !env1[:result]
119
+ b.use Call, GetState do |env1, b2|
120
+ if [:Running, :Waiting].include?(env1[:result])
121
+ b2.use DeleteJob
122
+ next
123
+ else
94
124
  b2.use MessageNotCreated
95
125
  next
96
126
  end
97
- b2.use DeleteJob
98
127
  end
99
128
  end
100
129
  end
@@ -103,9 +132,9 @@ module VagrantPlugins
103
132
  def self.action_provision
104
133
  Vagrant::Action::Builder.new.tap do |b|
105
134
  b.use ConfigValidate
106
- b.use Call, IsCreated do |env, b2|
107
- if !env[:result]
108
- b2.use MessageNotCreated
135
+ b.use Call, GetState do |env, b2|
136
+ if env[:result] != :Running
137
+ b2.use MessageNotRunning
109
138
  next
110
139
  end
111
140
  b2.use Provision
@@ -119,13 +148,16 @@ module VagrantPlugins
119
148
  autoload :CreateLocalWorkingDir, action_root.join("create_local_working_dir")
120
149
  autoload :DeleteJob, action_root.join("delete_job")
121
150
  autoload :DeleteDisk, action_root.join("delete_disk")
122
- autoload :IsCreated, action_root.join("is_created")
123
- autoload :MessageAlreadyCreated, action_root.join("message_already_created")
151
+ autoload :GetState, action_root.join("get_state")
152
+ autoload :MessageAlreadyRunning, action_root.join("message_already_running")
124
153
  autoload :MessageNotCreated, action_root.join("message_not_created")
154
+ autoload :MessageNotRunning, action_root.join("message_not_running")
125
155
  autoload :ReadSSHInfo, action_root.join("read_ssh_info")
126
156
  autoload :ReadState, action_root.join("read_state")
127
157
  autoload :RunInstance, action_root.join("run_instance")
128
158
  autoload :StartInstance, action_root.join("start_instance")
159
+ autoload :WaitInstance, action_root.join("wait_instance")
160
+
129
161
 
130
162
  end
131
163
  end
@@ -7,12 +7,6 @@ require 'thread'
7
7
  module VagrantPlugins
8
8
  module G5K
9
9
 
10
- class << self
11
- attr_accessor :g5k_lock
12
- attr_accessor :pool
13
- end
14
- @g5k_lock = Mutex.new
15
- @pool = {}
16
10
 
17
11
  module Action
18
12
  # This action connects to G5K, verifies credentials work, and
@@ -20,6 +14,7 @@ module VagrantPlugins
20
14
  # in the environment.
21
15
  class ConnectG5K
22
16
 
17
+ include VagrantPlugins::G5K
23
18
 
24
19
  def initialize(app, env)
25
20
  @app = app
@@ -46,7 +41,7 @@ module VagrantPlugins
46
41
  :forward_agent => true
47
42
  }
48
43
  options[:keys] = [private_key] if !private_key.nil?
49
- VagrantPlugins::G5K.g5k_lock.synchronize {
44
+ lockable(:lock => VagrantPlugins::G5K.g5k_lock) do
50
45
  if VagrantPlugins::G5K.pool[key].nil?
51
46
  @logger.debug "Creating a new session object for #{key}"
52
47
  if gateway.nil?
@@ -61,7 +56,7 @@ module VagrantPlugins
61
56
  else
62
57
  @logger.debug "Reusing existing session for #{key}"
63
58
  end
64
- }
59
+ end
65
60
  return VagrantPlugins::G5K.pool[key]
66
61
  end
67
62
  end
@@ -16,7 +16,7 @@ module VagrantPlugins
16
16
 
17
17
  def call(env)
18
18
  conn = env[:g5k_connection]
19
- conn.create_local_working_dir(env)
19
+ conn.create_local_working_dir()
20
20
  @app.call(env)
21
21
  end
22
22
 
@@ -0,0 +1,23 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module G5K
5
+ module Action
6
+ # This can be used with "Call" built-in to check if the machine
7
+ # is created and branch in the middleware.
8
+ class GetState
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_g5k::action::get_state")
12
+ end
13
+
14
+ def call(env)
15
+ machine_state_id = env[:machine].state.id
16
+ @logger.info "machine is in state #{machine_state_id}"
17
+ env[:result] = machine_state_id
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ require "log4r"
2
+
1
3
  module VagrantPlugins
2
4
  module G5K
3
5
  module Action
@@ -6,11 +8,13 @@ module VagrantPlugins
6
8
  class IsCreated
7
9
  def initialize(app, env)
8
10
  @app = app
11
+ @logger = Log4r::Logger.new("vagrant_g5k::action::is_created")
9
12
  end
10
13
 
11
14
  def call(env)
12
- state_id = env[:machine].state.id
13
- env[:result] = state_id == :Running and state_id == :shutdown
15
+ machine_state_id = env[:machine].state.id
16
+ @logger.info "machine is in state #{machine_state_id}"
17
+ env[:result] = machine_state_id == :Running or machine_state_id == :Waiting
14
18
  @app.call(env)
15
19
  end
16
20
  end
@@ -1,7 +1,7 @@
1
1
  module VagrantPlugins
2
2
  module G5K
3
3
  module Action
4
- class MessageAlreadyCreated
4
+ class MessageAlreadyRunning
5
5
  def initialize(app, env)
6
6
  @app = app
7
7
  end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module G5K
3
+ module Action
4
+ class MessageNotRunning
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info("vagrant_g5k.not_running")
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -12,15 +12,20 @@ module VagrantPlugins
12
12
  end
13
13
 
14
14
  def call(env)
15
- ports = env[:machine].provider_config.ports
16
- ssh_fwd = ports.select{ |x| x.split(':')[1] == '22'}.first
17
- if ssh_fwd.nil?
18
- env[:ui].error "SSH port 22 must be forwarded"
19
- raise Error "SSh port 22 isn't forwarded"
15
+ net = env[:machine].provider_config.net
16
+ # Note: better to encapsulate this in a NetDriver
17
+ if net["type"] == 'bridge'
18
+ env[:machine_ssh_info] = read_ssh_info(env[:g5k_connection], env[:machine])
19
+ else
20
+ ports = net["ports"]
21
+ ssh_fwd = ports.select{ |x| x.split(':')[1] == '22'}.first
22
+ if ssh_fwd.nil?
23
+ env[:ui].error "SSH port 22 must be forwarded"
24
+ raise Error "SSh port 22 isn't forwarded"
25
+ end
26
+ ssh_fwd = ssh_fwd.split('-:')[0]
27
+ env[:machine_ssh_info] = read_ssh_info(env[:g5k_connection], env[:machine], ssh_fwd)
20
28
  end
21
- ssh_fwd = ssh_fwd.split('-:')[0]
22
- env[:machine_ssh_info] = read_ssh_info(env[:g5k_connection], env[:machine], ssh_fwd)
23
-
24
29
  @app.call(env)
25
30
  end
26
31
 
@@ -33,18 +38,15 @@ module VagrantPlugins
33
38
  end
34
39
 
35
40
 
36
- def read_ssh_info(conn, machine, ssh_fwd)
41
+ def read_ssh_info(conn, machine, ssh_fwd = nil)
37
42
  return nil if machine.id.nil?
38
43
 
39
- if ssh_fwd.nil?
40
- raise Error "ssh_port should be forwarded"
41
- end
42
-
43
44
  ssh_info = {
44
45
  :host => conn.node,
45
- :port => ssh_fwd,
46
46
  }
47
47
 
48
+ ssh_info[:port] = ssh_fwd unless ssh_fwd.nil?
49
+
48
50
  if !conn.gateway.nil?
49
51
  ssh_info[:proxy_command] = "ssh #{conn.username}@#{conn.gateway} #{ssh_key(conn)} nc %h %p"
50
52
  end