Module: Occi::Api::Client::Base::EntityMethods

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

Instance Method Summary collapse

Instance Method Details

#get_entity_type_identifier(type) ⇒ String?

Retrieves available entity type identifier for the given entity type.

Examples:

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

Parameters:

  • type (String)

    short entity type

Returns:

  • (String, nil)

    entity type identifier for the given entity type


60
61
62
# File 'lib/occi/api/client/base/entity_methods.rb', line 60

def get_entity_type_identifier(type)
  get_type_identifier(type, Occi::Core::Entity.kind)
end

#get_entity_type_identifiersArray<String>

Retrieves all available entity type identifiers.

Examples:

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" ]

Returns:

  • (Array<String>)

    list of available entity types in a OCCI ID format


48
49
50
# File 'lib/occi/api/client/base/entity_methods.rb', line 48

def get_entity_type_identifiers
  get_kind_type_identifiers_related_to Occi::Core::Entity.kind.type_identifier
end

#get_entity_typesArray<String>

Retrieves all available entity types.

Examples:

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

Returns:

  • (Array<String>)

    list of available entity types in a human-readable format


35
36
37
# File 'lib/occi/api/client/base/entity_methods.rb', line 35

def get_entity_types
  get_types(Occi::Core::Entity.kind)
end

Retrieves available link type identifier for the given link type.

Examples:

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

Parameters:

  • type (String)

    short link type

Returns:

  • (String, nil)

    link type identifier for the given link type


129
130
131
# File 'lib/occi/api/client/base/entity_methods.rb', line 129

def get_link_type_identifier(type)
  get_type_identifier(type, Occi::Core::Link.kind)
end

Retrieves all available link type identifiers.

Examples:

client.get_link_type_identifiers
# => [ "http://schemas.ogf.org/occi/infrastructure#storagelink",
#      "http://schemas.ogf.org/occi/infrastructure#networkinterface" ]

Returns:

  • (Array<String>)

    list of available link types in a OCCI ID format


117
118
119
# File 'lib/occi/api/client/base/entity_methods.rb', line 117

def get_link_type_identifiers
  get_kind_type_identifiers_related_to Occi::Core::Link.kind.type_identifier
end

Retrieves all available link types.

Examples:

client.get_link_types # => [ "storagelink", "networkinterface" ]

Returns:

  • (Array<String>)

    list of available link types in a human-readable format


105
106
107
# File 'lib/occi/api/client/base/entity_methods.rb', line 105

def get_link_types
  get_types(Occi::Core::Link.kind)
end

#get_resource(resource_type) ⇒ Occi::Core::Resource

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

Examples:

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

Parameters:

  • resource_type (String)

    resource name or resource identifier

Returns:

  • (Occi::Core::Resource)

    new resource instance


17
18
19
20
21
22
23
24
25
26
27
# 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) ⇒ String?

Retrieves available resource type identifier for the given resource type.

Examples:

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

Parameters:

  • type (String)

    short resource type

Returns:

  • (String, nil)

    resource type identifier for the given resource type


95
96
97
# File 'lib/occi/api/client/base/entity_methods.rb', line 95

def get_resource_type_identifier(type)
  get_type_identifier(type, Occi::Core::Resource.kind)
end

#get_resource_type_identifiersArray<String>

Retrieves all available resource type identifiers.

Examples:

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" ]

Returns:

  • (Array<String>)

    list of available resource types in a Occi ID format


83
84
85
# File 'lib/occi/api/client/base/entity_methods.rb', line 83

def get_resource_type_identifiers
  get_kind_type_identifiers_related_to Occi::Core::Resource.kind.type_identifier
end

#get_resource_typesArray<String>

Retrieves all available resource types.

Examples:

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

Returns:

  • (Array<String>)

    list of available resource types in a human-readable format


70
71
72
# File 'lib/occi/api/client/base/entity_methods.rb', line 70

def get_resource_types
  get_types(Occi::Core::Resource.kind)
end

#get_type_identifier(type, related_to) ⇒ Object (private)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/occi/api/client/base/entity_methods.rb', line 135

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) ⇒ Object (private)


152
153
154
155
# File 'lib/occi/api/client/base/entity_methods.rb', line 152

def get_types(related_to)
  collection = @model.get(related_to.type_identifier)
  collection ? collection.kinds.to_a.collect { |kind| kind.term } : []
end