occi 3.1.3 → 4.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- metadata +16 -448
- data/.gitignore +0 -15
- data/.rspec +0 -1
- data/.travis.yml +0 -35
- data/.yardopts +0 -1
- data/AUTHORS +0 -9
- data/Gemfile +0 -13
- data/LICENSE +0 -13
- data/README.md +0 -471
- data/Rakefile +0 -37
- data/bin/occi +0 -356
- data/config/warble.rb +0 -151
- data/doc/macosx.md +0 -27
- data/examples/dsl_example.rb +0 -167
- data/examples/x509auth_example.rb +0 -161
- data/ext/mkrf_conf.rb +0 -30
- data/features/cassettes/Create_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
- data/features/cassettes/Delete_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +0 -288
- 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/Miscellaneous_operation_on_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.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.rb +0 -57
- data/lib/occi/api/client/client_amqp.rb +0 -767
- data/lib/occi/api/client/client_http.rb +0 -1100
- data/lib/occi/api/client/http/authn_utils.rb +0 -82
- data/lib/occi/api/client/http/httparty_fix.rb +0 -53
- data/lib/occi/api/client/http/net_http_fix.rb +0 -21
- data/lib/occi/api/dsl.rb +0 -146
- data/lib/occi/bin/helpers.rb +0 -149
- data/lib/occi/bin/occi_opts.rb +0 -384
- data/lib/occi/bin/resource_output_factory.rb +0 -97
- data/lib/occi/bin/templates/compute.erb +0 -18
- data/lib/occi/bin/templates/network.erb +0 -9
- data/lib/occi/bin/templates/os_tpl.erb +0 -7
- data/lib/occi/bin/templates/resource_tpl.erb +0 -7
- data/lib/occi/bin/templates/storage.erb +0 -8
- data/lib/occi/collection.rb +0 -186
- data/lib/occi/core.rb +0 -30
- data/lib/occi/core/action.rb +0 -32
- data/lib/occi/core/action_instance.rb +0 -24
- data/lib/occi/core/actions.rb +0 -22
- data/lib/occi/core/attribute_properties.rb +0 -52
- data/lib/occi/core/attributes.rb +0 -61
- data/lib/occi/core/categories.rb +0 -54
- data/lib/occi/core/category.rb +0 -149
- data/lib/occi/core/entities.rb +0 -50
- data/lib/occi/core/entity.rb +0 -246
- data/lib/occi/core/kind.rb +0 -58
- data/lib/occi/core/kinds.rb +0 -22
- data/lib/occi/core/link.rb +0 -100
- data/lib/occi/core/links.rb +0 -34
- data/lib/occi/core/mixin.rb +0 -55
- data/lib/occi/core/mixins.rb +0 -22
- data/lib/occi/core/related.rb +0 -20
- data/lib/occi/core/resource.rb +0 -76
- data/lib/occi/core/resources.rb +0 -14
- data/lib/occi/infrastructure.rb +0 -27
- data/lib/occi/infrastructure/compute.rb +0 -159
- data/lib/occi/infrastructure/network.rb +0 -131
- data/lib/occi/infrastructure/network/ipnetwork.rb +0 -34
- data/lib/occi/infrastructure/networkinterface.rb +0 -124
- data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +0 -34
- data/lib/occi/infrastructure/os_tpl.rb +0 -19
- data/lib/occi/infrastructure/resource_tpl.rb +0 -19
- data/lib/occi/infrastructure/storage.rb +0 -96
- data/lib/occi/infrastructure/storagelink.rb +0 -73
- data/lib/occi/log.rb +0 -66
- data/lib/occi/model.rb +0 -86
- data/lib/occi/parser.rb +0 -413
- data/lib/occi/version.rb +0 -3
- data/lib/occiantlr/.gitignore +0 -18
- data/lib/occiantlr/OCCIANTLR.g +0 -191
- data/lib/occiantlr/OCCIANTLR.tokens +0 -57
- data/lib/occiantlr/OCCIANTLRLexer.rb +0 -1868
- data/lib/occiantlr/OCCIANTLRParser.rb +0 -2906
- data/lib/occiantlr/README.md +0 -2
- data/occi.gemspec +0 -45
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_compute_resource.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_network_resource.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_storage_resource.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_compute_resource.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_network_resource.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_storage_resource.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deploys_an_instance_based_on_OVF_OVA_file.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_all_available_mixins.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_compute_resources.yml +0 -368
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_network_resources.yml +0 -370
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_os_tpl_mixins.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_resource_tpl_mixins.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_storage_resources.yml +0 -430
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/establishes_connection.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_compute_resource_using_type_identifier.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_compute_resource_using_type_name.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_network_resource_using_type_identifier.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_network_resource_using_type_name.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_storage_resource_using_type_identifier.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_storage_resource_using_type_name.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_entity_type_identifiers.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_entity_types.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_link_type_identifiers.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_link_types.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixin_type_identifiers.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixin_types.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixins.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_resource_type_identifiers.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_resource_types.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_compute_resources.yml +0 -308
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_network_resources.yml +0 -308
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_os_tpl_mixins.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_resource_tpl_mixins.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_storage_resources.yml +0 -310
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/refreshes_its_model.yml +0 -485
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_compute_resource.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_network_resource.yml +0 -266
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_storage_resource.yml +0 -266
- data/spec/occi/api/client/client_amqp_spec.rb +0 -159
- data/spec/occi/api/client/client_http_spec.rb +0 -253
- data/spec/occi/api/client/http/authn_utils_spec.rb +0 -55
- data/spec/occi/api/client/http/httparty_fix_spec.rb +0 -0
- data/spec/occi/api/client/http/net_http_fix_spec.rb +0 -0
- data/spec/occi/api/client/http/rocci-cred-cert.pem +0 -3
- data/spec/occi/api/client/http/rocci-cred-key-jruby.pem +0 -3
- data/spec/occi/api/client/http/rocci-cred-key.pem +0 -3
- data/spec/occi/api/client/http/rocci-cred.p12 +0 -0
- data/spec/occi/api/dsl_spec.rb +0 -22
- data/spec/occi/bin/helpers_spec.rb +0 -12
- data/spec/occi/bin/occi_opts_spec.rb +0 -60
- data/spec/occi/bin/resource_output_factory_spec.rb +0 -12
- data/spec/occi/collection_spec.rb +0 -41
- data/spec/occi/core/categories_spec.rb +0 -30
- data/spec/occi/core/category_spec.rb +0 -41
- data/spec/occi/core/entity_spec.rb +0 -52
- data/spec/occi/core/resource_spec.rb +0 -21
- data/spec/occi/infrastructure/compute_spec.rb +0 -32
- data/spec/occi/log_spec.rb +0 -17
- data/spec/occi/model_spec.rb +0 -51
- data/spec/occi/parser_spec.rb +0 -114
- data/spec/occi/test.json +0 -33
- data/spec/occi/test.ova +0 -0
- data/spec/occi/test.ovf +0 -198
- data/spec/occiantlr/parser_spec.rb +0 -82
- data/spec/spec_helper.rb +0 -43
@@ -1,32 +0,0 @@
|
|
1
|
-
Given /^endpoint : (.*)$/ do |endpoint|
|
2
|
-
@endpoint = endpoint
|
3
|
-
@endpoint =~ URI::ABS_URI
|
4
|
-
@endpoint.should_not be_nil
|
5
|
-
end
|
6
|
-
|
7
|
-
Given /^transfer_protocol : (http|amqp)$/ do |protocol|
|
8
|
-
@transfer_protocol = protocol
|
9
|
-
end
|
10
|
-
|
11
|
-
Given /^accept type : (text\/occi|text\/plain|application\/json)$/ do |accept_type|
|
12
|
-
@accept_type = accept_type
|
13
|
-
end
|
14
|
-
|
15
|
-
Given /^category filter : (.*)$/ do |category_filter|
|
16
|
-
@category_filter = category_filter
|
17
|
-
end
|
18
|
-
|
19
|
-
Given /^have an initialize Client$/ do
|
20
|
-
@client = Occi::Api::Client::ClientHttp.new({
|
21
|
-
:endpoint => @endpoint, #141.5.99.69 #11.5.99.82
|
22
|
-
:auth => { :type => "none" },
|
23
|
-
:log => { :out => "/dev/null",
|
24
|
-
:level => Occi::Log::DEBUG },
|
25
|
-
:auto_connect => true,
|
26
|
-
:media_type => @accept_type#"text/plain,text/occi"
|
27
|
-
})
|
28
|
-
end
|
29
|
-
|
30
|
-
Then /^the Client should have the response code (.*)$/ do |response_code|
|
31
|
-
@client.last_response.code.should == response_code.to_i
|
32
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Feature:
|
2
|
-
In order to create an OCCI Resource on the OCCI Server
|
3
|
-
As an OCCI Client
|
4
|
-
I want to get an success report of the create operation and receive the URI of the new Resource by the OCCI Server
|
5
|
-
|
6
|
-
@vcr_record
|
7
|
-
Scenario Outline: Create an OCCI Resource
|
8
|
-
Given endpoint : <endpoint>
|
9
|
-
And transfer_protocol : <protocol>
|
10
|
-
And accept type : <accept_type>
|
11
|
-
And have an initialize Client
|
12
|
-
When the Client makes a create request
|
13
|
-
Then the Client should have the response code <response_code>
|
14
|
-
|
15
|
-
@vcr_record
|
16
|
-
Scenarios:
|
17
|
-
| protocol | endpoint | accept_type | response_code |
|
18
|
-
| http | http://141.5.99.69/ | text/plain | 201 |
|
File without changes
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Feature:
|
2
|
-
In order to delete an OCCI Resource on the OCCI Server
|
3
|
-
As an OCCI Client
|
4
|
-
I want to get an success report of the delete operation
|
5
|
-
|
6
|
-
@vcr_record
|
7
|
-
Scenario Outline: Delete an OCCI Resource
|
8
|
-
Given endpoint : <endpoint>
|
9
|
-
And transfer_protocol : <protocol>
|
10
|
-
And accept type : <accept_type>
|
11
|
-
And have an initialize Client
|
12
|
-
When the Client makes a delete request
|
13
|
-
Then the Client should have the response code <response_code>
|
14
|
-
|
15
|
-
@vcr_record
|
16
|
-
Scenarios:
|
17
|
-
| protocol | endpoint | accept_type | response_code |
|
18
|
-
| http | http://141.5.99.69/ | text/plain | 201 |
|
File without changes
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# language: en
|
2
|
-
|
3
|
-
Feature: Discovery Interface
|
4
|
-
In order to discover the capabilities of an OCCI Server
|
5
|
-
As an OCCI Client
|
6
|
-
I want to receive all OCCI Categories supported by the OCCI Server
|
7
|
-
|
8
|
-
@vcr_record
|
9
|
-
Scenario Outline: Retrieving all OCCI Categories supported by the OCCI Server
|
10
|
-
Given endpoint : <endpoint>
|
11
|
-
And transfer_protocol : <protocol>
|
12
|
-
And accept type : <accept_type>
|
13
|
-
And category filter : <category_filter>
|
14
|
-
And have an initialize Client
|
15
|
-
When OCCI Client request all OCCI Categories supported by the OCCI Server
|
16
|
-
Then the Client should have the response code <response_code>
|
17
|
-
And OCCI Client should display the OCCI Categories received from the OCCI Server
|
18
|
-
|
19
|
-
@vcr_record
|
20
|
-
Scenarios:
|
21
|
-
| protocol | endpoint | accept_type | response_code | category_filter |
|
22
|
-
| http | http://141.5.99.69/ | application/json | 200 | |
|
23
|
-
#| http | http://141.5.99.69/ | text/occi | 200 | |
|
24
|
-
| http | http://141.5.99.69/ | text/plain | 200 | |
|
25
|
-
#| http | http://46.231.128.85:8086/| text/occi | 200 | |
|
26
|
-
| http | http://141.5.99.69/ | text/plain | 200 | action |
|
27
|
-
|
28
|
-
#Scenario: Retrieving the OCCI Categories with an OCCI Category filter from the OCCI Server
|
29
|
-
# Given an "http" OCCI Server with endpoint "http://141.5.99.69/"
|
30
|
-
# And the client accept "text/plain"
|
31
|
-
# And OCCI Client requests all OCCI Categories supported by the OCCI Server
|
32
|
-
# And select "action" Category from the OCCI Server
|
33
|
-
# When OCCI Client requests from the OCCI Server the OCCI Categories related to the selected OCCI Category
|
34
|
-
# Then OCCI Client should display the OCCI Categories received from the OCCI Server
|
35
|
-
# And displayed Categories should related to the selected OCCI Category
|
36
|
-
# And should be some
|
37
|
-
|
@@ -1,19 +0,0 @@
|
|
1
|
-
When /^OCCI Client request all OCCI Categories supported by the OCCI Server$/ do
|
2
|
-
if @category_filter.length > 0
|
3
|
-
@category_filter = @category_filter.pluralize
|
4
|
-
@selected_category = @client.model.send @category_filter.to_sym
|
5
|
-
@selected_category.should have_at_least(1).bla
|
6
|
-
pending
|
7
|
-
else
|
8
|
-
@client.refresh
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
Then /^OCCI Client should display the OCCI Categories received from the OCCI Server$/ do
|
13
|
-
@client.model.should_not be_empty
|
14
|
-
|
15
|
-
# @client.model.actions .should have_at_least(1).actions
|
16
|
-
@client.model.kinds .should have_at_least(4).kinds
|
17
|
-
@client.model.links .should be_empty
|
18
|
-
@client.model.resources.should be_empty
|
19
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Feature:
|
2
|
-
In order to manipulate an OCCI Resource on the OCCI Server
|
3
|
-
As an OCCI Client
|
4
|
-
I want to get an success report of the miscellaneous operation
|
5
|
-
|
6
|
-
@vcr_record
|
7
|
-
Scenario Outline: Miscellaneous operation on an OCCI Resource
|
8
|
-
Given endpoint : <endpoint>
|
9
|
-
And transfer_protocol : <protocol>
|
10
|
-
And accept type : <accept_type>
|
11
|
-
And have an initialize Client
|
12
|
-
When the Client makes a miscellaneous request
|
13
|
-
Then the Client should have the response code <response_code>
|
14
|
-
|
15
|
-
@vcr_record
|
16
|
-
Scenarios:
|
17
|
-
| protocol | endpoint | accept_type | response_code |
|
18
|
-
| http | http://141.5.99.69/ | text/plain | 201 |
|
File without changes
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Feature:
|
2
|
-
In order to read an OCCI Resource on the OCCI Server
|
3
|
-
As an OCCI Client
|
4
|
-
I want to get an success report of the read operation and receive Resource data from the OCCI Server
|
5
|
-
|
6
|
-
@vcr_record
|
7
|
-
Scenario Outline: Read an OCCI Resource
|
8
|
-
Given endpoint : <endpoint>
|
9
|
-
And transfer_protocol : <protocol>
|
10
|
-
And accept type : <accept_type>
|
11
|
-
And have an initialize Client
|
12
|
-
When the Client makes a read request
|
13
|
-
Then the Client should have the response code <response_code>
|
14
|
-
|
15
|
-
@vcr_record
|
16
|
-
Scenarios:
|
17
|
-
| protocol | endpoint | accept_type | response_code |
|
18
|
-
| http | http://141.5.99.69/ | text/plain | 201 |
|
File without changes
|
File without changes
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Feature:
|
2
|
-
In order to update an OCCI Resource on the OCCI Server
|
3
|
-
As an OCCI Client
|
4
|
-
I want to get an success report of the update operation
|
5
|
-
|
6
|
-
@vcr_record
|
7
|
-
Scenario Outline: Update an OCCI Resource
|
8
|
-
Given endpoint : <endpoint>
|
9
|
-
And transfer_protocol : <protocol>
|
10
|
-
And accept type : <accept_type>
|
11
|
-
And have an initialize Client
|
12
|
-
When the Client makes an update request
|
13
|
-
Then the Client should have the response code <response_code>
|
14
|
-
|
15
|
-
@vcr_record
|
16
|
-
Scenarios:
|
17
|
-
| protocol | endpoint | accept_type | response_code |
|
18
|
-
| http | http://141.5.99.69/ | text/plain | 201 |
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Feature:
|
2
|
-
In order to create an OCCI Resource on the OCCI Server
|
3
|
-
As an OCCI Client
|
4
|
-
I want to get an success report of the create operation and receive the URI of the new Resource by the OCCI Server
|
5
|
-
|
6
|
-
@vcr_record
|
7
|
-
Scenario Outline: Create an OCCI Resource
|
8
|
-
Given endpoint : <endpoint>
|
9
|
-
And transfer_protocol : <protocol>
|
10
|
-
And accept type : <accept_type>
|
11
|
-
And have an initialize Client
|
12
|
-
When the Client makes a create request
|
13
|
-
Then the Client should have the response code <response_code>
|
14
|
-
|
15
|
-
@vcr_record
|
16
|
-
Scenarios:
|
17
|
-
| protocol | endpoint | accept_type | response_code |
|
18
|
-
| http | http://141.5.99.69/ | text/plain | 201 |
|
File without changes
|
data/features/support/env.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'occi'
|
5
|
-
|
6
|
-
require 'vcr'
|
7
|
-
|
8
|
-
VCR.configure do |c|
|
9
|
-
c.hook_into :webmock
|
10
|
-
c.cassette_library_dir = 'features/cassettes'
|
11
|
-
end
|
12
|
-
|
13
|
-
VCR.cucumber_tags do |t|
|
14
|
-
t.tags '@vcr_ignore', :record => :none
|
15
|
-
t.tag '@vcr_record', {:use_scenario_name => true, :record => :new_episodes}
|
16
|
-
end
|
data/lib/occi.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
require 'set'
|
4
|
-
require 'hashie/mash'
|
5
|
-
|
6
|
-
require 'active_support/json'
|
7
|
-
require 'active_support/inflector'
|
8
|
-
require 'active_support/notifications'
|
9
|
-
|
10
|
-
require 'logger'
|
11
|
-
|
12
|
-
require 'uuidtools'
|
13
|
-
|
14
|
-
require 'httparty'
|
15
|
-
|
16
|
-
require 'nokogiri'
|
17
|
-
|
18
|
-
require 'rubygems/package'
|
19
|
-
|
20
|
-
require 'zlib'
|
21
|
-
|
22
|
-
require 'tempfile'
|
23
|
-
|
24
|
-
require 'occi/version'
|
25
|
-
require 'occi/collection'
|
26
|
-
require 'occi/parser'
|
27
|
-
require 'occi/model'
|
28
|
-
require 'occi/log'
|
29
|
-
require 'occi/core'
|
30
|
-
require 'occi/infrastructure'
|
31
|
-
|
32
|
-
require 'occiantlr/OCCIANTLRLexer'
|
33
|
-
require 'occiantlr/OCCIANTLRParser'
|
34
|
-
|
35
|
-
require 'occi/api/dsl'
|
36
|
-
require 'occi/api/client/client_http'
|
37
|
-
require 'occi/api/client/client_amqp'
|
38
|
-
|
39
|
-
module Occi
|
40
|
-
|
41
|
-
def kinds
|
42
|
-
Occi::Core::Kinds.new
|
43
|
-
end
|
44
|
-
|
45
|
-
def mixins
|
46
|
-
Occi::Core::Mixins.new
|
47
|
-
end
|
48
|
-
|
49
|
-
def actions
|
50
|
-
Occi::Core::Actions.new
|
51
|
-
end
|
52
|
-
|
53
|
-
# @return [Array] list of Occi::Core::Categories
|
54
|
-
def categories
|
55
|
-
self.kinds + self.mixins + self.actions
|
56
|
-
end
|
57
|
-
end
|
@@ -1,767 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require "amqp"
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
module Occi
|
6
|
-
module Api
|
7
|
-
module Client
|
8
|
-
|
9
|
-
class ClientAmqp
|
10
|
-
attr_reader :endpoint, :auth_options, :connected, :last_response_status
|
11
|
-
attr_accessor :media_type, :model
|
12
|
-
|
13
|
-
CONNECTION_SETTING = {
|
14
|
-
:host => 'localhost', #IP of the MessageBroker (RabbitMQ)
|
15
|
-
:port => 5672,
|
16
|
-
:vhost => '/' ,
|
17
|
-
:password => 'password'
|
18
|
-
}
|
19
|
-
|
20
|
-
# hash mapping HTTP response codes to human-readable messages
|
21
|
-
HTTP_CODES = {
|
22
|
-
"100" => "Continue",
|
23
|
-
"101" => "Switching Protocols",
|
24
|
-
"200" => "OK",
|
25
|
-
"201" => "Created",
|
26
|
-
"202" => "Accepted",
|
27
|
-
"203" => "Non-Authoritative Information",
|
28
|
-
"204" => "No Content",
|
29
|
-
"205" => "Reset Content",
|
30
|
-
"206" => "Partial Content",
|
31
|
-
"300" => "Multiple Choices",
|
32
|
-
"301" => "Moved Permanently",
|
33
|
-
"302" => "Found",
|
34
|
-
"303" => "See Other",
|
35
|
-
"304" => "Not Modified",
|
36
|
-
"305" => "Use Proxy",
|
37
|
-
"307" => "Temporary Redirect",
|
38
|
-
"400" => "Bad Request",
|
39
|
-
"401" => "Unauthorized",
|
40
|
-
"402" => "Payment Required",
|
41
|
-
"403" => "Forbidden",
|
42
|
-
"404" => "Not Found",
|
43
|
-
"405" => "Method Not Allowed",
|
44
|
-
"406" => "Not Acceptable",
|
45
|
-
"407" => "Proxy Authentication Required",
|
46
|
-
"408" => "Request Time-out",
|
47
|
-
"409" => "Conflict",
|
48
|
-
"410" => "Gone",
|
49
|
-
"411" => "Length Required",
|
50
|
-
"412" => "Precondition Failed",
|
51
|
-
"413" => "Request Entity Too Large",
|
52
|
-
"414" => "Request-URI Too Large",
|
53
|
-
"415" => "Unsupported Media Type",
|
54
|
-
"416" => "Requested range not satisfiable",
|
55
|
-
"417" => "Expectation Failed",
|
56
|
-
"500" => "Internal Server Error",
|
57
|
-
"501" => "Not Implemented",
|
58
|
-
"502" => "Bad Gateway",
|
59
|
-
"503" => "Service Unavailable",
|
60
|
-
"504" => "Gateway Time-out",
|
61
|
-
"505" => "HTTP Version not supported"
|
62
|
-
}
|
63
|
-
|
64
|
-
#TODO Should a client have some kind of timeout
|
65
|
-
|
66
|
-
# Initializes client data structures and retrieves OCCI model
|
67
|
-
# from the server.
|
68
|
-
#
|
69
|
-
# @example
|
70
|
-
# options = {
|
71
|
-
# :endpoint => "http://localhost:3300/",
|
72
|
-
# :auth => {:type => "none"},
|
73
|
-
# :log => {:out => STDERR, :level => Occi::Log::WARN, :logger => nil},
|
74
|
-
# :media_type => "text/plain"
|
75
|
-
# }
|
76
|
-
#
|
77
|
-
# Occi::Api::Client::ClientAmqp.new options # => #<Occi::Api::Client::ClientAmqp>
|
78
|
-
#
|
79
|
-
# @param [Hash] options, for available options and defaults see examples
|
80
|
-
# @return [Occi::Api::Client::ClientAmqp] client instance
|
81
|
-
def initialize(options = {})
|
82
|
-
|
83
|
-
defaults = {
|
84
|
-
:endpoint => "http://localhost:3300/",
|
85
|
-
:auth => {:type => "none"},
|
86
|
-
:log => {:out => STDERR, :level => Occi::Log::WARN, :logger => nil},
|
87
|
-
:media_type => "text/plain"
|
88
|
-
}
|
89
|
-
|
90
|
-
options = options.marshal_dump if options.is_a? OpenStruct
|
91
|
-
options = defaults.merge options
|
92
|
-
|
93
|
-
# check the validity and canonize the endpoint URI
|
94
|
-
prepare_endpoint options[:endpoint]
|
95
|
-
|
96
|
-
# set Occi::Log
|
97
|
-
set_logger options[:log]
|
98
|
-
|
99
|
-
# pass auth options to HTTParty
|
100
|
-
change_auth options[:auth]
|
101
|
-
|
102
|
-
@media_type = options[:media_type]
|
103
|
-
|
104
|
-
Occi::Log.debug("Media Type: #{@media_type}")
|
105
|
-
|
106
|
-
@connected = false
|
107
|
-
|
108
|
-
Thread.new { run }
|
109
|
-
|
110
|
-
Occi::Log.debug("Waiting for connection amqp ...")
|
111
|
-
|
112
|
-
#TODO find a better solution for the thread issue
|
113
|
-
while(!@thread_error && !@connected)
|
114
|
-
#dont use sleep - it blocks the eventmachine
|
115
|
-
end
|
116
|
-
|
117
|
-
# get model information from the endpoint
|
118
|
-
# and create Occi::Model instance
|
119
|
-
set_model unless @thread_error
|
120
|
-
end
|
121
|
-
|
122
|
-
# @describe Retrieves available resources represented by resource locations (URIs).
|
123
|
-
# If no type identifier is specified, all available resource are listed.
|
124
|
-
# Type identifier can be specified in its shortened format (e.g. "compute",
|
125
|
-
# "storage", "network").
|
126
|
-
#
|
127
|
-
# @example
|
128
|
-
# client.list
|
129
|
-
# # => [ "http://localhost:3300/compute/jh425jhj3h413-7dj29d7djd9e3-djh2jh4j4j",
|
130
|
-
# # "http://localhost:3300/network/kh425jhj3h413-7dj29d7djd9e3-djh2jh4j4j",
|
131
|
-
# # "http://localhost:3300/storage/lh425jhj3h413-7dj29d7djd9e3-djh2jh4j4j" ]
|
132
|
-
# client.list "compute"
|
133
|
-
# # => [ "http://localhost:3300/compute/jh425jhj3h413-7dj29d7djd9e3-djh2jh4j4j" ]
|
134
|
-
# client.list "http://schemas.ogf.org/occi/infrastructure#compute"
|
135
|
-
# # => [ "http://localhost:3300/compute/jh425jhj3h413-7dj29d7djd9e3-djh2jh4j4j" ]
|
136
|
-
#
|
137
|
-
# @param [String] resource type identifier or just type name
|
138
|
-
# @return [Array<String>] list of links
|
139
|
-
def list(resource_type_identifier = nil, is_wait = true, is_parse_response = true)
|
140
|
-
|
141
|
-
if resource_type_identifier
|
142
|
-
# convert type to type identifier
|
143
|
-
resource_type_identifier = @model.kinds.select {
|
144
|
-
|kind| kind.term == resource_type_identifier
|
145
|
-
}.first.type_identifier if @model.kinds.select {
|
146
|
-
|kind| kind.term == resource_type_identifier
|
147
|
-
}.any?
|
148
|
-
|
149
|
-
# check some basic pre-conditions
|
150
|
-
raise "Endpoint is not connected!" unless @connected
|
151
|
-
raise "Unkown resource type identifier! [#{resource_type_identifier}]" unless @model.get_by_id resource_type_identifier
|
152
|
-
|
153
|
-
# split the type identifier and get the most important part
|
154
|
-
uri_part = resource_type_identifier.split('#').last
|
155
|
-
|
156
|
-
# request uri-list from the server
|
157
|
-
path = uri_part + '/'
|
158
|
-
else
|
159
|
-
path = '/'
|
160
|
-
end
|
161
|
-
|
162
|
-
message_id = get(path, true)
|
163
|
-
|
164
|
-
return response_value(message_id, is_wait, is_parse_response)
|
165
|
-
end
|
166
|
-
|
167
|
-
# @describe Retrieves descriptions for available resources specified by a type
|
168
|
-
# identifier or resource location. If no type identifier or location
|
169
|
-
# is specified, all available resources in all available resource types
|
170
|
-
# will be described.
|
171
|
-
#
|
172
|
-
# @example
|
173
|
-
# client.describe
|
174
|
-
# # => [#<Occi::Collection>, #<Occi::Collection>, #<Occi::Collection>]
|
175
|
-
# client.describe "compute"
|
176
|
-
# # => [#<Occi::Collection>, #<Occi::Collection>, #<Occi::Collection>]
|
177
|
-
# client.describe "http://schemas.ogf.org/occi/infrastructure#compute"
|
178
|
-
# # => [#<Occi::Collection>, #<Occi::Collection>, #<Occi::Collection>]
|
179
|
-
# client.describe "http://localhost:3300/compute/j5hk1234jk2524-2j3j2k34jjh234-adfaf1234"
|
180
|
-
# # => [#<Occi::Collection>]
|
181
|
-
#
|
182
|
-
# @param [String] resource type identifier, type name or resource location
|
183
|
-
# @return [Array<Occi::Collection>] list of resource descriptions
|
184
|
-
def describe(resource_type_identifier=nil, is_wait = true, is_parse_response = true)
|
185
|
-
|
186
|
-
raise "Endpoint is not connected!" unless @connected
|
187
|
-
|
188
|
-
# convert type to type identifier
|
189
|
-
resource_type_identifier = @model.kinds.select {
|
190
|
-
|kind| kind.term == resource_type_identifier
|
191
|
-
}.first.type_identifier if @model.kinds.select {
|
192
|
-
|kind| kind.term == resource_type_identifier
|
193
|
-
}.any?
|
194
|
-
|
195
|
-
descriptions = []
|
196
|
-
|
197
|
-
if resource_type_identifier.nil?
|
198
|
-
descriptions << response_value(get('/'), is_wait, is_parse_response)
|
199
|
-
elsif @model.get_by_id resource_type_identifier
|
200
|
-
# we got type identifier
|
201
|
-
# get all available resources of this type
|
202
|
-
locations = list resource_type_identifier
|
203
|
-
|
204
|
-
# make the requests
|
205
|
-
locations.each do |location|
|
206
|
-
descriptions << response_value(get(sanitize_resource_link(location)), is_wait, is_parse_response)
|
207
|
-
end
|
208
|
-
elsif resource_type_identifier.start_with? @endpoint
|
209
|
-
# we got resource link
|
210
|
-
# make the request
|
211
|
-
descriptions << response_value(get(sanitize_resource_link(resource_type_identifier)), is_wait, is_parse_response)
|
212
|
-
else
|
213
|
-
raise "Unkown resource type identifier! [#{resource_type_identifier}]"
|
214
|
-
end
|
215
|
-
|
216
|
-
descriptions
|
217
|
-
end
|
218
|
-
|
219
|
-
# Creates a new resource on the server. Resource must be provided
|
220
|
-
# as an instance of Occi::Core::Entity, e.g. instantiated using
|
221
|
-
# the get_resource method.
|
222
|
-
#
|
223
|
-
# @example
|
224
|
-
# res = client.get_resource "compute"
|
225
|
-
#
|
226
|
-
# res.title = "MyComputeResource1"
|
227
|
-
# res.mixins << client.find_mixin('small', "resource_tpl")
|
228
|
-
# res.mixins << client.find_mixin('debian6', "os_tpl")
|
229
|
-
#
|
230
|
-
# client.create res # => "http://localhost:3300/compute/df7698...f987fa"
|
231
|
-
#
|
232
|
-
def create(entity, is_wait = true, is_parse_response = true)
|
233
|
-
|
234
|
-
# check some basic pre-conditions
|
235
|
-
raise "Endpoint is not connected!" unless @connected
|
236
|
-
raise "#{entity} not an entity" unless entity.kind_of? Occi::Core::Entity
|
237
|
-
|
238
|
-
# is this entity valid?
|
239
|
-
entity.model = @model
|
240
|
-
entity.check
|
241
|
-
kind = entity.kind
|
242
|
-
raise "No kind found for #{entity}" unless kind
|
243
|
-
|
244
|
-
# get location for this kind of entity
|
245
|
-
location = entity.kind.location
|
246
|
-
collection = Occi::Collection.new
|
247
|
-
|
248
|
-
# is this entity a Resource or a Link?
|
249
|
-
collection.resources << entity if entity.kind_of? Occi::Core::Resource
|
250
|
-
collection.links << entity if entity.kind_of? Occi::Core::Link
|
251
|
-
|
252
|
-
# make the request
|
253
|
-
response_value(post(location, collection), is_wait, is_parse_response)
|
254
|
-
end
|
255
|
-
|
256
|
-
# Deletes a resource or all resource of a certain resource type
|
257
|
-
# from the server.
|
258
|
-
#
|
259
|
-
# @example
|
260
|
-
# client.delete "compute" # => true
|
261
|
-
# client.delete "http://schemas.ogf.org/occi/infrastructure#compute" # => true
|
262
|
-
# client.delete "http://localhost:3300/compute/245j42594...98s9df8s9f" # => true
|
263
|
-
#
|
264
|
-
# @param [String] resource type identifier, type name or location
|
265
|
-
# @return [Boolean] status
|
266
|
-
def delete(resource_type_identifier, is_wait = true, is_parse_response = true)
|
267
|
-
# convert type to type identifier
|
268
|
-
resource_type_identifier = @model.kinds.select {
|
269
|
-
|kind| kind.term == resource_type_identifier
|
270
|
-
}.first.type_identifier if @model.kinds.select {
|
271
|
-
|kind| kind.term == resource_type_identifier
|
272
|
-
}.any?
|
273
|
-
|
274
|
-
# check some basic pre-conditions
|
275
|
-
raise "Endpoint is not connected!" unless @connected
|
276
|
-
|
277
|
-
if resource_type_identifier.nil? || resource_type_identifier == "/"
|
278
|
-
path = "/"
|
279
|
-
else
|
280
|
-
raise "Unknown resource identifier! #{resource_type_identifier}" unless resource_type_identifier.start_with? @endpoint
|
281
|
-
path = sanitize_resource_link(resource_type_identifier)
|
282
|
-
end
|
283
|
-
|
284
|
-
# make the request
|
285
|
-
response_value(del(path), is_wait, is_parse_response)
|
286
|
-
end
|
287
|
-
|
288
|
-
# Triggers given action on a specific resource.
|
289
|
-
#
|
290
|
-
# @example
|
291
|
-
# TODO: add examples
|
292
|
-
#
|
293
|
-
# @param [String] resource location
|
294
|
-
# @param [String] type of action
|
295
|
-
# @return [String] resource location
|
296
|
-
def trigger(resource_type_identifier, action, is_wait = true, is_parse_response = true)
|
297
|
-
|
298
|
-
# TODO: not tested
|
299
|
-
resource_type_identifier = @model.kinds.select {
|
300
|
-
|kind| kind.term == resource_type_identifier
|
301
|
-
}.first.type_identifier if @model.kinds.select {
|
302
|
-
|kind| kind.term == resource_type_identifier
|
303
|
-
}.any?
|
304
|
-
|
305
|
-
# check some basic pre-conditions
|
306
|
-
raise "Endpoint is not connected!" unless @connected
|
307
|
-
|
308
|
-
if resource_type_identifier.nil? || resource_type_identifier == "/"
|
309
|
-
path = "/"
|
310
|
-
else
|
311
|
-
raise "Unknown resource identifier! #{resource_type_identifier}" unless resource_type_identifier.start_with? @endpoint
|
312
|
-
path = sanitize_resource_link(resource_type_identifier)
|
313
|
-
end
|
314
|
-
|
315
|
-
# encapsulate the acion in a collection
|
316
|
-
collection = Occi::Collection.new
|
317
|
-
scheme, term = action.split('#')
|
318
|
-
collection.actions << Occi::Core::Action.new(scheme + '#', term)
|
319
|
-
|
320
|
-
#@media_type = "text/plain"
|
321
|
-
|
322
|
-
# make the request
|
323
|
-
path = path + '?action=' + term
|
324
|
-
response_value(post(path, collection))
|
325
|
-
end
|
326
|
-
|
327
|
-
def parse_message(message_id, delete_response = true)
|
328
|
-
raise "message is empty for message_id(#{ message_id })" if @response_messages.nil? || @response_messages[message_id].nil?
|
329
|
-
|
330
|
-
payload = @response_messages[message_id][:payload]
|
331
|
-
type = @response_messages[message_id][:type]
|
332
|
-
metadata = @response_messages[message_id][:metadata]
|
333
|
-
|
334
|
-
@last_response_status = metadata.headers["status_code"]
|
335
|
-
|
336
|
-
@response_messages.delete(message_id) if delete_response
|
337
|
-
|
338
|
-
raise "OCCI-Server raise error: #{ payload } server status: #{ @last_response_status }" if metadata.headers["is_error"]
|
339
|
-
|
340
|
-
begin
|
341
|
-
return method("parse_#{ type }").call(payload, metadata)
|
342
|
-
rescue Exception => e
|
343
|
-
error_msg = e.message + "\n" + e.backtrace.to_s
|
344
|
-
Occi::Log.error error_msg
|
345
|
-
raise "Can not parse #{ type } payload: #{ payload } metadata: #{ metadata.inspect }"
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
# Looks up a mixin using its name and, optionally, a type as well.
|
350
|
-
# Will return mixin's full location (a link) or a description.
|
351
|
-
#
|
352
|
-
# @example
|
353
|
-
# client.find_mixin "debian6"
|
354
|
-
# # => "http://my.occi.service/occi/infrastructure/os_tpl#debian6"
|
355
|
-
# client.find_mixin "debian6", "os_tpl"
|
356
|
-
# # => "http://my.occi.service/occi/infrastructure/os_tpl#debian6"
|
357
|
-
# client.find_mixin "large", "resource_tpl"
|
358
|
-
# # => "http://my.occi.service/occi/infrastructure/resource_tpl#large"
|
359
|
-
# client.find_mixin "debian6", "resource_tpl" # => nil
|
360
|
-
#
|
361
|
-
# @param [String] name of the mixin
|
362
|
-
# @param [String] type of the mixin
|
363
|
-
# @param [Boolean] should we describe the mixin or return its link?
|
364
|
-
# @return [String, Occi::Collection, nil] link, mixin description or nothing found
|
365
|
-
def find_mixin(name, type = nil, describe = false)
|
366
|
-
|
367
|
-
Occi::Log.debug("Looking for mixin #{name} + #{type} + #{describe}")
|
368
|
-
|
369
|
-
# is type valid?
|
370
|
-
if type
|
371
|
-
raise "Unknown mixin type! [#{type}]" unless @mixins.has_key? type.to_sym
|
372
|
-
end
|
373
|
-
|
374
|
-
# TODO: extend this code to support multiple matches and regex filters
|
375
|
-
# should we look for links or descriptions?
|
376
|
-
if describe
|
377
|
-
# we are looking for descriptions
|
378
|
-
if type
|
379
|
-
# get the first match from either os_tpls or resource_tpls
|
380
|
-
case
|
381
|
-
when type == "os_tpl"
|
382
|
-
get_os_templates.select { |mixin| mixin.term == name }.first
|
383
|
-
when type == "resource_tpl"
|
384
|
-
get_resource_templates.select { |template| template.term == name }.first
|
385
|
-
else
|
386
|
-
nil
|
387
|
-
end
|
388
|
-
else
|
389
|
-
# try in os_tpls first
|
390
|
-
found = get_os_templates.select { |os| os.term == name }.first
|
391
|
-
|
392
|
-
# then try in resource_tpls
|
393
|
-
found = get_resource_templates.select {
|
394
|
-
|template| template.term == name
|
395
|
-
}.first unless found
|
396
|
-
|
397
|
-
found
|
398
|
-
end
|
399
|
-
else
|
400
|
-
# we are looking for links
|
401
|
-
# prefix mixin name with '#' to simplify the search
|
402
|
-
name = "#" + name
|
403
|
-
if type
|
404
|
-
# return the first match with the selected type
|
405
|
-
@mixins[type.to_sym].select {
|
406
|
-
|mixin| mixin.to_s.reverse.start_with? name.reverse
|
407
|
-
}.first
|
408
|
-
else
|
409
|
-
# there is no type preference, return first global match
|
410
|
-
@mixins.flatten(2).select {
|
411
|
-
|mixin| mixin.to_s.reverse.start_with? name.reverse
|
412
|
-
}.first
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
# Creates a new resource instance, resource should be specified
|
418
|
-
# by its name or identifier.
|
419
|
-
#
|
420
|
-
# @example
|
421
|
-
# client.get_resource "compute" # => Occi::Core::Resource
|
422
|
-
# client.get_resource "storage" # => Occi::Core::Resource
|
423
|
-
# client.get_resource "http://schemas.ogf.org/occi/infrastructure#network"
|
424
|
-
# # => Occi::Core::Resource
|
425
|
-
#
|
426
|
-
# @param [String] resource name or resource identifier
|
427
|
-
# @return [Occi::Core::Resource] new resource instance
|
428
|
-
def get_resource(resource_type)
|
429
|
-
|
430
|
-
Occi::Log.debug("Instantiating #{resource_type} ...")
|
431
|
-
|
432
|
-
if @model.get_by_id resource_type
|
433
|
-
# we got a resource type identifier
|
434
|
-
Occi::Core::Resource.new resource_type
|
435
|
-
elsif @model.kinds.select { |kind| kind.term == resource_type }.any?
|
436
|
-
# we got a resource type name
|
437
|
-
Occi::Core::Resource.new @model.kinds.select {
|
438
|
-
|kind| kind.term == resource_type
|
439
|
-
}.first.type_identifier
|
440
|
-
else
|
441
|
-
raise "Unknown resource type! [#{resource_type}]"
|
442
|
-
end
|
443
|
-
|
444
|
-
end
|
445
|
-
|
446
|
-
# Retrieves available os_tpls from the model.
|
447
|
-
#
|
448
|
-
# @example
|
449
|
-
# get_os_templates # => #<Occi::Collection>
|
450
|
-
#
|
451
|
-
# @return [Occi::Collection] collection containing all registered OS templates
|
452
|
-
def get_os_templates
|
453
|
-
@model.get.mixins.select { |mixin| mixin.related.select { |rel| rel.end_with? 'os_tpl' }.any? }
|
454
|
-
end
|
455
|
-
|
456
|
-
# Retrieves available resource_tpls from the model.
|
457
|
-
#
|
458
|
-
# @example
|
459
|
-
# get_resource_templates # => #<Occi::Collection>
|
460
|
-
#
|
461
|
-
# @return [Occi::Collection] collection containing all registered resource templates
|
462
|
-
def get_resource_templates
|
463
|
-
@model.get.mixins.select { |mixin| mixin.related.select { |rel| rel.end_with? 'resource_tpl' }.any? }
|
464
|
-
end
|
465
|
-
|
466
|
-
# Refreshes the Occi::Model used inside the client. Useful for
|
467
|
-
# updating the model without creating a new instance or
|
468
|
-
# reconnecting. Saves a lot of time in an interactive mode.
|
469
|
-
#
|
470
|
-
# @example
|
471
|
-
# client.refresh
|
472
|
-
def refresh
|
473
|
-
# re-download the model from the server
|
474
|
-
set_model
|
475
|
-
end
|
476
|
-
|
477
|
-
# private stuff --------------------------------------------------------------------------------------------------
|
478
|
-
private
|
479
|
-
|
480
|
-
def parse_get(payload, metadata)
|
481
|
-
if metadata.content_type == "text/uri-list"
|
482
|
-
return payload.split("\n")
|
483
|
-
else
|
484
|
-
path = metadata.headers["path_info"]
|
485
|
-
kind = @model.get_by_location(('/' + path).match(/\/.*\//).to_s) if @model
|
486
|
-
kind ? entity_type = kind.entity_type : entity_type = nil
|
487
|
-
collection = Occi::Parser.parse(metadata.content_type, payload, path.include?("/-/"), entity_type)
|
488
|
-
return collection
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
def parse_post(payload, metadata)
|
493
|
-
return URI.parse(payload).to_s
|
494
|
-
end
|
495
|
-
|
496
|
-
def parse_delete(payload, metadata)
|
497
|
-
return true
|
498
|
-
end
|
499
|
-
|
500
|
-
def run
|
501
|
-
begin
|
502
|
-
AMQP.start(CONNECTION_SETTING) do |connection, open_ok|
|
503
|
-
@channel = AMQP::Channel.new(connection)
|
504
|
-
@exchange = @channel.default_exchange
|
505
|
-
|
506
|
-
@channel.on_error(&method(:handle_channel_exception))
|
507
|
-
|
508
|
-
@replies_queue = @channel.queue(Time.now.to_f.to_s + Kernel.rand().to_s, :exclusive => true)
|
509
|
-
@replies_queue.subscribe(&method(:handle_message))
|
510
|
-
|
511
|
-
@connected = true;
|
512
|
-
end
|
513
|
-
rescue Exception => e
|
514
|
-
@thread_error = true
|
515
|
-
Occi::Log.error "Amqp Thread get an Error: #{e.message} \n #{e.backtrace.join("\n")}"
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
def handle_message(metadata, payload)
|
520
|
-
|
521
|
-
correlation_id = metadata.correlation_id
|
522
|
-
|
523
|
-
unless correlation_id.size > 0
|
524
|
-
raise "Message has no correlation_id (message_id)"
|
525
|
-
end
|
526
|
-
|
527
|
-
@response_messages = Hash.new if @response_messages.nil?
|
528
|
-
raise "Double Response Message ID: (#{ correlation_id })" if @response_messages.has_key?(correlation_id)
|
529
|
-
|
530
|
-
#save responses message
|
531
|
-
@response_messages[correlation_id] = {:payload => payload, :metadata => metadata, :type => @response_waiting[correlation_id][:options][:type]}
|
532
|
-
|
533
|
-
#delete message_id from waiting stack
|
534
|
-
@response_waiting.delete(correlation_id) unless @response_waiting.nil?
|
535
|
-
end
|
536
|
-
|
537
|
-
def set_model
|
538
|
-
collection = response_value(get('/-/'))
|
539
|
-
@model = Occi::Model.new(collection)
|
540
|
-
|
541
|
-
@mixins = {
|
542
|
-
:os_tpl => [],
|
543
|
-
:resource_tpl => [],
|
544
|
-
:simulation => []
|
545
|
-
}
|
546
|
-
|
547
|
-
#
|
548
|
-
get_os_templates.each do |os_tpl|
|
549
|
-
@mixins[:os_tpl] << os_tpl.type_identifier unless os_tpl.nil? or os_tpl.type_identifier.nil?
|
550
|
-
end
|
551
|
-
|
552
|
-
#
|
553
|
-
get_resource_templates.each do |res_tpl|
|
554
|
-
@mixins[:resource_tpl] << res_tpl.type_identifier unless res_tpl.nil? or res_tpl.type_identifier.nil?
|
555
|
-
end
|
556
|
-
end
|
557
|
-
|
558
|
-
# Extracts the resource path from a resource link. It will remove the leading @endpoint
|
559
|
-
# and replace it with a slash.
|
560
|
-
#
|
561
|
-
# @example
|
562
|
-
# sanitize_resource_link "http://localhost:3300/compute/35ad4f45gsf-gsfg524s6gsfg-sfgsf4gsfg"
|
563
|
-
# # => "/compute/35ad4f45gsf-gsfg524s6gsfg-sfgsf4gsfg"
|
564
|
-
#
|
565
|
-
# @param [String] string containing the full resource link
|
566
|
-
# @return [String] extracted path, with a leading slash
|
567
|
-
def sanitize_resource_link(resource_link)
|
568
|
-
raise "Resource link #{resource_link} is not valid!" unless resource_link.start_with? @endpoint
|
569
|
-
|
570
|
-
resource_link.gsub @endpoint, '/'
|
571
|
-
end
|
572
|
-
|
573
|
-
#TODO filter
|
574
|
-
def get(path='', is_uri_list = false, filter=nil)
|
575
|
-
raise "OCCI AMQP is not connected!" if !@connected
|
576
|
-
|
577
|
-
options = {
|
578
|
-
:routing_key => @endpoint_queue,
|
579
|
-
:type => "get",
|
580
|
-
:content_type => "text/plain",
|
581
|
-
:reply_to => reply_queue_name,
|
582
|
-
:message_id => next_message_id,
|
583
|
-
:headers => {
|
584
|
-
:accept => is_uri_list ? "text/uri-list" : @media_type,
|
585
|
-
:path_info => "/" + path.gsub(/\A\//, '')
|
586
|
-
}
|
587
|
-
}
|
588
|
-
|
589
|
-
publish('', options)
|
590
|
-
|
591
|
-
return options[:message_id]
|
592
|
-
end
|
593
|
-
|
594
|
-
#@description
|
595
|
-
#@param [String] path path to the resource
|
596
|
-
#@param [OCCI::Collection] collection
|
597
|
-
def post(path, collection=nil)
|
598
|
-
path = path.reverse.chomp('/').reverse
|
599
|
-
|
600
|
-
if @media_type == 'application/occi+json'
|
601
|
-
message = collection.to_json
|
602
|
-
content_type = 'application/occi+json'
|
603
|
-
else
|
604
|
-
message = collection.to_text
|
605
|
-
content_type = 'text/plain'
|
606
|
-
end
|
607
|
-
|
608
|
-
options = {
|
609
|
-
:routing_key => @endpoint_queue,
|
610
|
-
:content_type => content_type,
|
611
|
-
:type => "post",
|
612
|
-
:reply_to => reply_queue_name, #queue for response from the rOCCI
|
613
|
-
:message_id => next_message_id, #Identifier for message so that the client can match the answer from the rOCCI
|
614
|
-
:headers => {
|
615
|
-
:accept => "text/uri-list",
|
616
|
-
:path_info => "/#{ path }",
|
617
|
-
:auth => {
|
618
|
-
:type => "basic",
|
619
|
-
:username => "user",
|
620
|
-
:password => "mypass",
|
621
|
-
},
|
622
|
-
}
|
623
|
-
}
|
624
|
-
|
625
|
-
publish(message, options)
|
626
|
-
|
627
|
-
return options[:message_id]
|
628
|
-
end
|
629
|
-
|
630
|
-
# Performs DELETE requests and returns True on success.
|
631
|
-
#
|
632
|
-
# @example
|
633
|
-
# del "/compute/65sf4g65sf4g-sf6g54sf5g-sfgsf32g3" # => true
|
634
|
-
#
|
635
|
-
# @param [String] path for the DELETE request
|
636
|
-
# @param [Occi::Collection] collection of filters (currently NOT used)
|
637
|
-
# @return [Boolean] status
|
638
|
-
def del(path, filter=nil)
|
639
|
-
# remove the leading slash
|
640
|
-
path.gsub!(/\A\//, '')
|
641
|
-
|
642
|
-
options = {
|
643
|
-
:routing_key => @endpoint_queue,
|
644
|
-
:content_type => "text/plain",
|
645
|
-
:type => "delete",
|
646
|
-
:reply_to => reply_queue_name, #queue for response from the rOCCI
|
647
|
-
:message_id => next_message_id, #Identifier for message so that the client can match the answer from the rOCCI
|
648
|
-
:headers => {
|
649
|
-
:accept => @media_type,
|
650
|
-
:path_info => "/#{ path }",
|
651
|
-
:auth => {
|
652
|
-
:type => "basic",
|
653
|
-
:username => "user",
|
654
|
-
:password => "mypass",
|
655
|
-
},
|
656
|
-
}
|
657
|
-
}
|
658
|
-
|
659
|
-
publish('', options)
|
660
|
-
|
661
|
-
return options[:message_id]
|
662
|
-
end
|
663
|
-
|
664
|
-
def response_value(message_id, is_wait = true, is_parse_response = true)
|
665
|
-
waiting_for_response(message_id) if is_wait || is_parse_response
|
666
|
-
|
667
|
-
if is_parse_response
|
668
|
-
value = parse_message(message_id)
|
669
|
-
else
|
670
|
-
value = message_id
|
671
|
-
end
|
672
|
-
|
673
|
-
return value
|
674
|
-
end
|
675
|
-
|
676
|
-
# @param [String] message_id '' == all
|
677
|
-
def waiting_for_response(message_id = '')
|
678
|
-
return if @response_waiting.nil?
|
679
|
-
|
680
|
-
if message_id.size > 0
|
681
|
-
while !@response_waiting[message_id].nil?
|
682
|
-
sleep(0.1)
|
683
|
-
end
|
684
|
-
else
|
685
|
-
while size(@response_waiting) > 0
|
686
|
-
sleep(0.1)
|
687
|
-
end
|
688
|
-
end
|
689
|
-
end
|
690
|
-
|
691
|
-
def publish(message, options = {})
|
692
|
-
raise "No Message Id found" if options[:message_id] == nil?
|
693
|
-
|
694
|
-
@exchange.publish(message, options)
|
695
|
-
|
696
|
-
@response_waiting = Hash.new if @response_waiting.nil?
|
697
|
-
@response_waiting[options[:message_id]] = {:options => options, :message => message}
|
698
|
-
end
|
699
|
-
|
700
|
-
def reply_queue_name
|
701
|
-
@replies_queue.name
|
702
|
-
end
|
703
|
-
|
704
|
-
def next_message_id
|
705
|
-
@message_id = 0 if @message_id.nil?
|
706
|
-
@message_id += 1
|
707
|
-
@message_id.to_s;
|
708
|
-
end
|
709
|
-
|
710
|
-
# Sets auth method and appropriate httparty attributes. Supported auth methods
|
711
|
-
# are: ["none"] and nil
|
712
|
-
#
|
713
|
-
# @example
|
714
|
-
# change_auth { :type => "none" }
|
715
|
-
#
|
716
|
-
# @param [Hash] authentication options
|
717
|
-
def change_auth(auth_options)
|
718
|
-
@auth_options = auth_options
|
719
|
-
|
720
|
-
case @auth_options[:type]
|
721
|
-
when "none", nil
|
722
|
-
# do nothing
|
723
|
-
else
|
724
|
-
raise ArgumentError, "Unknown AUTH method [#{@auth_options[:type]}]!"
|
725
|
-
end
|
726
|
-
end
|
727
|
-
|
728
|
-
def handle_channel_exception(channel, channel_close)
|
729
|
-
Occi::Log.error "OCCI/AMQP: Channel-level exception [ code = #{channel_close.reply_code}, message = #{channel_close.reply_text} ]"
|
730
|
-
end
|
731
|
-
|
732
|
-
# Sets the logger and log levels. This allows users to pass existing logger
|
733
|
-
# instances to the rOCCI client.
|
734
|
-
#
|
735
|
-
# @example
|
736
|
-
# set_logger { :out => STDERR, :level => Occi::Log::WARN, :logger => nil }
|
737
|
-
#
|
738
|
-
# @param [Hash] logger options
|
739
|
-
def set_logger(log_options)
|
740
|
-
if log_options[:logger].nil? or (not log_options[:logger].kind_of? Occi::Log)
|
741
|
-
logger = Occi::Log.new(log_options[:out])
|
742
|
-
logger.level = log_options[:level]
|
743
|
-
end
|
744
|
-
|
745
|
-
self.class.debug_output $stderr if log_options[:level] == Occi::Log::DEBUG
|
746
|
-
end
|
747
|
-
|
748
|
-
# Checks whether the given endpoint URI is valid and adds a trailing
|
749
|
-
# slash if necessary.
|
750
|
-
#
|
751
|
-
# @example
|
752
|
-
# prepare_endpoint "http://localhost:3300" # => "http://localhost:3300/"
|
753
|
-
#
|
754
|
-
# @param [String] endpoint URI in a non-canonical string
|
755
|
-
# @return [String] canonical endpoint URI in a string, with a trailing slash
|
756
|
-
def prepare_endpoint(endpoint)
|
757
|
-
raise 'Endpoint not a valid URI' if (endpoint =~ URI::ABS_URI).nil?
|
758
|
-
|
759
|
-
@endpoint = endpoint.chomp('/') + '/'
|
760
|
-
@endpoint_queue = "amqp.occi.#{@endpoint}"
|
761
|
-
end
|
762
|
-
|
763
|
-
end
|
764
|
-
|
765
|
-
end
|
766
|
-
end
|
767
|
-
end
|