occi-core 4.1.3 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +8 -0
  3. data/README.md +49 -17
  4. data/lib/occi/collection.rb +37 -21
  5. data/lib/occi/core/action.rb +5 -5
  6. data/lib/occi/core/action_instance.rb +45 -3
  7. data/lib/occi/core/actions.rb +2 -1
  8. data/lib/occi/core/attributes.rb +253 -73
  9. data/lib/occi/core/categories.rb +1 -0
  10. data/lib/occi/core/category.rb +25 -8
  11. data/lib/occi/core/entities.rb +1 -0
  12. data/lib/occi/core/entity.rb +51 -74
  13. data/lib/occi/core/kind.rb +15 -11
  14. data/lib/occi/core/kinds.rb +1 -1
  15. data/lib/occi/core/link.rb +14 -15
  16. data/lib/occi/core/links.rb +1 -1
  17. data/lib/occi/core/mixin.rb +5 -5
  18. data/lib/occi/core/mixins.rb +2 -2
  19. data/lib/occi/core/properties.rb +90 -12
  20. data/lib/occi/core/resource.rb +7 -3
  21. data/lib/occi/core/resources.rb +2 -2
  22. data/lib/occi/errors/attribute_definitions_converted_error.rb +5 -0
  23. data/lib/occi/errors/attribute_missing_error.rb +5 -0
  24. data/lib/occi/errors/attribute_name_invalid_error.rb +5 -0
  25. data/lib/occi/errors/attribute_not_defined_error.rb +5 -0
  26. data/lib/occi/errors/attribute_property_type_error.rb +5 -0
  27. data/lib/occi/errors/attribute_type_error.rb +5 -0
  28. data/lib/occi/errors/kind_not_defined_error.rb +5 -0
  29. data/lib/occi/errors/parser_input_error.rb +5 -0
  30. data/lib/occi/errors/parser_type_error.rb +5 -0
  31. data/lib/occi/errors.rb +1 -0
  32. data/lib/occi/extensions/hashie.rb +25 -0
  33. data/lib/occi/helpers/comparators/action_instance.rb +22 -0
  34. data/lib/occi/helpers/comparators/attributes.rb +22 -0
  35. data/lib/occi/helpers/comparators/categories.rb +22 -0
  36. data/lib/occi/helpers/comparators/category.rb +22 -0
  37. data/lib/occi/helpers/comparators/collection.rb +40 -0
  38. data/lib/occi/helpers/comparators/entities.rb +22 -0
  39. data/lib/occi/helpers/comparators/entity.rb +22 -0
  40. data/lib/occi/helpers/comparators/properties.rb +26 -0
  41. data/lib/occi/helpers/comparators.rb +1 -0
  42. data/lib/occi/infrastructure/compute.rb +11 -9
  43. data/lib/occi/infrastructure/network.rb +27 -27
  44. data/lib/occi/infrastructure/networkinterface.rb +22 -23
  45. data/lib/occi/infrastructure/os_tpl.rb +1 -1
  46. data/lib/occi/infrastructure/resource_tpl.rb +1 -1
  47. data/lib/occi/infrastructure/storage.rb +7 -6
  48. data/lib/occi/infrastructure/storagelink.rb +4 -4
  49. data/lib/occi/log.rb +13 -10
  50. data/lib/occi/model.rb +9 -8
  51. data/lib/occi/parser/json.rb +11 -9
  52. data/lib/occi/parser/ova.rb +12 -6
  53. data/lib/occi/parser/ovf.rb +173 -116
  54. data/lib/occi/parser/text/constants.rb +87 -0
  55. data/lib/occi/parser/text.rb +161 -200
  56. data/lib/occi/parser/xml.rb +10 -8
  57. data/lib/occi/parser.rb +100 -50
  58. data/lib/occi/settings.rb +2 -1
  59. data/lib/occi/version.rb +1 -1
  60. data/lib/occi-core.rb +6 -4
  61. data/occi-core.gemspec +0 -7
  62. data/spec/occi/collection_samples/collection1.json +1 -0
  63. data/spec/occi/collection_samples/directory2/collection2.json +1 -0
  64. data/spec/occi/collection_spec.rb +961 -31
  65. data/spec/occi/core/action_instance_spec.rb +317 -0
  66. data/spec/occi/core/action_spec.rb +71 -0
  67. data/spec/occi/core/attributes_spec.rb +582 -27
  68. data/spec/occi/core/category_spec.rb +194 -18
  69. data/spec/occi/core/entities_spec.rb +96 -0
  70. data/spec/occi/core/entity_spec.rb +317 -28
  71. data/spec/occi/core/kind_spec.rb +127 -16
  72. data/spec/occi/core/link_spec.rb +35 -0
  73. data/spec/occi/core/links_spec.rb +130 -0
  74. data/spec/occi/core/mixins_spec.rb +107 -0
  75. data/spec/occi/core/properties_spec.rb +167 -0
  76. data/spec/occi/core/resource_spec.rb +23 -9
  77. data/spec/occi/core_spec.rb +12 -0
  78. data/spec/occi/infrastructure/compute_spec.rb +218 -18
  79. data/spec/occi/infrastructure/network_spec.rb +96 -0
  80. data/spec/occi/infrastructure/networkinterface_spec.rb +96 -0
  81. data/spec/occi/infrastructure/storage_spec.rb +33 -0
  82. data/spec/occi/infrastructure/storagelink_spec.rb +45 -0
  83. data/spec/occi/log_spec.rb +104 -1
  84. data/spec/occi/model_spec.rb +251 -39
  85. data/spec/occi/{test.json → parser/json_samples/test.json} +0 -0
  86. data/spec/occi/parser/ova_samples/test.dump +0 -0
  87. data/spec/occi/{test.ova → parser/ova_samples/test.ova} +0 -0
  88. data/spec/occi/parser/ovf_samples/test.dump +0 -0
  89. data/spec/occi/{test.ovf → parser/ovf_samples/test.ovf} +0 -0
  90. data/spec/occi/parser/text_samples/occi_categories.dump +0 -0
  91. data/spec/occi/parser/text_samples/occi_categories.text +2 -0
  92. data/spec/occi/parser/text_samples/occi_compute_rocci_server.dump +0 -0
  93. data/spec/occi/parser/text_samples/occi_compute_rocci_server.resource.dump +0 -0
  94. data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +10 -0
  95. data/spec/occi/parser/text_samples/occi_link_resource_instance.dump +0 -0
  96. data/spec/occi/parser/text_samples/occi_link_resource_instance.text +7 -0
  97. data/spec/occi/parser/text_samples/occi_link_simple.dump +0 -0
  98. data/spec/occi/parser/text_samples/occi_link_simple.link_string.dump +0 -0
  99. data/spec/occi/parser/text_samples/occi_link_simple.text +1 -0
  100. data/spec/occi/parser/text_samples/occi_link_w_attributes.dump +0 -0
  101. data/spec/occi/parser/text_samples/occi_link_w_attributes.text +7 -0
  102. data/spec/occi/parser/text_samples/occi_link_w_category.dump +0 -0
  103. data/spec/occi/parser/text_samples/occi_link_w_category.text +3 -0
  104. data/spec/occi/parser/text_samples/occi_model_rocci_server.dump +0 -0
  105. data/spec/occi/parser/text_samples/occi_model_rocci_server.text +51 -0
  106. data/spec/occi/parser/text_samples/occi_network_rocci_server.dump +0 -0
  107. data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.dump +0 -0
  108. data/spec/occi/parser/text_samples/occi_network_rocci_server.text +11 -0
  109. data/spec/occi/parser/text_samples/occi_resource_w_attributes.dump +0 -0
  110. data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +11 -0
  111. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.dump +0 -0
  112. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +16 -0
  113. data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.dump +0 -0
  114. data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +13 -0
  115. data/spec/occi/parser/text_samples/occi_storage_rocci_server.dump +0 -0
  116. data/spec/occi/parser/text_samples/occi_storage_rocci_server.resource.dump +0 -0
  117. data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +9 -0
  118. data/spec/occi/parser/text_spec.rb +274 -78
  119. data/spec/occi/parser/xml_samples/test.xml +352 -0
  120. data/spec/occi/parser_spec.rb +255 -104
  121. data/spec/occi-core_spec.rb +31 -0
  122. data/spec/spec_helper.rb +6 -2
  123. metadata +110 -111
  124. checksums.yaml +0 -7
  125. data/spec/occi/core/attribute_spec.rb +0 -0
@@ -0,0 +1,5 @@
1
+ module Occi
2
+ module Errors
3
+ class ParserTypeError < ArgumentError; end
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'errors', '*.rb')].each { |file| require file.gsub('.rb', '') }
@@ -0,0 +1,25 @@
1
+ ##
2
+ # Monkeypatch for Hashie
3
+ module Hashie
4
+ class Hash
5
+
6
+ # Converts a mash back to a hash (with stringified keys)
7
+ def to_hash(options={})
8
+ out = {}
9
+ keys.each do |k|
10
+ if self[k].is_a?(Array)
11
+ k = options[:symbolize_keys] ? k.to_sym : k.to_s
12
+ out[k] ||= []
13
+ self[k].each do |array_object|
14
+ out[k] << (array_object.respond_to?(:to_hash) ? array_object.to_hash : array_object)
15
+ end
16
+ else
17
+ k = options[:symbolize_keys] ? k.to_sym : k.to_s
18
+ out[k] = self[k].respond_to?(:to_hash) ? self[k].to_hash : self[k]
19
+ end
20
+ end
21
+ out
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ module Occi
2
+ module Helpers
3
+ module Comparators
4
+ module ActionInstance
5
+
6
+ def ==(obj)
7
+ return false unless obj && obj.respond_to?(:action) && obj.respond_to?(:attributes)
8
+ (self.action == obj.action) && (self.attributes == obj.attributes)
9
+ end
10
+
11
+ def eql?(obj)
12
+ self == obj
13
+ end
14
+
15
+ def hash
16
+ [self.action, self.attributes].hash
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Occi
2
+ module Helpers
3
+ module Comparators
4
+ module Attributes
5
+
6
+ def ==(obj)
7
+ return false unless obj && obj.respond_to?(:names)
8
+ self.names == obj.names
9
+ end
10
+
11
+ def eql?(obj)
12
+ self == obj
13
+ end
14
+
15
+ def hash
16
+ self.names.hash
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Occi
2
+ module Helpers
3
+ module Comparators
4
+ module Categories
5
+
6
+ def ==(obj)
7
+ return false unless obj && obj.respond_to?(:to_a)
8
+ self.to_a == obj.to_a
9
+ end
10
+
11
+ def eql?(obj)
12
+ self == obj
13
+ end
14
+
15
+ def hash
16
+ self.to_a.hash
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Occi
2
+ module Helpers
3
+ module Comparators
4
+ module Category
5
+
6
+ def ==(obj)
7
+ return false unless obj && obj.respond_to?(:type_identifier)
8
+ self.type_identifier == obj.type_identifier
9
+ end
10
+
11
+ def eql?(obj)
12
+ self == obj
13
+ end
14
+
15
+ def hash
16
+ self.type_identifier.hash
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,40 @@
1
+ module Occi
2
+ module Helpers
3
+ module Comparators
4
+ module Collection
5
+
6
+ REQUIRED_ACCESSORS = [:kinds, :mixins, :actions, :resources, :links, :action].freeze
7
+
8
+ def ==(obj)
9
+ return false unless obj && has_accessors?(obj)
10
+ contents_matches?(obj)
11
+ end
12
+
13
+ def eql?(obj)
14
+ self == obj
15
+ end
16
+
17
+ def hash
18
+ REQUIRED_ACCESSORS.collect { |accessor| self.send(accessor) }.hash
19
+ end
20
+
21
+ def has_accessors?(obj)
22
+ result = true
23
+ REQUIRED_ACCESSORS.each { |accessor| result = result && obj.respond_to?(accessor) }
24
+
25
+ result
26
+ end
27
+ private :has_accessors?
28
+
29
+ def contents_matches?(obj)
30
+ result = true
31
+ REQUIRED_ACCESSORS.each { |accessor| result = result && (self.send(accessor) == obj.send(accessor)) }
32
+
33
+ result
34
+ end
35
+ private :contents_matches?
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,22 @@
1
+ module Occi
2
+ module Helpers
3
+ module Comparators
4
+ module Entities
5
+
6
+ def ==(obj)
7
+ return false unless obj && obj.respond_to?(:to_a)
8
+ self.to_a == obj.to_a
9
+ end
10
+
11
+ def eql?(obj)
12
+ self == obj
13
+ end
14
+
15
+ def hash
16
+ self.to_a.hash
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Occi
2
+ module Helpers
3
+ module Comparators
4
+ module Entity
5
+
6
+ def ==(obj)
7
+ return false unless obj && obj.respond_to?(:kind) && obj.respond_to?(:attributes)
8
+ (self.kind == obj.kind) && (self.attributes['occi.core.id'] == obj.attributes['occi.core.id'])
9
+ end
10
+
11
+ def eql?(obj)
12
+ self == obj
13
+ end
14
+
15
+ def hash
16
+ [self.kind, self.attributes['occi.core.id']].hash
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ module Occi
2
+ module Helpers
3
+ module Comparators
4
+ module Properties
5
+
6
+ def ==(obj)
7
+ return false unless obj && obj.respond_to?(:instance_variables)
8
+
9
+ local_attrs = self.instance_variables.map { |ivar| self.instance_variable_get ivar }
10
+ remote_attrs = obj.instance_variables.map { |ivar| obj.instance_variable_get ivar }
11
+
12
+ local_attrs == remote_attrs
13
+ end
14
+
15
+ def eql?(obj)
16
+ self == obj
17
+ end
18
+
19
+ def hash
20
+ self.instance_variables.map { |ivar| self.instance_variable_get ivar }.hash
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'comparators', '*.rb')].each { |file| require file.gsub('.rb', '') }
@@ -29,7 +29,7 @@ module Occi
29
29
 
