Class: OMF::SFA::AM::RPC::AMService

Inherits:
AbstractService show all
Includes:
Base::Loggable
Defined in:
lib/omf-sfa/am/am-rpc/am_rpc_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractService

implement, rpc

Instance Attribute Details

#authorizerObject

Returns the value of attribute authorizer.



22
23
24
# File 'lib/omf-sfa/am/am-rpc/am_rpc_service.rb', line 22

def authorizer
  @authorizer
end

Instance Method Details

#create_sliver(slice_urn, credentials, rspec_s, users, options) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/omf-sfa/am/am-rpc/am_rpc_service.rb', line 175

def create_sliver(slice_urn, credentials, rspec_s, users, options)
  debug 'CreateSliver: SLICE URN: ', slice_urn, ' RSPEC: ', rspec_s, ' USERS: ', users.inspect

  if slice_urn.nil? || credentials.nil? || rspec_s.nil?
    @return_struct[:code][:geni_code] = 1 # Bad Arguments
    @return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials', 'rspec'"
    @return_struct[:value] = {}
    return @return_struct
  end

  #@authorizer.check_credentials(slice_urn, credentials.first, @manager)
  authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)

  rspec = Nokogiri::XML.parse(rspec_s)
  resources = @manager.update_resources_from_rspec(rspec.root, true, authorizer)

  # TODO: Still need to implement USER handling

  res = OMF::SFA::Resource::OComponent.sfa_advertisement_xml(resources, {:type => 'manifest'}).to_s

  @return_struct[:code][:geni_code] = 0
  @return_struct[:value] = res
  return @return_struct

  #{ :code => {
  #    :geni_code => 0
  #  },
  #  :value => res
  #}
rescue OMF::SFA::AM::InsufficientPrivilegesException => e
  @return_struct[:code][:geni_code] = 3
  @return_struct[:output] = e.to_s
  @return_struct[:value] = {}
  return @return_struct
rescue OMF::SFA::AM::UnknownResourceException => e
  debug('CreateSliver Exception', e.to_s)
  @return_struct[:code][:geni_code] = 12 # Search Failed
  @return_struct[:output] = e.to_s
  @return_struct[:value] = {}
  return @return_struct
rescue OMF::SFA::AM::FormatException => e
  debug('CreateSliver Exception', e.to_s)
  @return_struct[:code][:geni_code] = 4 # Bad Version
  @return_struct[:output] = e.to_s
  @return_struct[:value] = {}
  return @return_struct
end

#delete_sliver(slice_urn, credentials, options) ⇒ Object

close the account and release the attached resources



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/omf-sfa/am/am-rpc/am_rpc_service.rb', line 323

def delete_sliver(slice_urn, credentials, options)
  debug('DeleteSliver ', slice_urn)

  if slice_urn.nil? || credentials.nil?
    @return_struct[:code][:geni_code] = 1 # Bad Arguments
    @return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials'"
    @return_struct[:value] = {}
    return @return_struct
  end
  #@authorizer.check_credentials(slice_urn, credentials.first, @manager)
  authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)

  # We don't like deleting things
   = @manager.({ :urn => slice_urn }, authorizer)
  # TODO: Should this really be here? Seems to be the job of the AM manager.
  #account = authorizer.account
  @manager.(, authorizer)
  debug "Slice '#{slice_urn}' associated with account '#{.id}:#{.closed_at}'"

  @return_struct[:code][:geni_code] = 0
  @return_struct[:value] = true
  return @return_struct

  #{ :code => {
  #    :geni_code => 0
  #  },
  #  :value => true
  #}
rescue OMF::SFA::AM::UnavailableResourceException => e
  @return_struct[:code][:geni_code] = 12 # Search Failed
  @return_struct[:output] = e.to_s
  @return_struct[:value] = {}
  return @return_struct
end

#get_version(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/omf-sfa/am/am-rpc/am_rpc_service.rb', line 27

