SimpleXMLRPCServer question

F

flagg

I am working on a very basic xmlrpc server, which will expose certain
functions for administering BIND zone files. The big problem I am
having is parsing the incoming xmlrpc request. Basically part of the
xmlrpc request will help deterime which zone file is edited. I have
been looking at the do_POST() method from SimpleXMLRPCDispatcher and
it seems like I could code something which overides that method,
however I am new to programming am at a loss, i might even be making
this tougher than it needs to be. Is there a way to parse the
incoming xmlrpc request before the function it is calling is executed?
 
R

rdmurray

Quoth flagg said:
I am working on a very basic xmlrpc server, which will expose certain
functions for administering BIND zone files. The big problem I am
having is parsing the incoming xmlrpc request. Basically part of the
xmlrpc request will help deterime which zone file is edited. I have
been looking at the do_POST() method from SimpleXMLRPCDispatcher and
it seems like I could code something which overides that method,
however I am new to programming am at a loss, i might even be making
this tougher than it needs to be. Is there a way to parse the
incoming xmlrpc request before the function it is calling is executed?

Wouldn't you be overriding '_dispatch' on SimpleXMLRPCServer instead?

It's been a while since I looked at XMLRPC, but why wouldn't you have
a operation names, with the zone file to operate on as an argument?
Then you'd just be defining your operations as methods on your
SimpleXMLRPCServer, and they'd use the argument to determine which file
to operate on.

If that doesn't make sense, either I've forgotten how XMLRPC works,
or you should explain your requirements a bit more.

--RDM
 
A

andrew cooke

I am working on a very basic xmlrpc server, which will expose certain
functions for administering BIND zone files.  The big problem I am
having is parsing the incoming xmlrpc request.  Basically part of the
[...]

at the risk of repeating what the other guy said, it sounds like
you're going about this in the wrong way. the xmlrpc server will
parse the incoming request for you if you supply it with a suitable
function to invoke. so, for normal use, you do not override anything.

andrew
 
F

flagg

Wouldn't you be overriding '_dispatch' on SimpleXMLRPCServer instead?

It's been a while since I looked at XMLRPC, but why wouldn't you have
a operation names, with the zone file to operate on as an argument?
Then you'd just be defining your operations as methods on your
SimpleXMLRPCServer, and they'd use the argument to determine which file
to operate on.

If that doesn't make sense, either I've forgotten how XMLRPC works,
or you should explain your requirements a bit more.

--RDM

Let me see if i can elaborate on the requirements. I have 20+
different zone files. I want the xmlrpc server to be able to
determine what zone file to open by looking at the incoming xml
request. For example one of the functions I have now is to show a DNS
record (I am using dnspython for most of this work)

If i send an xmlrpc request that uses the 'showRecord' function with
params of 'oracle1.foo.bar.com' I want to parse the "params" piece
and then instruct the xml-rpc server to open foo.bar.com.zone for
reading. The reason why i was looking at do_Post() and _dispatch was
to attempt to read the incoming params and do exactly that.

Do you think there is an easier way of accomplishing this, than the
way I am going about it?
 
R

rdmurray

Quoth flagg said:
Let me see if i can elaborate on the requirements. I have 20+
different zone files. I want the xmlrpc server to be able to
determine what zone file to open by looking at the incoming xml
request. For example one of the functions I have now is to show a DNS
record (I am using dnspython for most of this work)

If i send an xmlrpc request that uses the 'showRecord' function with
params of 'oracle1.foo.bar.com' I want to parse the "params" piece
and then instruct the xml-rpc server to open foo.bar.com.zone for
reading. The reason why i was looking at do_Post() and _dispatch was
to attempt to read the incoming params and do exactly that.

Do you think there is an easier way of accomplishing this, than the
way I am going about it?

Yeah. Take a look at the SimpleXLMRPC documentation:

http://docs.python.org/library/simplexmlrpcserver.html

In addition to setting up the server as instructed (let's assume you
assign it to the variable 'server'), you just need to do something like:

class MyFunctions:

def showRecord(self, dnsname):
domain = '.'.join(dnsname.split('.')[1:])
with open(domain+'.zone')) as myfile:
# do stuff with data from myfile

server.register_instance(MyFunctions())


You would modify the body of that function to meet your processing
requirements, of course. That is, SimpleXMLRPCServer does the request
parsing for you, calls the correspondingly named method, and passes it
the params as method arguments.

(This example is taken from the SimpleXMLRPC documentation, I just
selected one particular way of exposing the methods: via a class
instance).

--RDM
 
H

Hendrik van Rooyen

Let me see if i can elaborate on the requirements. I have 20+
different zone files. I want the xmlrpc server to be able to
determine what zone file to open by looking at the incoming xml
request. For example one of the functions I have now is to show a DNS
record (I am using dnspython for most of this work)

This is a wrong move, it is too magical - see below
If i send an xmlrpc request that uses the 'showRecord' function with
params of 'oracle1.foo.bar.com' I want to parse the "params" piece
and then instruct the xml-rpc server to open foo.bar.com.zone for
reading. The reason why i was looking at do_Post() and _dispatch was
to attempt to read the incoming params and do exactly that.

Do you think there is an easier way of accomplishing this, than the
way I am going about it?

Yes I do.

Why don't you split the functionality into two bits - exactly as if you were
doing
it locally:

- OpenTheThing(whatOrWhere)
- ReadTheRecordAndShowIt(PossiblyWhichRecord)

If it's a remote database you are accessing, then you may need even more
steps, like first doing some select, or whatever - I would get it running
locally, calling local functions directly on the server, and then make them
remote xmlrpc proxy functions, after it's all working.

If you are getting the request from some user input, you can either change
the way you ask the questions, or you do the parsing at point of origen, to
determine what to call, in which sequence.

- Hendrik
 
F

flagg

This is a wrong move, it is too magical - see below



Yes I do.

Why don't you split the functionality into two bits - exactly as if you were
doing
it locally:

- OpenTheThing(whatOrWhere)
- ReadTheRecordAndShowIt(PossiblyWhichRecord)

If it's a remote database you are accessing, then you may need even more
steps, like first doing some select, or whatever - I would get it running
locally, calling local functions directly on the server, and then make them
remote xmlrpc proxy functions, after it's all working.

If you are getting the request from some user input, you can either change
the way you ask the questions, or you do the parsing at point of origen, to
determine what to call, in which sequence.

- Hendrik

Actually I have it working as local functions, its wrapping those
local functions up in a way that makes sense that is throwing me off.
Your suggestion of making two functions one for opening the file and
one for showing records makes sense. I will give it a shot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,284
Latest member
alphabetsalphabets

Latest Threads

Top