30
30
  self.actions = Occi::Core::Actions.new << start << stop << restart << suspend
31
31
 
32
- self.attributes = Occi::Core::Attributes.new
32
+ self.attributes = Occi::Core::Attributes.new(Occi::Core::Resource.attributes)
33
33
  self.attributes['occi.compute.architecture'] = {:mutable => true,
34
34
  :pattern => 'x86|x64'}
35
35
  self.attributes['occi.compute.cores'] = {:type => 'number',
@@ -38,6 +38,8 @@ module Occi
38
38
  :pattern => '(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*'}
39
39
  self.attributes['occi.compute.memory'] = {:type => 'number',
40
40
  :mutable => true}
41
+ self.attributes['occi.compute.speed'] = {:type => 'number',
42
+ :mutable => true}
41
43
  self.attributes['occi.compute.state'] = {:pattern => 'inactive|active|suspended|error',
42
44
  :default => 'inactive'}
43
45
 
@@ -51,10 +53,10 @@ module Occi
51
53
 
52
54
  require 'occi/infrastructure/resource_tpl'
53
55
  require 'occi/infrastructure/os_tpl'
54
- self.mixins = Occi::Core::Mixins.new << Occi::Infrastructure::Resource_tpl.mixin << Occi::Infrastructure::Os_tpl.mixin
56
+ self.mixins = Occi::Core::Mixins.new << Occi::Infrastructure::ResourceTpl.mixin << Occi::Infrastructure::OsTpl.mixin
55
57
 
