occi 2.5.19 → 3.0.0.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.travis.yml +3 -1
- data/AUTHORS +4 -3
- data/Gemfile +9 -0
- data/Gemfile.lock +64 -21
- data/README.md +19 -14
- data/Rakefile +12 -8
- data/Test Results - discovery_interface.html +862 -0
- data/bin/occi +333 -83
- data/examples/dsl_example.rb +6 -6
- data/examples/x509auth_example.rb +6 -6
- data/features/common/step_definitions/common_steps.rb +32 -0
- data/features/occi/core/create/create.feature +17 -0
- data/features/occi/core/create/step_definitions/create_steps.rb +0 -0
- data/features/occi/core/delete/delete.feature +14 -0
- data/features/occi/core/delete/step_definitions/delete_steps.rb +0 -0
- data/features/occi/core/discovery_interface/discovery_interface.feature +35 -0
- data/features/occi/core/discovery_interface/step_definitions/discovery_interface_steps.rb +19 -0
- data/features/occi/core/miscellaneous/miscellaneous.feature +14 -0
- data/features/occi/core/miscellaneous/step_definitions/miscellaneous_steps.rb +0 -0
- data/features/occi/core/read/read.feature +14 -0
- 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 +14 -0
- data/features/occi/infrastructure/create/create.feature +14 -0
- data/features/occi/infrastructure/create/step_definitions/create_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/lib/occi.rb +29 -3
- data/lib/occi/api/client/client_amqp.rb +756 -0
- data/lib/occi/api/client/client_http.rb +922 -0
- data/lib/occi/api/client/http/httparty_fix.rb +53 -0
- data/lib/occi/api/client/http/net_http_fix.rb +46 -0
- data/lib/occi/api/dsl.rb +77 -73
- data/lib/occi/bin/helpers.rb +91 -0
- data/lib/occi/bin/occi_opts.rb +251 -0
- data/lib/occi/bin/resource_output_factory.rb +90 -0
- data/lib/occi/bin/templates/compute.erb +15 -0
- data/lib/occi/bin/templates/network.erb +11 -0
- data/lib/occi/bin/templates/os_tpl.erb +9 -0
- data/lib/occi/bin/templates/resource_tpl.erb +9 -0
- data/lib/occi/bin/templates/storage.erb +10 -0
- data/lib/occi/collection.rb +122 -25
- data/lib/occi/core.rb +18 -9
- data/lib/occi/core/action.rb +20 -4
- data/lib/occi/core/action_instance.rb +24 -0
- data/lib/occi/core/actions.rb +22 -0
- data/lib/occi/core/attribute_properties.rb +33 -84
- data/lib/occi/core/attributes.rb +32 -14
- data/lib/occi/core/categories.rb +46 -0
- data/lib/occi/core/category.rb +94 -20
- data/lib/occi/core/entities.rb +50 -0
- data/lib/occi/core/entity.rb +130 -89
- data/lib/occi/core/kind.rb +28 -35
- data/lib/occi/core/kinds.rb +22 -0
- data/lib/occi/core/link.rb +43 -40
- data/lib/occi/core/links.rb +34 -0
- data/lib/occi/core/mixin.rb +28 -23
- data/lib/occi/core/mixins.rb +22 -0
- data/lib/occi/core/related.rb +20 -0
- data/lib/occi/core/resource.rb +40 -40
- data/lib/occi/core/resources.rb +14 -0
- data/lib/occi/infrastructure.rb +27 -0
- data/lib/occi/infrastructure/compute.rb +159 -0
- data/lib/occi/infrastructure/network.rb +131 -0
- data/lib/occi/infrastructure/network/ipnetwork.rb +34 -0
- data/lib/occi/infrastructure/networkinterface.rb +124 -0
- data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +34 -0
- data/lib/occi/infrastructure/os_tpl.rb +19 -0
- data/lib/occi/infrastructure/resource_tpl.rb +19 -0
- data/lib/occi/infrastructure/storage.rb +96 -0
- data/lib/occi/infrastructure/storagelink.rb +73 -0
- data/lib/occi/log.rb +6 -2
- data/lib/occi/model.rb +38 -70
- data/lib/occi/parser.rb +108 -88
- data/lib/occi/version.rb +2 -2
- data/lib/occiantlr/OCCIANTLR.g +6 -5
- data/lib/occiantlr/OCCIANTLRLexer.rb +52 -52
- data/lib/occiantlr/OCCIANTLRParser.rb +678 -569
- data/lib/occiantlr/README.md +1 -1
- data/occi.gemspec +2 -1
- data/spec/cassettes/client_http_text_plain.yml +1066 -0
- data/spec/occi/api/client/client_amqp_spec.rb +148 -0
- data/spec/occi/api/client/client_http_0.5_spec.rb +292 -0
- data/spec/occi/api/client/client_http_spec.rb +259 -0
- data/spec/occi/api/dsl_spec.rb +0 -0
- data/spec/occi/collection_spec.rb +23 -10
- data/spec/occi/core/categories_spec.rb +30 -0
- data/spec/occi/core/category_spec.rb +41 -0
- data/spec/occi/core/entity_spec.rb +52 -0
- data/spec/occi/core/resource_spec.rb +21 -0
- data/spec/occi/infrastructure/compute_spec.rb +32 -0
- data/spec/occi/log_spec.rb +10 -10
- data/spec/occi/model_spec.rb +24 -24
- data/spec/occi/parser_spec.rb +89 -39
- data/spec/occi/test.json +22 -58
- data/spec/occiantlr/parser_spec.rb +5 -7
- data/spec/spec_helper.rb +13 -3
- metadata +116 -19
- data/etc/model/infrastructure/compute.json +0 -108
- data/etc/model/infrastructure/ipnetwork.json +0 -40
- data/etc/model/infrastructure/ipnetworkinterface.json +0 -40
- data/etc/model/infrastructure/network.json +0 -55
- data/etc/model/infrastructure/networkinterface.json +0 -38
- data/etc/model/infrastructure/os_template.json +0 -9
- data/etc/model/infrastructure/resource_template.json +0 -9
- data/etc/model/infrastructure/storage.json +0 -72
- data/etc/model/infrastructure/storagelink.json +0 -38
- data/lib/occi/api/client.rb +0 -596
- data/lib/occi/client/occiopts.rb +0 -146
- data/spec/occi/client_spec.rb +0 -12
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Occi
|
5
|
+
module Bin
|
6
|
+
|
7
|
+
class ResourceOutputFactory
|
8
|
+
|
9
|
+
@@allowed_formats = [:json, :plain].freeze
|
10
|
+
@@allowed_resource_types = [:compute, :storage, :network, :os_tpl, :resource_tpl].freeze
|
11
|
+
@@allowed_data_types = [:locations, :resources].freeze
|
12
|
+
|
13
|
+
attr_reader :output_format
|
14
|
+
|
15
|
+
def initialize(output_format = :plain)
|
16
|
+
raise "Unsupported output format!" unless @@allowed_formats.include? output_format
|
17
|
+
@output_format = output_format
|
18
|
+
end
|
19
|
+
|
20
|
+
def format(data, data_type, resource_type)
|
21
|
+
raise "Data has to be in an array!" unless data.is_a? Array
|
22
|
+
raise "Unsupported resource type! Got: #{resource_type.to_s}" unless @@allowed_resource_types.include? resource_type
|
23
|
+
raise "Unsupported data type! Got: #{data_type.to_s}" unless @@allowed_data_types.include? data_type
|
24
|
+
|
25
|
+
# validate incoming data
|
26
|
+
if data_type == :resources
|
27
|
+
data.each do |occi_collection|
|
28
|
+
raise "I need the resources to be in a Collection!" unless occi_collection.respond_to? :as_json
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# construct method name from data type and output format
|
33
|
+
method = (data_type.to_s + "_to_" + output_format.to_s).to_sym
|
34
|
+
|
35
|
+
ResourceOutputFactory.send method, data, resource_type
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.allowed_formats
|
39
|
+
@@allowed_formats
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.allowed_resource_types
|
43
|
+
@@allowed_resource_types
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.allowed_data_types
|
47
|
+
@@allowed_data_types
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.resources_to_json(occi_resources, resource_type)
|
51
|
+
# generate JSON document from an array of JSON objects
|
52
|
+
JSON.generate occi_resources
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.resources_to_plain(occi_resources, resource_type)
|
56
|
+
# using ERB templates for known resource and mixin types
|
57
|
+
file = File.expand_path("..", __FILE__) + '/templates/' + resource_type.to_s + ".erb"
|
58
|
+
template = ERB.new File.new(file).read
|
59
|
+
|
60
|
+
template.result(binding)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.locations_to_json(url_locations, resource_type)
|
64
|
+
# give all locatios a common key and convert to JSON
|
65
|
+
locations = { resource_type => [] }
|
66
|
+
|
67
|
+
url_locations.each do |location|
|
68
|
+
location = location.split("/").last if [:os_tpl, :resource_tpl].include? resource_type
|
69
|
+
locations[resource_type] << location
|
70
|
+
end
|
71
|
+
|
72
|
+
locations.to_json
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.locations_to_plain(url_locations, resource_type)
|
76
|
+
# just an attempt to make the array more readable
|
77
|
+
output = "\n" + resource_type.to_s.capitalize + " locations:\n"
|
78
|
+
|
79
|
+
url_locations.each do |location|
|
80
|
+
location = location.split("/").last if [:os_tpl, :resource_tpl].include? resource_type
|
81
|
+
output << "\t" << location << "\n"
|
82
|
+
end
|
83
|
+
|
84
|
+
output
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%# We always get an array of OCCI::Collections %>
|
2
|
+
Available COMPUTE resources:
|
3
|
+
<% occi_resources.each do |occi_compute| %>
|
4
|
+
<% compute = occi_compute.as_json %>
|
5
|
+
COMPUTE resource "<%= compute.resources.first.attributes.occi.core.title %>":
|
6
|
+
ID: <%= compute.resources.first.attributes.occi.core.id %>
|
7
|
+
TITLE: <%= compute.resources.first.attributes.occi.core.title %>
|
8
|
+
STATE: <%= compute.resources.first.attributes.occi.compute.state %>
|
9
|
+
LINKS:
|
10
|
+
<% if compute.links %><% compute.links.each do |link| %>
|
11
|
+
LINK "<%= link.attributes.occi.core.target.split("/")[1] %>":
|
12
|
+
ID: <%= link.attributes.occi.core.id %>
|
13
|
+
TARGET: <%= link.attributes.occi.core.target %>
|
14
|
+
<% end %><% end %>
|
15
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# We always get an array of OCCI::Collections %>
|
2
|
+
Available NETWORK resources:
|
3
|
+
<% occi_resources.each do |occi_network| %>
|
4
|
+
<% network = occi_network.as_json %>
|
5
|
+
NETWORK resource "<%= network.resources.first.attributes.occi.core.title %>":
|
6
|
+
ID: <%= network.resources.first.attributes.occi.core.id %>
|
7
|
+
TITLE: <%= network.resources.first.attributes.occi.core.title %>
|
8
|
+
STATE: <%= network.resources.first.attributes.occi.network.state %>
|
9
|
+
ALLOCATION: <%= network.resources.first.attributes.occi.network.allocation %>
|
10
|
+
ADDRESS: <%= network.resources.first.attributes.occi.network.address %>
|
11
|
+
<% end %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%# We always get an array of OCCI::Collections %>
|
2
|
+
Available OS templates:
|
3
|
+
<% occi_resources.each do |occi_os_tpl| %>
|
4
|
+
<% os_tpl = occi_os_tpl.as_json %>
|
5
|
+
OS template "os_tpl#<%= os_tpl.term %>":
|
6
|
+
TITLE: <%= os_tpl.title %>
|
7
|
+
TERM: <%= os_tpl.term %>
|
8
|
+
LOCATION: <%= os_tpl.location %>
|
9
|
+
<% end %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%# We always get an array of OCCI::Collections %>
|
2
|
+
Available RESOURCE templates:
|
3
|
+
<% occi_resources.each do |occi_res_tpl| %>
|
4
|
+
<% res_tpl = occi_res_tpl.as_json %>
|
5
|
+
RESOURCE template "resource_tpl#<%= res_tpl.term %>":
|
6
|
+
TITLE: <%= res_tpl.title %>
|
7
|
+
TERM: <%= res_tpl.term %>
|
8
|
+
LOCATION: <%= res_tpl.location %>
|
9
|
+
<% end %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%# We always get an array of OCCI::Collections %>
|
2
|
+
Available STORAGE resources:
|
3
|
+
<% occi_resources.each do |occi_storage| %>
|
4
|
+
<% storage = occi_storage.as_json %>
|
5
|
+
STORAGE resource "<%= storage.resources.first.attributes.occi.core.title %>":
|
6
|
+
ID: <%= storage.resources.first.attributes.occi.core.id %>
|
7
|
+
TITLE: <%= storage.resources.first.attributes.occi.core.title %>
|
8
|
+
STATE: <%= storage.resources.first.attributes.occi.storage.state%>
|
9
|
+
DESCRIPTION: <%= storage.resources.first.attributes.occi.core.summary %>
|
10
|
+
<% end %>
|
data/lib/occi/collection.rb
CHANGED
@@ -1,26 +1,32 @@
|
|
1
|
-
module
|
1
|
+
module Occi
|
2
2
|
class Collection
|
3
|
-
|
4
|
-
attr_accessor :mixins
|
5
|
-
attr_accessor :actions
|
6
|
-
attr_accessor :resources
|
7
|
-
attr_accessor :links
|
3
|
+
|
4
|
+
attr_accessor :kinds, :mixins, :actions, :resources, :links, :action, :model
|
8
5
|
|
9
6
|
# Initialize a new OCCI Collection by initializing all supplied OCCI objects
|
10
7
|
#
|
11
8
|
# @param [Hash] collection including one or more of the keys kinds, mixins, actions, resources, links
|
12
|
-
def initialize(collection={ })
|
13
|
-
collection = Hashie::Mash.new(collection)
|
14
|
-
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@
|
9
|
+
def initialize(collection={ }, model = Occi::Model.new)
|
10
|
+
collection = Hashie::Mash.new(collection) unless collection.kind_of? Occi::Collection
|
11
|
+
|
12
|
+
@kinds = Occi::Core::Kinds.new
|
13
|
+
@mixins = Occi::Core::Mixins.new
|
14
|
+
@actions = Occi::Core::Actions.new
|
15
|
+
@resources = Occi::Core::Resources.new
|
16
|
+
@links = Occi::Core::Links.new
|
17
|
+
|
18
|
+
self.model = model if model
|
19
|
+
|
20
|
+
@kinds.merge collection.kinds.to_a.collect { |kind| Occi::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions) }
|
21
|
+
@mixins.merge collection.mixins.to_a.collect { |mixin| Occi::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.related, mixin.actions) }
|
22
|
+
@actions.merge collection.actions.to_a.collect { |action| Occi::Core::Action.new(action.scheme, action.term, action.title, action.attributes) }
|
23
|
+
@resources.merge collection.resources.to_a.collect { |resource| Occi::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.links) }
|
24
|
+
@links.merge collection.links.to_a.collect { |link| Occi::Core::Link.new(link.kind, link.mixins, link.attributes) }
|
25
|
+
@action = Occi::Core::Action_instance.new(collection.action, collection.attributes) if collection.action
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(category)
|
29
|
+
not intersect(category).empty?
|
24
30
|
end
|
25
31
|
|
26
32
|
# @return [Array] categories combined list of all kinds, mixins and actions
|
@@ -33,9 +39,87 @@ module OCCI
|
|
33
39
|
@resources + @links
|
34
40
|
end
|
35
41
|
|
42
|
+
# @param [Occi::Core::Model] model
|
43
|
+
# @return [Occi::Core::Model]
|
44
|
+
def model=(model)
|
45
|
+
@model = model
|
46
|
+
@kinds.model = model
|
47
|
+
@mixins.model = model
|
48
|
+
@actions.model = model
|
49
|
+
@resources.model = model
|
50
|
+
@links.model = model
|
51
|
+
end
|
52
|
+
|
53
|
+
def check
|
54
|
+
@resources.check
|
55
|
+
@links.check
|
56
|
+
# TODO: check action instance format, should check be applicable?
|
57
|
+
#@action.check
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param [Occi::Collection] other_collection
|
61
|
+
# @return [Occi::Collection]
|
62
|
+
def merge!(other_collection)
|
63
|
+
merge other_collection, self
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param [Occi::Collection] other_collection
|
67
|
+
# @param [Occi::Collection] collection
|
68
|
+
# @return [Occi::Collection]
|
69
|
+
def merge(other_collection, collection=self.clone)
|
70
|
+
collection.kinds.merge other_collection.kinds.select { |kind| get_by_id(kind.type_identifier).nil? }
|
71
|
+
collection.mixins.merge other_collection.mixins.select { |mixin| get_by_id(mixin.type_identifier).nil? }
|
72
|
+
collection.actions.merge other_collection.actions.select { |action| get_by_id(action.type_identifier).nil? }
|
73
|
+
collection.resources.merge other_collection.resources.select { |resource| get_by_id(resource.id).nil? }
|
74
|
+
collection.links.merge other_collection.links.select { |link| get_by_id(link.type_identifier).nil? }
|
75
|
+
collection.action = other_collection.action if other_collection.action
|
76
|
+
collection
|
77
|
+
end
|
78
|
+
|
79
|
+
# @param [Occi::Collection] other_collection
|
80
|
+
# @return [Occi::Collection]
|
81
|
+
def intersect!(other_collection)
|
82
|
+
intersect other_collection, self
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param [Occi::Collection] other_collection
|
86
|
+
# @param [Occi::Collection] collection
|
87
|
+
# @return [Occi::Collection]
|
88
|
+
def intersect(other_collection, collection=self.clone)
|
89
|
+
collection.kinds.replace other_collection.kinds.select { |kind| get_by_id(kind.type_identifier) }
|
90
|
+
collection.mixins.replace other_collection.mixins.select { |mixin| get_by_id(mixin.type_identifier) }
|
91
|
+
collection.actions.replace other_collection.actions.select { |action| get_by_id(action.type_identifier) }
|
92
|
+
collection.resources.replace other_collection.resources.select { |resource| get_by_id(resource.id) }
|
93
|
+
collection.links.replace other_collection.links.select { |link| get_by_id(link.type_identifier) }
|
94
|
+
if collection.action == other_collection.action
|
95
|
+
collection.action = other_collection.action
|
96
|
+
else
|
97
|
+
collection.action = nil
|
98
|
+
end
|
99
|
+
collection
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns the category corresponding to a given id
|
103
|
+
#
|
104
|
+
# @param [String] id
|
105
|
+
# @return [Occi::Core::Category]
|
106
|
+
def get_by_id(id)
|
107
|
+
object = self.categories.select { |category| category.type_identifier == id }
|
108
|
+
object = self.entities.select { |entity| entity.id == id } if object.empty?
|
109
|
+
object.first
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns the category corresponding to a given location
|
113
|
+
#
|
114
|
+
# @param [URI] location
|
115
|
+
# @return [Occi::Core::Category]
|
116
|
+
def get_by_location(location)
|
117
|
+
self.categories.select { |category| category.location == location }.first
|
118
|
+
end
|
119
|
+
|
36
120
|
# @return [true,false] true if collection is empty, false otherwise
|
37
121
|
def empty?
|
38
|
-
@kinds.empty? && @mixins.empty? && @actions.empty? && @resources.empty? && @links.empty?
|
122
|
+
@kinds.empty? && @mixins.empty? && @actions.empty? && @resources.empty? && @links.empty? && @action.nil?
|
39
123
|
end
|
40
124
|
|
41
125
|
# @return [Hashie::Mash] json representation
|
@@ -43,9 +127,17 @@ module OCCI
|
|
43
127
|
collection = Hashie::Mash.new
|
44
128
|
collection.kinds = @kinds.collect { |kind| kind.as_json } if @kinds.any?
|
45
129
|
collection.mixins = @mixins.collect { |mixin| mixin.as_json } if @mixins.any?
|
46
|
-
collection.actions = @actions.collect { |
|
130
|
+
collection.actions = @actions.collect { |action_category| action_category.as_json } if @actions.any?
|
47
131
|
collection.resources = @resources.collect { |resource| resource.as_json } if @resources.any?
|
48
|
-
|
132
|
+
# if there is only one resource and the links inside the resource have no location,
|
133
|
+
# then these links must be rendered as separate links inside the collection
|
134
|
+
if !collection.resources.nil? && collection.resources.size == 1
|
135
|
+
lnks = @resources.first.links if collection.resources.first.links.blank? && @links.empty?
|
136
|
+
else
|
137
|
+
lnks = @links
|
138
|
+
end
|
139
|
+
collection.links = lnks.collect { |link| link.as_json } if lnks.to_a.any?
|
140
|
+
collection.action = @action.as_json if @action
|
49
141
|
collection
|
50
142
|
end
|
51
143
|
|
@@ -54,15 +146,20 @@ module OCCI
|
|
54
146
|
text = ""
|
55
147
|
text << self.categories.collect { |category| category.to_text }.join("\n")
|
56
148
|
text << "\n" if self.categories.any?
|
57
|
-
raise "Only one
|
58
|
-
text << self.
|
149
|
+
raise "Only one resource allowed for rendering to text/plain" if self.resources.size > 1
|
150
|
+
text << self.resources.collect { |resource| resource.to_text }.join("\n")
|
151
|
+
text << self.links.collect { |link| link.to_text_link }.join("\n")
|
152
|
+
text << self.action.to_text if self.action
|
59
153
|
text
|
60
154
|
end
|
61
155
|
|
62
156
|
def to_header
|
63
157
|
header = Hashie::Mash.new
|
64
|
-
header[
|
65
|
-
|
158
|
+
header['Category'] = self.categories.collect { |category| category.to_string_short }.join(',') if self.categories.any?
|
159
|
+
raise "Only one resource allowed for rendering to text/occi" if self.resources.size > 1
|
160
|
+
header = self.resources.first.to_header if self.resources.any?
|
161
|
+
header['Link'] = self.links.collect { |link| link.to_string }.join(',') if self.links.any?
|
162
|
+
header = self.action.to_header if self.action
|
66
163
|
header
|
67
164
|
end
|
68
165
|
|
data/lib/occi/core.rb
CHANGED
@@ -1,21 +1,30 @@
|
|
1
|
+
require 'occi/core/attributes'
|
2
|
+
require 'occi/core/attribute_properties'
|
1
3
|
require 'occi/core/category'
|
4
|
+
require 'occi/core/categories'
|
5
|
+
require 'occi/core/related'
|
2
6
|
require 'occi/core/kind'
|
7
|
+
require 'occi/core/kinds'
|
3
8
|
require 'occi/core/mixin'
|
9
|
+
require 'occi/core/mixins'
|
4
10
|
require 'occi/core/action'
|
11
|
+
require 'occi/core/action_instance'
|
12
|
+
require 'occi/core/actions'
|
13
|
+
require 'occi/core/entities'
|
5
14
|
require 'occi/core/entity'
|
6
15
|
require 'occi/core/link'
|
16
|
+
require 'occi/core/links'
|
7
17
|
require 'occi/core/resource'
|
8
|
-
|
9
|
-
require 'occi/core/attributes'
|
18
|
+
require 'occi/core/resources'
|
10
19
|
|
11
|
-
module
|
20
|
+
module Occi
|
12
21
|
module Core
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
categories << OCCI::Core::Resource.kind
|
22
|
+
|
23
|
+
extend Occi
|
24
|
+
|
25
|
+
def self.kinds
|
26
|
+
Occi::Core::Kinds.new << Occi::Core::Entity.kind << Occi::Core::Link.kind << Occi::Core::Resource.kind
|
19
27
|
end
|
28
|
+
|
20
29
|
end
|
21
30
|
end
|
data/lib/occi/core/action.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module OCCI
|
1
|
+
module Occi
|
4
2
|
module Core
|
5
|
-
class Action <
|
3
|
+
class Action < Occi::Core::Category
|
4
|
+
|
5
|
+
# @param [String ] scheme
|
6
|
+
# @param [String] term
|
7
|
+
# @param [String] title
|
8
|
+
# @param [Hash] attributes
|
9
|
+
def initialize(scheme='http://schemas.ogf.org/occi/core#',
|
10
|
+
term='action',
|
11
|
+
title=nil,
|
12
|
+
attributes=Occi::Core::Attributes.new)
|
13
|
+
super scheme, term, title, attributes
|
14
|
+
end
|
6
15
|
|
7
16
|
# @return [String] text representation
|
8
17
|
def to_text
|
@@ -11,6 +20,13 @@ module OCCI
|
|
11
20
|
text
|
12
21
|
end
|
13
22
|
|
23
|
+
# @return [Hash] hash containing the HTTP headers of the text/occi rendering
|
24
|
+
def to_header
|
25
|
+
header = super
|
26
|
+
header["Category"] << ';attributes=' + @attributes.combine.join(' ').inspect if @attributes.any?
|
27
|
+
header
|
28
|
+
end
|
29
|
+
|
14
30
|
end
|
15
31
|
end
|
16
32
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
class Action_instance
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :actions
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_accessor :action, :attributes, :model
|
10
|
+
|
11
|
+
@action = Occi::Core::Action.new('http://schemas.ogf.org/occi/core#', 'action_instance')
|
12
|
+
|
13
|
+
def initialize(action = self.action, attributes={ })
|
14
|
+
if action.kind_of? String
|
15
|
+
scheme, term = action.split '#'
|
16
|
+
action = Occi::Core::Action.new(scheme, term)
|
17
|
+
end
|
18
|
+
@action = action
|
19
|
+
@attributes = attributes
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
class Actions < Occi::Core::Categories
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def convert(category)
|
8
|
+
category = super category
|
9
|
+
|
10
|
+
if category.kind_of? String
|
11
|
+
scheme, term = category.split '#'
|
12
|
+
scheme += '#'
|
13
|
+
|
14
|
+
klass = Occi::Core::Category.get_class scheme, term, [Occi::Core::Action.new]
|
15
|
+
category = klass.new(scheme, term)
|
16
|
+
end
|
17
|
+
category
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|