Module: Occi::Api::Client::Base::ActionMethods

Included in:
ClientBase
Defined in:
lib/occi/api/client/base/action_methods.rb

Instance Method Summary collapse

Instance Method Details

#get_action_type_identifier(type, for_kind_w_term = nil) ⇒ String?

Retrieves available action type identifier for the given action type.

Examples:

client.get_action_type_identifier("start") # => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start'

client.get_action_type_identifier("start", "compute") # => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start'

client.get_action_type_identifier("start", "storage") # => nil

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/occi/api/client/base/action_methods.rb', line 42

def get_action_type_identifier(type, for_kind_w_term = nil)
  return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))

  acts = @model.actions.to_a.select { |k| k.term == type }
  tis = acts.collect { |c| c.type_identifier }
  tis.uniq!

  tis.keep_if { |ti| ti.include? "/#{for_kind_w_term}/" } unless for_kind_w_term.blank?

  if tis.length > 1
    raise Occi::Api::Client::Errors::AmbiguousNameError,
          "Action type #{type.inspect} is ambiguous, use a type identifier!"
  end

  tis.first
end

#get_action_type_identifiersArray<String>

Retrieves all available action type identifiers.

Examples:

client.get_action_type_identifiers# => [ "http://schemas.ogf.org/occi/infrastructure/compute/action#start",
#      "http://schemas.ogf.org/occi/infrastructure/compute/action#stop",
#      "http://schemas.ogf.org/occi/infrastructure/compute/action#suspend" ]

25
26
27
# File 'lib/occi/api/client/base/action_methods.rb', line 25

def get_action_type_identifiers
  @model.actions.to_a.collect { |action| action.type_identifier }
end

#get_action_typesArray<String>

Retrieves all available action types.

Examples:

client.get_action_types # => [ "stop", "start", "up", "down" ]

12
13
14
# File 'lib/occi/api/client/base/action_methods.rb', line 12

def get_action_types
  @model.actions.to_a.collect { |action| action.term }
end