56
58
  def architecture
57
- @attributes.occi.compute.architecture if @attributes.occi.compute if @attributes.occi
59
+ @attributes.occi_.compute_.architecture
58
60
  end
59
61
 
60
62
  def architecture=(architecture)
@@ -62,7 +64,7 @@ module Occi
62
64
  end
63
65
 
64
66
  def cores
65
- @attributes.occi.compute.cores if @attributes.occi.compute if @attributes.occi
67
+ @attributes.occi_.compute_.cores
66
68
  end
67
69
 
68
70
  def cores=(cores)
@@ -70,7 +72,7 @@ module Occi
70
72
  end
71
73
 
72
74
  def hostname
73
- @attributes.occi.compute.hostname if @attributes.occi.compute if @attributes.occi
75
+ @attributes.occi_.compute_.hostname
74
76
  end
75
77
 
76
78
  def hostname=(hostname)
@@ -78,7 +80,7 @@ module Occi
78
80
  end
79
81
 
80
82
  def speed
81
- @attributes.occi.compute.speed if @attributes.occi.compute if @attributes.occi
83
+ @attributes.occi_.compute_.speed
82
84
  end
83
85
 
84
86
  def speed=(speed)
@@ -86,7 +88,7 @@ module Occi
86
88
  end
87
89
 
88
90
  def memory
89
- @attributes.occi.compute.memory if @attributes.occi.compute if @attributes.occi
91
+ @attributes.occi_.compute_.memory
90
92
  end
91
93
 
92
94
  def memory=(memory)
@@ -94,7 +96,7 @@ module Occi
94
96
  end
95
97
 
96
98
  def state
97
- @attributes.occi.compute.state if @attributes.occi.compute if @attributes.occi
99
+ @attributes.occi_.compute_.state
98
100
  end
99
101
 
100
102
  def state=(state)
@@ -119,4 +121,4 @@ module Occi
119
121
 
120
122
  end
121
123
  end
122
- end
124
+ end
@@ -12,13 +12,14 @@ module Occi
12
12
 
13
13
  self.actions = Occi::Core::Actions.new << up << down
14
14
 
15
- self.attributes = Occi::Core::Attributes.new
15
+ self.attributes = Occi::Core::Attributes.new(Occi::Core::Resource.attributes)
16
16
  self.attributes['occi.network.vlan'] = {:type => 'number',
17
17
  :mutable => true,
18
- :pattern => 'x86|x64'}
19
- self.attributes['occi.network.label'] = {:type => 'number',
18
+ :pattern => '\d+'}
19
+ self.attributes['occi.network.label'] = {:type => 'string',
20
20
  :mutable => true}
21
- self.attributes['occi.network.state'] ={:pattern => 'active|inactive|error',
21
+ self.attributes['occi.network.state'] ={:type => 'string',
22
+ :pattern => 'active|inactive|error',
22
23
  :default => 'inactive'}
23
24
 
24
25
  self.kind = Occi::Core::Kind.new scheme='http://schemas.ogf.org/occi/infrastructure#',
@@ -32,16 +33,18 @@ module Occi
32
33
  require 'occi/infrastructure/network/ipnetwork'
33
34
  self.mixins = Occi::Core::Mixins.new << Occi::Infrastructure::Network::Ipnetwork.mixin
34
35
 
35
- def ipnetwork(boolean=true)
36
- if boolean
37
- mixins << Occi::Infrastructure::Network::Ipnetwork.mixin.type_identifier
36
+ def ipnetwork(add = true)
37
+ if add
38
+ Occi::Log.info "[#{self.class}] Adding mixin IPNetwork"
39
+ @mixins << Occi::Infrastructure::Network::Ipnetwork.mixin
38
40
  else
39
- mixins.delete Occi::Infrastructure::Network::Ipnetwork.mixin.type_identifier
41
+ Occi::Log.info "[#{self.class}] Removing mixin IPNetwork"
42
+ @mixins.delete Occi::Infrastructure::Network::Ipnetwork.mixin
40
43
  end
41
44
  end
42
45
 
43
46
  def vlan
44
- @attributes.occi.nework.vlan if @attributes.occi.network if @attributes.occi
47
+ @attributes.occi_.network_.vlan
45
48
  end
46
49
 
47
50
  def vlan=(vlan)
@@ -49,7 +52,7 @@ module Occi
49
52
  end
50
53
 
51
54
  def label
52
- @attributes.occi.nework.label if @attributes.occi.network if @attributes.occi
55
+ @attributes.occi_.network_.label
53
56
  end
54
57
 
55
58
  def label=(label)
@@ -57,7 +60,7 @@ module Occi
57
60
  end
58
61
 
59
62
  def state
60
- @attributes.occi.nework.state if @attributes.occi.network if @attributes.occi
63
+ @attributes.occi_.network_.state
61
64
  end
62
65
 
63
66
  def state=(state)
@@ -67,41 +70,38 @@ module Occi
67
70
  # IPNetwork Mixin attributes
68
71
 
69
72
  def address
70
- @attributes.occi.network.address if @attributes.occi.network if @attributes.occi
73
+ @attributes.occi_.network_.address
71
74
  end
72
75
 
73
76
  def address=(address)
74
- if @mixins.select { |mixin| mixin.kind_of? Occi::Infrastructure::Network::Ipnetwork }.empty?
75
- Occi::Log.info 'Adding mixin IPNetwork mixin'
76
- @mixins << Occi::Infrastructure::Network::Ipnetwork.new
77
- end
77
+ add_ipnetwork_mixin
78
78
  @attributes.occi!.network!.address = address
79
79
  end
80
80
 
81
81
  def gateway
82
- @attributes.occi.network.gateway if @attributes.occi.network if @attributes.occi
82
+ @attributes.occi_.network_.gateway
83
83
  end
84
84
 
85
85
  def gateway=(gateway)
86
- if @mixins.select { |mixin| mixin.kind_of? Occi::Infrastructure::Network::Ipnetwork }.empty?
87
- Occi::Log.info 'Adding mixin IP network'
88
- @mixins << Occi::Infrastructure::Network::Ipnetwork.new
89
- end
86
+ add_ipnetwork_mixin
90
87
  @attributes.occi!.network!.gateway = gateway
91
88
  end
92
89
 
93
90
  def allocation
94
- @attributes.occi.network.allocation if @attributes.occi.network if @attributes.occi
91
+ @attributes.occi_.network_.allocation
95
92
  end
96
93
 
97
94
  def allocation=(allocation)
98
- if @mixins.select { |mixin| mixin.kind_of? Occi::Infrastructure::Network::Ipnetwork }.empty?
99
- Occi::Log.info 'Adding mixin IPNetwork mixin'
100
- @mixins << Occi::Infrastructure::Network::Ipnetwork.new
101
- end
95
+ add_ipnetwork_mixin
102
96
  @attributes.occi!.network!.allocation = allocation
103
97
  end
104
98
 
99
+ private
100
+
101
+ def add_ipnetwork_mixin
102
+ ipnetwork(true) if @mixins.select { |mixin| mixin.type_identifier == Occi::Infrastructure::Network::Ipnetwork.mixin.type_identifier }.empty?
103
+ end
104
+
105
105
  end
106
106
  end
107
- end
107
+ end
@@ -12,7 +12,7 @@ module Occi
12
12
 
13
13
  self.actions = Occi::Core::Actions.new << up << down
14
14
 
15
- self.attributes = Occi::Core::Attributes.new
15
+ self.attributes = Occi::Core::Attributes.new(Occi::Core::Link.attributes)
16
16
  self.attributes['occi.networkinterface.interface'] ={:mutable => true}
17
17
  self.attributes['occi.networkinterface.mac'] = {:mutable => true,
18
18
  :pattern => '^([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})$'}
@@ -30,16 +30,18 @@ module Occi
30
30
  require 'occi/infrastructure/networkinterface/ipnetworkinterface'
31
31
  self.mixins = Occi::Core::Mixins.new << Occi::Infrastructure::Networkinterface::Ipnetworkinterface.mixin
32
32
 
33
- def ipnetworkinterface(boolean=true)
34
- if boolean
35
- @mixins << Occi::Infrastructure::Networkinterface::Ipnetworkinterface.type_identifier
33
+ def ipnetworkinterface(add = true)
34
+ if add
35
+ Occi::Log.info "[#{self.class}] Adding mixin IPNetworkInterface"
36
+ @mixins << Occi::Infrastructure::Networkinterface::Ipnetworkinterface.mixin
36
37
  else
37
- mixins.delete Occi::Infrastructure::Networkinterface::Ipnetworkinterface.type_identifier
38
+ Occi::Log.info "[#{self.class}] Removing mixin IPNetworkInterface"
39
+ @mixins.delete Occi::Infrastructure::Networkinterface::Ipnetworkinterface.mixin
38
40
  end
39
41
  end
40
42
 
41
43
  def interface
42
- @attributes.occi.networkinterface.interface if @attributes.occi.networkinterface if @attributes.occi
44
+ @attributes.occi_.networkinterface_.interface
43
45
  end
44
46
 
45
47
  def interface=(interface)
@@ -47,7 +49,7 @@ module Occi
47
49
  end
48
50
 
49
51
  def mac
50
- @attributes.occi.networkinterface.mac if @attributes.occi.networkinterface if @attributes.occi
52
+ @attributes.occi_.networkinterface_.mac
51
53
  end
52
54
 
53
55
  def mac=(mac)
@@ -55,7 +57,7 @@ module Occi
55
57
  end
56
58
 
57
59
  def state
58
- @attributes.occi.networkinterface.state if @attributes.occi.networkinterface if @attributes.occi
60
+ @attributes.occi_.networkinterface_.state
59
61
  end
60
62
 
61
63
  def state=(state)
@@ -63,41 +65,38 @@ module Occi
63
65
  end
64
66
 
65
67
  def address
66
- @attributes.occi.networkinterface.address if @attributes.occi.networkinterface if @attributes.occi
68
+ @attributes.occi_.networkinterface_.address
67
69
  end
68
70
 
69
71
  def address=(address)
70
- if @mixins.select { |mixin| mixin.kind_of? Occi::Infrastructure::Networkinterface::Ipnetworkinterface }.empty?
71
- Occi::Log.info 'Adding mixin IP network interface'
72
- @mixins << Occi::Infrastructure::Networkinterface::Ipnetworkinterface.new
73
- end
72
+ add_ipnetworkinterface_mixin
74
73
  @attributes.occi!.networkinterface!.address = address
75
74
  end
76
75
 
77
76
  def gateway
78
- @attributes.occi.networkinterface.gateway if @attributes.occi.networkinterface if @attributes.occi
77
+ @attributes.occi_.networkinterface_.gateway
79
78
  end
80
79
 
81
80
  def gateway=(gateway)
82
- if @mixins.select { |mixin| mixin.kind_of? Occi::Infrastructure::Networkinterface::Ipnetworkinterface }.empty?
83
- Occi::Log.info 'Adding mixin IP network interface'
84
- @mixins << Occi::Infrastructure::Networkinterface::Ipnetworkinterface.new
85
- end
81
+ add_ipnetworkinterface_mixin
86
82
  @attributes.occi!.networkinterface!.gateway = gateway
87
83
  end
88
84
 
89
85
  def allocation
90
- @attributes.occi.networkinterface.allocation if @attributes.occi.networkinterface if @attributes.occi
86
+ @attributes.occi_.networkinterface_.allocation
91
87
  end
92
88
 
93
89
  def allocation=(allocation)
94
- if @mixins.select { |mixin| mixin.kind_of? Occi::Infrastructure::Networkinterface::Ipnetworkinterface }.empty?
95
- Occi::Log.info 'Adding mixin IP network interface'
96
- @mixins << Occi::Infrastructure::Networkinterface::Ipnetworkinterface.new
97
- end
90
+ add_ipnetworkinterface_mixin
98
91
  @attributes.occi!.networkinterface!.allocation = allocation
99
92
  end
100
93
 
94
+ private
95
+
96
+ def add_ipnetworkinterface_mixin
97
+ ipnetworkinterface(true) if @mixins.select { |mixin| mixin.type_identifier == Occi::Infrastructure::Networkinterface::Ipnetworkinterface.mixin.type_identifier }.empty?
98
+ end
99
+
101
100
  end
102
101
  end
103
102
  end
@@ -1,6 +1,6 @@
1
1
  module Occi
2
2
  module Infrastructure
3
- module Os_tpl
3
+ module OsTpl
4
4
 
5
5
  mattr_accessor :attributes, :mixin
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Occi
2
2
  module Infrastructure
3
- module Resource_tpl
3
+ module ResourceTpl
4
4
 
5
5
  mattr_accessor :attributes, :mixin
6
6
 
@@ -26,9 +26,10 @@ module Occi
26
26
 
27
27
  self.actions = Occi::Core::Actions.new << online << offline << backup << snapshot << resize
28
28
 
29
- self.attributes = Occi::Core::Attributes.new
29
+ self.attributes = Occi::Core::Attributes.new(Occi::Core::Resource.attributes)
30
30
  self.attributes['occi.storage.size'] = {:type => 'number',
31
- :mutable => true}
31
+ :mutable => true,
32
+ :pattern => '\d+' }
32
33
  self.attributes['occi.storage.state'] = {:pattern => 'online|offline|backup|snapshot|resize|degraded',
33
34
  :default => 'offline'}
34
35
 
@@ -41,15 +42,15 @@ module Occi
41
42
  location = '/storage/'
42
43
 
43
44
  def size
44
- @attributes.occi.storage.size if @attributes.occi.storage if @attributes.occi
45
+ @attributes.occi_.storage_['size']
45
46
  end
46
47
 
47
48
  def size=(size)
48
- @attributes.occi!.storage!.size = size
49
+ @attributes.occi!.storage!['size'] = size
49
50
  end
50
51
 
51
52
  def state
52
- @attributes.occi.storage.state if @attributes.occi.storage if @attributes.occi
53
+ @attributes.occi_.storage_.state
53
54
  end
54
55
 
55
56
  def state=(state)
@@ -58,4 +59,4 @@ module Occi
58
59
 
59
60
  end
60
61
  end
61
- end
62
+ end
@@ -12,7 +12,7 @@ module Occi
12
12
 
13
13
  self.actions = Occi::Core::Actions.new << online << offline
14
14
 
15
- self.attributes = Occi::Core::Attributes.new
15
+ self.attributes = Occi::Core::Attributes.new(Occi::Core::Link.attributes)
16
16
  self.attributes['occi.storagelink.deviceid'] = {:mutable => true}
17
17
  self.attributes['occi.storagelink.mountpoint'] = {:mutable => true}
18
18
  self.attributes['occi.storagelink.state'] = {:pattern => 'active|inactive|error',
@@ -28,7 +28,7 @@ module Occi
28
28
 
29
29
 
30
30
  def deviceid
31
- @attributes.occi.storagelink.deviceid if @attributes.occi.storagelink if @attributes.occi
31
+ @attributes.occi_.storagelink_.deviceid
32
32
  end
33
33
 
34
34
  def deviceid=(deviceid)
@@ -36,7 +36,7 @@ module Occi
36
36
  end
37
37
 
38
38
  def mountpoint
39
- @attributes.occi.storagelink.mountpoint if @attributes.occi.storagelink if @attributes.occi
39
+ @attributes.occi_.storagelink_.mountpoint
40
40
  end
41
41
 
42
42
  def mountpoint=(mountpoint)
@@ -44,7 +44,7 @@ module Occi
44
44
  end
45
45
 
46
46
  def state
47
- @attributes.occi.storagelink.state if @attributes.occi.storagelink if @attributes.occi
47
+ @attributes.occi_.storagelink_.state
48
48
  end
49
49
 
50
50
  def state=(state)