~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to plugins/xenserver/xenapi/etc/xapi.d/plugins/agent

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
AGENT_TIMEOUT = 30
44
44
 
45
45
 
46
 
def jsonify(fnc):
47
 
    def wrapper(*args, **kwargs):
48
 
        return json.dumps(fnc(*args, **kwargs))
49
 
    return wrapper
50
 
 
51
 
 
52
46
class TimeoutError(StandardError):
53
47
    pass
54
48
 
105
99
    return resp
106
100
 
107
101
 
108
 
@jsonify
109
102
def resetnetwork(self, arg_dict):
110
103
    """Writes a resquest to xenstore that tells the agent
111
104
    to reset networking.
114
107
    request_id = arg_dict['id']
115
108
    arg_dict['path'] = "data/host/%s" % request_id
116
109
    xenstore.write_record(self, arg_dict)
 
110
    try:
 
111
        resp = _wait_for_agent(self, request_id, arg_dict)
 
112
    except TimeoutError, e:
 
113
        raise PluginError(e)
 
114
    return resp
117
115
 
118
116
 
119
117
def inject_file(self, arg_dict):
206
204
    arg_dict["path"] = "data/guest/%s" % request_id
207
205
    arg_dict["ignore_missing_path"] = True
208
206
    start = time.time()
209
 
    while True:
210
 
        if time.time() - start > AGENT_TIMEOUT:
211
 
            # No response within the timeout period; bail out
212
 
            # First, delete the request record
213
 
            arg_dict["path"] = "data/host/%s" % request_id
214
 
            xenstore.delete_record(self, arg_dict)
215
 
            raise TimeoutError(_("TIMEOUT: No response from agent within"
216
 
                    " %s seconds.") % AGENT_TIMEOUT)
 
207
    while time.time() - start < AGENT_TIMEOUT:
217
208
        ret = xenstore.read_record(self, arg_dict)
218
209
        # Note: the response for None with be a string that includes
219
210
        # double quotes.
220
211
        if ret != '"None"':
221
212
            # The agent responded
222
213
            return ret
223
 
        else:
224
 
            time.sleep(3)
 
214
 
 
215
        time.sleep(.5)
 
216
 
 
217
    # No response within the timeout period; bail out
 
218
    # First, delete the request record
 
219
    arg_dict["path"] = "data/host/%s" % request_id
 
220
    xenstore.delete_record(self, arg_dict)
 
221
    raise TimeoutError(_("TIMEOUT: No response from agent within"
 
222
                         " %s seconds.") % AGENT_TIMEOUT)
225
223
 
226
224
 
227
225
if __name__ == "__main__":