occi-core 4.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/.travis.yml +43 -0
- data/.yardopts +1 -0
- data/AUTHORS +9 -0
- data/Gemfile +11 -0
- data/LICENSE +13 -0
- data/README.md +212 -0
- data/Rakefile +28 -0
- data/config/occi.yml +4 -0
- data/ext/mkrf_conf.rb +35 -0
- data/lib/occi/collection.rb +192 -0
- data/lib/occi/core/action.rb +32 -0
- data/lib/occi/core/action_instance.rb +38 -0
- data/lib/occi/core/actions.rb +20 -0
- data/lib/occi/core/attribute.rb +99 -0
- data/lib/occi/core/attributes.rb +172 -0
- data/lib/occi/core/categories.rb +51 -0
- data/lib/occi/core/category.rb +153 -0
- data/lib/occi/core/entities.rb +47 -0
- data/lib/occi/core/entity.rb +264 -0
- data/lib/occi/core/kind.rb +58 -0
- data/lib/occi/core/kinds.rb +22 -0
- data/lib/occi/core/link.rb +95 -0
- data/lib/occi/core/links.rb +34 -0
- data/lib/occi/core/mixin.rb +55 -0
- data/lib/occi/core/mixins.rb +41 -0
- data/lib/occi/core/properties.rb +35 -0
- data/lib/occi/core/related.rb +7 -0
- data/lib/occi/core/resource.rb +78 -0
- data/lib/occi/core/resources.rb +14 -0
- data/lib/occi/core.rb +31 -0
- data/lib/occi/helpers/inspect.rb +12 -0
- data/lib/occi/infrastructure/compute.rb +122 -0
- data/lib/occi/infrastructure/network/ipnetwork.rb +27 -0
- data/lib/occi/infrastructure/network.rb +107 -0
- data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +27 -0
- data/lib/occi/infrastructure/networkinterface.rb +103 -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 +61 -0
- data/lib/occi/infrastructure/storagelink.rb +56 -0
- data/lib/occi/infrastructure.rb +25 -0
- data/lib/occi/log.rb +66 -0
- data/lib/occi/model.rb +86 -0
- data/lib/occi/parser/json.rb +34 -0
- data/lib/occi/parser/ova.rb +35 -0
- data/lib/occi/parser/ovf.rb +154 -0
- data/lib/occi/parser/text.rb +234 -0
- data/lib/occi/parser/xml.rb +18 -0
- data/lib/occi/parser.rb +78 -0
- data/lib/occi/settings.rb +9 -0
- data/lib/occi/version.rb +3 -0
- data/lib/occi-core.rb +50 -0
- data/occi-core.gemspec +36 -0
- data/spec/occi/collection_spec.rb +38 -0
- data/spec/occi/core/attribute_spec.rb +0 -0
- data/spec/occi/core/attributes_spec.rb +42 -0
- data/spec/occi/core/categories_spec.rb +27 -0
- data/spec/occi/core/category_spec.rb +38 -0
- data/spec/occi/core/entity_spec.rb +46 -0
- data/spec/occi/core/resource_spec.rb +18 -0
- data/spec/occi/infrastructure/compute_spec.rb +29 -0
- data/spec/occi/log_spec.rb +14 -0
- data/spec/occi/model_spec.rb +50 -0
- data/spec/occi/parser/text_spec.rb +31 -0
- data/spec/occi/parser_spec.rb +114 -0
- data/spec/occi/test.json +33 -0
- data/spec/occi/test.ova +0 -0
- data/spec/occi/test.ovf +198 -0
- data/spec/spec_helper.rb +25 -0
- metadata +304 -0
data/lib/occi/parser.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'occi/parser/text'
|
2
|
+
require 'occi/parser/json'
|
3
|
+
require 'occi/parser/xml'
|
4
|
+
require 'occi/parser/ova'
|
5
|
+
require 'occi/parser/ovf'
|
6
|
+
|
7
|
+
module Occi
|
8
|
+
module Parser
|
9
|
+
|
10
|
+
# Parses an OCCI message and extracts OCCI relevant information
|
11
|
+
# @param [String] media_type the media type of the OCCI message
|
12
|
+
# @param [String] body the body of the OCCI message
|
13
|
+
# @param [true, false] category for text/plain and text/occi media types information e.g. from the HTTP request location is needed to determine if the OCCI message includes a category or an entity
|
14
|
+
# @param [Occi::Core::Resource,Occi::Core::Link] entity_type entity type to use for parsing of text plain entities
|
15
|
+
# @param [Hash] header optional header of the OCCI message
|
16
|
+
# @return [Occi::Collection] list consisting of an array of locations and the OCCI object collection
|
17
|
+
def self.parse(media_type, body, category=false, entity_type=Occi::Core::Resource, header={})
|
18
|
+
Occi::Log.debug '### Parsing request data to OCCI Collection ###'
|
19
|
+
collection = Occi::Collection.new
|
20
|
+
|
21
|
+
# remove trailing HTTP_ prefix if present
|
22
|
+
header = Hash[header.map { |k, v| [k.gsub('HTTP_', '').upcase, v] }]
|
23
|
+
|
24
|
+
if category
|
25
|
+
collection = Occi::Parser::Text.categories(header.map { |k, v| v.to_s.split(',').collect { |w| "#{k}: #{w}" } }.flatten)
|
26
|
+
else
|
27
|
+
if entity_type == Occi::Core::Resource
|
28
|
+
collection = Occi::Parser::Text.resource(header.map { |k, v| v.to_s.split(',').collect { |w| "#{k}: #{w}" } }.flatten)
|
29
|
+
elsif entity_type == Occi::Core::Link
|
30
|
+
collection = Occi::Parser::Text.link(header.map { |k, v| v.to_s.split(',').collect { |w| "#{k}: #{w}" } }.flatten)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
case media_type
|
35
|
+
when 'text/uri-list'
|
36
|
+
nil
|
37
|
+
when 'text/occi'
|
38
|
+
nil
|
39
|
+
when 'text/plain', nil
|
40
|
+
if category
|
41
|
+
collection = Occi::Parser::Text.categories body.split "\n"
|
42
|
+
else
|
43
|
+
if entity_type == Occi::Core::Resource
|
44
|
+
collection = Occi::Parser::Text.resource body.split "\n"
|
45
|
+
elsif entity_type == Occi::Core::Link
|
46
|
+
collection = Occi::Parser::Text.link body.split "\n"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
when 'application/occi+json', 'application/json'
|
50
|
+
collection = Occi::Parser::Json.collection body
|
51
|
+
when 'application/occi+xml', 'application/xml'
|
52
|
+
collection = Occi::Parser::Xml.collection body
|
53
|
+
when 'application/ovf', 'application/ovf+xml'
|
54
|
+
collection = Occi::Parser::Ovf.collection body
|
55
|
+
when 'application/ova'
|
56
|
+
collection = Occi::Parser::Ova.collection body
|
57
|
+
else
|
58
|
+
raise "Content Type not supported"
|
59
|
+
end
|
60
|
+
collection
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.locations(media_type, body, header)
|
64
|
+
locations = Occi::Parser::Text.locations header.map { |k, v| v.to_s.split(',').collect { |w| "#{k}: #{w}" } }.flatten
|
65
|
+
locations << header['Location'] if !header['Location'].nil? && header['Location'].any?
|
66
|
+
case media_type
|
67
|
+
when 'text/uri-list'
|
68
|
+
locations << body.split("\n")
|
69
|
+
when 'text/plain', nil
|
70
|
+
locations << Occi::Parser::Text.locations(body)
|
71
|
+
else
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
locations
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
data/lib/occi/version.rb
ADDED
data/lib/occi-core.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
require 'hashie/mash'
|
5
|
+
|
6
|
+
require 'active_support/core_ext'
|
7
|
+
require 'active_support/json'
|
8
|
+
require 'active_support/inflector'
|
9
|
+
require 'active_support/notifications'
|
10
|
+
|
11
|
+
require 'logger'
|
12
|
+
require 'uuidtools'
|
13
|
+
require 'nokogiri'
|
14
|
+
require 'rubygems/package'
|
15
|
+
require 'zlib'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'settingslogic'
|
18
|
+
|
19
|
+
require 'occi/helpers/inspect'
|
20
|
+
|
21
|
+
require 'occi/settings'
|
22
|
+
require 'occi/log'
|
23
|
+
require 'occi/version'
|
24
|
+
require 'occi/collection'
|
25
|
+
require 'occi/parser'
|
26
|
+
require 'occi/model'
|
27
|
+
require 'occi/core'
|
28
|
+
require 'occi/infrastructure'
|
29
|
+
|
30
|
+
module Occi
|
31
|
+
|
32
|
+
VERIFY_ATTRIBUTE_PATTERN = false
|
33
|
+
|
34
|
+
def kinds
|
35
|
+
Occi::Core::Kinds.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def mixins
|
39
|
+
Occi::Core::Mixins.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def actions
|
43
|
+
Occi::Core::Actions.new
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Array] list of Occi::Core::Categories
|
47
|
+
def categories
|
48
|
+
self.kinds + self.mixins + self.actions
|
49
|
+
end
|
50
|
+
end
|
data/occi-core.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
|
5
|
+
require 'occi/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = 'occi-core'
|
9
|
+
gem.version = Occi::VERSION
|
10
|
+
gem.authors = ['Florian Feldhaus','Piotr Kasprzak', 'Boris Parak']
|
11
|
+
gem.email = ['florian.feldhaus@gmail.com', 'piotr.kasprzak@gwdg.de', 'xparak@mail.muni.cz']
|
12
|
+
gem.description = %q{OCCI is a collection of classes to simplify the implementation of the Open Cloud Computing API in Ruby}
|
13
|
+
gem.summary = %q{OCCI toolkit}
|
14
|
+
gem.homepage = 'https://github.com/gwdg/rOCCI-core'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split("\n")
|
17
|
+
gem.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
gem.extensions = 'ext/mkrf_conf.rb'
|
20
|
+
|
21
|
+
gem.add_dependency 'json'
|
22
|
+
gem.add_dependency 'hashie'
|
23
|
+
gem.add_dependency 'uuidtools', '>=2.1.3'
|
24
|
+
gem.add_dependency 'nokogiri', '~>1.5.0'
|
25
|
+
gem.add_dependency 'activesupport', '~>3.2'
|
26
|
+
gem.add_dependency 'settingslogic'
|
27
|
+
|
28
|
+
gem.add_development_dependency 'rspec'
|
29
|
+
gem.add_development_dependency 'rake'
|
30
|
+
gem.add_development_dependency 'builder'
|
31
|
+
gem.add_development_dependency 'simplecov'
|
32
|
+
gem.add_development_dependency 'yard'
|
33
|
+
gem.add_development_dependency 'yard-rspec'
|
34
|
+
|
35
|
+
gem.required_ruby_version = '>= 1.8.7'
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Occi
|
2
|
+
describe Collection do
|
3
|
+
|
4
|
+
it "creates a new Occi collection including the Occi base objects" do
|
5
|
+
collection = Occi::Collection.new
|
6
|
+
collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
|
7
|
+
collection.mixins << "http://example.com/occi/tags#my_mixin"
|
8
|
+
collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
|
9
|
+
collection.action = Occi::Core::ActionInstance.new
|
10
|
+
collection.resources << Occi::Core::Resource.new
|
11
|
+
collection.links << Occi::Core::Link.new
|
12
|
+
collection.kinds.first.should be_kind_of Occi::Core::Kind
|
13
|
+
collection.mixins.first.should be_kind_of Occi::Core::Mixin
|
14
|
+
collection.actions.first.should be_kind_of Occi::Core::Action
|
15
|
+
collection.resources.first.should be_kind_of Occi::Core::Resource
|
16
|
+
collection.links.first.should be_kind_of Occi::Core::Link
|
17
|
+
collection.action.should be_kind_of Occi::Core::ActionInstance
|
18
|
+
end
|
19
|
+
|
20
|
+
it "registers a model, creates a new OCCI Resource and checks it against the model" do
|
21
|
+
collection = Occi::Collection.new
|
22
|
+
collection.model.should be_kind_of Occi::Model
|
23
|
+
collection.resources.create 'http://schemas.ogf.org/occi/core#resource'
|
24
|
+
collection.resources.first.should be_kind_of Occi::Core::Resource
|
25
|
+
expect { collection.check }.to_not raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'successfully gets all categories related to a category' do
|
29
|
+
collection = Occi::Collection.new
|
30
|
+
collection.kinds << Occi::Core::Resource.kind
|
31
|
+
collection.kinds << Occi::Core::Link.kind
|
32
|
+
collection.get_related_to(Occi::Core::Entity.kind).should == collection
|
33
|
+
collection.get_related_to(Occi::Core::Resource.kind).kinds.first.should == Occi::Core::Resource.kind
|
34
|
+
collection.get_related_to(Occi::Core::Link.kind).kinds.first.should == Occi::Core::Link.kind
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
describe Attributes do
|
4
|
+
|
5
|
+
it 'stores properties using hashes in hash notation' do
|
6
|
+
attributes=Occi::Core::Attributes.new
|
7
|
+
attributes['test']={}
|
8
|
+
attributes['test'].should be_kind_of Occi::Core::Properties
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'stores properties using hashes in dot notation' do
|
12
|
+
attributes=Occi::Core::Attributes.new
|
13
|
+
attributes.test={}
|
14
|
+
attributes.test.should be_kind_of Occi::Core::Properties
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'removes attributes' do
|
18
|
+
attributes=Occi::Core::Attributes.new
|
19
|
+
attributes['one.two']={}
|
20
|
+
attributes['one.three']={}
|
21
|
+
attr=Occi::Core::Attributes.new
|
22
|
+
attr['one.two']={}
|
23
|
+
attributes.remove attr
|
24
|
+
attributes['one.two'].should be_nil
|
25
|
+
attributes['one.three'].should be_kind_of Occi::Core::Properties
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'converts properties to an empty attribute' do
|
29
|
+
attributes=Occi::Core::Attributes.new
|
30
|
+
attributes.test={}
|
31
|
+
attr = attributes.convert
|
32
|
+
attributes.test.should be_kind_of Occi::Core::Properties
|
33
|
+
attr.test.should be_nil
|
34
|
+
attr._test.should be_kind_of Occi::Core::Properties
|
35
|
+
attributes.convert!
|
36
|
+
attributes.test.should be_nil
|
37
|
+
attributes._test.should be_kind_of Occi::Core::Properties
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
describe Categories do
|
4
|
+
|
5
|
+
it "replaces an existing category instance when a model is added with the instance from the model" do
|
6
|
+
categories = Occi::Core::Categories.new
|
7
|
+
categories << Occi::Core::Resource.kind
|
8
|
+
model = Occi::Model.new
|
9
|
+
resource = model.get_by_id Occi::Core::Resource.type_identifier
|
10
|
+
resource.location = '/new_location/'
|
11
|
+
categories.model = model
|
12
|
+
categories.first.location.should == '/new_location/'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "replaces a category string when a model is added with the instance from the model" do
|
16
|
+
categories = Occi::Core::Categories.new
|
17
|
+
categories << Occi::Core::Resource.type_identifier
|
18
|
+
model = Occi::Model.new
|
19
|
+
resource = model.get_by_id Occi::Core::Resource.type_identifier
|
20
|
+
resource.location = '/new_location/'
|
21
|
+
categories.model = model
|
22
|
+
categories.first.location.should == '/new_location/'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
describe Category do
|
4
|
+
|
5
|
+
it "gets OCCI Resource class by term and scheme" do
|
6
|
+
scheme = 'http://schemas.ogf.org/occi/core'
|
7
|
+
term = 'resource'
|
8
|
+
klass = Occi::Core::Category.get_class scheme, term
|
9
|
+
klass.should be Occi::Core::Resource
|
10
|
+
klass.superclass.should be Occi::Core::Entity
|
11
|
+
end
|
12
|
+
|
13
|
+
it "gets non predefined OCCI class by term, scheme and related class" do
|
14
|
+
scheme = 'http://example.com/occi'
|
15
|
+
term = 'test'
|
16
|
+
related = ['http://schemas.ogf.org/occi/core#resource']
|
17
|
+
klass = Occi::Core::Category.get_class scheme, term, related
|
18
|
+
klass.should be Com::Example::Occi::Test
|
19
|
+
klass.superclass.should be Occi::Core::Resource
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does not get OCCI class by term and scheme if it relates to existing class not derived from OCCI Entity" do
|
23
|
+
scheme = 'http://hashie/'
|
24
|
+
term = 'mash'
|
25
|
+
related = ['http://schemas.ogf.org/occi/core#resource']
|
26
|
+
expect { Occi::Core::Category.get_class scheme, term, related }.to raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it "checks if the category is related to another category" do
|
30
|
+
category = Occi::Core::Resource.kind
|
31
|
+
category.related_to?(Occi::Core::Entity.kind).should be true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rendering
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
describe Entity do
|
4
|
+
|
5
|
+
it "initializes itself successfully" do
|
6
|
+
entity = Occi::Core::Entity.new
|
7
|
+
entity.should be_kind_of Occi::Core::Entity
|
8
|
+
end
|
9
|
+
|
10
|
+
it "initializes a subclass successfully using a type identifier" do
|
11
|
+
type_identifier = 'http://example.com/testnamespace#test'
|
12
|
+
entity = Occi::Core::Entity.new type_identifier
|
13
|
+
entity.should be_kind_of 'Com::Example::Testnamespace::Test'.constantize
|
14
|
+
entity.kind.type_identifier.should == type_identifier
|
15
|
+
entity.kind.related.first.should == Occi::Core::Entity.kind
|
16
|
+
end
|
17
|
+
|
18
|
+
it "initializes a subclass successfully using an OCCI Kind" do
|
19
|
+
kind = Occi::Core::Resource.kind
|
20
|
+
entity = Occi::Core::Entity.new kind
|
21
|
+
entity.should be_kind_of Occi::Core::Resource
|
22
|
+
entity.kind.type_identifier.should == Occi::Core::Resource.type_identifier
|
23
|
+
entity.kind.related.first.should == Occi::Core::Entity.kind
|
24
|
+
end
|
25
|
+
|
26
|
+
it "converts mixin type identifiers to objects if a mixin is added to the entities mixins" do
|
27
|
+
mixin = 'http://example.com/mynamespace#mymixin'
|
28
|
+
entity = Occi::Core::Entity.new
|
29
|
+
entity.mixins << mixin
|
30
|
+
entity.mixins.first.to_s.should == mixin
|
31
|
+
end
|
32
|
+
|
33
|
+
# TODO: check adding of model
|
34
|
+
it "checks a valid attribute value against their definition in its kind and associated mixins" do
|
35
|
+
entity = Occi::Core::Entity.new
|
36
|
+
expect { entity.check }.to raise_error
|
37
|
+
entity.model = Occi::Model.new
|
38
|
+
entity.title = 'test'
|
39
|
+
uuid = UUIDTools::UUID.random_create.to_s
|
40
|
+
entity.id = uuid
|
41
|
+
expect { entity.check }.to_not raise_error
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
describe Resource do
|
4
|
+
|
5
|
+
it "links another resource succesfully" do
|
6
|
+
resource = Occi::Core::Resource.new
|
7
|
+
target = Occi::Core::Resource.new
|
8
|
+
# create a random ID as the resource must already exist and therefore must have an ID assigned
|
9
|
+
target.id = UUIDTools::UUID.random_create.to_s
|
10
|
+
resource.link target
|
11
|
+
resource.links.should have(1).link
|
12
|
+
resource.links.first.should be_kind_of Occi::Core::Link
|
13
|
+
resource.links.first.target.should be target
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Occi
|
2
|
+
module Infrastructure
|
3
|
+
describe Compute do
|
4
|
+
|
5
|
+
it "creates a storagelink to an existing storage resource" do
|
6
|
+
compute = Occi::Infrastructure::Compute.new
|
7
|
+
target = Occi::Infrastructure::Storage.new
|
8
|
+
# create a random ID as the storage resource must already exist and therefore must have an ID assigned
|
9
|
+
target.id = UUIDTools::UUID.random_create.to_s
|
10
|
+
compute.storagelink target
|
11
|
+
compute.links.should have(1).link
|
12
|
+
compute.links.first.should be_kind_of Occi::Infrastructure::Storagelink
|
13
|
+
compute.links.first.target.should be target
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates a networkinterface to an existing network resource" do
|
17
|
+
compute = Occi::Infrastructure::Compute.new
|
18
|
+
target = Occi::Infrastructure::Network.new
|
19
|
+
# create a random ID as the network resource must already exist and therefore must have an ID assigned
|
20
|
+
target.id = UUIDTools::UUID.random_create.to_s
|
21
|
+
compute.networkinterface target
|
22
|
+
compute.links.should have(1).link
|
23
|
+
compute.links.first.should be_kind_of Occi::Infrastructure::Networkinterface
|
24
|
+
compute.links.first.target.should be target
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Occi
|
2
|
+
describe "Model" do
|
3
|
+
|
4
|
+
it "initializes Core Model successfully" do
|
5
|
+
model = Occi::Model.new
|
6
|
+
model.get_by_id('http://schemas.ogf.org/occi/core#entity').should be_kind_of Occi::Core::Kind
|
7
|
+
model.get_by_id('http://schemas.ogf.org/occi/core#resource').should be_kind_of Occi::Core::Kind
|
8
|
+
model.get_by_id('http://schemas.ogf.org/occi/core#link').should be_kind_of Occi::Core::Kind
|
9
|
+
end
|
10
|
+
|
11
|
+
it "initializes Infrastructure Model successfully" do
|
12
|
+
model = Occi::Model.new
|
13
|
+
model.register_infrastructure
|
14
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure#compute').should be_kind_of Occi::Core::Kind
|
15
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure#os_tpl').should be_kind_of Occi::Core::Mixin
|
16
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure#resource_tpl').should be_kind_of Occi::Core::Mixin
|
17
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure#network').should be_kind_of Occi::Core::Kind
|
18
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure/network#ipnetwork').should be_kind_of Occi::Core::Mixin
|
19
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure#networkinterface').should be_kind_of Occi::Core::Kind
|
20
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface').should be_kind_of Occi::Core::Mixin
|
21
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure#storage').should be_kind_of Occi::Core::Kind
|
22
|
+
model.get_by_id('http://schemas.ogf.org/occi/infrastructure#storagelink').should be_kind_of Occi::Core::Kind
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns all registered categories" do
|
26
|
+
model = Occi::Model.new
|
27
|
+
collection = model.get
|
28
|
+
collection.kind_of? Occi::Collection
|
29
|
+
collection.kinds.should have(3).kinds
|
30
|
+
collection.mixins.should be_empty
|
31
|
+
collection.actions.should be_empty
|
32
|
+
collection.resources.should be_empty
|
33
|
+
collection.links.should be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns categories with filter" do
|
37
|
+
model = Occi::Model.new
|
38
|
+
model.register_infrastructure
|
39
|
+
network = Occi::Infrastructure::Network.kind
|
40
|
+
collection = model.get(network)
|
41
|
+
collection.kind_of? Occi::Collection
|
42
|
+
collection.kinds.first.should == network
|
43
|
+
collection.mixins.first.should == Occi::Infrastructure::Network::Ipnetwork.mixin
|
44
|
+
collection.actions.should be_empty
|
45
|
+
collection.resources.should be_empty
|
46
|
+
collection.links.should be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Occi
|
4
|
+
module Parser
|
5
|
+
describe Text do
|
6
|
+
|
7
|
+
describe '.category' do
|
8
|
+
|
9
|
+
it 'parses a string to an OCCI Category' do
|
10
|
+
category_string = 'Category: a_a1-_;scheme="http://a.a/a#";class="kind";title="aA1!\"§$%&/()=?`´ß+*#-_.:,;<>";rel="http://a.a/b#a";location="/a1-A/";attributes="a_1-_.a1-_a a-1.a.b";actions="http://a.a/a1#a1 http://a.b1/b1#b2"'
|
11
|
+
category = Occi::Parser::Text.category category_string
|
12
|
+
category.term.should == 'a_a1-_'
|
13
|
+
category.scheme.should == 'http://a.a/a#'
|
14
|
+
category.class.should == Occi::Core::Kind
|
15
|
+
category.title.should == 'aA1!\"§$%&/()=?`´ß+*#-_.:,;<>'
|
16
|
+
category.related.first.should == 'http://a.a/b#a'
|
17
|
+
category.location.should == '/a1-A/'
|
18
|
+
category.attributes['a_1-_'].class.should == Occi::Core::Attributes
|
19
|
+
category.attributes['a_1-_']['a1-_a'].class.should == Occi::Core::Properties
|
20
|
+
category.attributes['a-1'].class.should == Occi::Core::Attributes
|
21
|
+
category.attributes['a-1']['a'].class.should == Occi::Core::Attributes
|
22
|
+
category.attributes['a-1']['a']['b'].class.should == Occi::Core::Properties
|
23
|
+
category.actions.to_a.first.to_s == 'http://a.a/a1#a1'
|
24
|
+
category.actions.to_a.last.to_s == 'http://a.b1/b1#b2'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Occi
|
2
|
+
describe "Parser" do
|
3
|
+
|
4
|
+
it "parses an OCCI message with MIME type text/plain containing an OCCI resource" do
|
5
|
+
# create new collection
|
6
|
+
collection = Occi::Collection.new
|
7
|
+
# create new resource within collection
|
8
|
+
resource = collection.resources.create
|
9
|
+
|
10
|
+
# render collection to text/plain MIME type
|
11
|
+
rendered_collection = collection.to_text
|
12
|
+
# parse rendered collection and compare with original collection
|
13
|
+
Occi::Parser.parse('text/plain', rendered_collection).to_json.should == collection.to_json
|
14
|
+
|
15
|
+
# add attributes to resource
|
16
|
+
resource.id = UUIDTools::UUID.random_create.to_s
|
17
|
+
resource.title = 'title'
|
18
|
+
|
19
|
+
# render collection to text/plain MIME type
|
20
|
+
rendered_collection = collection.to_text
|
21
|
+
# parse rendered collection and compare with original collection
|
22
|
+
Occi::Parser.parse('text/plain', rendered_collection).to_json.should == collection.to_json
|
23
|
+
|
24
|
+
# add mixin to resource
|
25
|
+
resource.mixins << Occi::Core::Mixin.new
|
26
|
+
|
27
|
+
# render collection to text/plain MIME type
|
28
|
+
rendered_collection = collection.to_text
|
29
|
+
# parse rendered collection and compare with original collection
|
30
|
+
Occi::Parser.parse('text/plain', rendered_collection).to_json.should == collection.to_json
|
31
|
+
|
32
|
+
# add link to resource
|
33
|
+
link = resource.links.create
|
34
|
+
link.id = UUIDTools::UUID.random_create.to_s
|
35
|
+
link.target = 'http://example.com/resource/aee5acf5-71de-40b0-bd1c-2284658bfd0e'
|
36
|
+
|
37
|
+
# render collection to text/plain MIME type
|
38
|
+
rendered_collection = collection.to_text
|
39
|
+
# parse rendered collection and compare with original collection
|
40
|
+
Occi::Parser.parse('text/plain', rendered_collection).to_json.should == collection.to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
it "parses an OCCI message with MIME type application/occi+json containing an OCCI resource" do
|
44
|
+
# create new collection
|
45
|
+
collection = Occi::Collection.new
|
46
|
+
# create new resource within collection
|
47
|
+
resource = collection.resources.create
|
48
|
+
|
49
|
+
# render collection to text/plain MIME type
|
50
|
+
rendered_collection = collection.to_json
|
51
|
+
# parse rendered collection and compare with original collection
|
52
|
+
Occi::Parser.parse('application/occi+json', rendered_collection).should == collection
|
53
|
+
|
54
|
+
# add attributes to resource
|
55
|
+
resource.id = UUIDTools::UUID.random_create.to_s
|
56
|
+
resource.title = 'title'
|
57
|
+
|
58
|
+
# render collection to text/plain MIME type
|
59
|
+
rendered_collection = collection.to_json
|
60
|
+
# parse rendered collection and compare with original collection
|
61
|
+
Occi::Parser.parse('application/occi+json', rendered_collection).should == collection
|
62
|
+
|
63
|
+
# add mixin to resource
|
64
|
+
resource.mixins << Occi::Core::Mixin.new
|
65
|
+
|
66
|
+
# render collection to text/plain MIME type
|
67
|
+
rendered_collection = collection.to_json
|
68
|
+
# parse rendered collection and compare with original collection
|
69
|
+
Occi::Parser.parse('application/occi+json', rendered_collection).should == collection
|
70
|
+
|
71
|
+
# add link to resource
|
72
|
+
link = resource.links.create
|
73
|
+
link.target = 'http://example.com/resource/aee5acf5-71de-40b0-bd1c-2284658bfd0e'
|
74
|
+
|
75
|
+
# render collection to text/plain MIME type
|
76
|
+
rendered_collection = collection.to_json
|
77
|
+
# parse rendered collection and compare with original collection
|
78
|
+
Occi::Parser.parse('application/occi+json', rendered_collection).should == collection
|
79
|
+
end
|
80
|
+
|
81
|
+
it "parses an OVF file" do
|
82
|
+
media_type = 'application/ovf+xml'
|
83
|
+
body = File.read('spec/occi/test.ovf')
|
84
|
+
collection = Occi::Parser.parse(media_type, body)
|
85
|
+
storage_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#storage' }
|
86
|
+
storage_resources.should have(1).storage_resource
|
87
|
+
storage_resources.first.title.should == 'lamp'
|
88
|
+
network_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#network' }
|
89
|
+
network_resources.should have(1).network_resource
|
90
|
+
network_resources.first.title.should == 'VM Network'
|
91
|
+
compute_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#compute' }
|
92
|
+
compute_resources.should have(1).compute_resource
|
93
|
+
compute_resources.first.attributes.occi!.compute!.cores.should == 1
|
94
|
+
compute_resources.first.attributes.occi!.compute!.memory.should == 0.25
|
95
|
+
end
|
96
|
+
|
97
|
+
it "parses an OVA container" do
|
98
|
+
media_type = 'application/ova'
|
99
|
+
body = File.read('spec/occi/test.ova')
|
100
|
+
collection = Occi::Parser.parse(media_type, body)
|
101
|
+
storage_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#storage' }
|
102
|
+
storage_resources.should have(1).storage_resource
|
103
|
+
storage_resources.first.title.should == 'lamp'
|
104
|
+
network_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#network' }
|
105
|
+
network_resources.should have(1).network_resource
|
106
|
+
network_resources.first.title.should == 'VM Network'
|
107
|
+
compute_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#compute' }
|
108
|
+
compute_resources.should have(1).compute_resource
|
109
|
+
compute_resources.first.attributes.occi!.compute!.cores.should == 1
|
110
|
+
compute_resources.first.attributes.occi!.compute!.memory.should == 0.25
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|