nitos_testbed_rc 1.0.0.pre.4 → 1.0.0.pre.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cm_proxy +122 -66
- data/bin/frisbee_proxy +120 -64
- data/bin/install_ntrc +3 -1
- data/bin/omf6 +380 -201
- data/etc/cm_proxy_conf.yaml +5 -0
- data/etc/frisbee_proxy_conf.yaml +3 -0
- data/lib/nitos_testbed_rc/cm_factory.rb +113 -67
- data/lib/nitos_testbed_rc/frisbee.rb +13 -6
- data/lib/nitos_testbed_rc/imagezip_client.rb +16 -14
- data/lib/nitos_testbed_rc/imagezip_server.rb +5 -3
- data/lib/nitos_testbed_rc/user.rb +118 -32
- data/lib/nitos_testbed_rc/user_factory.rb +1 -1
- data/lib/version.rb +1 -1
- data/nitos_testbed_rc.gemspec +2 -2
- metadata +7 -7
data/bin/cm_proxy
CHANGED
@@ -3,6 +3,10 @@ require 'rubygems'
|
|
3
3
|
require 'omf_rc'
|
4
4
|
require 'omf_common'
|
5
5
|
require 'yaml'
|
6
|
+
require "net/https"
|
7
|
+
require "uri"
|
8
|
+
require "json"
|
9
|
+
require 'time'
|
6
10
|
|
7
11
|
$stdout.sync = true
|
8
12
|
|
@@ -41,77 +45,129 @@ class CmPDP
|
|
41
45
|
def authorize(msg, &block)
|
42
46
|
debug "AUTH message received: #{msg.operation}"
|
43
47
|
if msg.operation.to_sym == :configure
|
44
|
-
|
45
|
-
result = nil
|
46
|
-
OmfCommon.comm.subscribe(@config[:testbedTopic]) do |am_con|
|
47
|
-
acc = _get_account_name(msg)
|
48
|
-
|
49
|
-
if acc.nil?
|
50
|
-
error "AUTH error: acc nill"
|
51
|
-
msg.properties.state.error_msg = "Account name not found"
|
52
|
-
result = msg
|
53
|
-
wait = false
|
54
|
-
next
|
55
|
-
end
|
48
|
+
acc = _get_account_name(msg)
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
leases.each do |l|
|
79
|
-
if Time.parse(l[:resource][:valid_from]) <= Time.now && Time.parse(l[:resource][:valid_until]) >= Time.now
|
80
|
-
unless l[:resource][:components].nil?
|
81
|
-
l[:resource][:components].each do |c|
|
82
|
-
if c[:component][:name] == node_name.to_s && l[:resource][:account][:name] == acc
|
83
|
-
lease = l
|
84
|
-
break #found the correct lease
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
if lease.nil? #if lease is nil it means no matching lease is found
|
92
|
-
error "AUTH error: Lease nill"
|
93
|
-
msg.properties.state.error_msg = "Node is not leased by your account."
|
94
|
-
result = msg
|
95
|
-
wait = false
|
96
|
-
next
|
97
|
-
else
|
98
|
-
debug "AUTH PASSED"
|
99
|
-
msg.properties.state.node = node
|
100
|
-
result = msg
|
101
|
-
wait = false
|
102
|
-
next
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
50
|
+
if acc.nil?
|
51
|
+
error "AUTH error: Account not found"
|
52
|
+
msg.properties.state.error_msg = "Account name not found"
|
53
|
+
return msg# next
|
54
|
+
end
|
55
|
+
|
56
|
+
node_name = msg.properties.state.node
|
57
|
+
broker = @config[:broker_url]
|
58
|
+
|
59
|
+
uri = URI.parse("#{broker}/resources/nodes?name=#{node_name}")
|
60
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
61
|
+
http.use_ssl = true
|
62
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
63
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
64
|
+
response = http.request(request)
|
65
|
+
resp = JSON.parse(response.body, :symbolize_names => true)
|
66
|
+
|
67
|
+
if response.header.code != '200'
|
68
|
+
error "AUTH error: empty response"
|
69
|
+
msg.properties.state.error_msg = "#{resp[:reason]} - code: '#{resp[:exception][:code]}'"
|
70
|
+
return msg# next
|
107
71
|
end
|
108
72
|
|
109
|
-
|
110
|
-
|
111
|
-
|
73
|
+
node = resp[:resource_response]
|
74
|
+
if node.nil?
|
75
|
+
error "AUTH error: Node '#{node_name}' not found"
|
76
|
+
msg.properties.state.error_msg = "Node '#{node_name}' does not exist - code: '#{resp[:exception][:code]}'"
|
77
|
+
return msg
|
112
78
|
end
|
113
79
|
|
114
|
-
|
80
|
+
node = node[:resources].first
|
81
|
+
lease = nil
|
82
|
+
node[:leases].each do |l|
|
83
|
+
l = l[:lease]
|
84
|
+
next if l[:account][:name] != acc
|
85
|
+
if Time.parse(l[:valid_from]) <= Time.now && Time.parse(l[:valid_until]) >= Time.now
|
86
|
+
lease = l
|
87
|
+
break
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if lease.nil?
|
92
|
+
error "AUTH error: node not available"
|
93
|
+
msg.properties.state.error_msg = "Node '#{node_name}' is not leased by your account."
|
94
|
+
return msg
|
95
|
+
else
|
96
|
+
debug "AUTH PASSED"
|
97
|
+
msg.properties.state.node = node
|
98
|
+
return msg
|
99
|
+
end
|
100
|
+
# wait = true
|
101
|
+
# result = nil
|
102
|
+
# OmfCommon.comm.subscribe(@config[:testbedTopic]) do |am_con|
|
103
|
+
# acc = _get_account_name(msg)
|
104
|
+
|
105
|
+
# if acc.nil?
|
106
|
+
# error "AUTH error: acc nill"
|
107
|
+
# msg.properties.state.error_msg = "Account name not found"
|
108
|
+
# result = msg
|
109
|
+
# wait = false
|
110
|
+
# next
|
111
|
+
# end
|
112
|
+
|
113
|
+
# node_name = msg.properties.state.node
|
114
|
+
# am_con.request([:nodes]) do |n_msg|
|
115
|
+
# nodes = n_msg.read_property("nodes")[:resources]
|
116
|
+
# node = nil
|
117
|
+
# nodes.each do |n|
|
118
|
+
# if n[:resource][:name].to_s == node_name.to_s
|
119
|
+
# node = n
|
120
|
+
# break
|
121
|
+
# end
|
122
|
+
# end
|
123
|
+
|
124
|
+
# lease = nil
|
125
|
+
# if node.nil?
|
126
|
+
# error "AUTH error: Node nill"
|
127
|
+
# msg.properties.state.error_msg = "Wrong node name."
|
128
|
+
# result = msg
|
129
|
+
# wait = false
|
130
|
+
# next
|
131
|
+
# else
|
132
|
+
# am_con.request([:leases]) do |l_msg|
|
133
|
+
# leases = l_msg.read_property("leases")[:resources]
|
134
|
+
# leases.each do |l|
|
135
|
+
# if Time.parse(l[:resource][:valid_from]) <= Time.now && Time.parse(l[:resource][:valid_until]) >= Time.now
|
136
|
+
# unless l[:resource][:components].nil?
|
137
|
+
# l[:resource][:components].each do |c|
|
138
|
+
# if c[:component][:name] == node_name.to_s && l[:resource][:account][:name] == acc
|
139
|
+
# lease = l
|
140
|
+
# break #found the correct lease
|
141
|
+
# end
|
142
|
+
# end
|
143
|
+
# end
|
144
|
+
# end
|
145
|
+
# end
|
146
|
+
|
147
|
+
# if lease.nil? #if lease is nil it means no matching lease is found
|
148
|
+
# error "AUTH error: Lease nill"
|
149
|
+
# msg.properties.state.error_msg = "Node is not leased by your account."
|
150
|
+
# result = msg
|
151
|
+
# wait = false
|
152
|
+
# next
|
153
|
+
# else
|
154
|
+
# debug "AUTH PASSED"
|
155
|
+
# msg.properties.state.node = node
|
156
|
+
# result = msg
|
157
|
+
# wait = false
|
158
|
+
# next
|
159
|
+
# end
|
160
|
+
# end
|
161
|
+
# end
|
162
|
+
# end
|
163
|
+
# end
|
164
|
+
|
165
|
+
# #waiting for the whole process to be completed
|
166
|
+
# while wait
|
167
|
+
# sleep 1
|
168
|
+
# end
|
169
|
+
|
170
|
+
# return result if result
|
115
171
|
else
|
116
172
|
debug "AUTH PASSED"
|
117
173
|
return msg
|
data/bin/frisbee_proxy
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
require 'omf_rc'
|
4
4
|
require 'omf_common'
|
5
5
|
require 'yaml'
|
6
|
+
require "net/https"
|
7
|
+
require "uri"
|
8
|
+
require "json"
|
9
|
+
require 'time'
|
6
10
|
|
7
11
|
$stdout.sync = true
|
8
12
|
@config = YAML.load_file('/etc/nitos_testbed_rc/frisbee_proxy_conf.yaml')
|
@@ -45,75 +49,127 @@ class FrisbeePDP
|
|
45
49
|
debug "AUTH message received: #{msg.operation}"
|
46
50
|
if msg.operation.to_sym == :create
|
47
51
|
if msg.rtype.to_sym == :frisbee || msg.rtype.to_sym == :imagezip_client
|
48
|
-
|
49
|
-
result = nil
|
50
|
-
OmfCommon.comm.subscribe(@config[:testbedTopic]) do |am_con|
|
51
|
-
acc = _get_account_name(msg)
|
52
|
-
|
53
|
-
if acc.nil?
|
54
|
-
error "AUTH error: acc nill"
|
55
|
-
msg.propertie.error_msg = "Account name not found"
|
56
|
-
result = msg
|
57
|
-
wait = false
|
58
|
-
next
|
59
|
-
end
|
52
|
+
acc = _get_account_name(msg)
|
60
53
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
leases.each do |l|
|
83
|
-
if Time.parse(l[:resource][:valid_from]) <= Time.now && Time.parse(l[:resource][:valid_until]) >= Time.now
|
84
|
-
l[:resource][:components].each do |c|
|
85
|
-
if c[:component][:name] == node_name.to_s && l[:resource][:account][:name] == acc
|
86
|
-
lease = l
|
87
|
-
break #found the correct lease
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
if lease.nil? #if lease is nil it means no matching lease is found
|
94
|
-
error "AUTH error: Lease nill"
|
95
|
-
msg.properties.error_msg = "Node is not leased by your account."
|
96
|
-
result = msg
|
97
|
-
wait = false
|
98
|
-
next
|
99
|
-
else
|
100
|
-
debug "AUTH PASSED"
|
101
|
-
msg.properties.node = node
|
102
|
-
result = msg
|
103
|
-
wait = false
|
104
|
-
next
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
54
|
+
if acc.nil?
|
55
|
+
error "AUTH error: Account not found"
|
56
|
+
msg.properties.state.error_msg = "Account name not found"
|
57
|
+
return msg# next
|
58
|
+
end
|
59
|
+
|
60
|
+
node_name = msg.properties.node_topic
|
61
|
+
broker = @config[:broker_url]
|
62
|
+
|
63
|
+
uri = URI.parse("#{broker}/resources/nodes?name=#{node_name}")
|
64
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
65
|
+
http.use_ssl = true
|
66
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
67
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
68
|
+
response = http.request(request)
|
69
|
+
resp = JSON.parse(response.body, :symbolize_names => true)
|
70
|
+
|
71
|
+
if response.header.code != '200'
|
72
|
+
error "AUTH error: empty response"
|
73
|
+
msg.properties.state.error_msg = "#{resp[:reason]} - code: '#{resp[:exception][:code]}'"
|
74
|
+
return msg# next
|
109
75
|
end
|
110
76
|
|
111
|
-
|
112
|
-
|
113
|
-
|
77
|
+
node = resp[:resource_response]
|
78
|
+
if node.nil?
|
79
|
+
error "AUTH error: Node not found"
|
80
|
+
msg.properties.state.error_msg = "#{resp[:reason]} - code: '#{resp[:exception][:code]}'"
|
81
|
+
return msg
|
114
82
|
end
|
115
83
|
|
116
|
-
|
84
|
+
node = node[:resources].first
|
85
|
+
lease = nil
|
86
|
+
node[:leases].each do |l|
|
87
|
+
l = l[:lease]
|
88
|
+
next if l[:account][:name] != acc
|
89
|
+
if Time.parse(l[:valid_from]) <= Time.now && Time.parse(l[:valid_until]) >= Time.now
|
90
|
+
lease = l
|
91
|
+
break
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if lease.nil?
|
96
|
+
error "AUTH error: node not available"
|
97
|
+
msg.properties.error_msg = "Node is not leased by your account."
|
98
|
+
return msg
|
99
|
+
else
|
100
|
+
debug "AUTH PASSED"
|
101
|
+
msg.properties.node = node
|
102
|
+
return msg
|
103
|
+
end
|
104
|
+
# wait = true
|
105
|
+
# result = nil
|
106
|
+
# OmfCommon.comm.subscribe(@config[:testbedTopic]) do |am_con|
|
107
|
+
# acc = _get_account_name(msg)
|
108
|
+
|
109
|
+
# if acc.nil?
|
110
|
+
# error "AUTH error: acc nill"
|
111
|
+
# msg.propertie.error_msg = "Account name not found"
|
112
|
+
# result = msg
|
113
|
+
# wait = false
|
114
|
+
# next
|
115
|
+
# end
|
116
|
+
|
117
|
+
# node_name = msg.properties.node_topic
|
118
|
+
# am_con.request([:nodes]) do |n_msg|
|
119
|
+
# nodes = n_msg.read_property("nodes")[:resources]
|
120
|
+
# node = nil
|
121
|
+
# nodes.each do |n|
|
122
|
+
# if n[:resource][:name].to_s == node_name.to_s
|
123
|
+
# node = n
|
124
|
+
# break
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
|
128
|
+
# lease = nil
|
129
|
+
# if node.nil?
|
130
|
+
# error "AUTH error: Node nill"
|
131
|
+
# msg.properties.error_msg = "Wrong node name."
|
132
|
+
# result = msg
|
133
|
+
# wait = false
|
134
|
+
# next
|
135
|
+
# else
|
136
|
+
# am_con.request([:leases]) do |l_msg|
|
137
|
+
# leases = l_msg.read_property("leases")[:resources]
|
138
|
+
# leases.each do |l|
|
139
|
+
# if Time.parse(l[:resource][:valid_from]) <= Time.now && Time.parse(l[:resource][:valid_until]) >= Time.now
|
140
|
+
# l[:resource][:components].each do |c|
|
141
|
+
# if c[:component][:name] == node_name.to_s && l[:resource][:account][:name] == acc
|
142
|
+
# lease = l
|
143
|
+
# break #found the correct lease
|
144
|
+
# end
|
145
|
+
# end
|
146
|
+
# end
|
147
|
+
# end
|
148
|
+
|
149
|
+
# if lease.nil? #if lease is nil it means no matching lease is found
|
150
|
+
# error "AUTH error: Lease nill"
|
151
|
+
# msg.properties.error_msg = "Node is not leased by your account."
|
152
|
+
# result = msg
|
153
|
+
# wait = false
|
154
|
+
# next
|
155
|
+
# else
|
156
|
+
# debug "AUTH PASSED"
|
157
|
+
# msg.properties.node = node
|
158
|
+
# result = msg
|
159
|
+
# wait = false
|
160
|
+
# next
|
161
|
+
# end
|
162
|
+
# end
|
163
|
+
# end
|
164
|
+
# end
|
165
|
+
# end
|
166
|
+
|
167
|
+
# #waiting for the whole process to be completed
|
168
|
+
# while wait
|
169
|
+
# sleep 1
|
170
|
+
# end
|
171
|
+
|
172
|
+
# return result if result
|
117
173
|
else
|
118
174
|
debug "AUTH PASSED"
|
119
175
|
return msg
|
data/bin/install_ntrc
CHANGED
@@ -18,17 +18,19 @@ unless File.directory?(log_path)
|
|
18
18
|
FileUtils.mkdir_p(log_path)
|
19
19
|
end
|
20
20
|
|
21
|
+
puts "Installing configuration files."
|
21
22
|
conf_files = []
|
22
23
|
conf_files << "cm_proxy_conf.yaml"
|
23
24
|
conf_files << "frisbee_proxy_conf.yaml"
|
24
25
|
conf_files << "user_proxy_conf.yaml"
|
25
|
-
|
26
|
+
conf_files << "omf_script_conf.yaml"
|
26
27
|
|
27
28
|
conf_files.each do |file|
|
28
29
|
puts "Copying configuration file '#{gem_root}/etc/#{file}' to '#{config_path}'."
|
29
30
|
FileUtils.cp "#{gem_root}/etc/#{file}", "#{config_path}/#{file}"
|
30
31
|
FileUtils.chmod 0644, "#{config_path}/#{file}"
|
31
32
|
end
|
33
|
+
puts "All configuration files have been installed, browse folder '#{config_path}' to alternate them appropriatly."
|
32
34
|
|
33
35
|
config_path = File.expand_path("~/.omf/etc")
|
34
36
|
unless File.directory?(config_path)
|