Class: Pxgrid::Client
- Inherits:
-
Object
- Object
- Pxgrid::Client
- Defined in:
- lib/pxgrid.rb
Instance Attribute Summary collapse
-
#nodename ⇒ Object
Returns the value of attribute nodename.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #accessSecret(peerNodeName) ⇒ Object
- #activate ⇒ Object
-
#initialize(pxgrid_ip, nodename, credentials = {}) ⇒ Client
constructor
A new instance of Client.
- #serviceLookup(service) ⇒ Object
Constructor Details
#initialize(pxgrid_ip, nodename, credentials = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pxgrid.rb', line 12 def initialize(pxgrid_ip, nodename, credentials = {}) @nodename = nodename @client = Faraday.new("https://#{pxgrid_ip}:8910/pxgrid/") do |conn| conn.adapter Faraday.default_adapter conn.ssl[:verify] = false conn.headers["Accept"] = "application/json" conn.headers["Content-Type"] = "application/json" end if credentials && credentials[:username] && credentials[:password] # Looks like we have an account. Validate the account. @username = credentials[:username] @password = credentials[:password] else # Don't have credentials. Create the account in pxGrid. # Create an account and get the username and password params = {"nodeName": nodename} response = @client.post("control/AccountCreate", params.to_json) if response.success? response = JSON.parse(response.body) @username = response["userName"] @password = response["password"] else raise "AccountCreationError" end end # Save the credentials as part of the connection @client.basic_auth(@username, @password) return @client end |
Instance Attribute Details
#nodename ⇒ Object
Returns the value of attribute nodename.
7 8 9 |
# File 'lib/pxgrid.rb', line 7 def nodename @nodename end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/pxgrid.rb', line 7 def username @username end |
Instance Method Details
#accessSecret(peerNodeName) ⇒ Object
63 64 65 66 |
# File 'lib/pxgrid.rb', line 63 def accessSecret(peerNodeName) params = {"peerNodeName": peerNodeName} return JSON.parse(@client.post("control/AccessSecret", params.to_json).body)["secret"] end |
#activate ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pxgrid.rb', line 43 def activate params = {"nodeName": @nodename} # Validate the credentials and activate it. response = JSON.parse(@client.post("control/AccountActivate", params.to_json).body) if response["accountState"] == "PENDING" # Approve the account in pxGrid return {"status": "PENDING", "description": "Account is pending approval. Approve it within pxGrid"} elsif response["accountState"] == "ENABLED" # Account is approved. return {"status": "ENABLED", "description": "Account is ready to be used"} else return {"status": "DISABLED", "description": "Account is disabled in pxGrid. Please enable account and try again."} end end |
#serviceLookup(service) ⇒ Object
58 59 60 61 |
# File 'lib/pxgrid.rb', line 58 def serviceLookup(service) params = {"name": service} services = JSON.parse(@client.post("control/ServiceLookup", params.to_json).body) end |