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



82
83
84
# 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_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



70
71
72
# 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_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



57
58
59
# File 'lib/occi/api/client/base/entity_methods.rb', line 57

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

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

Examples:

client.get_link "storagelink" # => Occi::Core::Link
client.get_link "http://schemas.ogf.org/occi/infrastructure#storagelink"
 # => Occi::Core::Link

Parameters:

  • link_type (String)

    link name or link identifier

Returns:

  • (Occi::Core::Link)

    new link instance



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/occi/api/client/base/entity_methods.rb', line 39

def get_link(link_type)
  Occi::Api::Log.debug("Instantiating #{link_type.inspect}")

  type_id = get_link_type_identifier(link_type)
  raise "Unknown link type! #{link_type.inspect}" unless type_id

  new_link = Occi::Core::Link.new(type_id)
  new_link.model = @model

  new_link
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



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

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



139
140
141
# File 'lib/occi/api/client/base/entity_methods.rb', line 139

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



127
128
129
# File 'lib/occi/api/client/base/entity_methods.rb', line 127

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



117
118
119
# 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_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



105
106
107
# 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_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



92
93
94
# File 'lib/occi/api/client/base/entity_methods.rb', line 92

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

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



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# 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) ⇒ Object (private)



174
175
176
177
# 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