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,402 @@
|
|
|
1
|
+
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'time'
|
|
4
|
+
require 'zlib'
|
|
5
|
+
require 'base64'
|
|
6
|
+
require 'openssl'
|
|
7
|
+
|
|
8
|
+
require 'omf-sfa/am/am-rpc/abstract_rpc_service'
|
|
9
|
+
require 'omf-sfa/am/am-rpc/am_authorizer'
|
|
10
|
+
|
|
11
|
+
require 'omf-sfa/am/am-rpc/am_rpc_api'
|
|
12
|
+
#require 'omf-sfa/am/privilege_credential'
|
|
13
|
+
#require 'omf-sfa/am/user_credential'
|
|
14
|
+
|
|
15
|
+
module OMF::SFA::AM::RPC
|
|
16
|
+
|
|
17
|
+
class NotAuthorizedException < XMLRPC::FaultException; end
|
|
18
|
+
|
|
19
|
+
class AMService < AbstractService
|
|
20
|
+
include OMF::Base::Loggable
|
|
21
|
+
|
|
22
|
+
attr_accessor :authorizer
|
|
23
|
+
|
|
24
|
+
#implement ServiceAPI
|
|
25
|
+
implement AMServiceAPI
|
|
26
|
+
|
|
27
|
+
def get_version(options = {})
|
|
28
|
+
debug "GetVersion"
|
|
29
|
+
@return_struct[:geni_api] = 2
|
|
30
|
+
@return_struct[:code][:geni_code] = 0
|
|
31
|
+
@return_struct[:value] = {
|
|
32
|
+
:geni_api => 2,
|
|
33
|
+
:geni_api_versions => {
|
|
34
|
+
2 => 'URL'
|
|
35
|
+
},
|
|
36
|
+
:geni_request_rspec_versions => [{
|
|
37
|
+
:type => "geni",
|
|
38
|
+
:version => "3",
|
|
39
|
+
:schema => "http://www.geni.net/resources/rspec/3/request.xsd",
|
|
40
|
+
:namespace => "http://www.geni.net/resources/rspec/3",
|
|
41
|
+
:extensions => ["http://nitlab.inf.uth.gr/schema/sfa/rspec/1/request-reservation.xsd"]
|
|
42
|
+
}],
|
|
43
|
+
:geni_ad_rspec_versions => [{
|
|
44
|
+
:type => "geni",
|
|
45
|
+
:version => "3",
|
|
46
|
+
:schema => "http://www.geni.net/resources/rspec/3/ad.xsd",
|
|
47
|
+
:namespace => "http://www.geni.net/resources/rspec/3",
|
|
48
|
+
:extensions => ["http://nitlab.inf.uth.gr/schema/sfa/rspec/1/ad-reservation.xsd"]
|
|
49
|
+
}],
|
|
50
|
+
:omf_am => "0.1"
|
|
51
|
+
}
|
|
52
|
+
return @return_struct
|
|
53
|
+
#{
|
|
54
|
+
# :geni_api => 2,
|
|
55
|
+
# :code => {
|
|
56
|
+
# :geni_code => 0
|
|
57
|
+
# },
|
|
58
|
+
# :value => {
|
|
59
|
+
# :geni_api => 2,
|
|
60
|
+
# :geni_api_versions => {
|
|
61
|
+
# 2 => 'URL'
|
|
62
|
+
# },
|
|
63
|
+
# :geni_request_rspec_versions => [{
|
|
64
|
+
# :type => "GENI",
|
|
65
|
+
# :version => "3",
|
|
66
|
+
# :schema => "http://www.geni.net/resources/rspec/3/request.xsd",
|
|
67
|
+
# :namespace => "http://www.geni.net/resources/rspec/3",
|
|
68
|
+
# :extensions => ["http://nitlab.inf.uth.gr/schema/sfa/rspec/1/request-reservation.xsd"]
|
|
69
|
+
# }],
|
|
70
|
+
# :geni_ad_rspec_versions => [{
|
|
71
|
+
# :type => "GENI",
|
|
72
|
+
# :version => "3",
|
|
73
|
+
# :schema => "http://www.geni.net/resources/rspec/3/ad.xsd",
|
|
74
|
+
# :namespace => "http://www.geni.net/resources/rspec/3",
|
|
75
|
+
# :extensions => ["http://nitlab.inf.uth.gr/schema/sfa/rspec/1/ad-reservation.xsd"]
|
|
76
|
+
# }],
|
|
77
|
+
# :omf_am => "0.1"
|
|
78
|
+
# },
|
|
79
|
+
# :output => {}
|
|
80
|
+
#}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def list_resources(credentials, options)
|
|
84
|
+
debug 'ListResources: Options: ', options.inspect
|
|
85
|
+
|
|
86
|
+
only_available = options["geni_available"]
|
|
87
|
+
compressed = options["geni_compressed"]
|
|
88
|
+
slice_urn = options["geni_slice_urn"]
|
|
89
|
+
rspec_version = options["geni_rspec_version"]
|
|
90
|
+
|
|
91
|
+
if rspec_version.nil?
|
|
92
|
+
@return_struct[:code][:geni_code] = 1 # Bad Arguments
|
|
93
|
+
@return_struct[:output] = "'geni_rspec_version' argument is missing."
|
|
94
|
+
@return_struct[:value] = {}
|
|
95
|
+
return @return_struct
|
|
96
|
+
#ans = {
|
|
97
|
+
# :code => {
|
|
98
|
+
# :geni_code => 1 # Bad Arguments
|
|
99
|
+
# },
|
|
100
|
+
# :output => "'geni_rspec_version' argument is missing."
|
|
101
|
+
#}
|
|
102
|
+
#return ans
|
|
103
|
+
end
|
|
104
|
+
unless rspec_version["type"].downcase.eql?("geni") && (rspec_version["version"].eql?("3.0") ||
|
|
105
|
+
rspec_version["version"].eql?("3"))
|
|
106
|
+
@return_struct[:code][:geni_code] = 4 # Bad Version
|
|
107
|
+
@return_struct[:output] = "'Version' or 'Type' of RSpecs are not the same with that 'GetVersion' returns."
|
|
108
|
+
@return_struct[:value] = {}
|
|
109
|
+
return @return_struct
|
|
110
|
+
#ans = {
|
|
111
|
+
# :code => {
|
|
112
|
+
# :geni_code => 4 # Bad Version
|
|
113
|
+
# },
|
|
114
|
+
# :output => "'Version' or 'Type' of RSpecs are not the same with that 'GetVersion' returns."
|
|
115
|
+
#}
|
|
116
|
+
#return ans
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)
|
|
120
|
+
#@authorizer.check_credentials(slice_urn, credentials.first, @manager)
|
|
121
|
+
if slice_urn
|
|
122
|
+
# have leases in top of rspec
|
|
123
|
+
resources = @manager.find_all_leases_for_account(authorizer.account, authorizer)
|
|
124
|
+
resources.concat(@manager.find_all_components_for_account(authorizer.account, authorizer))
|
|
125
|
+
|
|
126
|
+
# have leases inside the components
|
|
127
|
+
#resources = @manager.find_all_components_for_account(authorizer.account, authorizer)
|
|
128
|
+
|
|
129
|
+
res = OMF::SFA::Resource::OComponent.sfa_advertisement_xml(resources, {:type => 'manifest'}).to_xml
|
|
130
|
+
else
|
|
131
|
+
# have leases in top of rspec
|
|
132
|
+
resources = @manager.find_all_leases(authorizer)
|
|
133
|
+
resources.concat(@manager.find_all_components_for_account(@manager._get_nil_account, authorizer))
|
|
134
|
+
|
|
135
|
+
# have leases inside the components
|
|
136
|
+
#resources = @manager.find_all_components_for_account(@manager._get_nil_account, authorizer)
|
|
137
|
+
|
|
138
|
+
res = OMF::SFA::Resource::OComponent.sfa_advertisement_xml(resources).to_xml
|
|
139
|
+
end
|
|
140
|
+
# TODO: implement the "available_only" option
|
|
141
|
+
|
|
142
|
+
# only list independent resources (TODO: What does this mean??)
|
|
143
|
+
#resources = resources.select {|r| r.independent_component?}
|
|
144
|
+
#debug "Resources for '#{slice_urn}' >>> #{resources.inspect}"
|
|
145
|
+
|
|
146
|
+
#res = OMF::SFA::Resource::OComponent.sfa_advertisement_xml(resources).to_xml
|
|
147
|
+
if compressed
|
|
148
|
+
res = Base64.encode64(Zlib::Deflate.deflate(res))
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
@return_struct[:code][:geni_code] = 0
|
|
152
|
+
@return_struct[:value] = res
|
|
153
|
+
return @return_struct
|
|
154
|
+
|
|
155
|
+
#{
|
|
156
|
+
# :code => {
|
|
157
|
+
# :geni_code => 0
|
|
158
|
+
# },
|
|
159
|
+
# :value => res
|
|
160
|
+
#}
|
|
161
|
+
rescue OMF::SFA::AM::InsufficientPrivilegesException => e
|
|
162
|
+
@return_struct[:code][:geni_code] = 3
|
|
163
|
+
@return_struct[:output] = e.to_s
|
|
164
|
+
@return_struct[:value] = {}
|
|
165
|
+
return @return_struct
|
|
166
|
+
|
|
167
|
+
#{
|
|
168
|
+
# :code => {
|
|
169
|
+
# :geni_code => 3
|
|
170
|
+
# },
|
|
171
|
+
# :output => e
|
|
172
|
+
#}
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def create_sliver(slice_urn, credentials, rspec_s, users, options)
|
|
176
|
+
debug 'CreateSliver: SLICE URN: ', slice_urn, ' RSPEC: ', rspec_s, ' USERS: ', users.inspect
|
|
177
|
+
|
|
178
|
+
if slice_urn.nil? || credentials.nil? || rspec_s.nil?
|
|
179
|
+
@return_struct[:code][:geni_code] = 1 # Bad Arguments
|
|
180
|
+
@return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials', 'rspec'"
|
|
181
|
+
@return_struct[:value] = {}
|
|
182
|
+
return @return_struct
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
#@authorizer.check_credentials(slice_urn, credentials.first, @manager)
|
|
186
|
+
authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)
|
|
187
|
+
|
|
188
|
+
rspec = Nokogiri::XML.parse(rspec_s)
|
|
189
|
+
resources = @manager.update_resources_from_rspec(rspec.root, true, authorizer)
|
|
190
|
+
|
|
191
|
+
# TODO: Still need to implement USER handling
|
|
192
|
+
|
|
193
|
+
res = OMF::SFA::Resource::OComponent.sfa_advertisement_xml(resources, {:type => 'manifest'}).to_s
|
|
194
|
+
|
|
195
|
+
@return_struct[:code][:geni_code] = 0
|
|
196
|
+
@return_struct[:value] = res
|
|
197
|
+
return @return_struct
|
|
198
|
+
|
|
199
|
+
#{ :code => {
|
|
200
|
+
# :geni_code => 0
|
|
201
|
+
# },
|
|
202
|
+
# :value => res
|
|
203
|
+
#}
|
|
204
|
+
rescue OMF::SFA::AM::InsufficientPrivilegesException => e
|
|
205
|
+
@return_struct[:code][:geni_code] = 3
|
|
206
|
+
@return_struct[:output] = e.to_s
|
|
207
|
+
@return_struct[:value] = {}
|
|
208
|
+
return @return_struct
|
|
209
|
+
rescue OMF::SFA::AM::UnknownResourceException => e
|
|
210
|
+
debug('CreateSliver Exception', e.to_s)
|
|
211
|
+
@return_struct[:code][:geni_code] = 12 # Search Failed
|
|
212
|
+
@return_struct[:output] = e.to_s
|
|
213
|
+
@return_struct[:value] = {}
|
|
214
|
+
return @return_struct
|
|
215
|
+
rescue OMF::SFA::AM::FormatException => e
|
|
216
|
+
debug('CreateSliver Exception', e.to_s)
|
|
217
|
+
@return_struct[:code][:geni_code] = 4 # Bad Version
|
|
218
|
+
@return_struct[:output] = e.to_s
|
|
219
|
+
@return_struct[:value] = {}
|
|
220
|
+
return @return_struct
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def sliver_status(slice_urn, credentials, options)
|
|
224
|
+
debug('SliverStatus for ', slice_urn)
|
|
225
|
+
#@authorizer.check_credentials(slice_urn, credentials.first, @manager)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
if slice_urn.nil? || credentials.nil?
|
|
229
|
+
@return_struct[:code][:geni_code] = 1 # Bad Arguments
|
|
230
|
+
@return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials'"
|
|
231
|
+
@return_struct[:value] = false
|
|
232
|
+
return @return_struct
|
|
233
|
+
end
|
|
234
|
+
#@authorizer.check_credentials(slice_urn, credentials.first, @manager)
|
|
235
|
+
authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)
|
|
236
|
+
#raise OMF::SFA::AM::InsufficientPrivilegesException.new("Account is closed.") if authorizer.account.closed?
|
|
237
|
+
|
|
238
|
+
status = {}
|
|
239
|
+
status['omf_expires_at'] = authorizer.account.valid_until.utc.strftime('%Y%m%d%H%M%SZ')
|
|
240
|
+
|
|
241
|
+
resources = @manager.find_all_components_for_account(authorizer.account, authorizer)
|
|
242
|
+
# only list independent resources
|
|
243
|
+
resources = resources.select {|r| r.independent_component?}
|
|
244
|
+
|
|
245
|
+
unless resources.empty?
|
|
246
|
+
status['geni_urn'] = slice_urn
|
|
247
|
+
#status['geni_urn'] = "urn:publicid:IDN+omf:nitos+sliver+accdsw"
|
|
248
|
+
|
|
249
|
+
# Any of the following configuring, ready, failed, and unknown
|
|
250
|
+
status['geni_status'] = 'unknown'
|
|
251
|
+
|
|
252
|
+
status['geni_resources'] = resources.collect do |r|
|
|
253
|
+
{
|
|
254
|
+
'geni_urn'=> r.urn,
|
|
255
|
+
'geni_status' => r.status,
|
|
256
|
+
'geni_error' => '',
|
|
257
|
+
}
|
|
258
|
+
end
|
|
259
|
+
@return_struct[:value] = status
|
|
260
|
+
else
|
|
261
|
+
@return_struct[:value] = {}
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
@return_struct[:code][:geni_code] = 0
|
|
266
|
+
return @return_struct
|
|
267
|
+
|
|
268
|
+
#{ :code => {
|
|
269
|
+
# :geni_code => 0
|
|
270
|
+
# },
|
|
271
|
+
# :value => status
|
|
272
|
+
#}
|
|
273
|
+
rescue OMF::SFA::AM::InsufficientPrivilegesException => e
|
|
274
|
+
@return_struct[:code][:geni_code] = 3
|
|
275
|
+
@return_struct[:output] = e.to_s
|
|
276
|
+
@return_struct[:value] = false
|
|
277
|
+
return @return_struct
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def renew_sliver(slice_urn, credentials, expiration_time, options)
|
|
281
|
+
debug('RenewSliver ', slice_urn, ' until <', expiration_time, '>')
|
|
282
|
+
|
|
283
|
+
if slice_urn.nil? || credentials.nil? || expiration_time.nil?
|
|
284
|
+
@return_struct[:code][:geni_code] = 1 # Bad Arguments
|
|
285
|
+
@return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials', 'expiration_time'"
|
|
286
|
+
@return_struct[:value] = false
|
|
287
|
+
return @return_struct
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
if expiration_time.kind_of?(XMLRPC::DateTime)
|
|
291
|
+
expiration_time = expiration_time.to_time
|
|
292
|
+
else
|
|
293
|
+
expiration_time = Time.parse(expiration_time)
|
|
294
|
+
end
|
|
295
|
+
debug('RenewSliver ', slice_urn, ' until <', expiration_time, '>')
|
|
296
|
+
#authorizer.check_credentials(slice_urn, credentials.first, @manager)
|
|
297
|
+
authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)
|
|
298
|
+
|
|
299
|
+
@manager.renew_account_until({ :urn => slice_urn }, expiration_time, authorizer)
|
|
300
|
+
|
|
301
|
+
@return_struct[:code][:geni_code] = 0
|
|
302
|
+
@return_struct[:value] = true
|
|
303
|
+
return @return_struct
|
|
304
|
+
|
|
305
|
+
#{ :code => {
|
|
306
|
+
# :geni_code => 0
|
|
307
|
+
# },
|
|
308
|
+
# :value => true
|
|
309
|
+
#}
|
|
310
|
+
rescue OMF::SFA::AM::UnavailableResourceException => e
|
|
311
|
+
@return_struct[:code][:geni_code] = 12 # Search Failed
|
|
312
|
+
@return_struct[:output] = e.to_s
|
|
313
|
+
@return_struct[:value] = false
|
|
314
|
+
return @return_struct
|
|
315
|
+
rescue OMF::SFA::AM::InsufficientPrivilegesException => e
|
|
316
|
+
@return_struct[:code][:geni_code] = 3
|
|
317
|
+
@return_struct[:output] = e.to_s
|
|
318
|
+
@return_struct[:value] = false
|
|
319
|
+
return @return_struct
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# close the account and release the attached resources
|
|
323
|
+
def delete_sliver(slice_urn, credentials, options)
|
|
324
|
+
debug('DeleteSliver ', slice_urn)
|
|
325
|
+
|
|
326
|
+
if slice_urn.nil? || credentials.nil?
|
|
327
|
+
@return_struct[:code][:geni_code] = 1 # Bad Arguments
|
|
328
|
+
@return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials'"
|
|
329
|
+
@return_struct[:value] = {}
|
|
330
|
+
return @return_struct
|
|
331
|
+
end
|
|
332
|
+
#@authorizer.check_credentials(slice_urn, credentials.first, @manager)
|
|
333
|
+
authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)
|
|
334
|
+
|
|
335
|
+
# We don't like deleting things
|
|
336
|
+
account = @manager.close_account({ :urn => slice_urn }, authorizer)
|
|
337
|
+
# TODO: Should this really be here? Seems to be the job of the AM manager.
|
|
338
|
+
#account = authorizer.account
|
|
339
|
+
@manager.release_all_components_for_account(account, authorizer)
|
|
340
|
+
debug "Slice '#{slice_urn}' associated with account '#{account.id}:#{account.closed_at}'"
|
|
341
|
+
|
|
342
|
+
@return_struct[:code][:geni_code] = 0
|
|
343
|
+
@return_struct[:value] = true
|
|
344
|
+
return @return_struct
|
|
345
|
+
|
|
346
|
+
#{ :code => {
|
|
347
|
+
# :geni_code => 0
|
|
348
|
+
# },
|
|
349
|
+
# :value => true
|
|
350
|
+
#}
|
|
351
|
+
rescue OMF::SFA::AM::UnavailableResourceException => e
|
|
352
|
+
@return_struct[:code][:geni_code] = 12 # Search Failed
|
|
353
|
+
@return_struct[:output] = e.to_s
|
|
354
|
+
@return_struct[:value] = {}
|
|
355
|
+
return @return_struct
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
# close the account but do not release its resources
|
|
359
|
+
def shutdown_sliver(slice_urn, credentials, options = {})
|
|
360
|
+
#@authorizer.check_credentials(slice_urn, credentials.first, @manager)
|
|
361
|
+
authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)
|
|
362
|
+
|
|
363
|
+
if slice_urn.nil? || credentials.nil?
|
|
364
|
+
@return_struct[:code][:geni_code] = 1 # Bad Arguments
|
|
365
|
+
@return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials'"
|
|
366
|
+
return @return_struct
|
|
367
|
+
end
|
|
368
|
+
#puts "SLICE URN: #{slice_urn}"
|
|
369
|
+
account = @manager.close_account({ :urn => slice_urn }, authorizer)
|
|
370
|
+
|
|
371
|
+
@return_struct[:code][:geni_code] = 0
|
|
372
|
+
@return_struct[:value] = true
|
|
373
|
+
return @return_struct
|
|
374
|
+
|
|
375
|
+
#{ :code => {
|
|
376
|
+
# :geni_code => 0
|
|
377
|
+
# },
|
|
378
|
+
# :value => true
|
|
379
|
+
#}
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
private
|
|
383
|
+
|
|
384
|
+
def initialize(opts)
|
|
385
|
+
super
|
|
386
|
+
@manager = opts[:manager]
|
|
387
|
+
@liaison = opts[:liaison]
|
|
388
|
+
@return_struct = {
|
|
389
|
+
:code => {
|
|
390
|
+
:geni_code => ""
|
|
391
|
+
},
|
|
392
|
+
:value => {},
|
|
393
|
+
:output => {}
|
|
394
|
+
}
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
end # AMService
|
|
398
|
+
|
|
399
|
+
end # module
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require 'omf_base'
|
|
2
|
+
require 'omf_base/dsl/xmpp'
|
|
3
|
+
|
|
4
|
+
#require 'omf-sfa/resource'
|
|
5
|
+
require 'omf-sfa/am/am_manager'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
module OMF::SFA::AM
|
|
9
|
+
|
|
10
|
+
extend OMF::SFA::AM
|
|
11
|
+
|
|
12
|
+
# This class implements the AM Liaison
|
|
13
|
+
#
|
|
14
|
+
class AMLiaison < OMF::Base::LObject
|
|
15
|
+
|
|
16
|
+
include OmfCommon::DSL::Xmpp
|
|
17
|
+
|
|
18
|
+
attr_accessor :comm
|
|
19
|
+
@leases = {}
|
|
20
|
+
|
|
21
|
+
def initialize
|
|
22
|
+
#@comm = OmfCommon::Comm.new(:xmpp)
|
|
23
|
+
#EM.next_tick { @comm.connect('am_liaison', 'pw', 'localhost') }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#def self.leases
|
|
27
|
+
# @@leases ||= {}
|
|
28
|
+
#end
|
|
29
|
+
|
|
30
|
+
# It will send the corresponding create messages to the components contained
|
|
31
|
+
# in the lease when the lease is about to start. At the end of the
|
|
32
|
+
# lease the corresponding release messages will be sent to the components.
|
|
33
|
+
#
|
|
34
|
+
# @param [OLease] lease Contains the lease information "valid_from" and
|
|
35
|
+
# "valid_until" along with the reserved components
|
|
36
|
+
#
|
|
37
|
+
def enable_lease(lease, component)
|
|
38
|
+
debug "enable_lease: lease: '#{lease.inspect}' component: '#{component.inspect}'"
|
|
39
|
+
|
|
40
|
+
resource_topic = @comm.get_topic(component.name)
|
|
41
|
+
raise UnknownResourceException.new "Cannot find resource's pubsub topic: '#{component.inspect}'" unless resource_topic
|
|
42
|
+
|
|
43
|
+
msg = @comm.create_message do |message|
|
|
44
|
+
message.property('name', component.name)
|
|
45
|
+
message.property('type', component.type)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
msg.on_inform_created do |message|
|
|
49
|
+
logger.info "Resource '#{message.resource_id}' successfully created at #{Time.now}"
|
|
50
|
+
created_topic = @comm.get_topic(message.resource_id)
|
|
51
|
+
|
|
52
|
+
# TODO: we need to define whether we ask for specific resource_id in the create
|
|
53
|
+
# message or we let the resource_factory to pick one. We need to keep it synced
|
|
54
|
+
# with the resource_id we have in the DB.
|
|
55
|
+
resource_id = created_topic.id
|
|
56
|
+
|
|
57
|
+
r_msg = @comm.release_message { |m| m.element('resource_id', resource_id) }
|
|
58
|
+
|
|
59
|
+
r_msg.on_inform_released do |message|
|
|
60
|
+
logger.info "Resource (#{message.resource_id}) released at #{Time.now}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
timer = EventMachine::Timer.new(lease[:valid_until] - Time.now) do
|
|
64
|
+
r_msg.publish resource_topic.id
|
|
65
|
+
@leases[lease].delete(component.id)
|
|
66
|
+
@leases.delete(lease) if @leases[lease].empty?
|
|
67
|
+
end
|
|
68
|
+
@leases[lease][component.id] = {:end => timer}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
timer = EventMachine::Timer.new(lease[:valid_from] - Time.now) do
|
|
72
|
+
resource_topic.subscribe do
|
|
73
|
+
# If subscribed, we publish a 'create' message
|
|
74
|
+
msg.publish resource_topic.id
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
@leases[lease] = {} unless @leases[lease]
|
|
79
|
+
@leases[lease] = { component.id => {:start => timer} }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
#def release_lease(resource)
|
|
84
|
+
|
|
85
|
+
# resource_topic = @comm.get_topic(resource.name)
|
|
86
|
+
|
|
87
|
+
# raise UnknownResourceException.new "Cannot find resource's pubsub topic: '#{resource.inspect}'" unless resource_topic
|
|
88
|
+
|
|
89
|
+
#end
|
|
90
|
+
|
|
91
|
+
end # AMLiaison
|
|
92
|
+
end # OMF::SFA::AM
|
|
93
|
+
|