occi-api 4.1.1 → 4.2.0.beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +9 -0
- data/README.md +37 -11
- data/Rakefile +2 -9
- data/examples/dsl_example.rb +2 -2
- data/examples/x509auth_example.rb +9 -9
- data/lib/occi-api.rb +0 -1
- data/lib/occi/api/client/client_base.rb +102 -92
- data/lib/occi/api/client/client_http.rb +6 -6
- data/lib/occi/api/client/http/authn_plugins/keystone.rb +27 -11
- data/lib/occi/api/dsl.rb +7 -3
- data/lib/occi/api/version.rb +1 -1
- data/occi-api.gemspec +2 -14
- data/{features/cassettes/Create_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml → spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_all_available_mixins.yml} +125 -147
- data/{features/cassettes/Miscellaneous_operation_on_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml → spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/looks_up_a_mixin_type_identifier_for_os_tpl.yml} +126 -148
- data/{features/cassettes/Delete_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml → spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/looks_up_a_mixin_type_identifier_for_resource_tpl.yml} +126 -148
- data/spec/occi/api/client/client_http_spec.rb +52 -28
- data/spec/occi/api/dsl_spec.rb +0 -6
- data/spec/spec_helper.rb +4 -1
- metadata +31 -200
- checksums.yaml +0 -7
- data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__application_json_200_.yml +0 -333
- data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__text_plain_200_.yml +0 -529
- data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__text_plain_200_action_.yml +0 -288
- data/features/cassettes/Read_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
- data/features/cassettes/Update_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
- data/features/common/step_definitions/common_steps.rb +0 -32
- data/features/occi/core/create/create.feature +0 -18
- data/features/occi/core/create/step_definitions/create_steps.rb +0 -0
- data/features/occi/core/delete/delete.feature +0 -18
- data/features/occi/core/delete/step_definitions/delete_steps.rb +0 -0
- data/features/occi/core/discovery_interface/discovery_interface.feature +0 -37
- data/features/occi/core/discovery_interface/step_definitions/discovery_interface_steps.rb +0 -19
- data/features/occi/core/miscellaneous/miscellaneous.feature +0 -18
- data/features/occi/core/miscellaneous/step_definitions/miscellaneous_steps.rb +0 -0
- data/features/occi/core/read/read.feature +0 -18
- data/features/occi/core/read/step_definitions/read_steps.rb +0 -0
- data/features/occi/core/update/step_definitions/update_steps.rb +0 -0
- data/features/occi/core/update/update.feature +0 -18
- data/features/occi/infrastructure/create/create.feature +0 -18
- data/features/occi/infrastructure/create/step_definitions/create_steps.rb +0 -0
- data/features/support/env.rb +0 -16
- data/lib/occi/api/client/client_amqp.rb +0 -766
- data/spec/occi/api/client/client_amqp_spec.rb +0 -158
data/Gemfile
CHANGED
@@ -5,4 +5,13 @@ gemspec
|
|
5
5
|
group :development do
|
6
6
|
gem 'vcr', :git => 'git://github.com/arax/vcr.git', :branch => 'test_framework_patches', :ref => 'e82e843ceddd8822acea59846b015bcabf1906df'
|
7
7
|
gem 'rubygems-tasks', :git => 'git://github.com/postmodern/rubygems-tasks.git'
|
8
|
+
gem "rspec"
|
9
|
+
gem "rake"
|
10
|
+
gem "builder"
|
11
|
+
gem "simplecov"
|
12
|
+
gem "yard"
|
13
|
+
gem "yard-sinatra"
|
14
|
+
gem "yard-rspec"
|
15
|
+
gem "rspec-http"
|
16
|
+
gem "webmock", "~> 1.9.3"
|
8
17
|
end
|
data/README.md
CHANGED
@@ -14,20 +14,32 @@ Requirements
|
|
14
14
|
* RubyGems have to be installed
|
15
15
|
* Rake has to be installed (e.g., `gem install rake`)
|
16
16
|
|
17
|
-
###
|
18
|
-
* libxslt1-dev
|
19
|
-
* libxml2-dev
|
17
|
+
### Dependencies
|
18
|
+
* `libxslt1-dev` or `libxslt-devel`
|
19
|
+
* `libxml2-dev`or `libxml2-devel`
|
20
20
|
|
21
21
|
### Examples
|
22
|
-
For distros based on Debian:
|
22
|
+
#### For distros based on Debian:
|
23
23
|
~~~
|
24
24
|
apt-get install ruby rubygems ruby-dev libxslt1-dev libxml2-dev
|
25
25
|
~~~
|
26
|
+
~~~
|
27
|
+
ruby -v
|
28
|
+
~~~
|
29
|
+
|
30
|
+
**Unless you have Ruby >= 1.9.3, please, go to [rOCCI-api#RVM](#rvm) and install RVM with a newer Ruby version.**
|
26
31
|
|
27
|
-
For distros based on RHEL:
|
32
|
+
#### For distros based on RHEL:
|
28
33
|
~~~
|
29
34
|
yum install libxml2-devel libxslt-devel ruby-devel openssl-devel gcc gcc-c++ ruby rubygems
|
30
35
|
~~~
|
36
|
+
~~~
|
37
|
+
ruby -v
|
38
|
+
~~~
|
39
|
+
|
40
|
+
**Unless you have Ruby >= 1.9.3, please, go to [rOCCI-api#RVM](#rvm) and install RVM with a newer Ruby version.**
|
41
|
+
|
42
|
+
To use rOCCI-cli with Java, you need JRE 6 or 7. To build rOCCI-cli for Java, you need JDK 6 or 7.
|
31
43
|
|
32
44
|
Installation
|
33
45
|
------------
|
@@ -47,12 +59,8 @@ To install the most recent beta version
|
|
47
59
|
### From source (dev)
|
48
60
|
|
49
61
|
**Installation from source should never be your first choice! Especially, if you are not familiar with RVM, Bundler, Rake and other dev tools for Ruby!**
|
50
|
-
**However, if you wish to contribute to our project, this is the right way to start.**
|
51
62
|
|
52
|
-
|
53
|
-
|
54
|
-
curl -L https://get.rvm.io | bash -s stable --ruby
|
55
|
-
rvm install 1.9.3
|
63
|
+
**However, if you wish to contribute to our project, this is the right way to start.**
|
56
64
|
|
57
65
|
To build and install the bleeding edge version from master
|
58
66
|
|
@@ -60,9 +68,27 @@ To build and install the bleeding edge version from master
|
|
60
68
|
cd rOCCI-api
|
61
69
|
gem install bundler
|
62
70
|
bundle install
|
63
|
-
bundle exec rake
|
71
|
+
bundle exec rake test
|
64
72
|
rake install
|
65
73
|
|
74
|
+
### RVM
|
75
|
+
|
76
|
+
**Notice:** Follow the RVM installation guide linked below, we recommend using the default 'Single-User installation'.
|
77
|
+
|
78
|
+
**Warning:** NEVER install RVM as root! If you choose the 'Multi-User installation', use a different user account with sudo access instead!
|
79
|
+
|
80
|
+
* [Installing RVM](https://rvm.io/rvm/install#explained)
|
81
|
+
* Install Ruby
|
82
|
+
|
83
|
+
~~~
|
84
|
+
rvm requirements
|
85
|
+
rvm install 1.9.3
|
86
|
+
rvm use 1.9.3 --default
|
87
|
+
~~~
|
88
|
+
~~~
|
89
|
+
ruby -v
|
90
|
+
~~~
|
91
|
+
|
66
92
|
Usage
|
67
93
|
-----
|
68
94
|
### Auth
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems/tasks'
|
|
2
2
|
|
3
3
|
task :default => 'test'
|
4
4
|
|
5
|
-
desc "Run all tests; includes rspec
|
5
|
+
desc "Run all tests; includes rspec and coverage reports"
|
6
6
|
task :test => 'rcov:all'
|
7
7
|
|
8
8
|
Gem::Tasks.new(:build => {:tar => true, :zip => true}, :sign => {:checksum => true, :pgp => false})
|
@@ -10,22 +10,15 @@ Gem::Tasks.new(:build => {:tar => true, :zip => true}, :sign => {:checksum => tr
|
|
10
10
|
namespace :rcov do
|
11
11
|
|
12
12
|
require 'rspec/core/rake_task'
|
13
|
-
require 'cucumber/rake/task'
|
14
|
-
|
15
|
-
Cucumber::Rake::Task.new(:cucumber) do |t|
|
16
|
-
t.cucumber_opts = "--format pretty"
|
17
|
-
ENV['COVERAGE'] = "true"
|
18
|
-
end
|
19
13
|
|
20
14
|
RSpec::Core::RakeTask.new(:rspec) do |t|
|
21
15
|
ENV['COVERAGE'] = "true"
|
22
16
|
end
|
23
17
|
|
24
|
-
desc "Run
|
18
|
+
desc "Run rspec to generate aggregated coverage"
|
25
19
|
task :all do |t|
|
26
20
|
rm "coverage/coverage.data" if File.exist?("coverage/coverage.data")
|
27
21
|
Rake::Task['rcov:rspec'].invoke
|
28
|
-
Rake::Task["rcov:cucumber"].invoke
|
29
22
|
end
|
30
23
|
|
31
24
|
end
|
data/examples/dsl_example.rb
CHANGED
@@ -55,7 +55,7 @@ mixin_type_identifiers.each do |mixin_typeid|
|
|
55
55
|
end
|
56
56
|
|
57
57
|
puts "\n\nListing all available mixins:"
|
58
|
-
|
58
|
+
mixin_list.each do |mixin|
|
59
59
|
puts "\n#{mixin}"
|
60
60
|
end
|
61
61
|
|
@@ -158,7 +158,7 @@ while cmpt_data[0].resources.first.attributes.occi.compute.state == "inactive"
|
|
158
158
|
cmpt_data = describe cmpt_loc
|
159
159
|
end
|
160
160
|
|
161
|
-
puts "\nCompute resource #{cmpt_loc} is #{cmpt_data
|
161
|
+
puts "\nCompute resource #{cmpt_loc} is #{cmpt_data.first.state}"
|
162
162
|
|
163
163
|
## delete the resource and exit
|
164
164
|
if clean_up_compute
|
@@ -49,7 +49,7 @@ client.get_mixin_type_identifiers.each do |mixin_typeid|
|
|
49
49
|
end
|
50
50
|
|
51
51
|
puts "\n\nListing all available mixins:"
|
52
|
-
client.
|
52
|
+
client.list_mixins.each do |mixin|
|
53
53
|
puts "\n#{mixin}"
|
54
54
|
end
|
55
55
|
|
@@ -58,25 +58,25 @@ samples = [OS_TEMPLATE, "medium", "large", "small"]
|
|
58
58
|
puts "\n\nFind mixins using their names:"
|
59
59
|
samples.each do |mixin|
|
60
60
|
puts "\n#{mixin}:\n"
|
61
|
-
pp client.
|
61
|
+
pp client.get_mixin mixin
|
62
62
|
end
|
63
63
|
|
64
64
|
puts "\n\nFind mixins using their names and a type:"
|
65
65
|
samples.each do |mixin|
|
66
66
|
puts "\n#{mixin}:\n"
|
67
|
-
pp client.
|
67
|
+
pp client.get_mixin(mixin, "os_tpl")
|
68
68
|
end
|
69
69
|
|
70
70
|
puts "\n\nFind mixins using their names and a type:"
|
71
71
|
samples.each do |mixin|
|
72
72
|
puts "\n#{mixin}:\n"
|
73
|
-
pp client.
|
73
|
+
pp client.get_mixin(mixin, "resource_tpl")
|
74
74
|
end
|
75
75
|
|
76
76
|
puts "\n\nFind mixins using their names (showing detailed descriptions):"
|
77
77
|
samples.each do |mixin|
|
78
78
|
puts "\n#{mixin}:\n"
|
79
|
-
pp client.
|
79
|
+
pp client.get_mixin(mixin, nil, true)
|
80
80
|
end
|
81
81
|
|
82
82
|
## get links of all available resources
|
@@ -108,7 +108,7 @@ unless use_os_temlate
|
|
108
108
|
## network, storage and resource template (instance type)
|
109
109
|
|
110
110
|
## select instance type medium
|
111
|
-
cmpt.mixins << client.
|
111
|
+
cmpt.mixins << client.get_mixin('medium', "resource_tpl")
|
112
112
|
|
113
113
|
## list network/storage locations and select the appropriate ones (the first ones in this case)
|
114
114
|
puts "\nUsing:"
|
@@ -123,8 +123,8 @@ else
|
|
123
123
|
## with OS template, we have to find the template by name
|
124
124
|
## optionally we can change its "size" by choosing an instance type
|
125
125
|
puts "\nUsing:"
|
126
|
-
pp os = client.
|
127
|
-
pp size = client.
|
126
|
+
pp os = client.get_mixin(OS_TEMPLATE, "os_tpl")
|
127
|
+
pp size = client.get_mixin('medium', "resource_tpl")
|
128
128
|
|
129
129
|
## attach chosen resources to the compute resource
|
130
130
|
cmpt.mixins << os << size
|
@@ -152,7 +152,7 @@ while cmpt_data[0].resources.first.attributes.occi.compute.state == "inactive"
|
|
152
152
|
cmpt_data = client.describe cmpt_loc
|
153
153
|
end
|
154
154
|
|
155
|
-
puts "\nCompute resource #{cmpt_loc} is #{cmpt_data
|
155
|
+
puts "\nCompute resource #{cmpt_loc} is #{cmpt_data.first.state}"
|
156
156
|
|
157
157
|
## delete the resource and exit
|
158
158
|
if clean_up_compute
|
data/lib/occi-api.rb
CHANGED
@@ -91,16 +91,16 @@ module Occi
|
|
91
91
|
#
|
92
92
|
# @example
|
93
93
|
# client.describe
|
94
|
-
# # =>
|
94
|
+
# # => #<Occi::Core::Resources>
|
95
95
|
# client.describe "compute"
|
96
|
-
# # =>
|
96
|
+
# # => #<Occi::Core::Resources>
|
97
97
|
# client.describe "http://schemas.ogf.org/occi/infrastructure#compute"
|
98
|
-
# # =>
|
98
|
+
# # => #<Occi::Core::Resources>
|
99
99
|
# client.describe "http://localhost:3300/compute/j5hk1234jk2524-2j3j2k34jjh234-adfaf1234"
|
100
|
-
# # =>
|
100
|
+
# # => #<Occi::Core::Resources>
|
101
101
|
#
|
102
102
|
# @param [String] resource type identifier, type name or resource location
|
103
|
-
# @return [
|
103
|
+
# @return [Occi::Core::Resources] list of resource descriptions
|
104
104
|
def describe(resource_type_identifier=nil); end
|
105
105
|
|
106
106
|
# Creates a new resource on the server. Resource must be provided
|
@@ -111,8 +111,8 @@ module Occi
|
|
111
111
|
# res = client.get_resource "compute"
|
112
112
|
#
|
113
113
|
# res.title = "MyComputeResource1"
|
114
|
-
# res.mixins << client.
|
115
|
-
# res.mixins << client.
|
114
|
+
# res.mixins << client.get_mixin('small', "resource_tpl")
|
115
|
+
# res.mixins << client.get_mixin('debian6', "os_tpl")
|
116
116
|
#
|
117
117
|
# client.create res # => "http://localhost:3300/compute/df7698...f987fa"
|
118
118
|
#
|
@@ -203,11 +203,11 @@ module Occi
|
|
203
203
|
resource_type
|
204
204
|
else
|
205
205
|
# we got a resource type name
|
206
|
-
type_ids = @model.kinds.select { |kind| kind.term == resource_type }
|
206
|
+
type_ids = @model.kinds.to_a.select { |kind| kind.term == resource_type }
|
207
207
|
type_ids.first.type_identifier if type_ids.any?
|
208
208
|
end
|
209
209
|
|
210
|
-
raise "Unknown resource type!
|
210
|
+
raise "Unknown resource type! #{resource_type.inspect}" unless type_id
|
211
211
|
|
212
212
|
Occi::Core::Resource.new type_id
|
213
213
|
end
|
@@ -236,7 +236,7 @@ module Occi
|
|
236
236
|
# @return [Array<String>] list of available entity types in a human-readable format
|
237
237
|
def get_entity_types
|
238
238
|
Occi::Log.debug("Getting entity types ...")
|
239
|
-
@model.kinds.collect { |kind| kind.term }
|
239
|
+
@model.kinds.to_a.collect { |kind| kind.term }
|
240
240
|
end
|
241
241
|
|
242
242
|
# Retrieves all available entity type identifiers.
|
@@ -305,21 +305,21 @@ module Occi
|
|
305
305
|
# Will return mixin's full location (a link) or a description.
|
306
306
|
#
|
307
307
|
# @example
|
308
|
-
# client.
|
308
|
+
# client.get_mixin "debian6"
|
309
309
|
# # => "http://my.occi.service/occi/infrastructure/os_tpl#debian6"
|
310
|
-
# client.
|
311
|
-
# # => #<Occi::
|
312
|
-
# client.
|
310
|
+
# client.get_mixin "debian6", "os_tpl", true
|
311
|
+
# # => #<Occi::Core::Mixin>
|
312
|
+
# client.get_mixin "large", "resource_tpl"
|
313
313
|
# # => "http://my.occi.service/occi/infrastructure/resource_tpl#large"
|
314
|
-
# client.
|
314
|
+
# client.get_mixin "debian6", "resource_tpl" # => nil
|
315
315
|
#
|
316
316
|
# @param [String] name of the mixin
|
317
317
|
# @param [String] type of the mixin
|
318
318
|
# @param [Boolean] should we describe the mixin or return its link?
|
319
|
-
# @return [String, Occi::
|
320
|
-
def
|
319
|
+
# @return [String, Occi::Core::Mixin, nil] link, mixin description or nothing found
|
320
|
+
def get_mixin(name, type = nil, describe = false)
|
321
|
+
# TODO: mixin fix
|
321
322
|
Occi::Log.debug("Looking for mixin #{name} + #{type} + #{describe}")
|
322
|
-
raise "Unknown mixin type! [#{type}]" if type && !@mixins.has_key?(type.to_sym)
|
323
323
|
|
324
324
|
# TODO: extend this code to support multiple matches and regex filters
|
325
325
|
# should we look for links or descriptions?
|
@@ -331,19 +331,21 @@ module Occi
|
|
331
331
|
#
|
332
332
|
# @example
|
333
333
|
# client.describe_mixin "debian6"
|
334
|
-
# # => #<Occi::
|
334
|
+
# # => #<Occi::Core::Mixin>
|
335
335
|
# client.describe_mixin "debian6", "os_tpl"
|
336
|
-
# # => #<Occi::
|
336
|
+
# # => #<Occi::Core::Mixin>
|
337
337
|
# client.describe_mixin "large", "resource_tpl"
|
338
|
-
# # => #<Occi::
|
338
|
+
# # => #<Occi::Core::Mixin>
|
339
339
|
# client.describe_mixin "debian6", "resource_tpl" # => nil
|
340
340
|
#
|
341
341
|
# @param [String] name of the mixin
|
342
342
|
# @param [String] type of the mixin
|
343
|
-
# @return [Occi::
|
343
|
+
# @return [Occi::Core::Mixin, nil] mixin description or nothing found
|
344
344
|
def describe_mixin(name, type = nil)
|
345
|
-
|
346
|
-
|
345
|
+
mixins = get_mixins(type)
|
346
|
+
|
347
|
+
mixins = mixins.to_a.select { |m| m.term == name }
|
348
|
+
mixins.any? ? mixins.first : nil
|
347
349
|
end
|
348
350
|
|
349
351
|
# Looks up a mixin with a specific type, will return
|
@@ -351,10 +353,9 @@ module Occi
|
|
351
353
|
#
|
352
354
|
# @param [String] name of the mixin
|
353
355
|
# @param [String] type of the mixin
|
354
|
-
# @return [Occi::
|
356
|
+
# @return [Occi::Core::Mixin] mixin description
|
355
357
|
def describe_mixin_w_type(name, type)
|
356
|
-
|
357
|
-
send("get_#{type.to_s}s".to_sym).select { |mixin| mixin.term == name }
|
358
|
+
describe_mixin(name, type)
|
358
359
|
end
|
359
360
|
|
360
361
|
# Looks up a mixin in all available mixin types, will
|
@@ -362,14 +363,9 @@ module Occi
|
|
362
363
|
# first match found, search will start in os_tpl.
|
363
364
|
#
|
364
365
|
# @param [String] name of the mixin
|
365
|
-
# @return [Occi::
|
366
|
+
# @return [Occi::Core::Mixin] mixin description
|
366
367
|
def describe_mixin_wo_type(name)
|
367
|
-
|
368
|
-
found = send("get_#{type}s".to_sym).select { |mixin| mixin.term == name }
|
369
|
-
return found if found.any?
|
370
|
-
end
|
371
|
-
|
372
|
-
[]
|
368
|
+
describe_mixin(name, nil)
|
373
369
|
end
|
374
370
|
|
375
371
|
# Looks up a mixin using its name and, optionally, a type as well.
|
@@ -388,37 +384,68 @@ module Occi
|
|
388
384
|
# @param [String] type of the mixin
|
389
385
|
# @return [String, nil] link or nothing found
|
390
386
|
def list_mixin(name, type = nil)
|
391
|
-
|
392
|
-
|
393
|
-
mxns.any? ? mxns.first : nil
|
387
|
+
mixin = describe_mixin(name, type)
|
388
|
+
mixin ? mixin.type_identifier : nil
|
394
389
|
end
|
395
390
|
|
396
391
|
# Retrieves available mixins of a specified type or all available
|
397
392
|
# mixins if the type wasn't specified. Mixins are returned in the
|
398
|
-
# form of mixin
|
393
|
+
# form of mixin instances.
|
399
394
|
#
|
400
395
|
# @example
|
401
396
|
# client.get_mixins
|
402
|
-
# # =>
|
403
|
-
# # "http://my.occi.service/occi/infrastructure/resource_tpl#small"]
|
397
|
+
# # => #<Occi::Core::Mixins>
|
404
398
|
# client.get_mixins "os_tpl"
|
405
|
-
# # =>
|
399
|
+
# # => #<Occi::Core::Mixins>
|
406
400
|
# client.get_mixins "resource_tpl"
|
407
|
-
# # =>
|
401
|
+
# # => #<Occi::Core::Mixins>
|
408
402
|
#
|
409
403
|
# @param [String] type of mixins
|
410
|
-
# @return [
|
404
|
+
# @return [Occi::Core::Mixins] collection of available mixins
|
411
405
|
def get_mixins(type = nil)
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
406
|
+
unless type.blank?
|
407
|
+
unless get_mixin_types.include?(type) || get_mixin_type_identifiers.include?(type)
|
408
|
+
raise ArgumentError,
|
409
|
+
"There is no such mixin type registered in the model! #{type.inspect}"
|
410
|
+
end
|
411
|
+
|
412
|
+
type = get_mixin_type_identifier(type) if get_mixin_types.include?(type)
|
413
|
+
mixins = @model.mixins.to_a.select { |m| m.related_to?(type) }
|
414
|
+
|
415
|
+
# drop the type mixin itself
|
416
|
+
mixins.delete_if { |m| m.type_identifier == type }
|
416
417
|
else
|
417
418
|
# we did not get a type, return all mixins
|
418
|
-
mixins =
|
419
|
-
|
420
|
-
|
419
|
+
mixins = Occi::Core::Mixins.new(@model.mixins)
|
420
|
+
end
|
421
|
+
|
422
|
+
unless mixins.kind_of? Occi::Core::Mixins
|
423
|
+
col = Occi::Core::Mixins.new
|
424
|
+
mixins.each { |m| col << m }
|
425
|
+
else
|
426
|
+
col = mixins
|
421
427
|
end
|
428
|
+
|
429
|
+
col
|
430
|
+
end
|
431
|
+
|
432
|
+
# Retrieves available mixins of a specified type or all available
|
433
|
+
# mixins if the type wasn't specified. Mixins are returned in the
|
434
|
+
# form of mixin identifiers.
|
435
|
+
#
|
436
|
+
# @example
|
437
|
+
# client.list_mixins
|
438
|
+
# # => #<Array<String>>
|
439
|
+
# client.list_mixins "os_tpl"
|
440
|
+
# # => #<Array<String>>
|
441
|
+
# client.list_mixins "resource_tpl"
|
442
|
+
# # => #<Array<String>>
|
443
|
+
#
|
444
|
+
# @param [String] type of mixins
|
445
|
+
# @return [Array<String>] collection of available mixin identifiers
|
446
|
+
def list_mixins(type = nil)
|
447
|
+
mixins = get_mixins(type)
|
448
|
+
mixins.to_a.collect { |m| m.type_identifier }
|
422
449
|
end
|
423
450
|
|
424
451
|
# Retrieves available mixin types. Mixin types are presented
|
@@ -429,7 +456,7 @@ module Occi
|
|
429
456
|
#
|
430
457
|
# @return [Array<String>] list of available mixin types
|
431
458
|
def get_mixin_types
|
432
|
-
|
459
|
+
get_mixins.to_a.collect { |m| m.term }
|
433
460
|
end
|
434
461
|
|
435
462
|
# Retrieves available mixin type identifiers.
|
@@ -441,34 +468,40 @@ module Occi
|
|
441
468
|
#
|
442
469
|
# @return [Array<String>] list of available mixin type identifiers
|
443
470
|
def get_mixin_type_identifiers
|
444
|
-
|
445
|
-
|
446
|
-
get_mixin_types.each do |mixin_type|
|
447
|
-
identifiers << "http://schemas.ogf.org/occi/infrastructure##{mixin_type}"
|
448
|
-
end
|
471
|
+
list_mixins(nil)
|
472
|
+
end
|
449
473
|
|
450
|
-
|
474
|
+
# Retrieves available mixin type identifier for the given mixin type.
|
475
|
+
#
|
476
|
+
# @example
|
477
|
+
# client.get_mixin_type_identifier("os_tpl")
|
478
|
+
# # => 'http://schemas.ogf.org/occi/infrastructure#os_tpl'
|
479
|
+
#
|
480
|
+
# @return [String, nil] mixin type identifier for the given mixin type
|
481
|
+
def get_mixin_type_identifier(type)
|
482
|
+
mixins = get_mixins.to_a.select { |m| m.term == type }
|
483
|
+
mixins.collect { |m| m.type_identifier }.first
|
451
484
|
end
|
452
485
|
|
453
486
|
# Retrieves available os_tpls from the model.
|
454
487
|
#
|
455
488
|
# @example
|
456
|
-
# get_os_templates # => #<Occi::
|
489
|
+
# get_os_templates # => #<Occi::Core::Mixins>
|
457
490
|
#
|
458
|
-
# @return [Occi::
|
491
|
+
# @return [Occi::Core::Mixins] collection containing all registered OS templates
|
459
492
|
def get_os_templates
|
460
|
-
|
493
|
+
get_mixins "http://schemas.ogf.org/occi/infrastructure#os_tpl"
|
461
494
|
end
|
462
495
|
alias_method :get_os_tpls, :get_os_templates
|
463
496
|
|
464
497
|
# Retrieves available resource_tpls from the model.
|
465
498
|
#
|
466
499
|
# @example
|
467
|
-
# get_resource_templates # => #<Occi::
|
500
|
+
# get_resource_templates # => #<Occi::Core::Mixins>
|
468
501
|
#
|
469
|
-
# @return [Occi::
|
502
|
+
# @return [Occi::Core::Mixins] collection containing all registered resource templates
|
470
503
|
def get_resource_templates
|
471
|
-
|
504
|
+
get_mixins "http://schemas.ogf.org/occi/infrastructure#resource_tpl"
|
472
505
|
end
|
473
506
|
alias_method :get_resource_tpls, :get_resource_templates
|
474
507
|
|
@@ -493,7 +526,7 @@ module Occi
|
|
493
526
|
#we got an resource link
|
494
527
|
path = sanitize_resource_link(resource_type_identifier)
|
495
528
|
else
|
496
|
-
raise "Unknown resource identifier! #{resource_type_identifier}"
|
529
|
+
raise "Unknown resource identifier! #{resource_type_identifier.inspect}"
|
497
530
|
end
|
498
531
|
end
|
499
532
|
|
@@ -512,7 +545,7 @@ module Occi
|
|
512
545
|
# everything starting with '/' is considered to be a resource path
|
513
546
|
return resource_link if resource_link.start_with? '/'
|
514
547
|
|
515
|
-
raise "Resource link #{resource_link} is not valid!" unless resource_link.start_with? @endpoint
|
548
|
+
raise "Resource link #{resource_link.inspect} is not valid!" unless resource_link.start_with? @endpoint
|
516
549
|
|
517
550
|
resource_link.gsub @endpoint, '/'
|
518
551
|
end
|
@@ -593,13 +626,6 @@ module Occi
|
|
593
626
|
def set_model(model)
|
594
627
|
# build model
|
595
628
|
@model = Occi::Model.new(model)
|
596
|
-
|
597
|
-
@mixins = {
|
598
|
-
:os_tpl => get_os_tpl_mixins_ary,
|
599
|
-
:resource_tpl => get_resource_tpl_mixins_ary
|
600
|
-
}
|
601
|
-
|
602
|
-
@model
|
603
629
|
end
|
604
630
|
|
605
631
|
# Returns mixin type identifiers for os_tpl mixins
|
@@ -607,7 +633,8 @@ module Occi
|
|
607
633
|
#
|
608
634
|
# @return [Array] array of os_tpl mixin identifiers
|
609
635
|
def get_os_tpl_mixins_ary
|
610
|
-
|
636
|
+
mixins = get_os_tpls
|
637
|
+
mixins.to_a.collect { |m| m.type_identifier }
|
611
638
|
end
|
612
639
|
|
613
640
|
# Returns mixin type identifiers for resource_tpl mixins
|
@@ -615,25 +642,8 @@ module Occi
|
|
615
642
|
#
|
616
643
|
# @return [Array] array of resource_tpl mixin identifiers
|
617
644
|
def get_resource_tpl_mixins_ary
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
# Returns mixin type identifiers for given mixin type
|
622
|
-
# in an array.
|
623
|
-
#
|
624
|
-
# @param [Symbol] mixin type
|
625
|
-
# @return [Array] array of mixin identifiers
|
626
|
-
def get_mixins_ary(mixin_type)
|
627
|
-
mixins = []
|
628
|
-
|
629
|
-
send("get_#{mixin_type.to_s}s".to_sym).each do |mixin|
|
630
|
-
next if mixin.nil? || mixin.type_identifier.nil?
|
631
|
-
|
632
|
-
tid = mixin.type_identifier.strip
|
633
|
-
mixins << tid unless tid.empty?
|
634
|
-
end
|
635
|
-
|
636
|
-
mixins
|
645
|
+
mixins = get_resource_tpls
|
646
|
+
mixins.to_a.collect { |m| m.type_identifier }
|
637
647
|
end
|
638
648
|
|
639
649
|
end
|