priteau-vizir 0.1.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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Pierre Riteau
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ = Vizir
2
+
3
+ Disconnected from OAR job 960063
4
+
5
+ Ever been disconnected from Grid'5000 machines with a message like this, losing part or all of your work?
6
+
7
+ Vizir is a simple Ruby script that monitors your interactive jobs on Grid'5000[http://www.grid5000.org/].
8
+ It triggers Growl[http://growl.info/] notifications when your reservations are going to terminate, allowing you to save your work and/or your deployed environments.
9
+
10
+ Vizir only supports Mac OS X for now.
11
+
12
+ == Getting Started
13
+
14
+ Run the following if you haven't already:
15
+ $ gem sources -a http://gems.github.com
16
+
17
+ Install the gem:
18
+ $ sudo gem install mojombo-jekyll
19
+
20
+ Configure Growl to accept notifications. Go to the Growl preference panel, and in the Network options enable "Listen for incoming notifications" and "Allow remote application registration". Don't forget to setup a password.
21
+
22
+ Run it in the background, using the <tt>--login</tt> switch with your Grid'5000 login name and the <tt>--password</tt> switch with your Growl password.
23
+
24
+ $ vizir --login priteau --password mygrowlpassword &
25
+
26
+ == Getting the source
27
+
28
+ Clone it from GitHub:
29
+
30
+ $ git clone git://github.com/priteau/vizir.git
31
+
32
+ == Copyright
33
+
34
+ Copyright (c) 2009 Pierre Riteau. See LICENSE for details.
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "vizir"
8
+ gem.summary = "Growl notifications for Grid'5000 jobs"
9
+ gem.email = "pierre.riteau@gmail.com"
10
+ gem.homepage = "http://github.com/priteau/vizir"
11
+ gem.authors = ["Pierre Riteau"]
12
+ gem.add_dependency "json"
13
+ gem.add_dependency "net-ssh-gateway"
14
+ gem.add_dependency "rest-client"
15
+ gem.add_dependency "ruby-growl"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION.yml')
49
+ config = YAML.load(File.read('VERSION.yml'))
50
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
51
+ else
52
+ version = ""
53
+ end
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "vizir #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
60
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'json'
4
+ require 'net/ssh/gateway'
5
+ require 'optparse'
6
+ require 'rest_client'
7
+ require 'ruby-growl'
8
+
9
+ ALERT_TIME = 600
10
+ IGNORE_SITES = ['grenoble-exp', 'grenoble-ext', 'grenoble-obs', 'luxembourg', 'portoalegre']
11
+
12
+ def usage
13
+ puts 'usage: vizir [ -h | --help ] [ -l | --login login_name ] [ -p | --password mygrowlpassword ]'
14
+ exit 1
15
+ end
16
+
17
+ def get(api, uri)
18
+ begin
19
+ return JSON.parse(api[uri + '?structure=simple'].get(:accept => 'application/json'))
20
+ rescue => e
21
+ if e.respond_to?('http_code')
22
+ puts "Error: #{e.http_code}:\n #{e.response.body}"
23
+ return nil
24
+ else
25
+ puts e.inspect
26
+ exit 1
27
+ end
28
+ end
29
+ end
30
+
31
+ def setup_ssh_tunnel
32
+ gateway = Net::SSH::Gateway.new('access.grenoble.grid5000.fr', $login)
33
+ port = gateway.open('api.grenoble.grid5000.fr', 443)
34
+ return gateway, port
35
+ end
36
+
37
+ def apiuri(port)
38
+ return "https://localhost:#{port}/oargridapi"
39
+ end
40
+
41
+ def notify_via_growl(jobid, site_name, time, time_unit)
42
+ g = Growl.new("localhost", "Vizir", ["Job ending soon"], nil, $password)
43
+ g.notify("Job ending soon", "OAR job terminating soon", "Job #{jobid} in #{site_name} ending in #{time} #{time_unit}.")
44
+ end
45
+
46
+ def get_remaining_time(starttime, walltime)
47
+ remaining_sec = (Time.at(starttime + walltime) - Time.now).round
48
+ end
49
+
50
+ def humanize_time(time)
51
+ if time > 60 then
52
+ remaining_time = time / 60
53
+ remaining_time_unit = "minutes"
54
+ else
55
+ remaining_time = time
56
+ remaining_time_unit = "seconds"
57
+ end
58
+ return remaining_time, remaining_time_unit
59
+ end
60
+
61
+ $login = nil
62
+ $password = nil
63
+ opts = OptionParser.new
64
+ opts.on('-h', '--help') { usage }
65
+ opts.on('-l', '--login STRING', String) { |str| $login = str }
66
+ opts.on('-p', '--password STRING', String) { |str| $password = str }
67
+ opts.parse(ARGV)
68
+
69
+ if $login == nil or $password == nil
70
+ usage
71
+ end
72
+
73
+ gateway, port = setup_ssh_tunnel
74
+ api = RestClient::Resource.new(apiuri(port))
75
+
76
+ sites = get(api, '/sites')
77
+ if sites == nil then
78
+ exit 1
79
+ end
80
+ sites.each do |site|
81
+ site_name = site['site']
82
+ unless IGNORE_SITES.include?(site_name)
83
+ jobs = get(api, "#{site['uri']}/jobs")
84
+ if jobs == nil then
85
+ break
86
+ end
87
+ jobs.each do |job|
88
+ if job['owner'] == $login then
89
+ job_details = get(api, "#{job['uri']}")
90
+ if job_details == nil then
91
+ break
92
+ end
93
+ if job_details['jobType'] == 'INTERACTIVE' then
94
+ remaining_sec = get_remaining_time(Integer(job_details['startTime']), Integer(job_details['walltime']))
95
+ if remaining_sec < ALERT_TIME then
96
+ remaining_time, remaining_time_unit = humanize_time(remaining_sec)
97
+ notify_via_growl(job_details['Job_Id'], site_name.capitalize, remaining_time, remaining_time_unit)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ gateway.shutdown!
File without changes
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'vizir'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class VizirTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,62 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{vizir}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Pierre Riteau"]
9
+ s.date = %q{2009-05-29}
10
+ s.default_executable = %q{vizir}
11
+ s.email = %q{pierre.riteau@gmail.com}
12
+ s.executables = ["vizir"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "bin/vizir",
25
+ "lib/vizir.rb",
26
+ "test/test_helper.rb",
27
+ "test/vizir_test.rb",
28
+ "vizir.gemspec"
29
+ ]
30
+ s.has_rdoc = true
31
+ s.homepage = %q{http://github.com/priteau/vizir}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.1}
35
+ s.summary = %q{Growl notifications for Grid'5000 jobs}
36
+ s.test_files = [
37
+ "test/test_helper.rb",
38
+ "test/vizir_test.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 2
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<json>, [">= 0"])
47
+ s.add_runtime_dependency(%q<net-ssh-gateway>, [">= 0"])
48
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
49
+ s.add_runtime_dependency(%q<ruby-growl>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<json>, [">= 0"])
52
+ s.add_dependency(%q<net-ssh-gateway>, [">= 0"])
53
+ s.add_dependency(%q<rest-client>, [">= 0"])
54
+ s.add_dependency(%q<ruby-growl>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<json>, [">= 0"])
58
+ s.add_dependency(%q<net-ssh-gateway>, [">= 0"])
59
+ s.add_dependency(%q<rest-client>, [">= 0"])
60
+ s.add_dependency(%q<ruby-growl>, [">= 0"])
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: priteau-vizir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Pierre Riteau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-29 00:00:00 -07:00
13
+ default_executable: vizir
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: net-ssh-gateway
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rest-client
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: ruby-growl
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ description:
56
+ email: pierre.riteau@gmail.com
57
+ executables:
58
+ - vizir
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ files:
65
+ - .document
66
+ - .gitignore
67
+ - LICENSE
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - bin/vizir
72
+ - lib/vizir.rb
73
+ - test/test_helper.rb
74
+ - test/vizir_test.rb
75
+ - vizir.gemspec
76
+ has_rdoc: true
77
+ homepage: http://github.com/priteau/vizir
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.2.0
99
+ signing_key:
100
+ specification_version: 2
101
+ summary: Growl notifications for Grid'5000 jobs
102
+ test_files:
103
+ - test/test_helper.rb
104
+ - test/vizir_test.rb