lib/grid/grid.rb in grid-0.4.2 vs lib/grid/grid.rb in grid-0.4.3
- old
+ new
@@ -91,18 +91,16 @@
def self.rampup(params = {})
if params[:rampup]
params[:rampup] / @grid.size
else
- 0.5
+ 0.25
end
end
class Helper
def initialize(params = {})
- @grid_id = params[:grid_id]
- @api = params[:api]
@uri = params[:uri] || "http://gridin.it/api/v0"
logfile = STDOUT
@log = Logger.new(logfile, 'daily')
@log.level = Logger::DEBUG
@log.datetime_format = "%Y-%m-%d %H:%M:%S "
@@ -136,17 +134,29 @@
def home
homes = ["HOME", "HOMEPATH"]
homes.detect {|h| ENV[h] != nil}
end
- def token
+ def token(args=nil)
@token = get_token
open(ENV[home]+'/.gridrc', 'w') { |f| f << "TOKEN:#{@token}" } if home and @token
@log.debug("New token : #{@token}")
end
- def list
+ def credits(args=nil)
+ @log.debug("Listing credits available ...")
+ begin
+ response = RestClient.get "#{@uri}/credit.json" , {
+ :token => @token
+ }
+ ap JSON.parse(response)
+ rescue => e
+ @log.error("#{e}")
+ end
+ end
+
+ def list(args=nil)
@log.debug("Listing grids ...")
begin
response = RestClient.get "#{@uri}/grid.json" , {
:token => @token
}
@@ -154,12 +164,12 @@
rescue => e
@log.error("#{e}")
end
end
- def show
- @grid_id = ask("Grid ID: ") unless @grid_id
+ def show(grid_id=nil)
+ @grid_id = ( grid_id ? grid_id : ask("Grid ID: ") )
@log.debug("Listing grid ...")
begin
response = RestClient.get "#{@uri}/grid/#{@grid_id}.json" , {
:token => @token
}
@@ -167,117 +177,94 @@
rescue => e
@log.error("#{e}")
end
end
- def create_grid(name, description)
+ def create_grid(name, description, driver, location, total_nodes)
begin
@log.debug("Creating grid ...")
response = RestClient.post "#{@uri}/grid.json" , {
:token => @token,
:name => name,
- :description => description
+ :description => description,
+ :driver => driver,
+ :location => location,
+ :total_nodes => total_nodes
}
(JSON.parse(response)).first[1]["id"]
rescue => e
@log.error("#{e}")
end
end
- def create_intranode(grid_id, browser_type, location, nodes)
- begin
- @log.debug("Creating intranode ...")
- response = RestClient.post "#{@uri}/grid/#{grid_id.to_s}/intranode.json", {
- :token => @token,
- :browser_type => browser_type,
- :location => location,
- :nodes => nodes
- }
- rescue => e
- @log.error("#{e}")
- end
+ def create(args=nil)
+ name = ask("Grid name: ") { |q| q.default = "Grid" }
+ description = ask("Grid description: ") { |q| q.default = "Grid created #{Time.now}" }
+ total_nodes = ask("Number of nodes: ") { |q| q.default = 5 }
+ location = ask("Location of nodes: ") { |q| q.default = "us-east" }
+ driver = ask("Driver: ") { |q| q.default = "webdriver" } unless @api
+ @grid_id = create_grid(name, description, driver, location, total_nodes)
+ show(@grid_id)
end
- def delete_intranode
+ def launch(args=nil)
+ name = ask("Grid name: ") { |q| q.default = "Grid" }
+ description = ask("Grid description: ") { |q| q.default = "Grid created #{Time.now}" }
+ total_nodes = ask("Number of nodes: ") { |q| q.default = 5 }
+ location = ask("Location of nodes: ") { |q| q.default = "us-east" }
+ driver = ask("Driver: ") { |q| q.default = "webdriver" } unless @api
+ @grid_id = create_grid(name, description, driver, location, total_nodes)
+ @log.debug("Starting grid ...")
begin
- @log.debug("Deleting intranode ...")
- response = RestClient.delete "#{@uri}/grid/intranode/#{@intranode_id}.json", {
- :token => @token
- }
+ response = RestClient.put "#{@uri}/grid/#{@grid_id.to_s}/start.json", {:token => @token}
rescue => e
@log.error("#{e}")
end
+ show(@grid_id)
end
- def create
- name = ask("Grid name: ") { |q| q.default = "Grid" }
- description = ask("Grid description: ") { |q| q.default = "Grid created #{Time.now}" }
- nodes = ask("Number of nodes: ") { |q| q.default = 5 }
- location = ask("Location of nodes: ") { |q| q.default = "us-east" }
- browser_type = ask("Node type: ") { |q| q.default = "webdriver" } unless @api
- @grid_id = create_grid(name, description)
- create_intranode(@grid_id, browser_type, location, nodes)
- show
- end
-
- def add
- @grid_id = ask("Grid ID: ") unless @grid_id
- nodes = ask("Number of nodes: ") { |q| q.default = 5 }
- location = ask("Location of nodes: ") { |q| q.default = "us-east" }
- browser_type = ask("Node type: ") { |q| q.default = "webdriver" } unless @api
- create_intranode(@grid_id, browser_type, location, nodes)
- show
- end
-
- def delete
- @grid_id = ask("Grid ID: ") unless @grid_id
- @intranode_id= ask("Intranode ID: ") unless @intranode_id
- delete_intranode
- show
- end
-
- def start
- @grid_id = ask("Grid ID: ") unless @grid_id
+ def start(grid_id=nil)
+ @grid_id = ( grid_id ? grid_id : ask("Grid ID: ") )
@log.debug("Starting grid ...")
begin
response = RestClient.put "#{@uri}/grid/#{@grid_id.to_s}/start.json", {:token => @token}
rescue => e
@log.error("#{e}")
end
- show
+ show(@grid_id)
end
- def stop
- @grid_id = ask("Grid ID: ") unless @grid_id
+ def stop(grid_id=nil)
+ @grid_id = ( grid_id ? grid_id : ask("Grid ID: ") )
@log.debug("Stopping grid ...")
begin
response = RestClient.put "#{@uri}/grid/#{@grid_id.to_s}/stop.json", {:token => @token}
rescue => e
@log.error("#{e}")
end
- show
+ show(@grid_id)
end
- def restart
- @grid_id = ask("Grid ID: ") unless @grid_id
+ def restart(grid_id=nil)
+ @grid_id = ( grid_id ? grid_id : ask("Grid ID: ") )
@log.debug("Restarting grid ...")
begin
response = RestClient.put "#{@uri}/grid/#{@grid_id.to_s}/restart.json", {:token => @token}
rescue => e
@log.error("#{e}")
end
- show
+ show(@grid_id)
end
- def status
- @grid_id = ask("Grid ID: ") unless @grid_id
+ def status(grid_id=nil)
+ @grid_id = ( grid_id ? grid_id : ask("Grid ID: ") )
@log.debug("Updating status of grid ...")
begin
response = RestClient.put "#{@uri}/grid/#{@grid_id.to_s}/status.json", {:token => @token}
rescue => e
@log.error("#{e}")
end
- show
+ show(@grid_id)
end
end
end