RegisterRegister    Log inLog in    SearchSearch   

Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message

PostPosted: Wed Aug 13, 2008 4:51 pm    Post subject: HOWTO: Using GC's webservice from Python Reply with quote

Being a novice with SOAP, I had a bit of a job with accessing the Gamecreate
web interface from Python. However, after figuring out the problem/bug, it is
a very elegant way of working with GC from Python scripts, e.g. for checking
host and server status. I thought I would share the solution with you in case
anyone else wishes to use Python for the webservice.

The webservice is documented here:

You need the SOAPpy package for this. ZSI does not seem to work.

Following is a working example for the Permanent Servers and Subdomains
web service (Remote.asmx)

Import the module and create a proxy object for the service:
>>> import SOAPpy
>>> wsdlUrl = ''
>>> service = SOAPpy.WSDL.Proxy(wsdlUrl)

If you try to access one of the methods, you are most likely going to get a
failed response like this:
>>> statusList = service.GetHostStatusList(actorUsername='YOURUSERNAME',actorPassword='YOURPASSWORD',domainId=YOURDOMAINID)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/SOAPpy/", line 470, in __call__
    return self.__r_call(*args, **kw)
  File "/usr/lib/python2.4/site-packages/SOAPpy/", line 492, in __r_call
    self.__hd, self.__ma)
  File "/usr/lib/python2.4/site-packages/SOAPpy/", line 406, in __call
    raise p
SOAPpy.Types.faultType: <Fault soap:Server: Argument 2 is not valid in SqlBuilder>

After inspection of the HTTP-text that was transmitted, and comparing with
a working PHP example, I found that the trick to making this work was to
add the following two lines after the creation of the proxy object:

Alternatively, set these properties directly when creating the proxy:
>>> service = SOAPpy.WSDL.Proxy(wsdlUrl, noroot=1, methodattrs={'xmlns':""})

Now the webservice works and the results can be manipulated as any other
array/dict in Python:
>>> statusList = service.GetHostStatusList(actorUsername='YOURUSERNAME',actorPassword='YOURPASSWORD',domainId=YOURDOMAINID)
>>> len(statusList.HostStatus)
>>> statuslist.HostStatus[1]
<SOAPpy.Types.structType HostStatus at 1441875852>: {'Status': 'Online', 'Name': 'Alexandra', 'Memory': '1036308', 'CPU': '13', 'Online': 'true', 'Id': '2341', 'ServerCount': '3', 'Address': 'X.X.X.X', 'Disk': '6514', 'OperSystem': 'Linux'}
>>> statusList.HostStatus[1]['Status']
Back to top
View user's profile Send private message

PostPosted: Thu Mar 31, 2011 3:57 am 


PostPosted: Thu Aug 26, 2010 10:13 pm    Post subject: Reply with quote

Since SOAPpy is getting quite old, a better alternative may be to use suds:

>>> from suds.client import Client
>>> url = ""
>>> gc = Client(url)
>>> statusList = gc.service.GetHostStatusList(actorUsername='YOURUSERNAME',actorPassword='YOURPASSWORD',domainId=YOURDOMAINID)

Or simply:
>>> statusList = gc.service.GetHostStatusList('YOURUSERNAME','YOURPASSWORD',YOURDOMAINID)

Then just proceed as before:
>>> len(statusList.HostStatus)
>>> statusList.HostStatus[1]
   Id = 2332
   Name = "Beatrice"
   Address = "X.X.X.X"
   Status = "Online"
   OperSystem = "Linux"
   ServerCount = 1
   CPU = 5.5
   Memory = 906556
   Disk = 21660
   Online = True

The output is a bit cleaner than before, data types are reasonable, there is no need for the property settings, suds is better maintained than SOAPpy, and suds can be used in Twisted, if that's your preferred framework.

I did some tests with ZSI as well, but it was a pain to use, especially with Twisted. suds just works.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic All times are GMT + 10 Hours
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Forum powered by phpBB © 2001, 2005 phpBB Group