class OHServers
Attributes
conn[RW]
options[RW]
Public Class Methods
new(conn=OHConnection.connect, options={})
click to toggle source
# File lib/servers.rb, line 5 def initialize(conn=OHConnection.connect, options={}) @conn = conn @options = options end
Public Instance Methods
create(server, start=true)
click to toggle source
# File lib/servers.rb, line 33 def create(server, start=true) if ( server.is_a? OHServer ) body = server.to_json if ( start ) resp = @conn.post "#{@@subject}/#{__method__}", body return JSON.parse(resp.body) # rescue JSON::ParserError resp.body else resp = @conn.post "#{@@subject}/#{__method__}/stopped", body #would be cool if this returned an OHServer object to use later return JSON.parse(resp.body) #rescue JSON::ParserError resp.body end else raise TypeError, "First argument must be an instance of OHServer with a unique name" end end
destroy(uuid)
click to toggle source
# File lib/servers.rb, line 100 def destroy(uuid) loc = @@subject if ( uuid.length == 36 ) loc += "/#{uuid}" else raise TypeError, "The Server UUID passed is invalid. It is #{uuid}. It must be 36 characters" end loc += "/#{__method__}" resp = @conn.post loc return resp.status end
info(*uuid)
click to toggle source
# File lib/servers.rb, line 16 def info(*uuid) # add our subject, in this case "servers" loc = @@subject if ( uuid.size > 0 ) if ( uuid.first.length == 36 ) loc += "/#{uuid.first}" else raise TypeError, "The Server UUID passed is invalid. It is #{uuid.first}. It must be 36 characters" end end # add the verb, which is the method name loc += "/#{__method__}" resp = @conn.get loc return JSON.parse(resp.body) end
list()
click to toggle source
# File lib/servers.rb, line 10 def list # the __method__ instance var is the name of the method resp = @conn.get "#{@@subject}/#{__method__}" return JSON.parse(resp.body) end
reset(uuid)
click to toggle source
# File lib/servers.rb, line 88 def reset(uuid) loc = @@subject if ( uuid.length == 36 ) loc += "/#{uuid}" else raise TypeError, "The Server UUID passed is invalid. It is #{uuid}. It must be 36 characters" end loc += "/#{__method__}" resp = @conn.post loc return resp.status end
set(uuid, options={})
click to toggle source
# File lib/servers.rb, line 112 def set(uuid, options={}) # gonna need some schema validation logic here, as the options to set are significantly reduced when a server is active. options = options.to_json loc = @@subject if ( uuid.length == 36 ) loc += "/#{uuid}" else raise TypeError, "The Server UUID passed is invalid. It is #{uuid}. It must be 36 characters" end loc += "/#{__method__}" resp = @conn.post loc, options return JSON.parse(resp.body) end
shutdown(uuid)
click to toggle source
# File lib/servers.rb, line 76 def shutdown(uuid) loc = @@subject if ( uuid.length == 36 ) loc += "/#{uuid}" else raise TypeError, "The Server UUID passed is invalid. It is #{uuid}. It must be 36 characters" end loc += "/#{__method__}" resp = @conn.post loc return resp.status end
start(uuid)
click to toggle source
# File lib/servers.rb, line 52 def start(uuid) loc = @@subject if ( uuid.length == 36 ) loc += "/#{uuid}" else raise TypeError, "The Server UUID passed is invalid. It is #{uuid}. It must be 36 characters" end loc += "/#{__method__}" resp = @conn.post loc return resp.status end
stop(uuid)
click to toggle source
# File lib/servers.rb, line 64 def stop(uuid) loc = @@subject if ( uuid.length == 36 ) loc += "/#{uuid}" else raise TypeError, "The Server UUID passed is invalid. It is #{uuid}. It must be 36 characters" end loc += "/#{__method__}" resp = @conn.post loc return resp.status end