xp5k 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +38 -0
- data/LICENCE +21 -0
- data/README.md +2 -0
- data/lib/xp5k/config.rb +42 -0
- data/lib/xp5k/version.rb +3 -0
- data/lib/xp5k/xp.rb +137 -0
- data/lib/xp5k.rb +6 -0
- data/xp5k.gemspec +26 -0
- metadata +122 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
xp5k (0.0.1)
|
5
|
+
json (>= 1.5.1)
|
6
|
+
restfully (~> 0.6)
|
7
|
+
term-ansicolor (>= 1.0.7)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.3.2)
|
13
|
+
backports (2.6.5)
|
14
|
+
json (1.7.5)
|
15
|
+
mime-types (1.19)
|
16
|
+
rack (1.4.1)
|
17
|
+
rack-cache (1.2)
|
18
|
+
rack (>= 0.4)
|
19
|
+
rest-client (1.6.7)
|
20
|
+
mime-types (>= 1.16)
|
21
|
+
rest-client-components (1.2.0)
|
22
|
+
rack (>= 1.0.1)
|
23
|
+
rest-client (>= 1.6.0, < 1.7.0)
|
24
|
+
restfully (0.8.8)
|
25
|
+
addressable
|
26
|
+
backports
|
27
|
+
json (~> 1.5)
|
28
|
+
rack-cache
|
29
|
+
rest-client (~> 1.6)
|
30
|
+
rest-client-components
|
31
|
+
term-ansicolor (1.0.7)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler (>= 1.0.0)
|
38
|
+
xp5k!
|
data/LICENCE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2012 Pascal Morillon
|
2
|
+
Copyright (c) 2012 Université Rennes 1
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/lib/xp5k/config.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module XP5K
|
2
|
+
class Config
|
3
|
+
# Create a singleton
|
4
|
+
@@config = Hash.new
|
5
|
+
|
6
|
+
@@config[:debug] = false
|
7
|
+
@@config[:user] = ENV['USER']
|
8
|
+
@@config[:public_key] = File.join(ENV['HOME'], '.ssh', 'id_rsa.pub')
|
9
|
+
|
10
|
+
@@config[:loaded] = false
|
11
|
+
|
12
|
+
# Load the experiment configuration file
|
13
|
+
def self.load
|
14
|
+
if File.exist?(File.expand_path(File.join(Dir.pwd, 'xp.conf')))
|
15
|
+
file_path = File.expand_path(File.join(Dir.pwd, 'xp.conf'))
|
16
|
+
self.instance_eval(IO.read(file_path),file_path, 1)
|
17
|
+
end
|
18
|
+
@@config[:loaded] = true
|
19
|
+
end # def:: self.load
|
20
|
+
|
21
|
+
def self.loaded?
|
22
|
+
@@config[:loaded]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Configuration options getter
|
26
|
+
def self.[](opt)
|
27
|
+
@@config[opt.to_sym]
|
28
|
+
end # def:: self.[](opt)
|
29
|
+
|
30
|
+
# Configuration options setter
|
31
|
+
def self.[]=(opt, value)
|
32
|
+
@@config[opt.to_sym] = value
|
33
|
+
end # def:: self.[]=(opt, value)
|
34
|
+
|
35
|
+
# Using methods in configuration file and transform into hash keys
|
36
|
+
def self.method_missing(method_symbol, *args)
|
37
|
+
@@config[method_symbol] = args[0]
|
38
|
+
@@config[method_symbol]
|
39
|
+
end # def:: self.method_missing(method_symbol), *args)
|
40
|
+
|
41
|
+
end # class:: Config
|
42
|
+
end # module:: XP
|
data/lib/xp5k/version.rb
ADDED
data/lib/xp5k/xp.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require "json"
|
2
|
+
require "restfully"
|
3
|
+
require "fileutils"
|
4
|
+
require "term/ansicolor"
|
5
|
+
|
6
|
+
module XP5K
|
7
|
+
class XP
|
8
|
+
|
9
|
+
include Term::ANSIColor
|
10
|
+
|
11
|
+
attr_accessor :jobs, :jobs2submit, :deployments, :todeploy, :connection
|
12
|
+
attr_reader :starttime
|
13
|
+
|
14
|
+
def initialize(options = {})
|
15
|
+
@jobs = []
|
16
|
+
@jobs2submit = []
|
17
|
+
@deployments = []
|
18
|
+
@todeploy = []
|
19
|
+
@starttime = Time.now
|
20
|
+
@logger = options[:logger] || Logger.new(STDOUT)
|
21
|
+
XP5K::Config.load unless XP5K::Config.loaded?
|
22
|
+
|
23
|
+
@connection = Restfully::Session.new(
|
24
|
+
:configuration_file => "~/.restfully/api.grid5000.fr.yml",
|
25
|
+
:logger => begin
|
26
|
+
tmplogger = ::Logger.new(STDERR)
|
27
|
+
tmplogger.level = ::Logger::WARN
|
28
|
+
tmplogger
|
29
|
+
end
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def timer
|
34
|
+
Time.now - self.starttime
|
35
|
+
end
|
36
|
+
|
37
|
+
def define_deployment(deployment_hash)
|
38
|
+
self.todeploy << deployment_hash
|
39
|
+
end
|
40
|
+
|
41
|
+
def deploy
|
42
|
+
self.todeploy.each do |x|
|
43
|
+
x[:nodes] ||= []
|
44
|
+
# Get assigned resources to deploy
|
45
|
+
x[:jobs].each do |jobname|
|
46
|
+
job = self.job_with_name(jobname)
|
47
|
+
x[:nodes] += job["assigned_nodes"]
|
48
|
+
end
|
49
|
+
deployment = @connection.root.sites[x[:site].to_sym].deployments.submit(x)
|
50
|
+
self.deployments << { :uid => deployment["uid"], :site => deployment["site_uid"] }
|
51
|
+
update_cache
|
52
|
+
puts "Waiting for the deployment ##{deployment['uid']} to be terminated..."
|
53
|
+
while deployment.reload['status'] == 'processing'
|
54
|
+
print(".")
|
55
|
+
sleep 10
|
56
|
+
end
|
57
|
+
print(" [#{green("OK")}]\n")
|
58
|
+
update_cache
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def define_job(job_hash)
|
63
|
+
self.jobs2submit << job_hash
|
64
|
+
|
65
|
+
if File.exists?(".xp_cache")
|
66
|
+
# Reload job
|
67
|
+
datas = JSON.parse(File.read(".xp_cache"))
|
68
|
+
uid = datas["jobs"].select { |x| x["name"] == job_hash[:name] }.first["uid"]
|
69
|
+
unless uid.nil?
|
70
|
+
job = @connection.root.sites[job_hash[:site].to_sym].jobs["#{uid}".to_sym]
|
71
|
+
unless (job.nil? or job["state"] != "running")
|
72
|
+
j = job.reload
|
73
|
+
self.jobs << j
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def submit
|
80
|
+
self.jobs2submit.each do |job2submit|
|
81
|
+
job = self.job_with_name(job2submit[:name])
|
82
|
+
if job.nil?
|
83
|
+
job = @connection.root.sites[job2submit[:site].to_sym].jobs.submit(job2submit)
|
84
|
+
self.jobs << job
|
85
|
+
update_cache
|
86
|
+
logger.info "Waiting for the job #{job["name"]} ##{job['uid']} to be running at #{job2submit[:site]}..."
|
87
|
+
while job.reload["state"] != "running"
|
88
|
+
print(".")
|
89
|
+
sleep 3
|
90
|
+
end
|
91
|
+
print(" [#{green("OK")}]\n")
|
92
|
+
update_cache
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def job_with_name(name)
|
98
|
+
self.jobs.select { |x| x["name"] == name }.first
|
99
|
+
end
|
100
|
+
|
101
|
+
def status
|
102
|
+
# self.jobs2submit.each do |job2submit|
|
103
|
+
# job = self.job_with_name(job2submit[:name])
|
104
|
+
|
105
|
+
# end
|
106
|
+
self.jobs.each do |job|
|
107
|
+
logger.info "Job #{job["name"]} ##{job["uid"]} status : #{job["state"]}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def clean
|
112
|
+
self.jobs.each do |job|
|
113
|
+
if job.reload["state"] == "running"
|
114
|
+
job.delete
|
115
|
+
logger.info "Job ##{job["uid"]} deleted !"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
FileUtils.rm(".xp_cache")
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def logger
|
124
|
+
@logger
|
125
|
+
end
|
126
|
+
|
127
|
+
def update_cache
|
128
|
+
cache = { :jobs => self.jobs.collect { |x| x.properties },
|
129
|
+
:deployments => self.deployments
|
130
|
+
}
|
131
|
+
open(".xp_cache", "w") do |f|
|
132
|
+
f.puts cache.to_json
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
data/lib/xp5k.rb
ADDED
data/xp5k.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'xp5k/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'xp5k'
|
7
|
+
s.version = XP5K::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Pascal Morillon']
|
10
|
+
s.email = ['pascal.morillon@irisa.fr']
|
11
|
+
s.homepage = 'https://github.com/pmorillon/xp5k'
|
12
|
+
s.summary = %q{A small Grid'5000 helper to submit jobs and deploy environments via REST API}
|
13
|
+
s.description = %q{A small Grid'5000 helper to submit jobs and deploy environments via REST API}
|
14
|
+
|
15
|
+
s.required_rubygems_version = '>= 1.3.6'
|
16
|
+
|
17
|
+
s.add_dependency 'restfully', '~>0.6'
|
18
|
+
s.add_dependency 'term-ansicolor', '>= 1.0.7'
|
19
|
+
s.add_dependency 'json', '>= 1.5.1'
|
20
|
+
|
21
|
+
s.add_development_dependency 'bundler', '>= 1.0.0'
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.require_paths = ['lib']
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xp5k
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pascal Morillon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: restfully
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.6'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: term-ansicolor
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.7
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.7
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.5.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0
|
78
|
+
description: A small Grid'5000 helper to submit jobs and deploy environments via REST
|
79
|
+
API
|
80
|
+
email:
|
81
|
+
- pascal.morillon@irisa.fr
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- Gemfile.lock
|
89
|
+
- LICENCE
|
90
|
+
- README.md
|
91
|
+
- lib/xp5k.rb
|
92
|
+
- lib/xp5k/config.rb
|
93
|
+
- lib/xp5k/version.rb
|
94
|
+
- lib/xp5k/xp.rb
|
95
|
+
- xp5k.gemspec
|
96
|
+
homepage: https://github.com/pmorillon/xp5k
|
97
|
+
licenses: []
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 1.3.6
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.24
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: A small Grid'5000 helper to submit jobs and deploy environments via REST
|
120
|
+
API
|
121
|
+
test_files: []
|
122
|
+
has_rdoc:
|