Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into cloud_plu…
Browse files Browse the repository at this point in the history
…gfest

Conflicts:
	spec/occi/api/client/client_http_spec.rb
  • Loading branch information
Maik Srba committed Dec 14, 2012
2 parents 2b6a566 + 56a35e0 commit ac8ca53
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 7 deletions.
46 changes: 45 additions & 1 deletion bin/occi
Expand Up @@ -64,7 +64,7 @@ end

# running with an empty password, we should ask the user for one
# if auth method is not "none"
if options.auth[:password].nil? or options.auth[:user_cert_password].nil?
if options.auth[:password].nil? or options.auth[:user_cert_password].nil? or options.auth[:token].nil?
Occi::Log.debug "Password is not set, asking for it now ..."

say("\n")
Expand Down Expand Up @@ -104,6 +104,50 @@ rescue Errno::ECONNREFUSED
# there is nothing we can do ...
Occi::Log.error "Connection refused!"
exit!
rescue Exception => ex
# something went wrong during the execution
# hide the stack trace in non-debug modes
Occi::Log.error "An error occurred! Message: #{ex.message}"

raise ex if options.debug
exit!
end

# dump the occi model provided by the server and exit
if options.dump_model

if !model.respond_to? :instance_variables
puts "Your Ruby doesn't support 'instance_variables' calls!"
exit!
end

# iterate through available instance variables
model.instance_variables.each do |inst_var_sym|
puts "#"*79
puts "Dumping #{inst_var_sym.to_s}:"

inst_var = model.instance_variable_get(inst_var_sym)
next unless inst_var.respond_to? :each

# iterate through collection elements
inst_var.each do |coll_elm|
# respect user's output-format preferences
if options.output_format == :json and coll_elm.respond_to? :as_json
puts "\n"
pp coll_elm.as_json
puts "\n"
elsif coll_elm.respond_to? :to_string
puts "\n#{coll_elm.to_string}\n"
else
puts "\n#{coll_elm.inspect}\n"
end
end

#
puts "#"*79
end

exit! true
end

# start of the main loop, this part of the code is responsible for
Expand Down
5 changes: 5 additions & 0 deletions lib/occi/api/client/client_http.rb
Expand Up @@ -560,6 +560,7 @@ def set_logger(log_options)
# change_auth { :type => "digest", :username => "123", :password => "321" }
# change_auth { :type => "x509", :user_cert => "~/cert.pem",
# :user_cert_password => "321", :ca_path => nil }
# change_auth { :type => "keystone", :token => "005c8a5d7f2c437a9999302c458afbda" }
#
# @param [Hash] authentication options
def change_auth(auth_options)
Expand All @@ -583,6 +584,10 @@ def change_auth(auth_options)
self.class.ssl_ca_path @auth_options[:ca_path] unless @auth_options[:ca_path].nil?
self.class.ssl_ca_file @auth_options[:ca_file] unless @auth_options[:ca_file].nil?
self.class.ssl_extra_chain_cert certs_to_file_ary(@auth_options[:proxy_ca]) unless @auth_options[:proxy_ca].nil?
when "keystone"
# set up OpenStack Keystone token based auth
raise ArgumentError, "Missing required option 'token' for OpenStack Keystone auth!" unless @auth_options[:token]
self.class.headers['X-Auth-Token'] = @auth_options[:token]
when "none", nil
# do nothing
else
Expand Down
6 changes: 6 additions & 0 deletions lib/occi/api/dsl.rb
Expand Up @@ -52,6 +52,12 @@ def refresh
@client.refresh
end

def model
check

@client.model
end

###

def resource_types
Expand Down
22 changes: 19 additions & 3 deletions lib/occi/bin/occi_opts.rb
Expand Up @@ -7,7 +7,7 @@ module Bin

class OcciOpts

AUTH_METHODS = [:x509, :basic, :digest, :none].freeze
AUTH_METHODS = [:x509, :basic, :digest, :keystone, :none].freeze
MEDIA_TYPES = ["application/occi+json", "application/occi+xml", "text/plain,text/occi", "text/plain"].freeze
ACTIONS = [:list, :describe, :create, :delete, :trigger].freeze
LOG_OUTPUTS = [:stdout, :stderr].freeze
Expand All @@ -22,7 +22,9 @@ def self.parse(args)
options.log = {}
options.log[:out] = STDERR
options.log[:level] = Occi::Log::WARN


options.dump_model = false

options.interactive = false

options.endpoint = "https://localhost:3300/"
Expand Down Expand Up @@ -165,6 +167,12 @@ def self.parse(args)
options.output_format = output_format
end

