#!/usr/bin/python

import xmlrpclib, getopt, sys

params = \
{       "user"                  : "vdv",
        "password"      :       "whatever",
        "zone"                  :       "example.com",
        "name"                  :       "www",
        "ttl"           : "600",

}

server = "https://xname.whatever.com/xmlrpc.php"

def usage():
        print """xnameArec [-h|--help] 
                [-u|--user       <user>] 
                [-p|--password   <password>] 
                [-z|--zone       <zone>] 
                [-r|--recordname <record name>] 
                [-o|--oldaddress <old address> (use "*" for all)] 
                [-n|--newaddress <new address>] 
                [-t|--ttl <ttl value>]
                [-s|--server <xmlrpc server>] 
                """

def main():
        global server, params
        opts, args = getopt.getopt(sys.argv[1:], "hu:p:z:r:o:n:t:s:", ["help", "user=", "password=","zone=", "recordname=", "oldaddress="
, "newaddress=", "ttl=", "server="])
        for o, a in opts:
                if o in ("-u", "--user"):
                        params["user"] = a
                elif o in ("-p", "--password"):
                        params["password"] = a
                elif o in ("-z", "--zone"):
                        params["zone"] = a
                elif o in ("-r", "--recorname"):
                        params["name"] = a
                elif o in ("-o", "--oldaddress"):
                        params["oldaddress"] = a
                elif o in ("-n", "--newaddress"):
                        params["newaddress"] = a
                elif o in ("-t", "--ttl"):
                        params["ttl"] = a


                elif o in ("-s", "--server"):
                        server = a
                else:   
                        usage()
                        sys.exit()

        print "p: %s" % params
        client = xmlrpclib.Server(server)

        print "result: %s" % client.xname.updateArecord(params)


if __name__ == "__main__":
        main()


