vagrant-g5k 0.9.0 → 0.9.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e0e51fdb1bc354bce80d807d3b6c7500aa32e61
4
- data.tar.gz: f326ea37cee6bc501848b8deafda61af85a320a7
3
+ metadata.gz: bad549f807cf2aa5b7c6bc5bef799e00ea8bc5e7
4
+ data.tar.gz: 8b56db026b2a0712f338a8a983c6540bfa8ed865
5
5
  SHA512:
6
- metadata.gz: 0e632af665f7c61884dd62b0a105114fbe3a2896f848d66174cf09a79b394c6d365a04be4431e1c9425391c34a8d94d9e85ead25b516f691ef8950fa5175a2f0
7
- data.tar.gz: 8a67e80906ff550ed7befb257224cafdc01a613f7bc989889e552b46d4b046758dbb155fade5aca2eca7d3a618f174988255042a8a5f75da5368262b9cb1dd17
6
+ metadata.gz: c4cec907465a00958ab204513169098326701d52b1b19869b78dba7864739a394c260c5c3844b28db9c4d3d6f1007fe65e0bfbeb12dc467e3d22f2723d2afefd
7
+ data.tar.gz: 7214b015047e8ec53868471c99477e6054a6543dc8ae0920a28c64b41e0128951c846c1e63faa38d248c9c6abd69331fff6e925996d65005cb6d68c5f3674b0f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.9.1
2
+
3
+ * Allow custom cpu and memory demands.
4
+
1
5
  # 0.9.0
2
6
 
3
7
  * Code refactoring :
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ > The plugin is updated often, this may include breaking changes.
2
+
1
3
  # Vagrant G5K Provider
