occi 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ module OCCI
6
6
  module Core
7
7
  class Category
8
8
 
9
- attr_accessor :scheme, :term, :title, :attributes
9
+ attr_accessor :model, :scheme, :term, :title, :attributes
10
10
 
11
11
  # @param [String ] scheme
12
12
  # @param [String] term
@@ -34,9 +34,9 @@ module OCCI
34
34
  # check if category is related to another category
35
35
  # @param [String] category_id Type identifier of a related category
36
36
  # @return [true,false] true if category is related to category_id else false
37
- def related_to?(category_id, model)
37
+ def related_to?(category_id)
38
38
  self.related.each do |rel_id|
39
- return true if rel_id == category_id || model.get_by_id(rel_id).related_to?(category_id, model)
39
+ return true if rel_id == category_id || @model.get_by_id(rel_id).related_to?(category_id)
40
40
  end if self.class.method_defined? 'related'
41
41
  false
42
42
  end
@@ -30,7 +30,8 @@ module OCCI
30
30
  when "http://schemas.ogf.org/occi/core#link"
31
31
  return OCCI::Core::Link.name
32
32
  else
33
- OCCI::Model.get_by_id(self[:related].first).entity_type unless self[:term] == 'entity'
33
+ raise "no model back reference provided for kind #{self.typ_identifier}" unless @model
34
+ @model.get_by_id(self[:related].first).entity_type unless self[:term] == 'entity'
34
35
  end
35
36
  end
36
37
 
@@ -10,11 +10,11 @@ module OCCI
10
10
  attr_accessor :links
11
11
 
12
12
  def initialize(kind, mixins=nil, attributes=nil, links=nil)
13
- @href = nil
14
13
  @links = links.to_a
15
14
  super(kind, mixins, attributes)
16
15
  end
17
16
 
17
+ # @return [OCCI::Core::Kind] kind definition of Resource type
18
18
  def self.kind_definition
19
19
  kind = OCCI::Core::Kind.new('http://schemas.ogf.org/occi/core#', 'resource')
20
20
 
data/lib/occi/model.rb CHANGED
@@ -58,6 +58,8 @@ module OCCI
58
58
  OCCI::Log.debug "### Registering category #{category.type_identifier}"
59
59
  @categories[category.type_identifier] = category
60
60
  @locations[category.location] = category.type_identifier unless category.kind_of? OCCI::Core::Action
61
+ # add model to category as back reference
62
+ category.model = self
61
63
  end
62
64
 
63
65
  # ---------------------------------------------------------------------------------------------------------------------
@@ -99,7 +101,7 @@ module OCCI
99
101
  OCCI::Log.debug("### Filtering categories #{categories.collect { |c| c.type_identifier }.inspect}")
100
102
  while categories.any? do
101
103
  category = categories.pop
102
- categories.concat @categories.each_value.select { |cat| cat.related_to?(category.type_identifier, self) }
104
+ categories.concat @categories.each_value.select { |cat| cat.related_to?(category.type_identifier) }
103
105
  collection.kinds << get_by_id(category.type_identifier) if category.kind_of? OCCI::Core::Kind
104
106
  collection.mixins << get_by_id(category.type_identifier) if category.kind_of? OCCI::Core::Mixin
105
107
  collection.actions << get_by_id(category.type_identifier) if category.kind_of? OCCI::Core::Action
data/lib/occi/parser.rb CHANGED
@@ -87,11 +87,11 @@ module OCCI
87
87
  if entity_type == OCCI::Core::Link
88
88
  entity.target = link.attributes!.occi!.core!.target
89
89
  entity.source = link.attributes!.occi!.core!.source
90
- collection.links << OCCI::Core::Link.new(entity)
90
+ collection.links << OCCI::Core::Link.new(entity.kind,entity.mixins,entity.attributes)
91
91
  elsif entity_type == OCCI::Core::Resource
92
92
  link_strings = header['HTTP_LINK'].to_s.split(',')
93
93
  link_strings.each { |link| entity.links << OCCIANTLR::Parser.new('Link: ' + link).link }
94
- collection.resources << OCCI::Core::Resource.new(entity)
94
+ collection.resources << OCCI::Core::Resource.new(entity.kind,entity.mixins,entity.attributes,entity.links)
95
95
  end
96
96
  collection
97
97
  end
@@ -127,10 +127,10 @@ module OCCI
127
127
  if entity_type == OCCI::Core::Link
128
128
  entity.target = links.first.attributes!.occi!.core!.target
129
129
  entity.source = links.first.attributes!.occi!.core!.source
130
- collection.links << OCCI::Core::Link.new(entity)
130
+ collection.links << OCCI::Core::Link.new(entity.kind,entity.mixins,entity.attributes)
131
131
  elsif entity_type == OCCI::Core::Resource
132
132
  entity.links = links
133
- collection.resources << OCCI::Core::Resource.new(entity)
133
+ collection.resources << OCCI::Core::Resource.new(entity.kind,entity.mixins,entity.attributes,entity.links)
134
134
  end unless entity.kind.nil?
135
135
  collection
136
136
  end
@@ -216,7 +216,7 @@ module OCCI
216
216
  if href.relative?
217
217
  references[file.attributes['id'].to_s] = 'file://' + files[href.to_s] if files[href.to_s]
218
218
  else
219
- references[file.attributes['id'].to_s] = href
219
+ references[file.attributes['id'].to_s] = href.to_s
220
220
  end
221
221
  end
222
222
 
data/lib/occi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OCCI
2
- VERSION = "2.3.0" unless defined?(::OCCI::VERSION)
2
+ VERSION = "2.3.1" unless defined?(::OCCI::VERSION)
3
3
  end
@@ -4,16 +4,53 @@ require 'occi/parser'
4
4
  describe "Parser" do
5
5
 
6
6
  it "should parse OCCI message with entity in text plain format" do
7
- media_type = 'text/plain'
8
- body = %Q|Category: compute; scheme="http://schemas.ogf.org/occi/infrastructure#"; class="kind"\nX-OCCI-Attribute: occi.compute.cores=2|
9
- locations, collection = OCCI::Parser.parse(media_type, body)
7
+ media_type = 'text/plain'
8
+ body = %Q|Category: compute; scheme="http://schemas.ogf.org/occi/infrastructure#"; class="kind"\nX-OCCI-Attribute: occi.compute.cores=2|
9
+ _, collection = OCCI::Parser.parse(media_type, body)
10
+ collection.should be_kind_of OCCI::Collection
11
+ jj collection
12
+ compute_resources = collection.resources.select { |resource| resource.kind =='http://schemas.ogf.org/occi/infrastructure#compute' }
13
+ compute_resources.should have(1).compute_resource
14
+ compute_resources.first.attributes.occi!.compute!.cores.should == 2
15
+ end
16
+
17
+ it "should parse OCCI message with entity in JSON format" do
18
+ media_type = 'application/occi+json'
19
+ body = File.read('spec/occi/test.json')
20
+ _, collection = OCCI::Parser.parse(media_type, body)
21
+ storage_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#storage' }
22
+ storage_resources.should have(1).storage_resource
23
+ storage_resources.first.attributes.occi!.core!.title.should == 'lamp'
24
+ network_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#network' }
25
+ network_resources.should have(1).network_resource
26
+ network_resources.first.attributes.occi!.core!.title.should == 'VM Network'
27
+ compute_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#compute' }
28
+ compute_resources.should have(1).compute_resource
29
+ compute_resources.first.attributes.occi!.compute!.cores.should == 1
30
+ compute_resources.first.attributes.occi!.compute!.memory.should == 256
31
+ end
32
+
33
+ it "should parse an OVF file" do
34
+ media_type = 'application/ovf+xml'
35
+ body = File.read('spec/occi/test.ovf')
36
+ _, collection = OCCI::Parser.parse(media_type, body)
37
+ storage_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#storage' }
38
+ storage_resources.should have(1).storage_resource
39
+ storage_resources.first.attributes.occi!.core!.title.should == 'lamp'
40
+ network_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#network' }
41
+ network_resources.should have(1).network_resource
42
+ network_resources.first.attributes.occi!.core!.title.should == 'VM Network'
43
+ compute_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#compute' }
44
+ compute_resources.should have(1).compute_resource
45
+ compute_resources.first.attributes.occi!.compute!.cores.should == 1
46
+ compute_resources.first.attributes.occi!.compute!.memory.should == 256
10
47
  end
11
48
 
12
49
  it "should parse an OVA container" do
13
- media_type = 'application/ova'
14
- body = File.read('spec/occi/test.ova')
50
+ media_type = 'application/ova'
51
+ body = File.read('spec/occi/test.ova')
15
52
  locations, collection = OCCI::Parser.parse(media_type, body)
16
- storage_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#storage' }
53
+ storage_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#storage' }
17
54
  storage_resources.should have(1).storage_resource
18
55
  storage_resources.first.attributes.occi!.core!.title.should == 'lamp'
