module Occi::Api::Client::Base::EntityMethods

Public Instance Methods

get_entity_type_identifier(type) click to toggle source

Retrieves available entity type identifier for the given entity type.

@example

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

@param type [String] short entity type @return [String, nil] entity type identifier for the given entity type

# File lib/occi/api/client/base/entity_methods.rb, line 82
def get_entity_type_identifier(type)
  get_type_identifier(type, Occi::Core::Entity.kind)
end
get_entity_type_identifiers() click to toggle source

Retrieves all available entity type identifiers.

@example

client.get_kind_type_identifiers
# => [ "http://schemas.ogf.org/occi/core#entity",
#      "http://schemas.ogf.org/occi/core#resource",
#      "http://schemas.ogf.org/occi/core#link" ]

@return [Array<String>] list of available entity types in a OCCI ID format

# File lib/occi/api/client/base/entity_methods.rb, line 70
def get_entity_type_identifiers
  get_kind_type_identifiers_related_to Occi::Core::Entity.kind.type_identifier
end
get_entity_types() click to toggle source

Retrieves all available entity types.

@example

client.get_entity_types # => [ "entity", "resource", "link" ]

@return [Array<String>] list of available entity types in a human-readable format

# File lib/occi/api/client/base/entity_methods.rb, line 57
def get_entity_types
  get_types(Occi::Core::Entity.kind)
end
get_resource(resource_type) click to toggle source

Creates a new resource instance, resource should be specified by its name or identifier.

@example

client.get_resource "compute" # => Occi::Core::Resource
client.get_resource "storage" # => Occi::Core::Resource
client.get_resource "http://schemas.ogf.org/occi/infrastructure#network"
 # => Occi::Core::Resource

@param resource_type [String] resource name or resource identifier @return [Occi::Core::Resource] new resource instance

# File lib/occi/api/client/base/entity_methods.rb, line 17
def get_resource(resource_type)
  Occi::Api::Log.debug("Instantiating #{resource_type.inspect}")

  type_id = get_resource_type_identifier(resource_type)
  raise "Unknown resource type! #{resource_type.inspect}" unless type_id

  new_resource = Occi::Core::Resource.new(type_id)
  new_resource.model = @model

  new_resource
end
get_resource_type_identifier(type) click to toggle source

Retrieves available resource type identifier for the given resource type.

@example

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

@param type [String] short resource type @return [String, nil] resource type identifier for the given resource type

# File lib/occi/api/client/base/entity_methods.rb, line 117
def get_resource_type_identifier(type)
  get_type_identifier(type, Occi::Core::Resource.kind)
end
get_resource_type_identifiers() click to toggle source

Retrieves all available resource type identifiers.

@example

client.get_resource_type_identifiers
# => [ "http://schemas.ogf.org/occi/infrastructure#compute",
#      "http://schemas.ogf.org/occi/infrastructure#storage",
#      "http://schemas.ogf.org/occi/infrastructure#network" ]

@return [Array<String>] list of available resource types in a Occi ID format

# File lib/occi/api/client/base/entity_methods.rb, line 105
def get_resource_type_identifiers
  get_kind_type_identifiers_related_to Occi::Core::Resource.kind.type_identifier
end
get_resource_types() click to toggle source

Retrieves all available resource types.

@example

client.get_resource_types # => [ "compute", "storage", "network" ]

@return [Array<String>] list of available resource types in a human-readable format

# File lib/occi/api/client/base/entity_methods.rb, line 92
def get_resource_types
  get_types(Occi::Core::Resource.kind)
end

Private Instance Methods

get_type_identifier(type, related_to) click to toggle source
# File lib/occi/api/client/base/entity_methods.rb, line 157
def get_type_identifier(type, related_to)
  return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))

  collection = @model.get(related_to.type_identifier)
  e_kinds = collection.kinds.to_a.select { |e| e.term == type }
  tis = e_kinds.collect { |e| e.type_identifier }
  tis.uniq!

  if tis.length > 1
    raise Occi::Api::Client::Errors::AmbiguousNameError,
          "#{related_to.type_identifier.split('#').capitalize} type " \
          "#{type.inspect} is ambiguous, use a type identifier!"
  end

  tis.first
end
get_types(related_to) click to toggle source
# File lib/occi/api/client/base/entity_methods.rb, line 174
def get_types(related_to)
  collection = @model.get(related_to.type_identifier)
  collection ? collection.kinds.to_a.collect { |kind| kind.term } : []
end