Python ExampleΒΆ

This is an example of how to use the Memset API with Python and the standard module xmlrpclib for XML-RPC client access.

Substitute API_KEY_HEX with a valid API key and it can be run with a Python 2 interpreter.

#!/usr/bin/env python
"""
    Memset API example with Python.
"""

uri = "https://API_KEY_HEX:@api.memset.com/v1/xmlrpc/"

from xmlrpclib import ServerProxy
from pprint import pprint

def main():
    s = ServerProxy(uri)

    # list available methods
    print s.system.listMethods()

    # display help for service.list method
    print s.system.methodHelp("service.list")

    # get the product list
    r = s.service.list()
    pprint(r)

    # get the server list
    r = s.server.list()
    pprint(r)

    # get server information (one parameter)
    r = s.server.info(dict(name="myserver1"))
    pprint(r)

    # set a new nickname for a product (two parameters)
    r = s.service.set_nickname(dict(name="myserver1", nickname="www"))
    pprint(r)

    # reboot a server
    r = s.server.reboot(dict(name="myserver1"))
    pprint(r)

if __name__ == "__main__":
    main()

Previous topic

Changelog

Next topic

Python JSON-RPC Example

This Page