19
56
  network_resources = collection.resources.select { |resource| resource.kind == 'http://schemas.ogf.org/occi/infrastructure#network' }
@@ -0,0 +1,69 @@
1
+ {
2
+ "resources": [
3
+ {
4
+ "links": [
5
+ {
6
+ "kind": "http://schemas.ogf.org/occi/infrastructure#storagelink",
7
+ "attributes": {
8
+ "occi": {
9
+ "core": {
10
+ "id": "34cb5bce-d31a-11e1-a11a-a4b197fffef3",
11
+ "title": "lamp",
12
+ "target": "http://example.com/lamp.vmdk"
13
+ }
14
+ }
15
+ }
16
+ }
17
+ ],
18
+ "kind": "http://schemas.ogf.org/occi/infrastructure#storage",
19
+ "attributes": {
20
+ "occi": {
21
+ "core": {
22
+ "id": "34c88188-d31a-11e1-a11a-a4b197fffef3",
23
+ "title": "lamp"
24
+ }
25
+ }
26
+ }
27
+ },
28
+ {
29
+ "kind": "http://schemas.ogf.org/occi/infrastructure#network",
30
+ "attributes": {
31
+ "occi": {
32
+ "core": {
33
+ "id": "34cb6830-d31a-11e1-a11a-a4b197fffef3",
34
+ "title": "VM Network"
35
+ }
36
+ }
37
+ }
38
+ },
39
+ {
40
+ "links": [
41
+ {
42
+ "kind": "http://schemas.ogf.org/occi/infrastructure#storagelink",
43
+ "attributes": {
44
+ "occi": {
45
+ "core": {
46
+ "id": "34cbb948-d31a-11e1-a11a-a4b197fffef3",
47
+ "title": "Harddisk 1",
48
+ "target": "/storage/34c88188-d31a-11e1-a11a-a4b197fffef3"
49
+ }
50
+ }
51
+ }
52
+ }
53
+ ],
54
+ "kind": "http://schemas.ogf.org/occi/infrastructure#compute",
55
+ "attributes": {
56
+ "occi": {
57
+ "core": {
58
+ "id": "34cb6f60-d31a-11e1-a11a-a4b197fffef3",
59
+ "summary": ""
60
+ },
61
+ "compute": {
62
+ "cores": 1,
63
+ "memory": 256
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ]
69
+ }
@@ -0,0 +1,198 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
4
+ xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
5
+ xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
6
+ xmlns="http://schemas.dmtf.org/ovf/envelope/1"
7
+ xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 ../dsp8023.xsd">
8
+
9
+ <!-- This example reference a local schema file, to validate against online schema use:
10
+ xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.0.0.xsd"
11
+ -->
12
+
13
+ <!-- References to all external files -->
14
+ <References>
15
+ <File ovf:id="lamp" ovf:href="http://example.com/lamp.vmdk" ovf:size="180114671"/>
16
+ </References>
17
+ <!-- Describes meta-information about all virtual disks in the package -->
18
+ <DiskSection>
19
+ <Info>List of the virtual disks used in the package</Info>
20
+ <Disk ovf:diskId="lamp" ovf:fileRef="lamp" ovf:capacity="4294967296"
21
+ ovf:populatedSize="1924967692"
22
+ ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized"/>
23
+ </DiskSection>
24
+ <!-- Describes all networks used in the package -->
25
+ <NetworkSection>
26
+ <Info>Logical networks used in the package</Info>
27
+ <Network ovf:name="VM Network">
28
+ <Description>The network that the LAMP Service will be available
29
+ on</Description>
30
+ </Network>
31
+ </NetworkSection>
32
+ <VirtualSystem ovf:id="MyLampService">
33
+ <Info>Single-VM Virtual appliance with LAMP stack</Info>
34
+ <Name>LAMP Virtual Appliance</Name>
35
+ <!-- Overall information about the product -->
36
+ <ProductSection>
37
+ <Info>Product information for the service</Info>
38
+ <Product>Lamp Service</Product>
39
+ <Version>1.0</Version>
40
+ <FullVersion>1.0.0</FullVersion>
41
+ </ProductSection>
42
+ <!-- Linux component configuration parameters -->
43
+ <ProductSection ovf:class="org.linuxdist.x">
44
+ <Info>Product customization for the installed Linux system</Info>
45
+ <Product>Linux Distribution X</Product>
46
+ <Version>2.6.3</Version>
47
+ <Property ovf:key="hostname" ovf:type="string">
48
+ <Description>Specifies the hostname for the appliance</Description>
49
+ </Property>
50
+ <Property ovf:key="ip" ovf:type="string">
51
+ <Description>Specifies the IP address for the appliance</Description>
52
+ </Property>
53
+ <Property ovf:key="subnet" ovf:type="string">
54
+ <Description> Specifies the subnet to use on the deployed network
55
+ </Description>
56
+ </Property>
57
+ <Property ovf:key="gateway" ovf:type="string">
58
+ <Description> Specifies the gateway on the deployed network
59
+ </Description>
60
+ </Property>
61
+ <Property ovf:key="dns" ovf:type="string">
62
+ <Description> A comma separated list of DNS servers on the deployed
63
+ network </Description>
64
+ </Property>
65
+ <Property ovf:key="netCoreRmemMaxMB" ovf:type="uint16" ovf:value="16"
66
+ ovf:userConfigurable="true">
67
+ <Description> Specify TCP read max buffer size in mega bytes. Default is
68
+ 16. </Description>
69
+ </Property>
70
+ <Property ovf:key="netCoreWmemMaxMB" ovf:type="uint16" ovf:value="16"
71
+ ovf:userConfigurable="true">
72
+ <Description> Specify TCP write max buffer size in mega bytes. Default is
73
+ 16. </Description>
74
+ </Property>
75
+ </ProductSection>
76
+ <!-- Apache component configuration parameters -->
77
+ <ProductSection ovf:class="org.apache.httpd">
78
+ <Info>Product customization for the installed Apache Web Server</Info>
79
+ <Product>Apache Distribution Y</Product>
80
+ <Version>2.6.6</Version>
81
+ <Property ovf:key="httpPort" ovf:type="uint16" ovf:value="80"
82
+ ovf:userConfigurable="true">
83
+ <Description>Port number for HTTP requests</Description>
84
+ </Property>
85
+ <Property ovf:key="httpsPort" ovf:type="uint16" ovf:value="443"
86
+ ovf:userConfigurable="true">
87
+ <Description>Port number for HTTPS requests</Description>
88
+ </Property>
89
+ <Property ovf:key="startThreads" ovf:type="uint16" ovf:value="50"
90
+ ovf:userConfigurable="true">
91
+ <Description>Number of threads created on startup. </Description>
92
+ </Property>
93
+ <Property ovf:key="minSpareThreads" ovf:type="uint16" ovf:value="15"
94
+ ovf:userConfigurable="true">
95
+ <Description> Minimum number of idle threads to handle request spikes.
96
+ </Description>
97
+ </Property>
98
+ <Property ovf:key="maxSpareThreads" ovf:type="uint16" ovf:value="30"
99
+ ovf:userConfigurable="true">
100
+ <Description>Maximum number of idle threads </Description>
101
+ </Property>
102
+ <Property ovf:key="maxClients" ovf:type="uint16" ovf:value="256"
103
+ ovf:userConfigurable="true">
104
+ <Description>Limit the number of simultaneous requests that will be
105
+ served. </Description>
106
+ </Property>
107
+ </ProductSection>
108
+ <!-- MySQL component configuration parameters -->
109
+ <ProductSection ovf:class="org.mysql.db">
110
+ <Info>Product customization for the installed MySql Database Server</Info>
111
+ <Product>MySQL Distribution Z</Product>
112
+ <Version>5.0</Version>
113
+ <Property ovf:key="queryCacheSizeMB" ovf:type="uint16" ovf:value="32"
114
+ ovf:userConfigurable="true">
115
+ <Description>Buffer to cache repeated queries for faster access (in
116
+ MB)</Description>
117
+ </Property>
118
+ <Property ovf:key="maxConnections" ovf:type="uint16" ovf:value="500"
119
+ ovf:userConfigurable="true">
120
+ <Description>The number of concurrent connections that can be
121
+ served</Description>
122
+ </Property>
123
+ <Property ovf:key="waitTimeout" ovf:type="uint16" ovf:value="100"
124
+ ovf:userConfigurable="true">
125
+ <Description>Number of seconds to wait before timing out a connection
126
+ </Description>
127
+ </Property>
128
+ </ProductSection>
129
+ <!-- PHP component configuration parameters -->
130
+ <ProductSection ovf:class="net.php">
131
+ <Info>Product customization for the installed PHP component</Info>
132
+ <Product>PHP Distribution U</Product>
133
+ <Version>5.0</Version>
134
+ <Property ovf:key="sessionTimeout" ovf:type="uint16" ovf:value="5"
135
+ ovf:userConfigurable="true">
136
+ <Description> How many minutes a session has to be idle before it is
137
+ timed out </Description>
138
+ </Property>
139
+ <Property ovf:key="concurrentSessions" ovf:type="uint16" ovf:value="500"
140
+ ovf:userConfigurable="true">
141
+ <Description> The number of concurrent sessions that can be served
142
+ </Description>
143
+ </Property>
144
+ <Property ovf:key="memoryLimit" ovf:type="uint16" ovf:value="32"
145
+ ovf:userConfigurable="true">
146
+ <Description> How much memory in megabytes a script can consume before
147
+ being killed </Description>
148
+ </Property>
149
+ </ProductSection>
150
+ <OperatingSystemSection ovf:id="36">
151
+ <Info>Guest Operating System</Info>
152
+ <Description>Linux 2.6.x</Description>
153
+ </OperatingSystemSection>
154
+ <VirtualHardwareSection>
155
+ <Info>Virtual Hardware Requirements: 256MB, 1 CPU, 1 disk, 1 NIC</Info>
156
+ <System>
157
+ <vssd:ElementName>Virtual Hardware Family</vssd:ElementName>
158
+ <vssd:InstanceID>0</vssd:InstanceID>
159
+ <vssd:VirtualSystemType>vmx-04</vssd:VirtualSystemType>
160
+ </System>
161
+ <Item>
162
+ <rasd:Description>Number of virtual CPUs</rasd:Description>
163
+ <rasd:ElementName>1 virtual CPU</rasd:ElementName>
164
+ <rasd:InstanceID>1</rasd:InstanceID>
165
+ <rasd:ResourceType>3</rasd:ResourceType>
166
+ <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
167
+ </Item>
168
+ <Item>
169
+ <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
170
+ <rasd:Description>Memory Size</rasd:Description>
171
+ <rasd:ElementName>256 MB of memory</rasd:ElementName>
172
+ <rasd:InstanceID>2</rasd:InstanceID>
173
+ <rasd:ResourceType>4</rasd:ResourceType>
174
+ <rasd:VirtualQuantity>256</rasd:VirtualQuantity>
175
+ </Item>
176
+ <Item>
177
+ <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
178
+ <rasd:Connection>VM Network</rasd:Connection>
179
+ <rasd:ElementName>Ethernet adapter on "VM Network"</rasd:ElementName>
180
+ <rasd:InstanceID>3</rasd:InstanceID>
181
+ <rasd:ResourceType>10</rasd:ResourceType>
182
+ </Item>
183
+ <Item>
184
+ <rasd:ElementName>SCSI Controller 0 - LSI Logic</rasd:ElementName>
185
+ <rasd:InstanceID>4</rasd:InstanceID>
186
+ <rasd:ResourceSubType>LsiLogic</rasd:ResourceSubType>
187
+ <rasd:ResourceType>6</rasd:ResourceType>
188
+ </Item>
189
+ <Item>
190
+ <rasd:ElementName>Harddisk 1</rasd:ElementName>
191
+ <rasd:HostResource>ovf:/disk/lamp</rasd:HostResource>
192
+ <rasd:InstanceID>5</rasd:InstanceID>
193
+ <rasd:Parent>4</rasd:Parent>
194
+ <rasd:ResourceType>17</rasd:ResourceType>
195
+ </Item>
196
+ </VirtualHardwareSection>
197
+ </VirtualSystem>
198
+ </Envelope>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-19 00:00:00.000000000 Z
13
+ date: 2012-07-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -180,7 +180,9 @@ files:
180
180
  - spec/occi/log_spec.rb
181
181
  - spec/occi/model_spec.rb
182
182
  - spec/occi/parser_spec.rb
183
+ - spec/occi/test.json
183
184
  - spec/occi/test.ova
185
+ - spec/occi/test.ovf
184
186
  - spec/occiantlr/parser_spec.rb
185
187
  - spec/spec_helper.rb
186
188
  homepage: https://github.com/gwdg/occi
@@ -213,7 +215,9 @@ test_files:
213
215
  - spec/occi/log_spec.rb
214
216
  - spec/occi/model_spec.rb
215
217
  - spec/occi/parser_spec.rb
218
+ - spec/occi/test.json
216
219
  - spec/occi/test.ova
220
+ - spec/occi/test.ovf
217
221
  - spec/occiantlr/parser_spec.rb
218
222
  - spec/spec_helper.rb
219
223
  has_rdoc: