omf_sfa 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +24 -0
- data/Gemfile +6 -0
- data/README.md +211 -0
- data/Rakefile +23 -0
- data/bin/parse_rspec.rb +167 -0
- data/etc/omf-sfa/omf-sfa-am.yaml +12 -0
- data/examples/exogeni5nodemanifest.rspec +105 -0
- data/examples/instageni5nodemanifest.rspec +150 -0
- data/lib/omf-sfa/am/am-rest/REST_API.md +301 -0
- data/lib/omf-sfa/am/am-rest/account_handler.rb +145 -0
- data/lib/omf-sfa/am/am-rest/am_rest_server.rb +255 -0
- data/lib/omf-sfa/am/am-rest/api_template.html +48 -0
- data/lib/omf-sfa/am/am-rest/config.ru +110 -0
- data/lib/omf-sfa/am/am-rest/resource_handler.rb +178 -0
- data/lib/omf-sfa/am/am-rest/rest_handler.rb +573 -0
- data/lib/omf-sfa/am/am-rest/session_authenticator.rb +130 -0
- data/lib/omf-sfa/am/am-rpc/abstract_rpc_service.rb +60 -0
- data/lib/omf-sfa/am/am-rpc/am_authorizer.rb +161 -0
- data/lib/omf-sfa/am/am-rpc/am_rpc_api.rb +450 -0
- data/lib/omf-sfa/am/am-rpc/am_rpc_service.rb +402 -0
- data/lib/omf-sfa/am/am_liaison.rb +93 -0
- data/lib/omf-sfa/am/am_manager.rb +859 -0
- data/lib/omf-sfa/am/am_runner.rb +108 -0
- data/lib/omf-sfa/am/am_scheduler.rb +146 -0
- data/lib/omf-sfa/am/am_server.rb +194 -0
- data/lib/omf-sfa/am/config.ru +122 -0
- data/lib/omf-sfa/am/credential.rb +145 -0
- data/lib/omf-sfa/am/default_authorizer.rb +44 -0
- data/lib/omf-sfa/am/privilege_credential.rb +76 -0
- data/lib/omf-sfa/am/signature.rb +37 -0
- data/lib/omf-sfa/am/user_credential.rb +56 -0
- data/lib/omf-sfa/am.rb +7 -0
- data/lib/omf-sfa/model/abstract_prop_description.rb +87 -0
- data/lib/omf-sfa/model/model_class_description.rb +145 -0
- data/lib/omf-sfa/model/model_data_prop_description.rb +28 -0
- data/lib/omf-sfa/model/model_obj_prop_description.rb +49 -0
- data/lib/omf-sfa/model/ontology.rb +169 -0
- data/lib/omf-sfa/resource/README.md +24 -0
- data/lib/omf-sfa/resource/channel.rb +49 -0
- data/lib/omf-sfa/resource/comp_group.rb +41 -0
- data/lib/omf-sfa/resource/component_lease.rb +10 -0
- data/lib/omf-sfa/resource/constants.rb +24 -0
- data/lib/omf-sfa/resource/group_component.rb +35 -0
- data/lib/omf-sfa/resource/group_membership.rb +17 -0
- data/lib/omf-sfa/resource/gurn.rb +187 -0
- data/lib/omf-sfa/resource/interface.rb +78 -0
- data/lib/omf-sfa/resource/ip.rb +48 -0
- data/lib/omf-sfa/resource/link.rb +29 -0
- data/lib/omf-sfa/resource/node.rb +75 -0
- data/lib/omf-sfa/resource/oaccount.rb +94 -0
- data/lib/omf-sfa/resource/ocomponent.rb +134 -0
- data/lib/omf-sfa/resource/ogroup.rb +106 -0
- data/lib/omf-sfa/resource/olease.rb +61 -0
- data/lib/omf-sfa/resource/oproperty.rb +178 -0
- data/lib/omf-sfa/resource/oreference.rb +15 -0
- data/lib/omf-sfa/resource/oresource.rb +491 -0
- data/lib/omf-sfa/resource/project.rb +28 -0
- data/lib/omf-sfa/resource/project_membership.rb +13 -0
- data/lib/omf-sfa/resource/sfa_base.rb +544 -0
- data/lib/omf-sfa/resource/user.rb +25 -0
- data/lib/omf-sfa/resource.rb +20 -0
- data/lib/omf-sfa/util/create_sample_testbed.rb +68 -0
- data/lib/omf-sfa/util/load_from_sfa_xml.rb +65 -0
- data/lib/omf-sfa/version.rb +4 -0
- data/lib/omf_sfa.rb +5 -0
- data/omf_sfa.gemspec +46 -0
- data/owl/README +3 -0
- data/owl/ben-6509.rdf +1377 -0
- data/owl/ben-dell.rdf +586 -0
- data/owl/ben-dtn.rdf +1698 -0
- data/owl/ben.rdf +1335 -0
- data/owl/collections.owl +309 -0
- data/owl/compute.owl +1486 -0
- data/owl/domain.owl +444 -0
- data/owl/dtn.owl +1165 -0
- data/owl/ec2.owl +385 -0
- data/owl/ethernet.owl +466 -0
- data/owl/eucalyptus.owl +431 -0
- data/owl/id-mp-Request1.rdf +247 -0
- data/owl/itu-grid.owl +147 -0
- data/owl/kansei.owl +511 -0
- data/owl/layer.owl +645 -0
- data/owl/location.owl +117 -0
- data/owl/mass.rdf +608 -0
- data/owl/nlr.rdf +901 -0
- data/owl/orca.owl +181 -0
- data/owl/planetlab.owl +124 -0
- data/owl/protogeni.owl +467 -0
- data/owl/request-6509-2.rdf +150 -0
- data/owl/request-6509-3.rdf +158 -0
- data/owl/request-6509.rdf +199 -0
- data/owl/request.owl +222 -0
- data/owl/storage.owl +511 -0
- data/owl/topology.owl +608 -0
- data/schema/rspec-v3/ad-common.xsd +269 -0
- data/schema/rspec-v3/ad-reservation.rnc +12 -0
- data/schema/rspec-v3/ad-reservation.rng +28 -0
- data/schema/rspec-v3/ad-reservation.xsd +13 -0
- data/schema/rspec-v3/ad.rnc +151 -0
- data/schema/rspec-v3/ad.xsd +77 -0
- data/schema/rspec-v3/any-extension-schema.xsd +38 -0
- data/schema/rspec-v3/any-extension.rnc +30 -0
- data/schema/rspec-v3/common.rnc +185 -0
- data/schema/rspec-v3/manifest-common.xsd +244 -0
- data/schema/rspec-v3/manifest-request.xsd +95 -0
- data/schema/rspec-v3/manifest.rnc +62 -0
- data/schema/rspec-v3/manifest.xsd +34 -0
- data/schema/rspec-v3/request-common.xsd +219 -0
- data/schema/rspec-v3/request-reservation.rnc +12 -0
- data/schema/rspec-v3/request-reservation.xsd +13 -0
- data/schema/rspec-v3/request.rnc +118 -0
- data/schema/rspec-v3/request.xsd +94 -0
- data/share/assets/css/default.css +147 -0
- data/share/assets/css/rest_api.css +0 -0
- data/share/assets/network.html +28 -0
- data/share/assets/network.js +82 -0
- data/spec/am/am-rest/common.rb +29 -0
- data/spec/am/am-rest/resource_group_handler_XspecX.rb +97 -0
- data/spec/am/am-rest/resource_handler_spec.rb +204 -0
- data/spec/am/am-rpc/sfa_methods_spec.rb +150 -0
- data/spec/am/am_manager_spec.rb +307 -0
- data/spec/am/am_scheduler_spec.rb +57 -0
- data/spec/am/common.rb +24 -0
- data/spec/resource/common.rb +31 -0
- data/spec/resource/node_spec.rb +171 -0
- data/spec/resource/oaccount_spec.rb +92 -0
- data/spec/resource/ocomponent_spec.rb +225 -0
- data/spec/resource/ogroup_spec.rb +93 -0
- data/spec/resource/oresource_spec.rb +208 -0
- data/spec/resource_and_leases_spec.rb +377 -0
- data/test/OLD_FILES/assertion1.xml +117 -0
- data/test/OLD_FILES/greeter_spec.rb +15 -0
- data/test/OLD_FILES/mongo_test.rb +45 -0
- data/test/OLD_FILES/req-sfa-2.xml +6 -0
- data/test/OLD_FILES/req-sfa-g.xml +8 -0
- data/test/OLD_FILES/req-sfa-g2.xml +10 -0
- data/test/OLD_FILES/req-sfa-g3.xml +14 -0
- data/test/OLD_FILES/req-sfa.xml +6 -0
- data/test/OLD_FILES/req1.xml +22 -0
- data/test/OLD_FILES/req1b.xml +15 -0
- data/test/OLD_FILES/rspec-test.xml +1867 -0
- data/test/OLD_FILES/test.rb +67 -0
- data/test/OLD_FILES/test2.rb +32 -0
- data/test/am/am_manager_rspec_tests.rb +378 -0
- data/test/am/am_manager_tests.rb +518 -0
- data/test/am/am_scheduler_tests.rb +173 -0
- data/test/resource/olease_test.rb +74 -0
- data/test/sfa_requests/request.xml +5 -0
- data/test/sfa_requests/request1.xml +5 -0
- data/test/sfa_requests/request2.xml +5 -0
- data/test/sfa_requests/request3.xml +5 -0
- metadata +601 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'time'
|
|
4
|
+
require 'omf_base/lobject'
|
|
5
|
+
|
|
6
|
+
require 'omf-sfa/resource/gurn'
|
|
7
|
+
require 'omf-sfa/resource/constants'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
module OMF::SFA
|
|
12
|
+
module Resource
|
|
13
|
+
|
|
14
|
+
module Base
|
|
15
|
+
|
|
16
|
+
SFA_NAMESPACE_URI = "http://www.geni.net/resources/rspec/3"
|
|
17
|
+
|
|
18
|
+
module ClassMethods
|
|
19
|
+
|
|
20
|
+
def default_domain()
|
|
21
|
+
Constants.default_domain
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def default_component_manager_id()
|
|
25
|
+
Constants.default_component_manager_id
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
@@sfa_defs = {}
|
|
29
|
+
@@sfa_namespaces = {}
|
|
30
|
+
@@sfa_classes = {}
|
|
31
|
+
@@sfa_name2class = {}
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# @opts
|
|
35
|
+
# :namespace
|
|
36
|
+
#
|
|
37
|
+
def sfa_class(name = nil, opts = {})
|
|
38
|
+
if name
|
|
39
|
+
name = _sfa_add_ns(name, opts)
|
|
40
|
+
#sfa_defs()['_class_'] = name
|
|
41
|
+
@@sfa_classes[self] = name
|
|
42
|
+
@@sfa_name2class[name] = self
|
|
43
|
+
else
|
|
44
|
+
@@sfa_classes[self]
|
|
45
|
+
#sfa_def_for('_class_')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def sfa_add_namespace(prefix, urn)
|
|
50
|
+
@@sfa_namespaces[prefix] = urn
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def sfa_add_namespaces_to_document(doc)
|
|
54
|
+
root = doc.root
|
|
55
|
+
root.add_namespace(nil, SFA_NAMESPACE_URI)
|
|
56
|
+
@@sfa_namespaces.each do |name, uri|
|
|
57
|
+
root.add_namespace(name.to_s, uri) #'omf', 'http://tenderlovemaking.com')
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Define a SFA property
|
|
62
|
+
#
|
|
63
|
+
# @param [Symbol] name name of resource in RSpec
|
|
64
|
+
# @param [Hash] opts options to further describe mappings
|
|
65
|
+
# @option opts [Boolean] :inline ????
|
|
66
|
+
# @option opts [Boolean] :has_manny If true, can occur multiple time forming an array
|
|
67
|
+
# @option opts [Boolean] :attribute If true, ????
|
|
68
|
+
# @option opts [String] :attr_value ????
|
|
69
|
+
#
|
|
70
|
+
def sfa(name, opts = {})
|
|
71
|
+
name = name.to_s
|
|
72
|
+
props = sfa_defs() # get all the sfa properties of this class
|
|
73
|
+
props[name] = opts
|
|
74
|
+
# recalculate sfa properties of the descendants
|
|
75
|
+
descendants.each do |c| c.sfa_defs(false) end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# opts:
|
|
79
|
+
# :valid_for - valid [sec] from now
|
|
80
|
+
#
|
|
81
|
+
def sfa_advertisement_xml(resources, opts = {})
|
|
82
|
+
doc = Nokogiri::XML::Document.new
|
|
83
|
+
#<rspec expires="2011-09-13T09:07:09Z" generated="2011-09-13T09:07:09Z" type="advertisement" xmlns="http://www.geni.net/resources/rspec/3" xmlns:ol="http://nitlab.inf.uth.gr/schema/sfa/rspec/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/ad.xsd http://nitlab.inf.uth.gr/schema/sfa/rspec/1 http://nitlab.inf.uth.gr/schema/sfa/rspec/1/ad-reservation.xsd">
|
|
84
|
+
root = doc.add_child(Nokogiri::XML::Element.new('rspec', doc))
|
|
85
|
+
root.add_namespace(nil, SFA_NAMESPACE_URI)
|
|
86
|
+
root.add_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
|
|
87
|
+
|
|
88
|
+
opts[:type] = 'advertisement' unless opts[:type]
|
|
89
|
+
if opts[:type] == 'manifest'
|
|
90
|
+
schema = 'manifest.xsd'
|
|
91
|
+
else
|
|
92
|
+
schema = 'ad.xsd'
|
|
93
|
+
end
|
|
94
|
+
root['xsi:schemaLocation'] = "#{SFA_NAMESPACE_URI} #{SFA_NAMESPACE_URI}/#{schema} #{@@sfa_namespaces[:ol]} #{@@sfa_namespaces[:ol]}/ad-reservation.xsd"
|
|
95
|
+
@@sfa_namespaces.each do |prefix, urn|
|
|
96
|
+
root.add_namespace(prefix.to_s, urn)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
root.set_attribute('type', opts[:type])
|
|
100
|
+
now = Time.now
|
|
101
|
+
root.set_attribute('generated', now.iso8601)
|
|
102
|
+
root.set_attribute('expires', (now + (opts[:valid_for] || 600)).iso8601)
|
|
103
|
+
|
|
104
|
+
#root = doc.create_element('rspec', doc)
|
|
105
|
+
#doc.add_child root
|
|
106
|
+
obj2id = {}
|
|
107
|
+
_to_sfa_xml(resources, root, obj2id, opts)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def from_sfa(resource_el, context = {})
|
|
111
|
+
resource = nil
|
|
112
|
+
uuid = nil
|
|
113
|
+
comp_gurn = nil
|
|
114
|
+
|
|
115
|
+
unless resource_el.namespace.href == SFA_NAMESPACE_URI
|
|
116
|
+
warn "WARNING: '#{resource_el.name}' Can't handle non-default namespaces '#{resource_el.namespace.href}'"
|
|
117
|
+
return
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
client_id_attr = resource_el.attributes['client_id']
|
|
121
|
+
client_id = client_id_attr ? client_id_attr.value : nil
|
|
122
|
+
|
|
123
|
+
if uuid_attr = (resource_el.attributes['uuid'] || resource_el.attributes['idref'])
|
|
124
|
+
uuid = UUIDTools::UUID.parse(uuid_attr.value)
|
|
125
|
+
if resource = OMF::SFA::Resource::OResource.first(:uuid => uuid)
|
|
126
|
+
context[client_id] = resource if client_id
|
|
127
|
+
return resource.from_sfa(resource_el, context)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
if comp_id_attr = resource_el.attributes['component_id']
|
|
132
|
+
comp_id = comp_id_attr.value
|
|
133
|
+
comp_gurn = OMF::SFA::Resource::GURN.parse(comp_id)
|
|
134
|
+
#begin
|
|
135
|
+
if uuid = comp_gurn.uuid
|
|
136
|
+
resource = OMF::SFA::Resource::OResource.first(:uuid => uuid)
|
|
137
|
+
context[client_id] = resource if client_id
|
|
138
|
+
return resource.from_sfa(resource_el, context)
|
|
139
|
+
end
|
|
140
|
+
if resource = OMF::SFA::Resource::OComponent.first(:urn => comp_gurn)
|
|
141
|
+
context[client_id] = resource if client_id
|
|
142
|
+
return resource.from_sfa(resource_el, context)
|
|
143
|
+
end
|
|
144
|
+
else
|
|
145
|
+
# need to create a comp_gurn (the link is an example of that)
|
|
146
|
+
unless sliver_id_attr = resource_el.attributes['sliver_id']
|
|
147
|
+
raise "Need 'sliver_id' for resource '#{resource_el}'"
|
|
148
|
+
end
|
|
149
|
+
sliver_gurn = OMF::SFA::Resource::GURN.parse(sliver_id_attr.value)
|
|
150
|
+
unless client_id
|
|
151
|
+
raise "Need 'client_id' for resource '#{resource_el}'"
|
|
152
|
+
end
|
|
153
|
+
opts = {
|
|
154
|
+
:domain => sliver_gurn.domain,
|
|
155
|
+
:type => resource_el.name # TODO: This most likely will break with NS
|
|
156
|
+
}
|
|
157
|
+
comp_gurn = OMF::SFA::Resource::GURN.create("#{sliver_gurn.short_name}:#{client_id}", opts)
|
|
158
|
+
if resource = OMF::SFA::Resource::OComponent.first(:urn => comp_gurn)
|
|
159
|
+
context[client_id] = resource if client_id
|
|
160
|
+
return resource.from_sfa(resource_el, context)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Appears the resource doesn't exist yet, let's see if we can create one
|
|
165
|
+
type = comp_gurn.type
|
|
166
|
+
if res_class = @@sfa_name2class[type]
|
|
167
|
+
resource = res_class.new(:name => comp_gurn.short_name)
|
|
168
|
+
context[client_id] = resource if client_id
|
|
169
|
+
return resource.from_sfa(resource_el, context)
|
|
170
|
+
end
|
|
171
|
+
raise "Unknown resource type '#{type}' (#{@@sfa_name2class.keys.join(', ')})"
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def _to_sfa_xml(resources, root, obj2id, opts = {})
|
|
175
|
+
#puts "RRRXXX> #{resources}"
|
|
176
|
+
if resources.kind_of? Enumerable
|
|
177
|
+
#puts "RRRXXX2> #{resources}"
|
|
178
|
+
resources.each do |r|
|
|
179
|
+
#puts "R3> #{r}"
|
|
180
|
+
_to_sfa_xml(r, root, obj2id, opts)
|
|
181
|
+
end
|
|
182
|
+
# elsif resources.kind_of? OMF::SFA::Resource::OGroup
|
|
183
|
+
# # NOTE: Should be adding a GROUP element!
|
|
184
|
+
# resources.each_resource do |r|
|
|
185
|
+
# _to_sfa_xml(r, root, obj2id, opts)
|
|
186
|
+
# end
|
|
187
|
+
else
|
|
188
|
+
resources.to_sfa_xml(root, obj2id, opts)
|
|
189
|
+
end
|
|
190
|
+
root.document
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Return all the property definitions for this class.
|
|
194
|
+
#
|
|
195
|
+
# +cached+ - If false, recalculate
|
|
196
|
+
#
|
|
197
|
+
def sfa_defs(cached = true)
|
|
198
|
+
unless cached && props = @@sfa_defs[self]
|
|
199
|
+
# this assumes that all the properties of the super classes are already set
|
|
200
|
+
props = {}
|
|
201
|
+
klass = self
|
|
202
|
+
while klass = klass.superclass
|
|
203
|
+
if sp = @@sfa_defs[klass]
|
|
204
|
+
props = sp.merge(props)
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
#puts "PROP #{self}:#{props.keys.inspect}"
|
|
208
|
+
@@sfa_defs[self] = props
|
|
209
|
+
end
|
|
210
|
+
props
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def sfa_def_for(name)
|
|
214
|
+
sfa_defs()[name.to_s]
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def sfa_cast_property_value(value, property_name, context, type = nil)
|
|
218
|
+
name = property_name.to_s
|
|
219
|
+
unless type
|
|
220
|
+
pdef = sfa_def_for(name)
|
|
221
|
+
raise "Unknow SFA property '#{name}'" unless pdef
|
|
222
|
+
type = pdef[:type]
|
|
223
|
+
end
|
|
224
|
+
if type.kind_of?(Symbol)
|
|
225
|
+
if type == :boolean
|
|
226
|
+
unless value.kind_of?(TrueClass) || value.kind_of?(FalseClass)
|
|
227
|
+
raise "Wrong type for '#{name}', is #{value.type}, but should be #{type}"
|
|
228
|
+
end
|
|
229
|
+
else
|
|
230
|
+
raise "Unknown type '#{type}', use real Class"
|
|
231
|
+
end
|
|
232
|
+
elsif !(value.kind_of?(type))
|
|
233
|
+
if type.respond_to? :sfa_create
|
|
234
|
+
value = type.sfa_create(value, context)
|
|
235
|
+
else
|
|
236
|
+
raise "Wrong type for '#{name}', is #{value.class}, but should be #{type}"
|
|
237
|
+
end
|
|
238
|
+
# puts "XXX>>> #{name}--#{! value.kind_of?(type)}--#{value.class}||#{type}||#{pdef.inspect}"
|
|
239
|
+
|
|
240
|
+
end
|
|
241
|
+
value
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def _sfa_add_ns(name, opts = {})
|
|
245
|
+
if ns = opts[:namespace]
|
|
246
|
+
unless @@sfa_namespaces[ns]
|
|
247
|
+
raise "Unknown namespace '#{ns}'"
|
|
248
|
+
end
|
|
249
|
+
name = "#{ns}:#{name}"
|
|
250
|
+
end
|
|
251
|
+
name
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def descendants
|
|
255
|
+
result = []
|
|
256
|
+
ObjectSpace.each_object(Class) do |klass|
|
|
257
|
+
result = result << klass if klass < self
|
|
258
|
+
end
|
|
259
|
+
result
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
end # ClassMethods
|
|
263
|
+
|
|
264
|
+
module InstanceMethods
|
|
265
|
+
|
|
266
|
+
def resource_type
|
|
267
|
+
sfa_class
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def component_id
|
|
271
|
+
unless id = attribute_get(:component_id)
|
|
272
|
+
#self.component_id ||= GURN.create(self.uuid.to_s, self)
|
|
273
|
+
#return GURN.create(self.uuid.to_s, { :model => self.class })
|
|
274
|
+
return GURN.create(self.urn, { :model => self.class })
|
|
275
|
+
end
|
|
276
|
+
id
|
|
277
|
+
end
|
|
278
|
+
#
|
|
279
|
+
# def component_id=(value)
|
|
280
|
+
# self.component_uuid = value
|
|
281
|
+
# end
|
|
282
|
+
|
|
283
|
+
def component_manager_id
|
|
284
|
+
unless uuid = attribute_get(:component_manager_id)
|
|
285
|
+
return (self.class.default_component_manager_id ||= GURN.create("authority+am"))
|
|
286
|
+
end
|
|
287
|
+
uuid
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# def component_name
|
|
291
|
+
# self.name || 'unknown'
|
|
292
|
+
# end
|
|
293
|
+
|
|
294
|
+
def default_domain
|
|
295
|
+
self.class.default_domain()
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
# def sfa_id=(id)
|
|
300
|
+
# @sfa_id = id
|
|
301
|
+
# end
|
|
302
|
+
|
|
303
|
+
def sfa_id()
|
|
304
|
+
#@sfa_id ||= "c#{object_id}"
|
|
305
|
+
self.uuid.to_s
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def sfa_class()
|
|
309
|
+
self.class.sfa_class()
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# def sfa_property_set(name, value)
|
|
313
|
+
# value = self.class.sfa_cast_property_value(value, name, self)
|
|
314
|
+
# instance_variable_set("sfa_#{name}", value)
|
|
315
|
+
# end
|
|
316
|
+
|
|
317
|
+
def sfa_property(name)
|
|
318
|
+
instance_variable_get("sfa_#{name}")
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def _xml_name()
|
|
322
|
+
if pd = self.sfa_class
|
|
323
|
+
return pd
|
|
324
|
+
end
|
|
325
|
+
self.class.name.gsub('::', '_')
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def to_sfa_short_xml(parent)
|
|
329
|
+
n = parent.add_child(Nokogiri::XML::Element.new('resource', parent.document))
|
|
330
|
+
n.set_attribute('type', _xml_name())
|
|
331
|
+
n.set_attribute('status', 'unimplemented')
|
|
332
|
+
n.set_attribute('name', component_name())
|
|
333
|
+
n
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
#
|
|
337
|
+
# Return all SFA related properties as a hash
|
|
338
|
+
#
|
|
339
|
+
# +opts+
|
|
340
|
+
# :detail - detail to reveal about resource 0..min, 99 .. max
|
|
341
|
+
#
|
|
342
|
+
def to_sfa_hash(href2obj = {}, opts = {})
|
|
343
|
+
res = to_sfa_hash_short(opts)
|
|
344
|
+
res['comp_gurn'] = self.urn
|
|
345
|
+
href = res['href']
|
|
346
|
+
if obj = href2obj[href]
|
|
347
|
+
# have described myself before
|
|
348
|
+
raise "Different object with same href '#{href}'" unless obj == self
|
|
349
|
+
return res
|
|
350
|
+
end
|
|
351
|
+
href2obj[href] = self
|
|
352
|
+
|
|
353
|
+
defs = self.class.sfa_defs()
|
|
354
|
+
#puts ">> #{defs.inspect}"
|
|
355
|
+
defs.keys.sort.each do |k|
|
|
356
|
+
next if k.start_with?('_')
|
|
357
|
+
pdef = defs[k]
|
|
358
|
+
pname = pdef[:prop_name] ||k
|
|
359
|
+
v = send(pname.to_sym)
|
|
360
|
+
if v.nil?
|
|
361
|
+
v = pdef[:default]
|
|
362
|
+
end
|
|
363
|
+
#puts "!#{k} => '#{v}' - #{self}"
|
|
364
|
+
unless v.nil?
|
|
365
|
+
m = "_to_sfa_#{k}_property_hash".to_sym
|
|
366
|
+
if self.respond_to? m
|
|
367
|
+
res[k] = send(m, v, pdef, href2obj, opts)
|
|
368
|
+
#puts ">>>> #{k}::#{res[k]}"
|
|
369
|
+
else
|
|
370
|
+
res[k] = _to_sfa_property_hash(v, pdef, href2obj, opts)
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
res
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
def to_sfa_hash_short(opts = {})
|
|
378
|
+
uuid = self.uuid.to_s
|
|
379
|
+
href_prefix = opts[:href_prefix] ||= default_href_prefix
|
|
380
|
+
{
|
|
381
|
+
'name' => self.name,
|
|
382
|
+
'uuid' => uuid,
|
|
383
|
+
'sfa_class' => sfa_class(),
|
|
384
|
+
'href' => "#{href_prefix}/#{uuid}"
|
|
385
|
+
}
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
def _to_sfa_property_hash(value, pdef, href2obj, opts)
|
|
389
|
+
if !value.kind_of?(String) && value.kind_of?(Enumerable)
|
|
390
|
+
value.collect do |o|
|
|
391
|
+
if o.respond_to? :to_sfa_hash
|
|
392
|
+
o.to_sfa_hash_short(opts)
|
|
393
|
+
else
|
|
394
|
+
o.to_s
|
|
395
|
+
end
|
|
396
|
+
end
|
|
397
|
+
else
|
|
398
|
+
value.to_s
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
#
|
|
403
|
+
# +opts+
|
|
404
|
+
# :detail - detail to reveal about resource 0..min, 99 .. max
|
|
405
|
+
#
|
|
406
|
+
def to_sfa_xml(parent = nil, obj2id = {}, opts = {})
|
|
407
|
+
if parent.nil?
|
|
408
|
+
parent = Nokogiri::XML::Document.new
|
|
409
|
+
end
|
|
410
|
+
_to_sfa_xml(parent, obj2id, opts)
|
|
411
|
+
parent
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
def _to_sfa_xml(parent, obj2id, opts)
|
|
415
|
+
new_element = parent.add_child(Nokogiri::XML::Element.new(_xml_name(), parent.document))
|
|
416
|
+
if parent.document == parent
|
|
417
|
+
# first time around, add namespace
|
|
418
|
+
self.class.sfa_add_namespaces_to_document(parent)
|
|
419
|
+
end
|
|
420
|
+
defs = self.class.sfa_defs()
|
|
421
|
+
if (id = obj2id[self])
|
|
422
|
+
new_element.set_attribute('idref', id)
|
|
423
|
+
return parent
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
id = sfa_id()
|
|
427
|
+
obj2id[self] = id
|
|
428
|
+
new_element.set_attribute('id', id) #if detail_level > 0
|
|
429
|
+
#if href = self.href(opts)
|
|
430
|
+
# new_element.set_attribute('omf:href', href)
|
|
431
|
+
#end
|
|
432
|
+
level = opts[:level] ? opts[:level] : 0
|
|
433
|
+
opts[:level] = level + 1
|
|
434
|
+
defs.keys.sort.each do |key|
|
|
435
|
+
next if key.start_with?('_')
|
|
436
|
+
pdef = defs[key]
|
|
437
|
+
if (ilevel = pdef[:include_level])
|
|
438
|
+
#next if level > ilevel
|
|
439
|
+
end
|
|
440
|
+
#puts ">>>> #{k} <#{self}> #{pdef.inspect}"
|
|
441
|
+
value = send(key.to_sym)
|
|
442
|
+
#puts "#{k} <#{v}> #{pdef.inspect}"
|
|
443
|
+
if value.nil?
|
|
444
|
+
value = pdef[:default]
|
|
445
|
+
end
|
|
446
|
+
unless value.nil?
|
|
447
|
+
#if detail_level > 0 || k == 'component_name'
|
|
448
|
+
if value.is_a?(Time)
|
|
449
|
+
value = value.xmlschema # xs:dateTime
|
|
450
|
+
end
|
|
451
|
+
_to_sfa_property_xml(key, value, new_element, pdef, obj2id, opts)
|
|
452
|
+
#end
|
|
453
|
+
end
|
|
454
|
+
end
|
|
455
|
+
opts[:level] = level # restore original level
|
|
456
|
+
new_element
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
def _to_sfa_property_xml(pname, value, res_el, pdef, obj2id, opts)
|
|
460
|
+
pname = self.class._sfa_add_ns(pname, pdef)
|
|
461
|
+
if pdef[:attribute]
|
|
462
|
+
res_el.set_attribute(pname, value.to_s)
|
|
463
|
+
elsif aname = pdef[:attr_value]
|
|
464
|
+
el = res_el.add_child(Nokogiri::XML::Element.new(pname, res_el.document))
|
|
465
|
+
el.set_attribute(aname, value.to_s)
|
|
466
|
+
else
|
|
467
|
+
if pdef[:inline] == true
|
|
468
|
+
cel = res_el
|
|
469
|
+
else
|
|
470
|
+
cel = res_el.add_child(Nokogiri::XML::Element.new(pname, res_el.document))
|
|
471
|
+
end
|
|
472
|
+
if !value.kind_of?(String) && value.kind_of?(Enumerable)
|
|
473
|
+
value.each do |v|
|
|
474
|
+
if v.respond_to?(:to_sfa_xml)
|
|
475
|
+
v.to_sfa_xml(cel, obj2id, opts)
|
|
476
|
+
else
|
|
477
|
+
el = cel.add_child(Nokogiri::XML::Element.new(pname, cel.document))
|
|
478
|
+
#puts (el.methods - Object.new.methods).sort.inspect
|
|
479
|
+
el.content = v.to_s
|
|
480
|
+
#el.set_attribute('type', (pdef[:type] || 'string').to_s)
|
|
481
|
+
end
|
|
482
|
+
end
|
|
483
|
+
else
|
|
484
|
+
cel.content = value.to_s
|
|
485
|
+
#cel.set_attribute('type', (pdef[:type] || 'string').to_s)
|
|
486
|
+
end
|
|
487
|
+
end
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
#
|
|
491
|
+
# @param context Already defined resources in this context
|
|
492
|
+
#
|
|
493
|
+
def from_sfa(resource_el, context = {})
|
|
494
|
+
els = {} # this doesn't work with generic namespaces
|
|
495
|
+
resource_el.children.each do |el|
|
|
496
|
+
next unless el.is_a? Nokogiri::XML::Element
|
|
497
|
+
unless ns = el.namespace
|
|
498
|
+
raise "Missing namespace declaration for '#{el}'"
|
|
499
|
+
end
|
|
500
|
+
unless ns.href == SFA_NAMESPACE_URI
|
|
501
|
+
warn "WARNING: '#{el.name}' Can't handle non-default namespaces '#{ns.href}'"
|
|
502
|
+
next
|
|
503
|
+
end
|
|
504
|
+
(els[el.name] ||= []) << el
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
#puts ">>>>> #{self} - #{self.class.sfa_defs.keys}"
|
|
508
|
+
self.class.sfa_defs.each do |name, props|
|
|
509
|
+
mname = "_from_sfa_#{name}_property_xml".to_sym
|
|
510
|
+
#puts "#{self}; Checking for #{mname} - #{props[:attribute]} - #{self.respond_to?(mname)}"
|
|
511
|
+
if self.respond_to?(mname)
|
|
512
|
+
send(mname, resource_el, props, context)
|
|
513
|
+
elsif props[:attribute] == true
|
|
514
|
+
#puts "Checking '#{name}'"
|
|
515
|
+
next if name.to_s == 'component_name' # skip that one for the moment
|
|
516
|
+
if v = resource_el.attributes[props[:attribute_name] || name]
|
|
517
|
+
#puts "#{name}::#{name.class} = #{v}--#{v.class} (#{props})"
|
|
518
|
+
name = props[:prop_name] || name
|
|
519
|
+
send("#{name}=".to_sym, v.value)
|
|
520
|
+
end
|
|
521
|
+
elsif arr = els[name.to_s]
|
|
522
|
+
#puts "Handling #{name} -- #{props}"
|
|
523
|
+
name = props[:prop_name] || name
|
|
524
|
+
arr.each do |el|
|
|
525
|
+
#puts "#{self}: #{name} = #{el.text}"
|
|
526
|
+
send("#{name}=".to_sym, el.text)
|
|
527
|
+
end
|
|
528
|
+
# else
|
|
529
|
+
# puts "Don't know how to handle '#{name}' (#{props})"
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
unless self.save
|
|
533
|
+
raise "Couldn't save resource '#{self}'"
|
|
534
|
+
end
|
|
535
|
+
return self
|
|
536
|
+
end
|
|
537
|
+
end # InstanceMethods
|
|
538
|
+
|
|
539
|
+
end # Base
|
|
540
|
+
end # Resource
|
|
541
|
+
end # OMF::SFA
|
|
542
|
+
|
|
543
|
+
#DataMapper::Model.append_extensions(OMF::SFA::Resource::Base::ClassMethods)
|
|
544
|
+
#DataMapper::Model.append_inclusions(OMF::SFA::Resource::Base::InstanceMethods)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
require 'omf-sfa/resource/oresource'
|
|
3
|
+
|
|
4
|
+
module OMF::SFA::Resource
|
|
5
|
+
|
|
6
|
+
# This class represents a user in the system.
|
|
7
|
+
#
|
|
8
|
+
class User < OResource
|
|
9
|
+
|
|
10
|
+
oproperty :projects, :project, :functional => false, :inverse => :users
|
|
11
|
+
|
|
12
|
+
# has n, :project_memberships
|
|
13
|
+
# has n, :projects, :through => :project_memberships, :via => :project
|
|
14
|
+
|
|
15
|
+
def to_hash_long(h, objs, opts = {})
|
|
16
|
+
super
|
|
17
|
+
href_only = opts[:level] >= opts[:max_level]
|
|
18
|
+
h[:projects] = self.projects.map do |p|
|
|
19
|
+
href_only ? p.href : p.to_hash(objs, opts)
|
|
20
|
+
end
|
|
21
|
+
h
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end # User
|
|
25
|
+
end # module
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
require 'omf_sfa'
|
|
3
|
+
module OMF::SFA
|
|
4
|
+
module Resource; end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'omf-sfa/resource/gurn'
|
|
8
|
+
require 'omf-sfa/resource/oresource'
|
|
9
|
+
require 'omf-sfa/resource/oreference'
|
|
10
|
+
require 'omf-sfa/resource/oproperty'
|
|
11
|
+
require 'omf-sfa/resource/ogroup'
|
|
12
|
+
require 'omf-sfa/resource/group_membership'
|
|
13
|
+
require 'omf-sfa/resource/oaccount'
|
|
14
|
+
require 'omf-sfa/resource/olease'
|
|
15
|
+
require 'omf-sfa/resource/component_lease'
|
|
16
|
+
|
|
17
|
+
#require 'omf-sfa/resource/sliver'
|
|
18
|
+
require 'omf-sfa/resource/link'
|
|
19
|
+
require 'omf-sfa/resource/interface'
|
|
20
|
+
require 'omf-sfa/resource/node'
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Populate an AM database with a simple topology
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
require 'rubygems'
|
|
6
|
+
require 'data_mapper'
|
|
7
|
+
require 'nokogiri'
|
|
8
|
+
require 'omf_base/lobject'
|
|
9
|
+
|
|
10
|
+
require 'omf-sfa/resource'
|
|
11
|
+
|
|
12
|
+
ROUTERS = 3
|
|
13
|
+
NODES_PER_ROUTER = 2
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
OMF::Base::Loggable.init_log 'sample_tb'
|
|
17
|
+
|
|
18
|
+
include OMF::SFA::Resource
|
|
19
|
+
|
|
20
|
+
GURN.default_prefix = "urn:publicid:IDN+acme.org"
|
|
21
|
+
# Component.default_domain = "acme.org"
|
|
22
|
+
# Component.default_component_manager_id = "authority+am"
|
|
23
|
+
|
|
24
|
+
# Configure the data store
|
|
25
|
+
#
|
|
26
|
+
DataMapper::Logger.new($stdout, :note)
|
|
27
|
+
#path = ARGV[2] || '/tmp/am_test2'
|
|
28
|
+
#DataMapper.setup(:default, :adapter => 'yaml', :path => path)
|
|
29
|
+
DataMapper.setup(:default, 'sqlite:///tmp/am_test.db')
|
|
30
|
+
DataMapper::Model.raise_on_save_failure = true
|
|
31
|
+
|
|
32
|
+
#puts DataMapper::SubjectSet.entries.inspect
|
|
33
|
+
|
|
34
|
+
DataMapper::Model.descendants.each do |m| puts m.inspect end
|
|
35
|
+
puts '-----------'
|
|
36
|
+
Node.descendants.each do |m| puts m.inspect end
|
|
37
|
+
puts '-----------'
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
DataMapper.finalize
|
|
41
|
+
DataMapper.auto_upgrade!
|
|
42
|
+
|
|
43
|
+
sliver = OMF::SFA::Resource::Sliver.def_sliver
|
|
44
|
+
|
|
45
|
+
routers = []
|
|
46
|
+
|
|
47
|
+
ROUTERS.times do |ri|
|
|
48
|
+
rname = "r#{ri}"
|
|
49
|
+
r = Node.create(:name => rname, :sliver => sliver)
|
|
50
|
+
routers << r
|
|
51
|
+
NODES_PER_ROUTER.times do |ni|
|
|
52
|
+
name = "c#{ri}_#{ni}"
|
|
53
|
+
n = Node.create(:name => name, :sliver => sliver)
|
|
54
|
+
l = Link.create(:name => "la#{ri}_#{ni}", :sliver => sliver)
|
|
55
|
+
i1 = Interface.create(:node => r, :channel => l)
|
|
56
|
+
i2 = Interface.create(:node => n, :channel => l)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
ROUTERS.times do |i|
|
|
61
|
+
(i + 1 .. ROUTERS - 1).each do |j|
|
|
62
|
+
l = Link.create(:name => "l#{i}_#{j}", :sliver => sliver)
|
|
63
|
+
i1 = Interface.create(:node => routers[i], :channel => l)
|
|
64
|
+
i2 = Interface.create(:node => routers[j], :channel => l)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|