Class: RequestHelper
- Inherits:
-
Object
- Object
- RequestHelper
- Includes:
- CookieJar
- Defined in:
- lib/request_helper.rb
Instance Method Summary collapse
- #create_vm(options) ⇒ Object
-
#initialize(conf) ⇒ RequestHelper
constructor
A new instance of RequestHelper.
- #perform_action(options) ⇒ Object
Methods included from CookieJar
Constructor Details
#initialize(conf) ⇒ RequestHelper
Returns a new instance of RequestHelper.
9 10 11 12 13 14 |
# File 'lib/request_helper.rb', line 9 def initialize(conf) @server = conf[:server] || "localhost" @username = conf[:username] @password = conf[:password] @cookies = end |
Instance Method Details
#create_vm(options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/request_helper.rb', line 16 def create_vm() = .dup update_owner_field() handle_multi_instances() handle_custom_request() handle_location_specs() begin response = RestClient.post("http://#{@server}/vm", {:vm_request => }, {:cookies => @cookies, :content_type => 'application/json', :accept => :json}) result = JSON.parse(response) if [:json] puts JSON.pretty_generate(result) else puts result['message'] end rescue => e puts e.inspect end end |
#perform_action(options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/request_helper.rb', line 38 def perform_action() action = ['action'] hosts = ['hosts'] begin response = RestClient.post("http://#{@server}/vm/#{action}", {:id => hosts.first}, {:cookies => @cookies, :content_type => 'application/json', :accept => :json}) result = JSON.parse(response) if [:json] puts JSON.pretty_generate(result) else puts result['message'] end rescue => e puts e.inspect end end |