vagrant-g5k 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -2
- data/Vagrantfile +24 -6
- data/lib/vagrant-g5k/action.rb +32 -2
- data/lib/vagrant-g5k/action/connect_g5k.rb +11 -8
- data/lib/vagrant-g5k/action/delete_disk.rb +18 -0
- data/lib/vagrant-g5k/action/delete_job.rb +1 -0
- data/lib/vagrant-g5k/action/is_created.rb +2 -1
- data/lib/vagrant-g5k/action/message_already_created.rb +1 -1
- data/lib/vagrant-g5k/action/read_state.rb +21 -7
- data/lib/vagrant-g5k/config.rb +17 -8
- data/lib/vagrant-g5k/errors.rb +6 -0
- data/lib/vagrant-g5k/plugin.rb +1 -1
- data/lib/vagrant-g5k/util/g5k_utils.rb +186 -54
- data/lib/vagrant-g5k/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fe452d0c9d49354e7ab25094dcc73723103d67f
|
4
|
+
data.tar.gz: 13f854e214d65d43109608ae487c10f642ba81d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bad68ae00e744df6b480825fb5da0fb68eaf981a791cd2a7f5ad4c9f1ce1538ebdd9030de1d8a6e8b7a88f30c3be1b85f253350fe6d5fc4ffd88344c57e2a39
|
7
|
+
data.tar.gz: c58fc1ef51ccabb2bb1739608f58e77676f1e46eed5222336d7de5cde8aaeebc6430a5c8d4b3f2f9446344fb4bc4e90082f7268fc1e2e624ace76336b3500c29
|
data/README.md
CHANGED
@@ -26,8 +26,26 @@ $ vagrant up --provider=g5k
|
|
26
26
|
|
27
27
|
Check the Vagrantfile.
|
28
28
|
|
29
|
+
## Note on disk format and backing strategy
|
30
|
+
|
31
|
+
Virtual Machines can be booted either :
|
32
|
+
|
33
|
+
* From a `qcow2` image stored in the frontend filesystem
|
34
|
+
* From a rbd image stored in one of the ceph cluster of Grid'5000.
|
35
|
+
|
36
|
+
Once the base image is chosen, you can pick one of the following strategy
|
37
|
+
to back the disk image of the virtual machines :
|
38
|
+
|
39
|
+
* `copy`: will make a full copy of the image in your home directory (resp. in the same pool as the rbd)
|
40
|
+
* `cow`: will create a Copy On write image in your home directory (resp. in the same pool as the rbd)
|
41
|
+
* `direct`: will use the image directly (you'll need r/w access to the image)
|
42
|
+
* `snapshot`: will let `kvm` create an ephemeral copy on write image.
|
43
|
+
|
29
44
|
## Supported operations
|
30
45
|
|
31
|
-
* `vagrant up`
|
32
|
-
* `vagrant ssh`
|
33
46
|
* `vagrant destroy`
|
47
|
+
* `vagrant halt`
|
48
|
+
* `vagrant provision`
|
49
|
+
* `vagrant ssh`
|
50
|
+
* `vagrant status`
|
51
|
+
* `vagrant up`
|
data/Vagrantfile
CHANGED
@@ -8,14 +8,22 @@ Vagrant.configure(2) do |config|
|
|
8
8
|
# box isn't used
|
9
9
|
config.vm.define "vm" do |my|
|
10
10
|
my.vm.box = "dummy"
|
11
|
+
|
12
|
+
# make sure the insecure-key of vagrant is authorized
|
13
|
+
my.vm.provision "shell", inline: "echo hello", privileged: false
|
11
14
|
end
|
12
15
|
|
13
16
|
# user to log with inside the vm
|
14
17
|
config.ssh.username = "root"
|
15
18
|
# password to use to log inside the vm
|
16
|
-
config.ssh.password = ""
|
17
|
-
|
19
|
+
# config.ssh.password = ""
|
20
|
+
|
18
21
|
config.vm.provider "g5k" do |g5k|
|
22
|
+
# The project id.
|
23
|
+
# It is used to generate uniq remote storage for images
|
24
|
+
# It must be uniq accros all project managed by vagrant.
|
25
|
+
g5k.project_id = "vagrant-g5k"
|
26
|
+
|
19
27
|
# user name used to connect to g5k
|
20
28
|
g5k.username = ENV['USER']
|
21
29
|
|
@@ -29,19 +37,29 @@ Vagrant.configure(2) do |config|
|
|
29
37
|
# g5k.walltime = "02:00:00"
|
30
38
|
|
31
39
|
# image location
|
32
|
-
g5k.
|
40
|
+
#g5k.image = {
|
41
|
+
# "path" => "/grid5000/virt-images/alpine_docker.qcow2",
|
42
|
+
# "backing" => "cow"
|
43
|
+
#}
|
33
44
|
|
34
45
|
# it could be backed by the ceph
|
35
|
-
|
46
|
+
g5k.image = {
|
47
|
+
"pool" => "msimonin_rbds",
|
48
|
+
"rbd" => "bases/alpine_docker",
|
49
|
+
"snapshot" => "parent",
|
50
|
+
"id" => "$USER",
|
51
|
+
"conf" => "$HOME/.ceph/config",
|
52
|
+
"backing" => "copy"
|
53
|
+
}
|
36
54
|
|
37
55
|
# g5k.backing_strategy = "snapshot"
|
38
56
|
# this is a copy on write strategy
|
39
57
|
# image_location is use to read, an epehemeral disk will hold the writes
|
40
58
|
# if not specified this means that the image is used in r/w mode.
|
41
59
|
# changes will be persistent
|
42
|
-
g5k.backing_strategy = "
|
60
|
+
g5k.backing_strategy = "cow"
|
43
61
|
# ports to expose (at least ssh has to be forwarded)
|
44
|
-
g5k.ports = ['2222-:22']
|
62
|
+
g5k.ports = ['2222-:22','3000-:3000']
|
45
63
|
end
|
46
64
|
|
47
65
|
|
data/lib/vagrant-g5k/action.rb
CHANGED
@@ -68,14 +68,14 @@ module VagrantPlugins
|
|
68
68
|
b.use Call, DestroyConfirm do |env, b2|
|
69
69
|
if env[:result]
|
70
70
|
b2.use ConfigValidate
|
71
|
+
b2.use ConnectG5K
|
71
72
|
b2.use Call, IsCreated do |env2, b3|
|
72
73
|
if !env2[:result]
|
73
74
|
b3.use MessageNotCreated
|
74
75
|
next
|
75
76
|
end
|
76
|
-
|
77
|
-
b3.use ConnectG5K
|
78
77
|
b3.use DeleteJob
|
78
|
+
b3.use DeleteDisk
|
79
79
|
end
|
80
80
|
else
|
81
81
|
b2.use MessageWillNotDestroy
|
@@ -84,11 +84,41 @@ module VagrantPlugins
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
# This action is called to shutdown the remote machine.
|
88
|
+
def self.action_halt
|
89
|
+
Vagrant::Action::Builder.new.tap do |b|
|
90
|
+
b.use ConfigValidate
|
91
|
+
b.use ConnectG5K
|
92
|
+
b.use Call, IsCreated do |env1, b2|
|
93
|
+
if !env1[:result]
|
94
|
+
b2.use MessageNotCreated
|
95
|
+
next
|
96
|
+
end
|
97
|
+
b2.use DeleteJob
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# This action is called when `vagrant provision` is called.
|
103
|
+
def self.action_provision
|
104
|
+
Vagrant::Action::Builder.new.tap do |b|
|
105
|
+
b.use ConfigValidate
|
106
|
+
b.use Call, IsCreated do |env, b2|
|
107
|
+
if !env[:result]
|
108
|
+
b2.use MessageNotCreated
|
109
|
+
next
|
110
|
+
end
|
111
|
+
puts "provision"
|
112
|
+
b2.use Provision
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
87
116
|
|
88
117
|
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
89
118
|
autoload :ConnectG5K, action_root.join("connect_g5k")
|
90
119
|
autoload :CreateLocalWorkingDir, action_root.join("create_local_working_dir")
|
91
120
|
autoload :DeleteJob, action_root.join("delete_job")
|
121
|
+
autoload :DeleteDisk, action_root.join("delete_disk")
|
92
122
|
autoload :IsCreated, action_root.join("is_created")
|
93
123
|
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
|
94
124
|
autoload :MessageNotCreated, action_root.join("message_not_created")
|
@@ -14,15 +14,18 @@ module VagrantPlugins
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env)
|
17
|
+
args = {
|
18
|
+
:@ui => env[:ui]
|
19
|
+
}
|
20
|
+
a = env[:machine].provider_config.instance_variables.map do |attr|
|
21
|
+
[ attr, env[:machine].provider_config.instance_variable_get(attr)]
|
22
|
+
end.to_h
|
23
|
+
args.merge!(a)
|
24
|
+
#.map do |attr|
|
25
|
+
# {attr => env[:machine].provider_config.instance_variable_get(attr)}
|
26
|
+
#end
|
17
27
|
env[:g5k_connection] = Connection.new(
|
18
|
-
|
19
|
-
:username => env[:machine].provider_config.username,
|
20
|
-
:private_key => env[:machine].provider_config.private_key,
|
21
|
-
:walltime => env[:machine].provider_config.walltime,
|
22
|
-
:image_location => env[:machine].provider_config.image_location,
|
23
|
-
:site => env[:machine].provider_config.site,
|
24
|
-
:ports => env[:machine].provider_config.ports,
|
25
|
-
:backing_strategy => env[:machine].provider_config.backing_strategy
|
28
|
+
args
|
26
29
|
)
|
27
30
|
@app.call(env)
|
28
31
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module G5K
|
3
|
+
module Action
|
4
|
+
class DeleteDisk
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
conn = env[:g5k_connection]
|
11
|
+
env[:ui].info("Deleting the associated disk")
|
12
|
+
conn.delete_disk(env)
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -12,19 +12,33 @@ module VagrantPlugins
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call(env)
|
15
|
-
env[:machine_state_id] = read_state(env
|
15
|
+
env[:machine_state_id] = read_state(env)
|
16
16
|
@app.call(env)
|
17
17
|
end
|
18
18
|
|
19
|
-
def read_state(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def read_state(env)
|
20
|
+
machine = env[:machine]
|
21
|
+
conn = env[:g5k_connection]
|
22
|
+
id = machine.id
|
23
|
+
local_storage = conn.check_local_storage(env)
|
24
|
+
if id.nil? and local_storage.nil?
|
24
25
|
return :not_created
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
+
if id.nil? and not local_storage.nil?
|
29
|
+
return :shutdown
|
30
|
+
end
|
31
|
+
|
32
|
+
if not id.nil?
|
33
|
+
# is there a job running for this vm ?
|
34
|
+
job = conn.check_job(id)
|
35
|
+
if job.nil?
|
36
|
+
return :not_created
|
37
|
+
end
|
38
|
+
return job["state"].to_sym
|
39
|
+
end
|
40
|
+
|
41
|
+
return :guru_meditation
|
28
42
|
end
|
29
43
|
end
|
30
44
|
end
|
data/lib/vagrant-g5k/config.rb
CHANGED
@@ -14,6 +14,11 @@ module VagrantPlugins
|
|
14
14
|
# @return [String]
|
15
15
|
attr_accessor :private_key
|
16
16
|
|
17
|
+
# G5K project_id
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
attr_accessor :project_id
|
21
|
+
|
17
22
|
# G5K walltime
|
18
23
|
#
|
19
24
|
# @return [String]
|
@@ -23,10 +28,12 @@ module VagrantPlugins
|
|
23
28
|
#
|
24
29
|
# @return [String]
|
25
30
|
attr_accessor :site
|
26
|
-
|
31
|
+
|
32
|
+
# G5K image
|
27
33
|
#
|
28
|
-
# @return [
|
29
|
-
attr_accessor :
|
34
|
+
# @return [Hash]
|
35
|
+
attr_accessor :image
|
36
|
+
|
30
37
|
|
31
38
|
# G5K ports mapping
|
32
39
|
#
|
@@ -41,11 +48,11 @@ module VagrantPlugins
|
|
41
48
|
attr_accessor :backing_strategy
|
42
49
|
|
43
50
|
def initialize()
|
44
|
-
@username
|
45
|
-
@
|
46
|
-
@site
|
51
|
+
@username = nil
|
52
|
+
@project_id = nil
|
53
|
+
@site = "rennes"
|
47
54
|
@backing_strategy = ""
|
48
|
-
@walltime
|
55
|
+
@walltime = "01:00:00"
|
49
56
|
end
|
50
57
|
|
51
58
|
def finalize!()
|
@@ -57,8 +64,10 @@ module VagrantPlugins
|
|
57
64
|
errors = _detected_errors
|
58
65
|
|
59
66
|
errors << "g5k username is required" if @username.nil?
|
60
|
-
errors << "g5k
|
67
|
+
errors << "g5k image is required" if @image.nil?
|
68
|
+
errors << "g5k image is required" if @project_id.nil?
|
61
69
|
|
70
|
+
# TODO validate image hash
|
62
71
|
{ "G5K Provider" => errors }
|
63
72
|
end
|
64
73
|
|
data/lib/vagrant-g5k/errors.rb
CHANGED
data/lib/vagrant-g5k/plugin.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'net/ssh/multi'
|
2
2
|
require 'net/scp'
|
3
3
|
require 'json'
|
4
|
+
require 'digest'
|
4
5
|
|
5
6
|
require 'vagrant/util/retryable'
|
6
7
|
|
7
|
-
WORKING_DIR = ".vagrant-g5k"
|
8
8
|
LAUNCHER_SCRIPT = "launch_vm_fwd.sh"
|
9
|
-
|
9
|
+
|
10
|
+
STRATEGY_SNAPSHOT = "snapshot"
|
11
|
+
STRATEGY_COPY = "copy"
|
12
|
+
STRATEGY_COW = "cow"
|
13
|
+
STRATEGY_DIRECT = "direct"
|
10
14
|
|
11
15
|
module VagrantPlugins
|
12
16
|
module G5K
|
@@ -17,6 +21,8 @@ module VagrantPlugins
|
|
17
21
|
|
18
22
|
attr_accessor :username
|
19
23
|
|
24
|
+
attr_accessor :project_id
|
25
|
+
|
20
26
|
attr_accessor :private_key
|
21
27
|
|
22
28
|
attr_accessor :site
|
@@ -35,55 +41,32 @@ module VagrantPlugins
|
|
35
41
|
|
36
42
|
attr_accessor :backing_strategy
|
37
43
|
|
38
|
-
# legacy
|
39
|
-
@@locations = [
|
40
|
-
{
|
41
|
-
:path => "/grid5000/virt-images",
|
42
|
-
:type => "local"
|
43
|
-
}
|
44
|
-
]
|
45
|
-
|
46
44
|
def initialize(args)
|
47
45
|
# initialize
|
48
46
|
args.each do |k,v|
|
49
|
-
instance_variable_set("
|
47
|
+
instance_variable_set("#{k}", v) unless v.nil?
|
50
48
|
end
|
51
|
-
@logger.
|
49
|
+
@logger = Log4r::Logger.new("vagrant::environment")
|
50
|
+
@logger.debug("connecting with #{@username} on site #{@site}")
|
52
51
|
options = {
|
53
52
|
:forward_agent => true
|
54
53
|
}
|
55
54
|
options[:keys] = [@private_key] if !@private_key.nil?
|
56
55
|
gateway = Net::SSH::Gateway.new("access.grid5000.fr", @username, options)
|
57
|
-
|
58
56
|
@session = gateway.ssh(@site, @username, options)
|
59
57
|
end
|
60
58
|
|
61
|
-
def list_images()
|
62
|
-
images = []
|
63
|
-
@@locations.each do |location|
|
64
|
-
if location[:type] == "local"
|
65
|
-
stdout = ""
|
66
|
-
@session.exec!("ls #{location[:path]}/*.qcow2") do |channel, stream, data|
|
67
|
-
stdout << data
|
68
|
-
end
|
69
|
-
images += stdout.split("\n").map{ |i| {:path => i, :type => 'local'} }
|
70
|
-
#elsif location[:type] == "ceph"
|
71
|
-
# stdout = ""
|
72
|
-
# @session.exec!("rbd --pool #{location[:pool]} --conf $HOME/.ceph/config --id #{location[:id]} ls") do |channel, stream, data|
|
73
|
-
# stdout << data
|
74
|
-
# end
|
75
|
-
# images += stdout.split("\n").map{ |i| {:path => i, :type => 'ceph'} }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
images
|
79
|
-
end
|
80
|
-
|
81
59
|
def create_local_working_dir(env)
|
82
|
-
@session.exec("mkdir -p #{
|
60
|
+
@session.exec("mkdir -p #{cwd(env)}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def cwd(env)
|
64
|
+
# remote working directory
|
65
|
+
File.join("/home", @username, ".vagrant", @project_id)
|
83
66
|
end
|
84
67
|
|
85
68
|
|
86
|
-
|
69
|
+
def check_job(job_id)
|
87
70
|
oarstat = exec("oarstat --json")
|
88
71
|
oarstat = JSON.load(oarstat)
|
89
72
|
r = oarstat.select!{ |k,v| k == job_id and v["owner"] == @username }.values.first
|
@@ -95,30 +78,60 @@ module VagrantPlugins
|
|
95
78
|
return r
|
96
79
|
end
|
97
80
|
|
81
|
+
def check_local_storage(env)
|
82
|
+
# Is the disk image already here ?
|
83
|
+
if @image["pool"].nil?
|
84
|
+
file = _check_file_local_storage(env)
|
85
|
+
else
|
86
|
+
file = _check_rbd_local_storage(env)
|
87
|
+
end
|
88
|
+
return file if file != ""
|
89
|
+
return nil
|
90
|
+
end
|
91
|
+
|
92
|
+
def _check_file_local_storage(env)
|
93
|
+
strategy = @image["backing"]
|
94
|
+
file_to_check = ""
|
95
|
+
if [STRATEGY_SNAPSHOT, STRATEGY_DIRECT].include?(strategy)
|
96
|
+
file_to_check = @image[path]
|
97
|
+
else
|
98
|
+
file_to_check = File.join(cwd(env), env[:machine].name.to_s)
|
99
|
+
end
|
100
|
+
exec("[ -f \"#{file_to_check}\" ] && echo #{file_to_check} || echo \"\"")
|
101
|
+
end
|
102
|
+
|
103
|
+
def _check_rbd_local_storage(env)
|
104
|
+
strategy = @image["backing"]
|
105
|
+
file_to_check = ""
|
106
|
+
if [STRATEGY_SNAPSHOT, STRATEGY_DIRECT].include?(strategy)
|
107
|
+
file_to_check = @image[path]
|
108
|
+
else
|
109
|
+
file_to_check = File.join(cwd(env), env[:machine].name.to_s)[1..-1]
|
110
|
+
end
|
111
|
+
exec("(rbd --pool #{@image["pool"]} --id #{@image["id"]} --conf #{@image["conf"]} ls | grep #{file_to_check}) || echo \"\"")
|
112
|
+
end
|
113
|
+
|
114
|
+
|
98
115
|
def launch_vm(env)
|
99
116
|
launcher_path = File.join(File.dirname(__FILE__), LAUNCHER_SCRIPT)
|
100
|
-
@
|
117
|
+
@ui.info("Launching the VM on Grid'5000")
|
101
118
|
# Checking the subnet job
|
102
|
-
@logger.info("Uploading launcher")
|
103
119
|
# uploading the launcher
|
104
|
-
launcher_remote_path = File.join(
|
120
|
+
launcher_remote_path = File.join(cwd(env), LAUNCHER_SCRIPT)
|
105
121
|
upload(launcher_path, launcher_remote_path)
|
106
122
|
|
107
123
|
# Generate partial arguments for the kvm command
|
108
|
-
drive = _generate_drive()
|
124
|
+
drive = _generate_drive(env)
|
109
125
|
net = _generate_net()
|
110
|
-
# TODO implement different backing strategy
|
111
|
-
snapshot_flag = "-snapshot" if @backing_strategy == "snapshot"
|
112
126
|
|
113
|
-
args = [drive, net
|
127
|
+
args = [drive, net].join(" ")
|
114
128
|
# Submitting a new job
|
115
|
-
@logger.info("Starting a new job")
|
116
129
|
job_id = exec("oarsub -t allow_classic_ssh -l \"{virtual!=\'none\'}/nodes=1,walltime=#{@walltime}\" --name #{env[:machine].name} --checkpoint 60 --signal 12 \"#{launcher_remote_path} #{args}\" | grep OAR_JOB_ID | cut -d '=' -f2").chomp
|
117
130
|
|
118
131
|
|
119
132
|
begin
|
120
133
|
retryable(:on => VagrantPlugins::G5K::Errors::JobNotRunning, :tries => 100, :sleep => 2) do
|
121
|
-
@
|
134
|
+
@ui.info("Waiting for the job to be running")
|
122
135
|
job = check_job(job_id)
|
123
136
|
if job.nil? or job["state"] != "Running"
|
124
137
|
raise VagrantPlugins::G5K::Errors::JobNotRunning
|
@@ -128,29 +141,150 @@ module VagrantPlugins
|
|
128
141
|
break
|
129
142
|
end
|
130
143
|
rescue VagrantPlugins::G5K::Errors::JobNotRunning
|
131
|
-
@
|
144
|
+
@ui.error("Tired of waiting")
|
132
145
|
raise VagrantPlugins::G5K::Errors::JobNotRunning
|
133
146
|
end
|
134
|
-
@
|
147
|
+
@ui.info("VM booted on Grid'5000")
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
def delete_disk(env)
|
152
|
+
if [STRATEGY_DIRECT, STRATEGY_SNAPSHOT].include?(@image["backing"])
|
153
|
+
@ui.error("Destroy not support for the strategy #{@image["backing"]}")
|
154
|
+
return
|
155
|
+
end
|
135
156
|
|
157
|
+
if @image["pool"].nil?
|
158
|
+
disk = File.join(cwd(env), env[:machine].name.to_s)
|
159
|
+
exec("rm #{disk}")
|
160
|
+
else
|
161
|
+
disk = File.join(@image["pool"], cwd(env), env[:machine].name.to_s)
|
162
|
+
begin
|
163
|
+
retryable(:on => VagrantPlugins::G5K::Errors::CommandError, :tries => 10, :sleep => 5) do
|
164
|
+
exec("rbd rm #{disk} --conf #{@image["conf"]} --id #{@image["id"]}" )
|
165
|
+
break
|
166
|
+
end
|
167
|
+
rescue VagrantPlugins::G5K::Errors::CommandError
|
168
|
+
@ui.error("Reach max attempt while trying to remove the rbd")
|
169
|
+
raise VagrantPlugins::G5K::Errors::CommandError
|
170
|
+
end
|
171
|
+
end
|
136
172
|
end
|
137
173
|
|
138
174
|
|
139
175
|
def exec(cmd)
|
140
|
-
@logger.
|
176
|
+
@logger.debug("Executing #{cmd}")
|
141
177
|
stdout = ""
|
142
|
-
|
143
|
-
|
178
|
+
stderr = ""
|
179
|
+
exit_code = 0
|
180
|
+
@session.open_channel do |channel|
|
181
|
+
channel.exec(cmd) do |ch, success|
|
182
|
+
abort "could not execute command" unless success
|
183
|
+
|
184
|
+
channel.on_data do |c, data|
|
185
|
+
stdout << data.chomp
|
186
|
+
end
|
187
|
+
|
188
|
+
channel.on_extended_data do |c, type, data|
|
189
|
+
stderr << data.chomp
|
190
|
+
end
|
191
|
+
|
192
|
+
channel.on_request("exit-status") do |c,data|
|
193
|
+
exit_code = data.read_long
|
194
|
+
end
|
195
|
+
|
196
|
+
channel.on_close do |c|
|
197
|
+
end
|
198
|
+
end
|
144
199
|
end
|
145
|
-
|
200
|
+
@session.loop
|
201
|
+
if exit_code != 0
|
202
|
+
@logger.error(:stderr => stderr, :code => exit_code)
|
203
|
+
raise VagrantPlugins::G5K::Errors::CommandError
|
204
|
+
end
|
205
|
+
@logger.debug("Returning #{stdout}")
|
206
|
+
stdout
|
146
207
|
end
|
147
208
|
|
148
209
|
def upload(src, dst)
|
149
210
|
@session.scp.upload!(src, dst)
|
150
211
|
end
|
151
212
|
|
152
|
-
def _generate_drive()
|
153
|
-
|
213
|
+
def _generate_drive(env)
|
214
|
+
# Depending on the strategy we generate the file location
|
215
|
+
# This code smells a bit better
|
216
|
+
file = ""
|
217
|
+
snapshot = ""
|
218
|
+
if @image["backing"] == STRATEGY_SNAPSHOT
|
219
|
+
snapshot = "-snapshot"
|
220
|
+
end
|
221
|
+
|
222
|
+
if @image["pool"].nil?
|
223
|
+
file = _generate_drive_local(env)
|
224
|
+
else
|
225
|
+
file = _generate_drive_rbd(env)
|
226
|
+
end
|
227
|
+
|
228
|
+
return "-drive file=#{file},if=virtio #{snapshot}"
|
229
|
+
end
|
230
|
+
|
231
|
+
def _generate_drive_rbd(env)
|
232
|
+
strategy = @image["backing"]
|
233
|
+
if [STRATEGY_SNAPSHOT, STRATEGY_DIRECT].include?(strategy)
|
234
|
+
file = @image["path"]
|
235
|
+
elsif strategy == STRATEGY_COW
|
236
|
+
file = _rbd_clone_or_copy_image(env, clone = true)
|
237
|
+
elsif strategy == STRATEGY_COPY
|
238
|
+
file = _rbd_clone_or_copy_image(env, clone = false)
|
239
|
+
end
|
240
|
+
return file
|
241
|
+
end
|
242
|
+
|
243
|
+
def _generate_drive_local(env)
|
244
|
+
strategy = @image["backing"]
|
245
|
+
if [STRATEGY_SNAPSHOT, STRATEGY_DIRECT].include?(strategy)
|
246
|
+
file = @image["path"]
|
247
|
+
elsif strategy == STRATEGY_COW
|
248
|
+
file = _file_clone_or_copy_image(env, clone = true)
|
249
|
+
elsif strategy == STRATEGY_COPY
|
250
|
+
file = _file_clone_or_copy_image(env, clone = false)
|
251
|
+
end
|
252
|
+
return file
|
253
|
+
end
|
254
|
+
|
255
|
+
def _rbd_clone_or_copy_image(env, clone = true)
|
256
|
+
@ui.info("Clone the rbd image")
|
257
|
+
# destination in the same pool under the .vagrant ns
|
258
|
+
destination = File.join(@image["pool"], cwd(env), env[:machine].name.to_s)
|
259
|
+
# Even if nothing will happen when the destination already exist, we should test it before
|
260
|
+
exists = _check_rbd_local_storage(env)
|
261
|
+
if exists == ""
|
262
|
+
# we create the destination
|
263
|
+
if clone
|
264
|
+
# parent = pool/rbd@snap
|
265
|
+
parent = File.join(@image["pool"], "#{@image["rbd"]}@#{@image["snapshot"]}")
|
266
|
+
exec("rbd clone #{parent} #{destination} --conf #{@image["conf"]} --id #{@image["id"]}" )
|
267
|
+
else
|
268
|
+
# parent = pool/rbd@snap
|
269
|
+
parent = File.join(@image["pool"], "#{@image["rbd"]}")
|
270
|
+
exec("rbd cp #{parent} #{destination} --conf #{@image["conf"]} --id #{@image["id"]}" )
|
271
|
+
end
|
272
|
+
end
|
273
|
+
return "rbd:#{destination}:id=#{@image["id"]}:conf=#{@image["conf"]}"
|
274
|
+
end
|
275
|
+
|
276
|
+
def _file_clone_or_copy_image(env, clone = true)
|
277
|
+
@ui.info("Clone the file image")
|
278
|
+
file = File.join(cwd(env), env[:machine].name.to_s)
|
279
|
+
exists = _check_file_local_storage(env)
|
280
|
+
if exists == ""
|
281
|
+
if clone
|
282
|
+
exec("qemu-img create -f qcow2 -b #{@image["path"]} #{file}")
|
283
|
+
else
|
284
|
+
exec("cp #{@image["path"]} #{file}")
|
285
|
+
end
|
286
|
+
end
|
287
|
+
return file
|
154
288
|
end
|
155
289
|
|
156
290
|
def _generate_net()
|
@@ -160,8 +294,6 @@ module VagrantPlugins
|
|
160
294
|
net = "-net nic,model=virtio -net user,#{fwd_ports}"
|
161
295
|
return net
|
162
296
|
end
|
163
|
-
|
164
|
-
|
165
297
|
end
|
166
298
|
end
|
167
299
|
end
|
data/lib/vagrant-g5k/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.10
|
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-09-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iniparse
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/vagrant-g5k/action.rb
|
133
133
|
- lib/vagrant-g5k/action/connect_g5k.rb
|
134
134
|
- lib/vagrant-g5k/action/create_local_working_dir.rb
|
135
|
+
- lib/vagrant-g5k/action/delete_disk.rb
|
135
136
|
- lib/vagrant-g5k/action/delete_job.rb
|
136
137
|
- lib/vagrant-g5k/action/is_created.rb
|
137
138
|
- lib/vagrant-g5k/action/message_already_created.rb
|