コード例 #1
0
ファイル: NaServer.py プロジェクト: optionalg/sanscripts
    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)
コード例 #2
0
    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)
コード例 #3
0
ファイル: NaServer.py プロジェクト: optionalg/sanscripts
    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)
コード例 #4
0
ファイル: NaServer.py プロジェクト: optionalg/sanscripts
 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
コード例 #5
0
    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)
コード例 #6
0
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
コード例 #7
0
 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