Class: A4Tools::UsherMgmtClient
Instance Attribute Summary collapse
#timeout
Attributes inherited from AcresClient
#connect_time, #connected, #history, #password, #ready, #server_info, #start_time, #token, #uri, #username, #version
Instance Method Summary
collapse
-
#acl_for_service(host, name) ⇒ Object
-
#acls_for_host_id(id, sync = false) ⇒ Object
-
#datacenter(id, sync = false) ⇒ Object
-
#delete_device(serial) ⇒ Object
-
#env_type(type) ⇒ Object
-
#find_device_in_info(serial, site_info_list = nil, sync = false) ⇒ Object
-
#host_for_url(url) ⇒ Object
-
#host_matches_url(host, url) ⇒ Object
-
#host_named(hostname, sync = false) ⇒ Object
-
#host_with_id(host_id, sync = false) ⇒ Object
-
#hosts_for_provider(provider) ⇒ Object
-
#initialize(destination, username, password, timeout = 300) ⇒ UsherMgmtClient
constructor
A new instance of UsherMgmtClient.
-
#make_device(serial, description, site) ⇒ Object
-
#make_edit_for_device(device) ⇒ Object
-
#provider(id, sync = false) ⇒ Object
-
#provider_for_product(site_id, product) ⇒ Object
-
#providers_for_site(site_id) ⇒ Object
-
#service_for_id(id, sync = false) ⇒ Object
-
#site_with_id(site_id, sync = false) ⇒ Object
-
#site_with_name(site_name, sync = false) ⇒ Object
-
#system_type(type) ⇒ Object
-
#update_device(serial, description, site, default_description = "Added via API") ⇒ Object
-
#url_for_provider(provider) ⇒ Object
#[], #cache, cache, #dirty, #ensure_fresh, #fresh?, query, #query, #refresh, #refresh_async, #send_update_request, #timestamp_expired?, #update_from_method
Methods inherited from AcresClient
#add_message_to_history, #app_info, #attempt_snoop, #authenticate, #authenticate_if_needed, #connect, #connect_if_needed, #device_info, #disconnect, #empty_query, #inject_token, #jsonrpc_message, #make_password, #next_msg_id, #response_body, #send_message, #snoop_token, #transport_connect, #wrapped_message
#on, #passthrough, #signal
Constructor Details
#initialize(destination, username, password, timeout = 300) ⇒ UsherMgmtClient
Returns a new instance of UsherMgmtClient.
6
7
8
|
# File 'lib/clients/usher_mgmt_client.rb', line 6
def initialize(destination, username, password, timeout=300)
super(destination || "https://usherm.acres4.net:8181/usher2/json", username, password, timeout)
end
|
Instance Attribute Details
#cache_timeout ⇒ Object
Returns the value of attribute cache_timeout.
5
6
7
|
# File 'lib/clients/usher_mgmt_client.rb', line 5
def cache_timeout
@cache_timeout
end
|
Instance Method Details
#acl_for_service(host, name) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/clients/usher_mgmt_client.rb', line 140
def acl_for_service(host, name)
begin
host = host_named(host) if host.is_a? String
acls = acls_for_host_id(host[:idSystemHost])
acls.each do |acl|
service = service_for_id(acl[:idService])
return acl if service[:name] == name
end
rescue
host
end
nil
end
|
#acls_for_host_id(id, sync = false) ⇒ Object
132
133
134
|
# File 'lib/clients/usher_mgmt_client.rb', line 132
def acls_for_host_id(id, sync=false)
(cache(:usherInfo, sync)[:systemAcls].select { |acl| acl[:idSystemHost] == id }) rescue nil
end
|
#datacenter(id, sync = false) ⇒ Object
76
77
78
79
|
# File 'lib/clients/usher_mgmt_client.rb', line 76
def datacenter(id, sync=false)
cache(:usherSystemId,sync)[:dataCenters].each { |ctr| return ctr if ctr[:idDataCenter] == id }
nil
end
|
#delete_device(serial) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/clients/usher_mgmt_client.rb', line 65
def delete_device(serial)
return nil unless authenticate_if_needed
device = find_device_in_info(serial) || make_device(serial, description || default_description, site)
return nil if device.nil?
device[:idDevSiteInfo] = -1 * device[:idDevSiteInfo]
result = send_message(jsonrpc_message("usherEdit", nil, "com.acres4.common.info.usher.UsherEditRequest", make_edit_for_device(device)))
response_body(result)
end
|
#env_type(type) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/clients/usher_mgmt_client.rb', line 86
def env_type(type)
case type
when 0
"Development"
when 1
"QA"
when 2
"Production"
else
"Unknown (#{type})"
end
end
|
#find_device_in_info(serial, site_info_list = nil, sync = false) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/clients/usher_mgmt_client.rb', line 19
def find_device_in_info(serial, site_info_list=nil, sync=false)
if site_info_list.nil? then
site_info_list = cache(:devSiteInfoSync, sync)
return nil if site_info_list.nil?
end
site_info_list ||= @site_info_list
site_info_list[:devSiteInfoArray].each do |info|
return info if info[:serialNumber] == serial
end
nil
end
|
#host_for_url(url) ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/clients/usher_mgmt_client.rb', line 182
def host_for_url(url)
url = URI(url) unless url.is_a? URI
self[:usherSystemId][:systemProviders].each do |prov|
hosts_for_provider(prov).each do |host|
return host[:hostName] if host_matches_url(host, url)
end
end
nil
end
|
#host_matches_url(host, url) ⇒ Object
194
195
196
197
198
199
|
# File 'lib/clients/usher_mgmt_client.rb', line 194
def host_matches_url(host, url)
host_url = URI(host[:url]) rescue nil
return true if host_url and url.host == host_url.host and url.port == host_url.port and url.scheme == host_url.scheme
return true if url.host == host[:hostName] and url.port == host[:port]
false
end
|
#host_named(hostname, sync = false) ⇒ Object
112
113
114
115
|
# File 'lib/clients/usher_mgmt_client.rb', line 112
def host_named(hostname, sync=false)
(cache(:usherSystemId, sync)[:systemHosts].each { |host| return host if host[:hostName] == hostname }) rescue nil
nil
end
|
#host_with_id(host_id, sync = false) ⇒ Object
117
118
119
120
|
# File 'lib/clients/usher_mgmt_client.rb', line 117
def host_with_id(host_id, sync=false)
(cache(:usherSystemId, sync)[:systemHosts].each { |host| return host if host[:idSystemHost] == host_id.to_i }) rescue nil
nil
end
|
#hosts_for_provider(provider) ⇒ Object
160
161
162
163
164
165
166
167
|
# File 'lib/clients/usher_mgmt_client.rb', line 160
def hosts_for_provider(provider)
internal = provider[:usherHostsInternal] || []
external = provider[:usherHostsExternal] || []
hosts = internal + external
secure = hosts.select { |host| host[:product] == provider[:product] + "-Secure" }
return hosts if secure.empty?
secure
end
|
#make_device(serial, description, site) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/clients/usher_mgmt_client.rb', line 34
def make_device(serial, description, site)
{
idDevSiteInfo: 0,
serialNumber: serial,
description: description,
idSite: site,
__class: "com.acres4.common.info.usher.DevSiteInfo"
}
end
|
#make_edit_for_device(device) ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/clients/usher_mgmt_client.rb', line 44
def make_edit_for_device(device)
{
editObj: {
className:"com.acres4.common.info.usher.DevSiteInfo",
body:device
},
tok:@token
}
end
|
#provider(id, sync = false) ⇒ Object
81
82
83
84
|
# File 'lib/clients/usher_mgmt_client.rb', line 81
def provider(id, sync=false)
cache(:usherSystemId,sync)[:systemProviders].each { |provider| return provider if provider[:idSystemProvider].to_i == id.to_i }
nil
end
|
#provider_for_product(site_id, product) ⇒ Object
169
170
171
172
173
174
|
# File 'lib/clients/usher_mgmt_client.rb', line 169
def provider_for_product(site_id, product)
providers = providers_for_site(site_id)
return nil if providers.nil?
providers.each { |prov| return prov if prov[:product] == product }
nil
end
|
#providers_for_site(site_id) ⇒ Object
154
155
156
157
158
|
# File 'lib/clients/usher_mgmt_client.rb', line 154
def providers_for_site(site_id)
providers = self[:usherSystemId][:systemProviders]
providers = providers.sort { |a,b| a[:product] <=> b[:product] }
providers = providers.reject { |p| p[:idSites].nil? or not p[:idSites].include?(site_id.to_i) }
end
|
#service_for_id(id, sync = false) ⇒ Object
136
137
138
|
# File 'lib/clients/usher_mgmt_client.rb', line 136
def service_for_id(id, sync=false)
(cache(:usherInfo, sync)[:services].each { |service| return service if service[:idService] == id }) rescue nil
end
|
#site_with_id(site_id, sync = false) ⇒ Object
122
123
124
125
|
# File 'lib/clients/usher_mgmt_client.rb', line 122
def site_with_id(site_id, sync=false)
(cache(:usherSystemId, sync)[:usherSites].each { |site| return site if site[:idSite] == site_id.to_i }) rescue nil
nil
end
|
#site_with_name(site_name, sync = false) ⇒ Object
127
128
129
130
|
# File 'lib/clients/usher_mgmt_client.rb', line 127
def site_with_name(site_name, sync=false)
(cache(:usherSystemId, sync)[:usherSites].each { |site| return site if site[:name] == site_name }) rescue nil
nil
end
|
#system_type(type) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/clients/usher_mgmt_client.rb', line 99
def system_type(type)
case type
when -1
"All"
when -2
"Development"
when -3
"Production"
else
"Unknown (#{type})"
end
end
|
#update_device(serial, description, site, default_description = "Added via API") ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/clients/usher_mgmt_client.rb', line 54
def update_device(serial, description, site, default_description="Added via API")
return nil unless authenticate_if_needed
device = find_device_in_info(serial) || make_device(serial, description || default_description, site)
device[:description] = description unless description.nil?
device[:idSite] = site
result = send_message(jsonrpc_message("usherEdit", nil, "com.acres4.common.info.usher.UsherEditRequest", make_edit_for_device(device)))
dirty
response_body(result)
end
|
#url_for_provider(provider) ⇒ Object
176
177
178
179
180
|
# File 'lib/clients/usher_mgmt_client.rb', line 176
def url_for_provider(provider)
opts = hosts_for_provider(provider).map { |host| { :host => host[:host], :port => host[:port], :url => host[:url] } }
result = try_connection_options(opts)
return (result[:url] rescue nil)
end
|