2
4
  This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds an [G5K](https://www.grid5000.fr)
3
5
  provider to Vagrant, allowing Vagrant to control and provision **virtual machines** on Grid5000.
data/Vagrantfile CHANGED
@@ -1,9 +1,8 @@
1
1
  # -*- mode: ruby -*-
2
2
  # vi: set ft=ruby :
3
3
  #
4
- # Testing purpose only
5
- #Vagrant.require_plugin "vagrant-g5k"
6
-
4
+ # Sample Vagrantfile
5
+ #
7
6
  Vagrant.configure(2) do |config|
8
7
 
9
8
  config.vm.provider "g5k" do |g5k|
@@ -16,49 +15,64 @@ Vagrant.configure(2) do |config|
16
15
  g5k.gateway = "access.grid5000.fr"
17
16
  g5k.walltime = "01:00:00"
18
17
 
19
- # Image backed by the ceph cluster
20
- g5k.image = {
21
- :pool => "msimonin_rbds",
22
- :rbd => "bases/ubuntu1404-9p",
23
- :snapshot => "parent",
24
- :id => "$USER",
25
- :conf => "$HOME/.ceph/config",
26
- :backing => "copy"
27
- }
28
- #
18
+ ## Image backed by the ceph cluster
19
+ #g5k.image = {
20
+ # :pool => "msimonin_rbds",
21
+ # :rbd => "bases/ubuntu1404-9p",
22
+ # :snapshot => "parent",
23
+ # :id => "$USER",
24
+ # :conf => "$HOME/.ceph/config",
25
+ # :backing => "copy"
26
+ #}
27
+
29
28
  # Image backed on the frontend filesystem
30
- # g5k.image = {
31
- # :path => "/grid5000/virt-images/alpine_docker.qcow2",
32
- # :backing => "copy"
33
- # }
29
+ g5k.image = {
30
+ :path => "/grid5000/virt-images/alpine_docker.qcow2",
31
+ :backing => "copy"
32
+ }
34
33
 
35
- # g5k.net = {
36
- # :type => "bridge"
37
- # }
34
+ ## Bridged network : this allow VMs to communicate
35
+ #g5k.net = {
36
+ # :type => "bridge"
37
+ #}
38
+
39
+ ## Nat network : VMs will only have access to the external world
40
+ ## Forwarding ports will allow you to access services hosted inside the
41
+ ## VM.
38
42
  g5k.net = {
39
43
  :type => "nat",
40
44
  :ports => ["2222-:22"]
41
45
  }
42
46
 
43
-
44
- # oar selection of resource
47
+ ## OAR selection of resource
45
48
  g5k.oar = "virtual != 'none'"
46
- end #g5k
47
49
 
50
+ ## VM size customization default values are
51
+ ## cpu => -1 -> all the cpu of the reserved node
52
+ ## mem => -1 -> all the mem of the reserved node
53
+ ##
54
+ #g5k.resources = {
55
+ # :cpu => 1,
56
+ # :mem => 2048
57
+ #}
58
+ end #g5k
48
59
 
49
- (1..1).each do |i|
50
- config.vm.define "vm#{i}" do |my|
51
- my.vm.box = "dummy"
52
-
53
- # my.ssh.username = "root"
54
- # my.ssh.password = ""
60
+ ## This define a VM.
61
+ ## a g5k provider section will override top level options
62
+ ## To define multiple VMs you can
63
+ ## * either repeat the block
64
+ ## * loop over using (1..N).each block
65
+ config.vm.define "vm" do |my|
66
+ my.vm.box = "dummy"
67
+
68
+ ## Access to the vm
69
+ ## This is specific to alpine_docker
70
+ ## It's better to use a vagrant image
71
+ ## converted to qcow2
72
+ my.ssh.username = "root"
73
+ my.ssh.password = ""
55
74
 
56
- end #vm
57
- end
58
- # Repeat block to define another vm
59
- # config.vm.define "vm2" do |my|
60
- #
61
- # end
75
+ end #vm
62
76
 
63
77
  end
64
78
 
@@ -52,6 +52,12 @@ module VagrantPlugins
52
52
  # @return [String]
53
53
  attr_accessor :oar
54
54
 
55
+ # VM resource demand
56
+ #
57
+ #
58
+ # @return [Hash]
59
+ attr_accessor :resources
60
+
55
61
  def initialize()
56
62
  @username = ENV['USER']
57
63
  @project_id = nil
@@ -60,13 +66,19 @@ module VagrantPlugins
60
66
  @walltime = "01:00:00"
61
67
  @oar = ""
62
68
  @net = {
63
- :type => 'nat',
64
- :ports => ['2222-:22']
69
+ :type => 'nat'
70
+ }
71
+ @resources = {
65
72
  }
66
73
  end
67
74
 
68
75
  def finalize!()
69
- # This is call by the plugin mecanism after initialize
76
+ # set default ssh redirection
77
+ if @net[:type] == 'nat' && @net[:ports].nil?
78
+ @net[:ports] = ["2222-:22"]
79
+ end
80
+ @resources[:cpu] = -1 if @resources[:cpu].nil?
81
+ @resources[:mem] = -1 if @resources[:mem].nil?
70
82
  end
71
83
 
72
84
 
@@ -78,6 +90,7 @@ module VagrantPlugins
78
90
  errors << "g5k image is required" if @image.nil?
79
91
  errors << "g5k image must be a Hash" if !@image.is_a?(Hash)
80
92
  errors << "g5k net must be a Hash" if !@net.is_a?(Hash)
93
+ errors << "g5k resources must be a Hash" if !@resources.is_a?(Hash)
81
94
 
82
95
  { "G5K Provider" => errors }
83
96
  end
@@ -28,7 +28,8 @@ module VagrantPlugins
28
28
  @walltime = @provider_config.walltime
29
29
  @image= @provider_config.image
30
30
  @oar = "{#{@provider_config.oar}}/" if @provider_config.oar != ""
31
-
31
+ @resources = @provider_config.resources
32
+ @oar_unit = init_oar_unit(@resources[:cpu], @resources[:mem])
32
33
  @cwd = cwd
33
34
  @driver = driver
34
35
  @oar_driver = oar_driver
@@ -36,6 +37,15 @@ module VagrantPlugins
36
37
  @disk_driver = disk_driver
37
38
  end
38
39
 
40
+ def init_oar_unit(cpu, mem)
41
+ if cpu != -1 and mem != -1
42
+ unit = "core=#{cpu}"
43
+ else
44
+ unit = "nodes=1"
45
+ end
46
+ return unit
47
+ end
48
+
39
49
 
40
50
  def create_local_working_dir()
41
51
  exec("mkdir -p #{@cwd}")
@@ -86,12 +96,19 @@ module VagrantPlugins
86
96
  net = @net_driver.generate_net()
87
97
  drive = _generate_drive(env)
88
98
 
89
- args = [net, drive].join(" ")
99
+ args = [@resources[:cpu], @resources[:mem], net, drive].join(" ")
90
100
  # Submitting a new job
91
101
  # Getting the job_id as a ruby string
102
+ options = []
103
+
104
+ if @oar_unit =~ /core/
105
+ # allow classic ssh only work when the node is reserved as a whole
106
+ # this implies that nat networking won't work when core is the unit of
107
+ # deployment
108
+ options << '-t allow_classic_ssh'
109
+ end
92
110
  options = [
93
- "-t allow_classic_ssh",
94
- "-l \"#{@oar}nodes=1, walltime=#{@walltime}\"",
111
+ "-l \"#{@oar}#{@oar_unit}, walltime=#{@walltime}\"",
95
112
  "--name #{env[:machine].name}",
96
113
  "--checkpoint 60",
97
114
  "--signal 12"
@@ -78,7 +78,7 @@ module VagrantPlugins
78
78
  def _process_errors(job_id)
79
79
  job = check_job(job_id)
80
80
  stderr_file = job["stderr_file"]
81
- stderr = exec("cat #{stderr_file}")
81
+ stderr = @driver.exec("cat #{stderr_file}")
82
82
  @ui.error("#{stderr_file}: #{stderr}")
83
83
  raise VagrantPlugins::G5K::Errors::JobError
84
84
  end
@@ -4,8 +4,15 @@
4
4
  # Thanks to him !
5
5
  # I've made some addition though :)
6
6
 
7
- #
7
+ # ARGS
8
+ # $1: cpu demand
9
+ # $2: mem demand
10
+ # $3: net type {BRIDGE, NAT}
11
+ # BRIDGE | NAT
12
+ # $4 subnet_file | $left other net, drive options
13
+ # $left net/drive options
8
14
 
15
+ set -x
9
16
 
10
17
  function net_bridge() {
11
18
  SUBNET_FILE=$1
@@ -23,6 +30,29 @@ function net_bridge() {
23
30
  echo "-net nic,model=virtio,macaddr=$MAC_ADDR -net tap,ifname=$TAP,script=no"
24
31
  }
25
32
 
33
+ # CPU demand
34
+ if [ "$1" == "-1" ]
35
+ then
36
+ SMP=$(nproc)
37
+ else
38
+ SMP=$1
39
+ fi
40
+ echo "SMP = $SMP"
41
+ shift
42
+
43
+ # Memory demand
44
+ KEEP_SYSTEM_MEM=1 # Gb
45
+ if [ "$1" == "-1" ]
46
+ then
47
+ TOTAL_MEM=$(cat /proc/meminfo | grep -e '^MemTotal:' | awk '{print $2}')
48
+ VM_MEM=$(( ($TOTAL_MEM / 1024) - $KEEP_SYSTEM_MEM * 1024 ))
49
+ else
50
+ VM_MEM=$1
51
+ fi
52
+ echo "VM_MEM = $VM_MEM"
53
+ shift
54
+
55
+ # net demand
26
56
  net=""
27
57
  if [ "$1" == "BRIDGE" ]
28
58
  then
@@ -40,14 +70,6 @@ fi
40
70
  # Directory for qcow2 snapshots
41
71
  export TMPDIR=/tmp
42
72
 
43
- # Memory allocation
44
- KEEP_SYSTEM_MEM=1 # Gb
45
- TOTAL_MEM=$(cat /proc/meminfo | grep -e '^MemTotal:' | awk '{print $2}')
46
- VM_MEM=$(( ($TOTAL_MEM / 1024) - $KEEP_SYSTEM_MEM * 1024 ))
47
-
48
- # CPU
49
- SMP=$(nproc)
50
-
51
73
  # Clean shutdown of the VM at the end of the OAR job
52
74
  clean_shutdown() {
53
75
  echo "Caught shutdown signal at $(date)"
@@ -57,8 +79,7 @@ clean_shutdown() {
57
79
  trap clean_shutdown 12
58
80
 
59
81
  # Launch virtual machine
60
- #kvm -m $VM_MEM -smp $SMP -drive file=$IMAGE,if=virtio -snapshot -fsdev local,security_model=none,id=fsdev0,path=$HOME -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare -nographic -net nic,model=virtio,macaddr=$MAC_ADDR -net tap,ifname=$TAP,script=no -monitor unix:/tmp/vagrant-g5k.mon,server,nowait -localtime -enable-kvm &
61
- kvm -m $VM_MEM -smp $SMP -fsdev local,security_model=none,id=fsdev0,path=$HOME -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare -nographic -monitor unix:/tmp/vagrant-g5k.mon,server,nowait -localtime -enable-kvm $net $@ &
82
+ kvm -m $VM_MEM -smp cores=$SMP,threads=1,sockets=1 -fsdev local,security_model=none,id=fsdev0,path=$HOME -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare -nographic -monitor unix:/tmp/vagrant-g5k.mon,server,nowait -localtime -enable-kvm $net $@ &
62
83
 
63
84
  wait
64
85
 
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module G5K
3
- VERSION = '0.9.0'
3
+ VERSION = '0.9.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-g5k
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Simonin