opts.on_tail("-m",
"--dump-model",
"Contact the endpoint and dump its model") do |dump_model|
options.dump_model = dump_model
end

opts.on_tail("-d",
"--debug",
"Enable debugging messages") do |debug|
Expand Down Expand Up @@ -203,7 +211,14 @@ def self.parse(args)
exit!
end

if not options.interactive
if options.interactive && options.dump_model
puts "You cannot use '--dump-model' and '--interactive' at the same time!"
puts opts

exit!
end

if !(options.interactive or options.dump_model)
mandatory = []

if options.action == :trigger
Expand All @@ -222,6 +237,7 @@ def self.parse(args)
if not missing.empty?
puts "Missing required arguments: #{missing.join(', ')}"
puts opts

exit!
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/occi/collection.rb
Expand Up @@ -22,7 +22,7 @@ def initialize(collection={ }, model = Occi::Model.new)
@actions.merge collection.actions.to_a.collect { |action| Occi::Core::Action.new(action.scheme, action.term, action.title, action.attributes) }
@resources.merge collection.resources.to_a.collect { |resource| Occi::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.links) }
@links.merge collection.links.to_a.collect { |link| Occi::Core::Link.new(link.kind, link.mixins, link.attributes) }
@action = Occi::Core::Action.new(collection.action.scheme, collection.action.term, collection.action.title, collection.action.attributes) if collection.action
@action = Occi::Core::Action_instance.new(collection.action, collection.attributes) if collection.action
end

def ==(category)
Expand Down
5 changes: 3 additions & 2 deletions lib/occi/core.rb
@@ -1,3 +1,5 @@
require 'occi/core/attributes'
require 'occi/core/attribute_properties'
require 'occi/core/category'
require 'occi/core/categories'
require 'occi/core/related'
Expand All @@ -6,9 +8,8 @@
require 'occi/core/mixin'
require 'occi/core/mixins'
require 'occi/core/action'
require 'occi/core/action_instance'
require 'occi/core/actions'
require 'occi/core/attributes'
require 'occi/core/attribute_properties'
require 'occi/core/entities'
require 'occi/core/entity'
require 'occi/core/link'
Expand Down
11 changes: 11 additions & 0 deletions lib/occi/core/action.rb
Expand Up @@ -2,6 +2,17 @@ module Occi
module Core
class Action < Occi::Core::Category

# @param [String ] scheme
# @param [String] term
# @param [String] title
# @param [Hash] attributes
def initialize(scheme='http://schemas.ogf.org/occi/core#',
term='action',
title=nil,
attributes=Occi::Core::Attributes.new)
super scheme, term, title, attributes
end

# @return [String] text representation
def to_text
text = super
Expand Down
24 changes: 24 additions & 0 deletions lib/occi/core/action_instance.rb
@@ -0,0 +1,24 @@
module Occi
module Core
class Action_instance

class << self
attr_accessor :actions
end

attr_accessor :action, :attributes, :model

@action = Occi::Core::Action.new('http://schemas.ogf.org/occi/core#', 'action_instance')

def initialize(action = self.action, attributes={ })
if action.kind_of? String
scheme, term = action.split '#'
action = Occi::Core::Action.new(scheme, term)
end
@action = action
@attributes = attributes
end

end
end
end
1 change: 1 addition & 0 deletions spec/occi/api/client/client_http_spec.rb
Expand Up @@ -6,6 +6,7 @@ module Api
module Client

describe ClientHttp do

describe "using media type text/plain" do

use_vcr_cassette "client_http_text_plain"
Expand Down
2 changes: 2 additions & 0 deletions spec/occi/collection_spec.rb
Expand Up @@ -9,13 +9,15 @@ module Occi
collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
collection.mixins << "http://example.com/occi/tags#my_mixin"
collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
collection.action = Occi::Core::Action_instance.new
collection.resources << Occi::Core::Resource.new
collection.links << Occi::Core::Link.new
collection.kinds.first.should be_kind_of Occi::Core::Kind
collection.mixins.first.should be_kind_of Occi::Core::Mixin
collection.actions.first.should be_kind_of Occi::Core::Action
collection.resources.first.should be_kind_of Occi::Core::Resource
collection.links.first.should be_kind_of Occi::Core::Link
collection.action.should be_kind_of Occi::Core::Action_instance
end

it "registers a model, creates a new OCCI Resource and checks it against the model" do
Expand Down

0 comments on commit ac8ca53

Please sign in to comment.