Class: Wisebed::Testbed

Inherits:
Client
  • Object
show all
Defined in:
lib/wisebedclientruby/testbed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#delete_from_wisebed, #experimentconfiguration, #post_to_wisebed, #request_from_wisebed, #testbeds

Constructor Details

#initialize(testbed_id) ⇒ Testbed



7
8
9
10
# File 'lib/wisebedclientruby/testbed.rb', line 7

def initialize(testbed_id)
  @cookie = ""
  @id = testbed_id
end

Instance Attribute Details

Returns the value of attribute cookie.



5
6
7
# File 'lib/wisebedclientruby/testbed.rb', line 5

def cookie
  @cookie
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



5
6
7
# File 'lib/wisebedclientruby/testbed.rb', line 5

def credentials
  @credentials
end

Instance Method Details

#delete_reservation(reservation_hash) ⇒ Object



59
60
61
# File 'lib/wisebedclientruby/testbed.rb', line 59

def delete_reservation(reservation_hash)
  delete_from_wisebed(@id+"/reservations", reservation_hash)
end

#experiments(reservation_data = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/wisebedclientruby/testbed.rb', line 63

def experiments(reservation_data=nil)
  unless reservation_data
    reservation_data = personal_reservations(Time.now, Time.now+(24*60*60)).last["data"]
    reservation_data[0].delete("username")
    reservation_data = {"reservations" => reservation_data}
  end            
  res = post_to_wisebed(@id+"/experiments", reservation_data)
  res.split("/").last
end

#flash(secret_keservation_key, flash_this_json) ⇒ Object



73
74
75
# File 'lib/wisebedclientruby/testbed.rb', line 73

def flash(secret_keservation_key, flash_this_json)
  post_to_wisebed(@id+"/experiments/"+secret_keservation_key+"/flash", flash_this_json)
end

#is_logged_in?Boolean



30
31
32
33
# File 'lib/wisebedclientruby/testbed.rb', line 30

def is_logged_in?
  res = request_from_wisebed @id+"/isLoggedIn"
  not res.include? "not logged in"
end

#login!(credentials = nil) ⇒ Object

Raises:

  • (SecurityError)


17
18
19
20
21
22
23
# File 'lib/wisebedclientruby/testbed.rb', line 17

def login!(credentials=nil)
  @credentials = credentials if credentials
  raise "Cannot login: No credentials given!" if not @credentials
  res = post_to_wisebed @id+"/login", @credentials
  raise SecurityError, "could not log into #{@id}: wrong username/password" if res.include? "Authentication failed"
  @secret_authentication_keys = res
end

#logout!Object



25
26
27
28
# File 'lib/wisebedclientruby/testbed.rb', line 25

def logout!
  request_from_wisebed @id + "/logout"
  @cookie = ""
end

#make_reservation(from, to, user_data, node_URNs) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wisebedclientruby/testbed.rb', line 47

def make_reservation(from, to, user_data, node_URNs)
  content = {
    "from"     => from.iso8601_no_tz,
    "nodeURNs" => node_URNs,
    "to"       => to.iso8601_no_tz(),
    "userData" => user_data # description or something
  }
  res = post_to_wisebed(@id+"/reservations/create", content)
  raise "Another reservation is in conflict with yours" if res.include? "Another reservation is in conflict with yours"
  res
end

#personal_reservations(from = nil, to = nil) ⇒ Object



35
36
37
38
# File 'lib/wisebedclientruby/testbed.rb', line 35

def personal_reservations(from=nil, to=nil)
  login! if @cookie.empty?
  public_reservations(from, to, true)["reservations"]
end

#public_reservations(from = nil, to = nil, useronly = false) ⇒ Object



40
41
42
43
44
45
# File 'lib/wisebedclientruby/testbed.rb', line 40

def public_reservations(from=nil, to=nil, useronly=false)
  # Time.iso8601 includes the timezone (+01:00), however XMLGreagorianCalendar does not parse this
  res = request_from_wisebed @id+"/reservations?userOnly="+useronly.to_s+"&"+
    (from ? ("from=" + from.iso8601_no_tz + "&") : "") + (to ? ("to="+to.iso8601_no_tz + "&") : "")
  res.nil? ? "not logged in for personal reservations" : res["reservations"]
end

#wise_ml(experiment_id = nil, json_or_xml = "json") ⇒ Object



12
13
14
15
# File 'lib/wisebedclientruby/testbed.rb', line 12

def wise_ml(experiment_id = nil, json_or_xml = "json")
  # TODO: handle xml
  request_from_wisebed(@id+ "/experiments/" + (experiment_id ? experiment_id+"/" : "") + "network")
end