class A4Tools::UsherMgmtClient
Attributes
cache_timeout[RW]
Public Class Methods
new(destination, username, password, timeout=300)
click to toggle source
Calls superclass method
A4Tools::CachingClient::new
# 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
Public Instance Methods
acl_for_service(host, name)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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")
click to toggle source
# 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)
click to toggle source
# 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