RestConsole
From OpenSimulator
m |
(Add info about login settings and fix some spelling and formatting) |
||
Line 11: | Line 11: | ||
==Syntax== | ==Syntax== | ||
− | We take the user service(http://foo.bar:8002) as example here. | + | We take the user service (<nowiki>http://foo.bar:8002</nowiki>) as example here. Start up the user service with: |
mono OpenSim.Grid.UserServer.exe -console rest | mono OpenSim.Grid.UserServer.exe -console rest | ||
− | First start a new session by sending a POST. | + | First start a new session by sending a HTTP POST request. User name and password should match the settings for <tt>ConsoleUser</tt> and <tt>ConsolePass</tt> in section <tt>[Network]</tt> of OpenSim.ini.<br> |
− | + | Parameters: USER, PASS | |
− | http://foo.bar:8002/StartSession/ | + | <nowiki>http://foo.bar:8002/StartSession/</nowiki> |
Return: (XML) <ConsoleSession><SessionID></SessionID><Prompt></Prompt></ConsoleSession> | Return: (XML) <ConsoleSession><SessionID></SessionID><Prompt></Prompt></ConsoleSession> | ||
− | Now we got the SessionID, which can be used to send a command and to receive output. First, retrieve the console scrollback buffer. | + | Now we got the SessionID, which can be used to send a command and to receive output. First, retrieve the console scrollback buffer.<br> |
− | + | Parameters: none | |
− | http://foo.bar:8002/ | + | <nowiki>http://foo.bar:8002/ReadResponses/<SessionID>/</nowiki> |
− | Return: (XML) <ConsoleSession><Line Number=x></Line></ConsoleSession> | + | Return: (XML) <ConsoleSession><Line Number=x></Line></ConsoleSession><br> |
The reply contains all lines currently in the buffer. Subsequent fetches will only retrieve new lines. The fetch will hold for up to 30 seconds if there is no data, then return an error. The client is expected to try again (polling). | The reply contains all lines currently in the buffer. Subsequent fetches will only retrieve new lines. The fetch will hold for up to 30 seconds if there is no data, then return an error. The client is expected to try again (polling). | ||
− | Use the SessionID as ID | + | Use the SessionID as ID parameter, and send a POST request again.<br> |
− | + | Parameters: ID, COMMAND | |
− | http://foo.bar:8002/SessionCommand/ | + | <nowiki>http://foo.bar:8002/SessionCommand/</nowiki> |
− | Return: (XML) <ConsoleSession><Result></Result></ConsoleSession> | + | Return: (XML) <ConsoleSession><Result></Result></ConsoleSession><br> |
If everything went well, the command should have been executed. Try another command. | If everything went well, the command should have been executed. Try another command. | ||
− | When you want to close down the connection, send a POST again. | + | When you want to close down the connection, send a POST request again.<br> |
− | + | Parameters: ID | |
− | http://foo.bar:8002/CloseSession/ | + | <nowiki>http://foo.bar:8002/CloseSession/</nowiki> |
− | Return: (XML) <ConsoleSession><Result></Result></ConsoleSession> | + | Return: (XML) <ConsoleSession><Result></Result></ConsoleSession><br> |
− | The session is closed, and you have to | + | The session is closed, and you have to log in again, when you want to send a command again. |
==Examples== | ==Examples== | ||
Line 88: | Line 88: | ||
# set the base url to the REST console (with port) | # set the base url to the REST console (with port) | ||
− | console = UserConsoleClient('http://127.0.0.1:8300/') | + | console = UserConsoleClient('<nowiki>http://127.0.0.1:8300/</nowiki>') |
console.read_buffer() | console.read_buffer() | ||
print 'quit with a "."' | print 'quit with a "."' |
Revision as of 00:33, 4 September 2010
About
The REST console makes remote administration of the various OpenSim services possible.
The interface allows sending commands to the server and retrieving command output. Sending and receiving data is done through RESTful HTTP calls.
While sending is very straightforward, receiving is not. Receiving uses reverse HTTP, performing a long poll to a CAPS URI.
In order to make the protocol more efficient, the help functionality has been pushed to the client side. Rather than sending each keystroke to the server, only validated command lines are sent. To make this possible, the server sends a "connect burst" of data, which is the tree of allowed commands and their help information. This can be used by the client to create the "help" command output locally as well as provide command line help interactively.
The sample console client, OpenSim.ConsoleClient.exe, shows how this is done.
Syntax
We take the user service (http://foo.bar:8002) as example here. Start up the user service with:
mono OpenSim.Grid.UserServer.exe -console rest
First start a new session by sending a HTTP POST request. User name and password should match the settings for ConsoleUser and ConsolePass in section [Network] of OpenSim.ini.
Parameters: USER, PASS
http://foo.bar:8002/StartSession/
Return: (XML) <ConsoleSession><SessionID></SessionID><Prompt></Prompt></ConsoleSession>
Now we got the SessionID, which can be used to send a command and to receive output. First, retrieve the console scrollback buffer.
Parameters: none
http://foo.bar:8002/ReadResponses/<SessionID>/
Return: (XML) <ConsoleSession><Line Number=x></Line></ConsoleSession>
The reply contains all lines currently in the buffer. Subsequent fetches will only retrieve new lines. The fetch will hold for up to 30 seconds if there is no data, then return an error. The client is expected to try again (polling).
Use the SessionID as ID parameter, and send a POST request again.
Parameters: ID, COMMAND
http://foo.bar:8002/SessionCommand/
Return: (XML) <ConsoleSession><Result></Result></ConsoleSession>
If everything went well, the command should have been executed. Try another command.
When you want to close down the connection, send a POST request again.
Parameters: ID
http://foo.bar:8002/CloseSession/
Return: (XML) <ConsoleSession><Result></Result></ConsoleSession>
The session is closed, and you have to log in again, when you want to send a command again.
Examples
In python:
#!/usr/bin/python # This piece of code is published by thomax (txOh) (c) 2010 under the # Artistic License 1.0 (http://www.perlfoundation.org/artistic_license_1_0) import urllib, urllib2 import xml.dom.minidom class UserConsoleClient(): def __init__(self, addr): self.addr = addr url = self.addr + 'StartSession/' params = urllib.urlencode({ 'USER': 'Test', # REST username 'PASS': 'secret' # REST password }) data = urllib2.urlopen(url, params).read() dom = xml.dom.minidom.parseString(data) elem = dom.getElementsByTagName('SessionID') self.sessionid = elem[0].childNodes[0].nodeValue def close(self): url = self.addr + 'CloseSession/' params = urllib.urlencode({ 'ID': self.sessionid }) print urllib2.urlopen(url, params).read() def do_cmd(self, cmd): url = self.addr + '/SessionCommand/' params = urllib.urlencode({ 'ID': self.sessionid, 'COMMAND': cmd }) print urllib2.urlopen(url, params).read() def read_buffer(self): url = self.addr + 'ReadResponses/' + self.sessionid + '/' params = urllib.urlencode({ 'ID': self.sessionid }) print urllib2.urlopen(url, params).read() # set the base url to the REST console (with port) console = UserConsoleClient('http://127.0.0.1:8300/') console.read_buffer() print 'quit with a "."' cmd = "" while cmd != ".": if cmd != "": console.do_cmd(cmd) console.read_buffer() cmd = raw_input("> ") console.close()