def get_version(options = {})
  debug "GetVersion"
  @return_struct[:geni_api] = 2
  @return_struct[:code][:geni_code] = 0
  @return_struct[:value] = {
    :geni_api => 2,
    :geni_api_versions => {
      2 => 'URL'
    },
    :geni_request_rspec_versions => [{
      :type => "geni",
      :version => "3",
      :schema => "http://www.geni.net/resources/rspec/3/request.xsd",
      :namespace => "http://www.geni.net/resources/rspec/3",
      :extensions => ["http://nitlab.inf.uth.gr/schema/sfa/rspec/1/request-reservation.xsd"]
    }],
    :geni_ad_rspec_versions => [{
      :type => "geni",
      :version => "3",
      :schema => "http://www.geni.net/resources/rspec/3/ad.xsd",
      :namespace => "http://www.geni.net/resources/rspec/3",
      :extensions => ["http://nitlab.inf.uth.gr/schema/sfa/rspec/1/ad-reservation.xsd"]
    }],
    :omf_am => "0.1"
  }
  return @return_struct
  #{
  #  :geni_api => 2,
  #  :code => {
  #    :geni_code => 0
  #  },
  #  :value => {
  #    :geni_api => 2,
  #    :geni_api_versions => {
  #      2 => 'URL'
  #    },
  #    :geni_request_rspec_versions => [{
  #      :type => "GENI",
  #      :version => "3",
  #      :schema => "http://www.geni.net/resources/rspec/3/request.xsd",
  #      :namespace => "http://www.geni.net/resources/rspec/3",
  #      :extensions => ["http://nitlab.inf.uth.gr/schema/sfa/rspec/1/request-reservation.xsd"]
  #    }],
  #    :geni_ad_rspec_versions => [{
  #      :type => "GENI",
  #      :version => "3",
  #      :schema => "http://www.geni.net/resources/rspec/3/ad.xsd",
  #      :namespace => "http://www.geni.net/resources/rspec/3",
  #      :extensions => ["http://nitlab.inf.uth.gr/schema/sfa/rspec/1/ad-reservation.xsd"]
  #    }],
  #    :omf_am => "0.1"
  #  },
  #  :output => {}
  #}
end

#list_resources(credentials, options) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/omf-sfa/am/am-rpc/am_rpc_service.rb', line 83

def list_resources(credentials, options)
  debug 'ListResources: Options: ', options.inspect

  only_available = options["geni_available"]
  compressed = options["geni_compressed"]
  slice_urn = options["geni_slice_urn"]
  rspec_version = options["geni_rspec_version"]

  if rspec_version.nil?
    @return_struct[:code][:geni_code] = 1 # Bad Arguments
    @return_struct[:output] = "'geni_rspec_version' argument is missing."
    @return_struct[:value] = {}
    return @return_struct
    #ans = {
    #  :code => {
    #    :geni_code => 1 # Bad Arguments
    #  },
    #  :output => "'geni_rspec_version' argument is missing."
    #}
    #return ans
  end
  unless rspec_version["type"].downcase.eql?("geni") && (rspec_version["version"].eql?("3.0") ||
                                                         rspec_version["version"].eql?("3"))
    @return_struct[:code][:geni_code] = 4 # Bad Version
    @return_struct[:output] = "'Version' or 'Type' of RSpecs are not the same with that 'GetVersion' returns."
    @return_struct[:value] = {}
    return @return_struct
    #ans = {
    #  :code => {
    #    :geni_code => 4 # Bad Version
    #  },
    #  :output => "'Version' or 'Type' of RSpecs are not the same with that 'GetVersion' returns."
    #}
    #return ans
  end

  authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)
  #@authorizer.check_credentials(slice_urn, credentials.first, @manager)
  if slice_urn
    # have leases in top of rspec
    resources = @manager.(authorizer., authorizer)
    resources.concat(@manager.(authorizer., authorizer))

    # have leases inside the components
    #resources = @manager.find_all_components_for_account(authorizer.account, authorizer)

    res = OMF::SFA::Resource::OComponent.sfa_advertisement_xml(resources, {:type => 'manifest'}).to_xml
  else
    # have leases in top of rspec
    resources = @manager.find_all_leases(authorizer)
    resources.concat(@manager.(@manager., authorizer))

    # have leases inside the components
    #resources = @manager.find_all_components_for_account(@manager._get_nil_account, authorizer)

    res = OMF::SFA::Resource::OComponent.sfa_advertisement_xml(resources).to_xml
  end
  # TODO: implement the "available_only" option

  # only list independent resources (TODO: What does this mean??)
  #resources = resources.select {|r| r.independent_component?}
  #debug "Resources for '#{slice_urn}' >>> #{resources.inspect}"

  #res = OMF::SFA::Resource::OComponent.sfa_advertisement_xml(resources).to_xml
  if compressed
   res = Base64.encode64(Zlib::Deflate.deflate(res))
  end

  @return_struct[:code][:geni_code] = 0
  @return_struct[:value] = res
  return @return_struct

  #{
  #  :code => {
  #    :geni_code => 0
  #  },
  #  :value => res
  #}
rescue OMF::SFA::AM::InsufficientPrivilegesException => e
  @return_struct[:code][:geni_code] = 3
  @return_struct[:output] = e.to_s
  @return_struct[:value] = {}
  return @return_struct

  #{
  #  :code => {
  #    :geni_code => 3
  #  },
  #  :output => e
  #}
