def invoke(self, api, *arg): """A convenience routine which wraps invoke_elem(). It constructs an NaElement with name $api, and for each argument name/value pair, adds a child element to it. It's an error to have an even number of arguments to this function. Example: myserver->invoke('snapshot-create', 'snapshot', 'mysnapshot', 'volume', 'vol0'); """ num_parms = len(arg) if ((num_parms & 1) != 0): return self.fail_response( 13001, "in Zapi::invoke, invalid number of parameters") xi = NaElement(api) i = 0 while (i < num_parms): key = arg[i] i = i + 1 value = arg[i] i = i + 1 xi.child_add(NaElement(key, value)) return self.invoke_elem(xi)
def invoke(self, api, *arg): """A convenience routine which wraps invoke_elem(). It constructs an NaElement with name $api, and for each argument name/value pair, adds a child element to it. It's an error to have an even number of arguments to this function. Example: myserver->invoke('snapshot-create', 'snapshot', 'mysnapshot', 'volume', 'vol0'); """ num_parms = len(arg) if ((num_parms & 1)!= 0): return self.fail_response(13001,"in Zapi::invoke, invalid number of parameters") xi = NaElement(api) i = 0 while(i < num_parms): key = arg[i] i = i+1 value = arg[i] i = i+1 xi.child_add(NaElement(key, value)) return self.invoke_elem(xi)
def start_element(self, name, attrs): """This is a private function, not to be called from outside NaElement """ n = NaElement(name) self.ZAPI_stack.append(n) self.ZAPI_atts = {} attr_name = list(attrs.keys()) attr_value = list(attrs.values()) i = 0 for att in attr_name: val = attr_value[i] i = i + 1 self.ZAPI_atts[att] = val n.attr_set(att, val)
def fail_response(self, errno, reason): """This is a private function, not to be called from outside NaElement """ n = NaElement("results") n.attr_set("status", "failed") n.attr_set("reason", reason) n.attr_set("errno", errno) return n
def start_element(self, name, attrs): """This is a private function, not to be called from outside NaElement """ n = NaElement(name) self.ZAPI_stack.append(n) self.ZAPI_atts = {} attr_name = list(attrs.keys()) attr_value = list(attrs.values()) i = 0 for att in attr_name : val = attr_value[i] i = i+1 self.ZAPI_atts[att] = val n.attr_set(att,val)
def _invoke_api(conn, *args): api = NaElement(*args) call = conn.invoke_elem(api) if call.results_errno() != 0: raise IOError('Failed api call=%s, errno=%s, desc=%s' % (args, call.results_errno(), call.sprintf())) return call
def fail_response(self, errno, reason): """This is a private function, not to be called from outside NaElement """ n = NaElement("results") n.attr_set("status","failed") n.attr_set("reason",reason) n.attr_set("errno",errno) return n