2

my question is quite hard to describe, so I will focus on explaining the situation. So let's say I have 2 different entities, which may run on different machines. Let's call the first one Manager and the second one Generator. The manager is the only one which can be called via the user.

The manager has a method called getVM(scenario_Id), which takes the ID of a scenario as a parameter, and retrieve a BLOB from the database corresponding to the ID given as a parameter. This BLOB is actually a XML structure that I need to send to the Generator. Both have a Flask running.

On another machine, I have my generator with a generateVM() method, which will create a VM according to the XML structure it recieves. We will not talk about how the VM is created from the XML.

Currently I made this :

Manager

# This method will be called by the user
@app.route("/getVM/<int:scId>", methods=['GET']) 
def getVM(scId):
    xmlContent = db.getXML(scId)  # So here is what I want to send
    generatorAddr = sgAdd + "/generateVM"   # sgAdd is declared in the Initialize() [IP of the Generator]

    # Here how should I put my data ? 
    # How can I transmit xmlContent ? 

    testReturn = urlopen(generatorAddr).read()
    return json.dumps(testReturn) 

Generator

# This method will be called by the user
@app.route("/generateVM", methods=['POST']) 
def generateVM():
    # Retrieve the XML content...
    return "Whatever"

So as you can see, I am stuck on how to transmit the data itself (the XML structure), and then how to treat it... So if you have any strategy, hint, tip, clue on how I should proceed, please feel free to answer. Maybe there are some things I do not really understand about Flask, so feel free to correct everything wrong I said.

Best regards and thank you

PS : Lines with routes are commented because they mess up the syntax coloration

4

1 回答 1

0

unless i'm missing something couldn't you just transmit it in the body of a post request? Isn't that how your generateVM method is setup?

@app.route("/getVM/<int:scId>", methods=['GET']) 
def getVM(scId):
    xmlContent = db.getXML(scId)  
    generatorAddr = sgAdd + "/generateVM"   

xml_str = some_method_to_generate_xml()
data_str = urllib.urlencode({'xml': xml_str})
urllib.urlopen(generatorAddr, data=data_str).read()
return json.dumps(testReturn) 

http://docs.python.org/2/library/urllib.html#urllib.urlopen

于 2012-11-14T15:41:17.677 回答