end

#renew_sliver(slice_urn, credentials, expiration_time, options) ⇒ Object



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/omf-sfa/am/am-rpc/am_rpc_service.rb', line 280

def renew_sliver(slice_urn, credentials, expiration_time, options)
  debug('RenewSliver ', slice_urn, ' until <', expiration_time, '>')

  if slice_urn.nil? || credentials.nil? || expiration_time.nil?
    @return_struct[:code][:geni_code] = 1 # Bad Arguments
    @return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials', 'expiration_time'"
    @return_struct[:value] = false
    return @return_struct
  end

  if expiration_time.kind_of?(XMLRPC::DateTime)
    expiration_time = expiration_time.to_time
  else
    expiration_time = Time.parse(expiration_time)
  end
  debug('RenewSliver ', slice_urn, ' until <', expiration_time, '>')
  #authorizer.check_credentials(slice_urn, credentials.first, @manager)
  authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)

  @manager.({ :urn => slice_urn }, expiration_time, authorizer)

  @return_struct[:code][:geni_code] = 0
  @return_struct[:value] = true
  return @return_struct

  #{ :code => {
  #    :geni_code => 0
  #  },
  #  :value => true
  #}
rescue OMF::SFA::AM::UnavailableResourceException => e
  @return_struct[:code][:geni_code] = 12 # Search Failed
  @return_struct[:output] = e.to_s
  @return_struct[:value] = false
  return @return_struct
rescue OMF::SFA::AM::InsufficientPrivilegesException => e
  @return_struct[:code][:geni_code] = 3
  @return_struct[:output] = e.to_s
  @return_struct[:value] = false
  return @return_struct
end

#shutdown_sliver(slice_urn, credentials, options = {}) ⇒ Object

close the account but do not release its resources



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/omf-sfa/am/am-rpc/am_rpc_service.rb', line 359

def shutdown_sliver(slice_urn, credentials, options = {})
  #@authorizer.check_credentials(slice_urn, credentials.first, @manager)
  authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)

  if slice_urn.nil? || credentials.nil?
    @return_struct[:code][:geni_code] = 1 # Bad Arguments
    @return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials'"
    return @return_struct
  end
  #puts "SLICE URN: #{slice_urn}"
   = @manager.({ :urn => slice_urn }, authorizer)

  @return_struct[:code][:geni_code] = 0
  @return_struct[:value] = true
  return @return_struct

  #{ :code => {
  #    :geni_code => 0
  #  },
  #  :value => true
  #}
end

#sliver_status(slice_urn, credentials, options) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/omf-sfa/am/am-rpc/am_rpc_service.rb', line 223

def sliver_status(slice_urn, credentials, options)
  debug('SliverStatus for ', slice_urn)
  #@authorizer.check_credentials(slice_urn, credentials.first, @manager)


  if slice_urn.nil? || credentials.nil?
    @return_struct[:code][:geni_code] = 1 # Bad Arguments
    @return_struct[:output] = "Some of the following arguments are missing: 'slice_urn', 'credentials'"
    @return_struct[:value] = false
    return @return_struct
  end
  #@authorizer.check_credentials(slice_urn, credentials.first, @manager)
  authorizer = OMF::SFA::AM::RPC::AMAuthorizer.create_for_sfa_request(slice_urn, credentials, @request, @manager)
  #raise OMF::SFA::AM::InsufficientPrivilegesException.new("Account is closed.") if authorizer.account.closed?

  status = {}
  status['omf_expires_at'] = authorizer..valid_until.utc.strftime('%Y%m%d%H%M%SZ')

  resources = @manager.(authorizer., authorizer)
  # only list independent resources
  resources = resources.select {|r| r.independent_component?}

  unless resources.empty?
    status['geni_urn'] = slice_urn
    #status['geni_urn'] = "urn:publicid:IDN+omf:nitos+sliver+accdsw"

    # Any of the following configuring, ready, failed, and unknown
    status['geni_status'] = 'unknown'

    status['geni_resources'] = resources.collect do |r|
      {
        'geni_urn'=> r.urn,
        'geni_status' => r.status,
        'geni_error' => '',
      }
    end
    @return_struct[:value] = status
  else
    @return_struct[:value] = {}
  end


  @return_struct[:code][:geni_code] = 0
  return @return_struct

  #{ :code => {
  #    :geni_code => 0
  #  },
  #  :value => status
  #}
rescue OMF::SFA::AM::InsufficientPrivilegesException => e
  @return_struct[:code][:geni_code] = 3
  @return_struct[:output] = e.to_s
  @return_struct[:value] = false
  return @return_struct
end