class Arvados
Attributes
debuglevel[RW]
Public Class Methods
api_model_sym()
click to toggle source
# File lib/arvados.rb, line 87 def self.api_model_sym @api_model_sym end
api_models_sym()
click to toggle source
# File lib/arvados.rb, line 84 def self.api_models_sym @api_models_sym end
arvados()
click to toggle source
# File lib/arvados.rb, line 81 def self.arvados @arvados end
debuglog(message, verbosity=1)
click to toggle source
# File lib/arvados.rb, line 135 def self.debuglog(message, verbosity=1) $stderr.puts "#{File.split($0).last} #{$$}: #{message}" if @@debuglevel >= verbosity end
new(opts={})
click to toggle source
# 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 # Define a class and an Arvados instance method for each Arvados # resource. After this, self.job will return Arvados::Job; # self.job.new() and self.job.find() will do what you want. _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 # Define the resource methods (create, get, update, delete, ...) 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 # Give the new class access to the API klass.instance_eval do @arvados = _arvados # TODO: Pull these from the discovery document instead. @api_models_sym = classname.underscore.split('/').last.pluralize.to_sym @api_model_sym = classname.underscore.split('/').last.to_sym end # Create the new class in namespace_class so it doesn't # interfere with classes created by other Arvados objects. The # result looks like Arvados::A26949680::Job. namespace_class.const_set classname, klass self.define_singleton_method classname.underscore do klass end end end
Public Instance Methods
arvados_api()
click to toggle source
# File lib/arvados.rb, line 131 def arvados_api @arvados_api ||= self.client.discovered_api('arvados', @arvados_api_version) end
client()
click to toggle source
# 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()
click to toggle source
# 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")
click to toggle source
# File lib/arvados.rb, line 143 def config(config_file_path="~/.config/arvados/settings.conf") return @config if @config # Initialize config settings with environment variables. 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'] # Environment variables take precedence over the config file, so # there is no point reading the config file. If the environment # specifies a _HOST without asking for _INSECURE, we certainly # shouldn't give the config file a chance to create a # system-wide _INSECURE state for this user. # # Note: If we start using additional configuration settings from # this file in the future, we might have to read the file anyway # instead of returning here. return (@config = config) end begin expanded_path = File.expand_path config_file_path if File.exist? expanded_path # Load settings from the config file. lineno = 0 File.open(expanded_path).each do |line| lineno = lineno + 1 # skip comments and blank lines next if line.match('^\s*#') or not line.match('\S') var, val = line.chomp.split('=', 2) var.strip! val.strip! # allow environment settings to override config files. 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)
click to toggle source
# File lib/arvados.rb, line 139 def debuglog *args self.class.debuglog(*args) end
Protected Instance Methods
suppress_warnings() { || ... }
click to toggle source
# File lib/arvados.rb, line 295 def suppress_warnings original_verbosity = $VERBOSE begin $VERBOSE = nil yield ensure $VERBOSE = original_verbosity end end