Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created June 4, 2010 08:52
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 ohadlevy/425171 to your computer and use it in GitHub Desktop.
Save ohadlevy/425171 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require "rubygems"
require 'net/http'
require "mechanize"
agent = Mechanize.new
url = "http://localhost:3000"
new_host_url = "#{url}/hosts/new"
#uncomment to enable authentication
#agent.get url
#form = agent.page.forms.first
#form["login[login]"] = "username"
#form["login[password]"] = "password"
#form.submit
agent.get new_host_url
form = agent.page.forms.first
form["host[name]"] = "test1.example.com"
env = form.field("host[environment_id]")
env.option_with(:text => /production/).select
hostgroup = form.field("host[hostgroup_id]")
hostgroup.option_with(:text => /base/i).select
form["host[host_parameters_attributes][0][name]"] = "Test_Parm"
form["host[host_parameters_attributes][0][value]"] = "Test_Val"
form["host[host_parameters_attributes][1][name]"] = "Test_Parm 2"
form["host[host_parameters_attributes][1][value]"] = "Test_Val 2"
form["host[host_parameters_attributes][1][nested]"] = ""
form["host[host_parameters_attributes][1][_destroy]"] = ""
form["host[comment]"] = "Batch added via script"
form.submit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment