tng-gtk-utils 0.3.1 → 0.4.0
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.
- checksums.yaml +4 -4
- data/lib/tng/gtk/utils/functions.rb +116 -0
- data/lib/tng/gtk/utils/services.rb +122 -0
- data/lib/tng/gtk/utils/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99e606a92c3081912e1ac1595a7b1a554e43996afb971a8ed1266ef02500e271
|
4
|
+
data.tar.gz: 73182e07bf66045124103c73f7461ed1c02c2b3246a85aaa6d376b4020b5d01a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f18e089baed8541b880ca87393f911fe5c4bdd673438f6706dd5f70ee856f206f0f7a7d4e9630f7910f41e93765917afe6ae5064b26888d969c250bf6cfd1bf
|
7
|
+
data.tar.gz: e1825f73b98f88e6b811ff405bfb13302c4d7a5f818ad595464f836835574f9d412c9107e70051c82f7dc801ba017b50655ddf5260d66ea7e160bc48b402de75
|
@@ -0,0 +1,116 @@
|
|
1
|
+
## SONATA - Gatekeeper
|
2
|
+
##
|
3
|
+
## Copyright (c) 2015 SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
|
4
|
+
## ALL RIGHTS RESERVED.
|
5
|
+
##
|
6
|
+
## Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
## you may not use this file except in compliance with the License.
|
8
|
+
## You may obtain a copy of the License at
|
9
|
+
##
|
10
|
+
## http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
##
|
12
|
+
## Unless required by applicable law or agreed to in writing, software
|
13
|
+
## distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
## See the License for the specific language governing permissions and
|
16
|
+
## limitations under the License.
|
17
|
+
##
|
18
|
+
## Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
|
19
|
+
## nor the names of its contributors may be used to endorse or promote
|
20
|
+
## products derived from this software without specific prior written
|
21
|
+
## permission.
|
22
|
+
##
|
23
|
+
## This work has been performed in the framework of the SONATA project,
|
24
|
+
## funded by the European Commission under Grant number 671517 through
|
25
|
+
## the Horizon 2020 and 5G-PPP programmes. The authors would like to
|
26
|
+
## acknowledge the contributions of their colleagues of the SONATA
|
27
|
+
## partner consortium (www.sonata-nfv.eu).
|
28
|
+
# frozen_string_literal: true
|
29
|
+
# encoding: utf-8
|
30
|
+
require 'sinatra'
|
31
|
+
require 'json'
|
32
|
+
require 'securerandom'
|
33
|
+
require 'net/http'
|
34
|
+
require 'ostruct'
|
35
|
+
require 'json'
|
36
|
+
require 'tng/gtk/utils/application_controller'
|
37
|
+
require 'tng/gtk/utils/logger'
|
38
|
+
require 'tng/gtk/utils/fetch'
|
39
|
+
|
40
|
+
LOGGER=Tng::Gtk::Utils::Logger
|
41
|
+
|
42
|
+
class FetchVNFDsService < Tng::Gtk::Utils::Fetch
|
43
|
+
NO_CATALOGUE_URL_DEFINED_ERROR='The CATALOGUE_URL ENV variable needs to defined and pointing to the Catalogue where to fetch functions'
|
44
|
+
LOGGED_COMPONENT=self.name
|
45
|
+
|
46
|
+
CATALOGUE_URL = ENV.fetch('CATALOGUE_URL', '')
|
47
|
+
if CATALOGUE_URL == ''
|
48
|
+
LOGGER.error(component:LOGGED_COMPONENT, operation:'fetching CATALOGUE_URL ENV variable', message:NO_CATALOGUE_URL_DEFINED_ERROR)
|
49
|
+
raise ArgumentError.new(NO_CATALOGUE_URL_DEFINED_ERROR)
|
50
|
+
end
|
51
|
+
self.site=CATALOGUE_URL+'/vnfs'
|
52
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:'site definition', message:"self.site=#{self.site}")
|
53
|
+
end
|
54
|
+
|
55
|
+
class FunctionsController < Tng::Gtk::Utils::ApplicationController
|
56
|
+
|
57
|
+
ERROR_FUNCTION_NOT_FOUND="No function with UUID '%s' was found"
|
58
|
+
LOGGED_COMPONENT=self.name
|
59
|
+
@@began_at = Time.now.utc
|
60
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:'initializing', start_stop: 'START', message:"Started at #{@@began_at}")
|
61
|
+
|
62
|
+
get '/?' do
|
63
|
+
msg='#get (many)'
|
64
|
+
began_at = Time.now.utc
|
65
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'START', message:"Started at #{began_at}")
|
66
|
+
captures=params.delete('captures') if params.key? 'captures'
|
67
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"params=#{params}")
|
68
|
+
result = FetchVNFDsService.call(symbolized_hash(params))
|
69
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"result=#{result}")
|
70
|
+
if result.to_s.empty? # covers nil
|
71
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '404', time_elapsed:"#{Time.now.utc-began_at}")
|
72
|
+
halt 404, {}, {error: "No functions fiting the provided parameters ('#{params}') were found"}.to_json
|
73
|
+
end
|
74
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '200', time_elapsed:"#{Time.now.utc-began_at}")
|
75
|
+
halt 200, {}, result.to_json
|
76
|
+
end
|
77
|
+
|
78
|
+
get '/:function_uuid/?' do
|
79
|
+
msg='#get (single)'
|
80
|
+
began_at = Time.now.utc
|
81
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'START', message:"Started at #{began_at}")
|
82
|
+
captures=params.delete('captures') if params.key? 'captures'
|
83
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"params['function_uuid']='#{params['function_uuid']}'")
|
84
|
+
result = FetchVNFDsService.call(uuid: params['function_uuid'])
|
85
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"result=#{result}")
|
86
|
+
if result == {}
|
87
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '404', time_elapsed:"#{Time.now.utc-began_at}")
|
88
|
+
halt 404, {}, {error: ERROR_FUNCTION_NOT_FOUND % params['function_uuid']}.to_json
|
89
|
+
end
|
90
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '200', time_elapsed:"#{Time.now.utc-began_at}")
|
91
|
+
halt 200, {}, result.to_json
|
92
|
+
end
|
93
|
+
|
94
|
+
options '/?' do
|
95
|
+
msg='#options'
|
96
|
+
began_at = Time.now.utc
|
97
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'START', message:"Started at #{began_at}")
|
98
|
+
response.headers['Access-Control-Allow-Origin'] = '*'
|
99
|
+
response.headers['Access-Control-Allow-Methods'] = 'GET,DELETE'
|
100
|
+
response.headers['Access-Control-Allow-Headers'] = 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With'
|
101
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '200', time_elapsed:"#{Time.now.utc-began_at}")
|
102
|
+
halt 200
|
103
|
+
end
|
104
|
+
|
105
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:'initializing', start_stop: 'STOP', message:"Ending at #{Time.now.utc}", time_elapsed: Time.now.utc - @@began_at)
|
106
|
+
|
107
|
+
private
|
108
|
+
def uuid_valid?(uuid)
|
109
|
+
return true if (uuid =~ /[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}/) == 0
|
110
|
+
false
|
111
|
+
end
|
112
|
+
|
113
|
+
def symbolized_hash(hash)
|
114
|
+
Hash[hash.map{|(k,v)| [k.to_sym,v]}]
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
## Copyright (c) 2015 SONATA-NFV, 2017 5GTANGO [, ANY ADDITIONAL AFFILIATION]
|
2
|
+
## ALL RIGHTS RESERVED.
|
3
|
+
##
|
4
|
+
## Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
## you may not use this file except in compliance with the License.
|
6
|
+
## You may obtain a copy of the License at
|
7
|
+
##
|
8
|
+
## http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
##
|
10
|
+
## Unless required by applicable law or agreed to in writing, software
|
11
|
+
## distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
## See the License for the specific language governing permissions and
|
14
|
+
## limitations under the License.
|
15
|
+
##
|
16
|
+
## Neither the name of the SONATA-NFV, 5GTANGO [, ANY ADDITIONAL AFFILIATION]
|
17
|
+
## nor the names of its contributors may be used to endorse or promote
|
18
|
+
## products derived from this software without specific prior written
|
19
|
+
## permission.
|
20
|
+
##
|
21
|
+
## This work has been performed in the framework of the SONATA project,
|
22
|
+
## funded by the European Commission under Grant number 671517 through
|
23
|
+
## the Horizon 2020 and 5G-PPP programmes. The authors would like to
|
24
|
+
## acknowledge the contributions of their colleagues of the SONATA
|
25
|
+
## partner consortium (www.sonata-nfv.eu).
|
26
|
+
##
|
27
|
+
## This work has been performed in the framework of the 5GTANGO project,
|
28
|
+
## funded by the European Commission under Grant number 761493 through
|
29
|
+
## the Horizon 2020 and 5G-PPP programmes. The authors would like to
|
30
|
+
## acknowledge the contributions of their colleagues of the 5GTANGO
|
31
|
+
## partner consortium (www.5gtango.eu).
|
32
|
+
# encoding: utf-8
|
33
|
+
require 'sinatra'
|
34
|
+
require 'json'
|
35
|
+
require 'securerandom'
|
36
|
+
require 'net/http'
|
37
|
+
require 'ostruct'
|
38
|
+
require 'json'
|
39
|
+
require 'tng/gtk/utils/application_controller'
|
40
|
+
require 'tng/gtk/utils/logger'
|
41
|
+
require 'tng/gtk/utils/fetch'
|
42
|
+
|
43
|
+
LOGGER=Tng::Gtk::Utils::Logger
|
44
|
+
|
45
|
+
class FetchNSDService < Tng::Gtk::Utils::Fetch
|
46
|
+
NO_CATALOGUE_URL_DEFINED_ERROR='The CATALOGUE_URL ENV variable needs to defined and pointing to the Catalogue where to fetch services'
|
47
|
+
LOGGED_COMPONENT=self.name
|
48
|
+
|
49
|
+
CATALOGUE_URL = ENV.fetch('CATALOGUE_URL', '')
|
50
|
+
if CATALOGUE_URL == ''
|
51
|
+
LOGGER.error(component:LOGGED_COMPONENT, operation:'fetching CATALOGUE_URL ENV variable', message:NO_CATALOGUE_URL_DEFINED_ERROR)
|
52
|
+
raise ArgumentError.new(NO_CATALOGUE_URL_DEFINED_ERROR)
|
53
|
+
end
|
54
|
+
self.site=CATALOGUE_URL+'/network-services'
|
55
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:'site definition', message:"self.site=#{self.site}")
|
56
|
+
end
|
57
|
+
|
58
|
+
class ServicesController < Tng::Gtk::Utils::ApplicationController
|
59
|
+
|
60
|
+
ERROR_SERVICE_NOT_FOUND="No service with UUID '%s' was found"
|
61
|
+
LOGGER=Tng::Gtk::Utils::Logger
|
62
|
+
LOGGED_COMPONENT=self.name
|
63
|
+
|
64
|
+
@@began_at = Time.now.utc
|
65
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:'initializing', start_stop: 'START', message:"Started at #{@@began_at}")
|
66
|
+
|
67
|
+
get '/?' do
|
68
|
+
msg='#get (many)'
|
69
|
+
began_at = Time.now.utc
|
70
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'START', message:"Started at #{began_at}")
|
71
|
+
captures=params.delete('captures') if params.key? 'captures'
|
72
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"params=#{params}")
|
73
|
+
result = FetchNSDService.call(symbolized_hash(params))
|
74
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"result=#{result}")
|
75
|
+
if result.to_s.empty? # covers nil
|
76
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '404', time_elapsed:"#{Time.now.utc-began_at}")
|
77
|
+
halt 404, {}, {error: "No packages fiting the provided parameters ('#{params}') were found"}.to_json
|
78
|
+
end
|
79
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '200', time_elapsed:"#{Time.now.utc-began_at}")
|
80
|
+
halt 200, {}, result.to_json
|
81
|
+
end
|
82
|
+
|
83
|
+
get '/:service_uuid/?' do
|
84
|
+
msg='#get (single)'
|
85
|
+
began_at = Time.now.utc
|
86
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'START', message:"Started at #{began_at}")
|
87
|
+
captures=params.delete('captures') if params.key? 'captures'
|
88
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"params['service_uuid']='#{params['service_uuid']}'")
|
89
|
+
result = FetchNSDService.call(symbolized_hash(params))
|
90
|
+
LOGGER.debug(component:LOGGED_COMPONENT, operation:msg, message:"result=#{result}")
|
91
|
+
if result.to_s.empty? # covers nil
|
92
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '404', time_elapsed:"#{Time.now.utc-began_at}")
|
93
|
+
halt 404, {}, {error: ERROR_SERVICE_NOT_FOUND % params[:service_uuid]}.to_json
|
94
|
+
end
|
95
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '200', time_elapsed:"#{Time.now.utc-began_at}")
|
96
|
+
halt 200, {}, result.to_json
|
97
|
+
end
|
98
|
+
|
99
|
+
options '/?' do
|
100
|
+
msg='#options'
|
101
|
+
began_at = Time.now.utc
|
102
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'START', message:"Started at #{began_at}")
|
103
|
+
response.headers['Access-Control-Allow-Origin'] = '*'
|
104
|
+
response.headers['Access-Control-Allow-Methods'] = 'GET,DELETE'
|
105
|
+
response.headers['Access-Control-Allow-Headers'] = 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With'
|
106
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:msg, start_stop: 'STOP', message:"Ended at #{Time.now.utc}", status: '200', time_elapsed:"#{Time.now.utc-began_at}")
|
107
|
+
halt 200
|
108
|
+
end
|
109
|
+
|
110
|
+
LOGGER.info(component:LOGGED_COMPONENT, operation:'initializing', start_stop: 'STOP', message:"Ending at #{Time.now.utc}", time_elapsed: Time.now.utc - @@began_at)
|
111
|
+
|
112
|
+
private
|
113
|
+
def uuid_valid?(uuid)
|
114
|
+
return true if (uuid =~ /[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}/) == 0
|
115
|
+
false
|
116
|
+
end
|
117
|
+
|
118
|
+
def symbolized_hash(hash)
|
119
|
+
Hash[hash.map{|(k,v)| [k.to_sym,v]}]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tng-gtk-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Bonnet
|
@@ -120,7 +120,9 @@ files:
|
|
120
120
|
- lib/tng/gtk/utils/application_controller.rb
|
121
121
|
- lib/tng/gtk/utils/cache.rb
|
122
122
|
- lib/tng/gtk/utils/fetch.rb
|
123
|
+
- lib/tng/gtk/utils/functions.rb
|
123
124
|
- lib/tng/gtk/utils/logger.rb
|
125
|
+
- lib/tng/gtk/utils/services.rb
|
124
126
|
- lib/tng/gtk/utils/version.rb
|
125
127
|
- spec/spec_helper.rb
|
126
128
|
- spec/tng/gtk/utils/cache_spec.rb
|