Пример #1
0
    def _modifyCKPHeadStr(self, options):
        """ modify exp self._h_head_cfg based on options

        @type options: dir
        @param options: like {'spicehost': 'xxx',
                              'spiceport': xxx(str)}
        @rtype: str
        @return: 1 success, else 0
        """
        str_io = StringIO(self._h_head_cfg)
        sxp_obj = sxp.parse(str_io)
        sxp_obj = sxp_obj[0]
        str_io.close()

        # python param and return use reference for list,
        # which makes the modify reflecting to sxp_obj
        for k in options.keys():
            if k == XenOptions.SPICEPORT:
                cld_spiceport = sxp.child_with_element(sxp_obj,
                                              XenOptions.SPICEPORT)
                ## FIXME: how to deal with if it's <
                #if len(cld_spiceport[1]) > len(options[k]):
                #    options[k] = (len(cld_spiceport[1]) -
                #                len(options[k])) * '0' + options[k]
                cld_spiceport[1] = options[k]
            elif k == XenOptions.SPICEHOST:
                cld_spicehost = sxp.child_with_element(sxp_obj,
                                              XenOptions.SPICEHOST)

                ## FIXME: how to deal with if it's <
                #if len(cld_spicehost[1]) > len(options[k]):
                #    options[k] = (len(cld_spicehost[1]) -
                #                len(options[k])) * '0' + options[k]
                cld_spicehost[1] = options[k]
            else:
                print "Untion option: %s" % k
                return 0

        th = self._h_head_cfg
        self._h_head_cfg = sxp.to_string(sxp_obj)
        # fill ' ' as placeholder, not '\0', '\0' cause sxp parse err
        if len(th) > len(self._h_head_cfg):
            self._h_head_cfg = (self._h_head_cfg +
                                (len(th) - len(self._h_head_cfg)) * ' ')
                               
        # sync with ._h_head_cfg
        self._header = self._header.replace(th, self._h_head_cfg, 1)
        return 1
Пример #2
0
print sxp.children(sxp_obj[0])

print "\nchildren(sxp_obj[0], 'domid')"
print sxp.children(sxp_obj[0], 'domid')

print "\nchildren(sxp_obj[0], 'image')"
print sxp.children(sxp_obj[0], 'image')

print "\nchild(sxp_obj[0], 'domid')"
print sxp.child(sxp_obj[0], 'domid')


print "\nsxp.child(sxp.child(sxp.child(sxp_obj[0], 'image'), 'hvm'), 'spiceport')"
print sxp.child(sxp.child(sxp.child(sxp_obj[0], 'image'), 'hvm'), 'spiceport')
print sxp.child(sxp.child(sxp.child(sxp_obj[0], 'image'), 'hvm'), 'spicehost')
print sxp.child_value(sxp.child(sxp.child(sxp_obj[0], 'image'), 'hvm'), 'spicehost')

print "sxp.child_with_id(sxp_obj, 'spicehost')"
print sxp.child_with_id(sxp_obj, 'spicehost')

print "sxp.elements(sxp_obj)"
print type(sxp.elements(sxp_obj))
print str(sxp.elements(sxp_obj))

# I add child_with_element
print "sxp.child_with_element(sxp_obj[0], 'spiceport')"
print sxp.child_with_element(sxp_obj[0], 'spiceport')
print "sxp.child_with_element(sxp_obj[0], 'spiceport')[1]"
print sxp.child_with_element(sxp_obj[0], 'spiceport')[1]