Class: Appforce::Spawn::Api::Call
- Inherits:
-
Object
- Object
- Appforce::Spawn::Api::Call
- Defined in:
- lib/appforce/spawn/api/call.rb
Class Method Summary collapse
- .get_active_users(*args) ⇒ Object
- .get_all_host_data(*args) ⇒ Object
- .get_clients ⇒ Object
- .get_host_scout_vars(*args) ⇒ Object
- .get_hosts(*args) ⇒ Object
- .get_inactive_users(*args) ⇒ Object
- .get_main_scout(*args) ⇒ Object
- .get_private_key(*args) ⇒ Object
- .get_vars(*args) ⇒ Object
- .latest_version(*args) ⇒ Object
- .list_clients ⇒ Object
- .list_hosts(*args) ⇒ Object
- .ping(*args) ⇒ Object
- .ssh_to_host(*args) ⇒ Object
Class Method Details
.get_active_users(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/appforce/spawn/api/call.rb', line 25 def self.get_active_users(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end url = "#{client_url(opts[:client_api_name])}/users/active.yml?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.get_all_host_data(*args) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/appforce/spawn/api/call.rb', line 97 def self.get_all_host_data(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end url = "#{client_url(opts[:client_api_name])}/all_host_data.json?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.get_clients ⇒ Object
7 8 9 10 11 |
# File 'lib/appforce/spawn/api/call.rb', line 7 def self.get_clients url = "#{base_api_url}client/list?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.get_host_scout_vars(*args) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/appforce/spawn/api/call.rb', line 85 def self.get_host_scout_vars(*args) opts = args[1] unless opts[:host_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Host API Name" raise Appforce::Spawn::MissingParameters, "Missing Host API Name" end url = "#{host_url(opts[:host_api_name])}/scout.yml?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.get_hosts(*args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/appforce/spawn/api/call.rb', line 13 def self.get_hosts(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end url = "#{client_url(opts[:client_api_name])}/hosts?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.get_inactive_users(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/appforce/spawn/api/call.rb', line 37 def self.get_inactive_users(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end url = "#{client_url(opts[:client_api_name])}/users/inactive.yml?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.get_main_scout(*args) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/appforce/spawn/api/call.rb', line 61 def self.get_main_scout(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end url = "#{client_url(opts[:client_api_name])}/scout.yml?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.get_private_key(*args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/appforce/spawn/api/call.rb', line 73 def self.get_private_key(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end url = "#{client_url(opts[:client_api_name])}/private_key.pem?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.get_vars(*args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/appforce/spawn/api/call.rb', line 49 def self.get_vars(*args) opts = args[1] unless opts[:client_api_name] logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingParameters -- Missing Client API Name" raise Appforce::Spawn::MissingParameters, "Missing Client API Name" end url = "#{client_url(opts[:client_api_name])}/vars.yml?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call(url) end |
.latest_version(*args) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/appforce/spawn/api/call.rb', line 154 def self.latest_version(*args) url = rubygem_latest_version_url logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" resp = make_api_call(url) resp['version'] end |
.list_clients ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/appforce/spawn/api/call.rb', line 109 def self.list_clients resp = get_clients puts Appforce::Logger.header("Client List") resp.each do |item| printf " Client: %-16s API Name: %s\n", item['name'], item['api_name'] end puts Appforce::Logger. end |
.list_hosts(*args) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/appforce/spawn/api/call.rb', line 118 def self.list_hosts(*args) resp = get_all_host_data(*args) puts Appforce::Logger.header("Host List") i = 1 resp.each do |item| printf " #{i} - '%s' host: %s ip: %s\n", item['desc'], item['hostname'], item['ip'] i += 1 end puts Appforce::Logger. resp end |
.ping(*args) ⇒ Object
148 149 150 151 152 |
# File 'lib/appforce/spawn/api/call.rb', line 148 def self.ping(*args) url = "#{base_api_url}ping?#{token_param}" logger.debug "[#{self.name}##{__method__.to_s}] URL: #{url}" make_api_call("#{base_api_url}ping?#{token_param}") end |
.ssh_to_host(*args) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/appforce/spawn/api/call.rb', line 130 def self.ssh_to_host(*args) hosts = list_hosts(*args) input = HighLine.ask("\nWhich host to ssh to? ", Integer) { |q| q.in = 1..hosts.count } machine = hosts[input - 1] $stderr.print "\n" logger.info "Establishing SSH seesion as '#{machine['username']}' to #{machine['desc']}" logger.debug "SSH command: #{ssh_cmd(machine)}" pid = fork { exec ssh_cmd(machine) } Process.wait pid $stderr.print "\n" logger.info "SSH session terminated." end |