Class: Arvados
- Inherits:
-
Object
show all
- Defined in:
- lib/arvados.rb
Defined Under Namespace
Classes: ArvadosClient, Model, TransactionFailedError
Constant Summary
collapse
- @@debuglevel =
0
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Arvados
Returns a new instance of Arvados.
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/arvados.rb', line 48
def initialize(opts={})
@application_version ||= 0.0
@application_name ||= File.split($0).last
@arvados_api_version = opts[:api_version] || 'v1'
@config = nil
[[:api_host, 'ARVADOS_API_HOST'],
[:api_token, 'ARVADOS_API_TOKEN']].each do |op, en|
if opts[op]
config[en] = opts[op]
end
if !config[en]
raise "#{$0}: no :#{op} or ENV[#{en}] provided."
end
end
if (opts[:suppress_ssl_warnings] or
%w(1 true yes).index(config['ARVADOS_API_HOST_INSECURE'].
andand.downcase))
suppress_warnings do
OpenSSL::SSL.const_set 'VERIFY_PEER', OpenSSL::SSL::VERIFY_NONE
end
end
_arvados = self
namespace_class = Arvados.const_set "A#{self.object_id}", Class.new
self.arvados_api.schemas.each do |classname, schema|
next if classname.match(/List$/)
klass = Class.new(Arvados::Model) do
def self.arvados
@arvados
end
def self.api_models_sym
@api_models_sym
end
def self.api_model_sym
@api_model_sym
end
end
self.
arvados_api.
send(classname.underscore.split('/').last.pluralize.to_sym).
discovered_methods.
each do |method|
class << klass; self; end.class_eval do
define_method method.name do |*params|
self.api_exec method, *params
end
end
end
klass.instance_eval do
@arvados = _arvados
@api_models_sym = classname.underscore.split('/').last.pluralize.to_sym
@api_model_sym = classname.underscore.split('/').last.to_sym
end
namespace_class.const_set classname, klass
self.define_singleton_method classname.underscore do
klass
end
end
end
|
Class Attribute Details
.debuglevel ⇒ Object
Returns the value of attribute debuglevel.
45
46
47
|
# File 'lib/arvados.rb', line 45
def debuglevel
@debuglevel
end
|
Class Method Details
.debuglog(message, verbosity = 1) ⇒ Object
135
136
137
|
# File 'lib/arvados.rb', line 135
def self.debuglog(message, verbosity=1)
$stderr.puts "#{File.split($0).last} #{$$}: #{message}" if @@debuglevel >= verbosity
end
|
Instance Method Details
#arvados_api ⇒ Object
131
132
133
|
# File 'lib/arvados.rb', line 131
def arvados_api
@arvados_api ||= self.client.discovered_api('arvados', @arvados_api_version)
end
|
#client ⇒ Object
124
125
126
127
128
129
|
# File 'lib/arvados.rb', line 124
def client
@client ||= ArvadosClient.
new(:host => config["ARVADOS_API_HOST"],
:application_name => @application_name,
:application_version => @application_version.to_s)
end
|
#cluster_config ⇒ Object
192
193
194
195
196
197
198
199
|
# File 'lib/arvados.rb', line 192
def cluster_config
return @cluster_config if @cluster_config
uri = URI("https://#{config()["ARVADOS_API_HOST"]}/arvados/v1/config")
cc = JSON.parse(Net::HTTP.get(uri))
@cluster_config = cc
end
|
#config(config_file_path = "~/.config/arvados/settings.conf") ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/arvados.rb', line 143
def config(config_file_path="~/.config/arvados/settings.conf")
return @config if @config
config = {}
config['ARVADOS_API_HOST'] = ENV['ARVADOS_API_HOST']
config['ARVADOS_API_TOKEN'] = ENV['ARVADOS_API_TOKEN']
config['ARVADOS_API_HOST_INSECURE'] = ENV['ARVADOS_API_HOST_INSECURE']
if config['ARVADOS_API_HOST'] and config['ARVADOS_API_TOKEN']
return (@config = config)
end
begin
expanded_path = File.expand_path config_file_path
if File.exist? expanded_path
lineno = 0
File.open(expanded_path).each do |line|
lineno = lineno + 1
next if line.match('^\s*#') or not line.match('\S')
var, val = line.chomp.split('=', 2)
var.strip!
val.strip!
if !var.empty? and val
config[var] ||= val
else
debuglog "#{expanded_path}: #{lineno}: could not parse `#{line}'", 0
end
end
end
rescue StandardError => e
debuglog "Ignoring error reading #{config_file_path}: #{e}", 0
end
@config = config
end
|
#debuglog(*args) ⇒ Object
139
140
141
|
# File 'lib/arvados.rb', line 139
def debuglog *args
self.class.debuglog(*args)
end
|