Skip to content

Instantly share code, notes, and snippets.

@kmcminn
Created November 15, 2013 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmcminn/7491308 to your computer and use it in GitHub Desktop.
Save kmcminn/7491308 to your computer and use it in GitHub Desktop.
sample ruby main!()
def main!
script = RemoteInfo.new
script.log.debug "Usage looks sane"
script.log.debug "script.options.list: #{script.options.list}" if script.options.list
script.log.debug "script.options.host: #{script.options.host}" if script.options.host
script.log.debug "script.options.user: #{script.options.user}" if script.options.user
script.log.debug "script.options.timeout: #{script.options.timeout}" if script.options.timeout
script.log.debug "script.options.inventory: #{script.options.inventory}" if script.options.inventory
script.usage "You didn't specify a host" unless script.options.host
script.usage "You didn't specify a user" unless script.options.user
remote_info = script.connect.fetch_all
script.log.debug "fetched system info for #{script.options.host}: #{remote_info.inspect}"
script.log.debug "Invalid args for device update: #{remote_info.inspect}" unless script.valid_args? remote_info
unless script.options.dryrun
response = script.valid_args?(remote_info) ? script.create_update_device!(remote_info) : nil
end
exit 1 if response.nil?
script.log.debug "api response headers: #{response.headers}"
script.log.debug "api response body: #{response.to_s}"
script.log.debug "api response code: #{response.code}"
/20[0-9]/ =~ response.code.to_s ? exit(0) : exit(1)
end
main!() if __FILE__ == $0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment