Exemple #1
0
    def _update_publish(cls, upd_root):
        subscribe_item = etree.Element('resultItem')
        subscribe_item.extend(deepcopy(upd_root))
        from_name = escape(upd_root[0].attrib['name'])
        to_name = None
        if not from_name in cls._graph:
            cls._graph[from_name] = {'ident': upd_root[0], 'links': {}}

        if len(upd_root) == 2:
            meta_name = re.sub("{.*}", "contrail:", upd_root[1][0].tag)
            link_key = meta_name
            link_info = {'meta': upd_root[1]}
            cls._graph[from_name]['links'][link_key] = link_info
        elif len(upd_root) == 3:
            meta_name = re.sub("{.*}", "contrail:", upd_root[2][0].tag)
            to_name = escape(upd_root[1].attrib['name'])
            link_key = '%s %s' % (meta_name, to_name)
            link_info = {'meta': upd_root[2], 'other': upd_root[1]}
            cls._graph[from_name]['links'][link_key] = link_info

            if not to_name in cls._graph:
                cls._graph[to_name] = {'ident': upd_root[1], 'links': {}}
            link_key = '%s %s' % (meta_name, from_name)
            link_info = {'meta': upd_root[2], 'other': upd_root[0]}
            cls._graph[to_name]['links'][link_key] = link_info
        else:
            raise Exception("Unknown ifmap update: %s" %
                            (etree.tostring(upd_root)))

        subscribe_result = etree.Element('updateResult')
        subscribe_result.append(subscribe_item)
        return subscribe_result, (from_name, to_name)
    def _update_publish(cls, upd_root):
        subscribe_item = etree.Element('resultItem')
        subscribe_item.extend(deepcopy(upd_root))
        from_name = escape(upd_root[0].attrib['name'])
        to_name = None
        if not from_name in cls._graph:
            cls._graph[from_name] = {'ident': upd_root[0], 'links': {}}

        if len(upd_root) == 2:
            meta_name = re.sub("{.*}", "contrail:", upd_root[1][0].tag)
            link_key = meta_name
            link_info = {'meta': upd_root[1]}
            cls._graph[from_name]['links'][link_key] = link_info
        elif len(upd_root) == 3:
            meta_name = re.sub("{.*}", "contrail:", upd_root[2][0].tag)
            to_name = escape(upd_root[1].attrib['name'])
            link_key = '%s %s' % (meta_name, to_name)
            link_info = {'meta': upd_root[2], 'other': upd_root[1]}
            cls._graph[from_name]['links'][link_key] = link_info

            if not to_name in cls._graph:
                cls._graph[to_name] = {'ident': upd_root[1], 'links': {}}
            link_key = '%s %s' % (meta_name, from_name)
            link_info = {'meta': upd_root[2], 'other': upd_root[0]}
            cls._graph[to_name]['links'][link_key] = link_info
        else:
            raise Exception("Unknown ifmap update: %s" %
                            (etree.tostring(upd_root)))

        subscribe_result = etree.Element('updateResult')
        subscribe_result.append(subscribe_item)
        return subscribe_result, (from_name, to_name)
    def _update_publish(cls, upd_root):
        subscribe_item = etree.Element("resultItem")
        subscribe_item.extend(deepcopy(upd_root))
        from_name = escape(upd_root[0].attrib["name"])
        to_name = None
        if not from_name in cls._graph:
            cls._graph[from_name] = {"ident": upd_root[0], "links": {}}

        if len(upd_root) == 2:
            meta_name = re.sub("{.*}", "contrail:", upd_root[1][0].tag)
            link_key = meta_name
            link_info = {"meta": upd_root[1]}
            cls._graph[from_name]["links"][link_key] = link_info
        elif len(upd_root) == 3:
            meta_name = re.sub("{.*}", "contrail:", upd_root[2][0].tag)
            to_name = escape(upd_root[1].attrib["name"])
            link_key = "%s %s" % (meta_name, to_name)
            link_info = {"meta": upd_root[2], "other": upd_root[1]}
            cls._graph[from_name]["links"][link_key] = link_info

            if not to_name in cls._graph:
                cls._graph[to_name] = {"ident": upd_root[1], "links": {}}
            link_key = "%s %s" % (meta_name, from_name)
            link_info = {"meta": upd_root[2], "other": upd_root[0]}
            cls._graph[to_name]["links"][link_key] = link_info
        else:
            raise Exception("Unknown ifmap update: %s" % (etree.tostring(upd_root)))

        subscribe_result = etree.Element("updateResult")
        subscribe_result.append(subscribe_item)
        return subscribe_result, (from_name, to_name)
    def _update_publish(cls, upd_root):
        subscribe_item = etree.Element('resultItem')
        subscribe_item.extend(deepcopy(upd_root))
        from_name = escape(upd_root[0].attrib['name'])
        if not from_name in cls._graph:
            cls._graph[from_name] = {'ident': upd_root[0], 'links': {}}

        if len(upd_root) == 2:
            meta_name = re.sub("{.*}", "contrail:", upd_root[1][0].tag)
            link_key = meta_name
            link_info = {'meta': upd_root[1]}
            cls._graph[from_name]['links'][link_key] = link_info
        elif len(upd_root) == 3:
            meta_name = re.sub("{.*}", "contrail:", upd_root[2][0].tag)
            to_name = escape(upd_root[1].attrib['name'])
            link_key = '%s %s' % (meta_name, to_name)
            link_info = {'meta': upd_root[2], 'other': upd_root[1]}
            cls._graph[from_name]['links'][link_key] = link_info

            # reverse mapping only for strong refs
            # currently refs from same type to each other is weak ref
            from_type = from_name.split(':')[1]
            to_type = to_name.split(':')[1]
            if not to_name in cls._graph:
                cls._graph[to_name] = {'ident': upd_root[1], 'links': {}}
            link_key = '%s %s' % (meta_name, from_name)
            link_info = {'meta': upd_root[2], 'other': upd_root[0]}
            cls._graph[to_name]['links'][link_key] = link_info
        else:
            raise Exception("Unknown ifmap update: %s" %
                            (etree.tostring(upd_root)))

        subscribe_result = etree.Element('updateResult')
        subscribe_result.append(subscribe_item)
        return subscribe_result
    def _update_publish(cls, upd_root):
        subscribe_item = etree.Element('resultItem')
        subscribe_item.extend(deepcopy(upd_root))
        from_name = escape(upd_root[0].attrib['name'])
        if not from_name in cls._graph:
            cls._graph[from_name] = {'ident': upd_root[0], 'links': {}}

        if len(upd_root) == 2:
            meta_name = re.sub("{.*}", "contrail:", upd_root[1][0].tag)
            link_key = meta_name
            link_info = {'meta': upd_root[1]}
            cls._graph[from_name]['links'][link_key] = link_info
        elif len(upd_root) == 3:
            meta_name = re.sub("{.*}", "contrail:", upd_root[2][0].tag)
            to_name = escape(upd_root[1].attrib['name'])
            link_key = '%s %s' % (meta_name, to_name)
            link_info = {'meta': upd_root[2], 'other': upd_root[1]}
            cls._graph[from_name]['links'][link_key] = link_info

            # reverse mapping only for strong refs
            # currently refs from same type to each other is weak ref
            from_type = from_name.split(':')[1]
            to_type = to_name.split(':')[1]
            if not to_name in cls._graph:
                cls._graph[to_name] = {'ident': upd_root[1], 'links': {}}
            link_key = '%s %s' % (meta_name, from_name)
            link_info = {'meta': upd_root[2], 'other': upd_root[0]}
            cls._graph[to_name]['links'][link_key] = link_info
        else:
            raise Exception("Unknown ifmap update: %s" %
                            (etree.tostring(upd_root)))

        subscribe_result = etree.Element('updateResult')
        subscribe_result.append(subscribe_item)
        return subscribe_result
    def object_alloc(obj_class, parent_res_type, fq_name):
        """Allocate IF-MAP ID of the resource and its parent."""
        res_type = obj_class.resource_type
        my_fqn = ":".join(fq_name)
        parent_fqn = ":".join(fq_name[:-1])

        ifmap_id = "contrail:%s:%s" % (res_type, my_fqn)
        if parent_fqn:
            if parent_res_type is None:
                err_msg = "Parent: %s type is none for: %s" % (parent_fqn, my_fqn)
                return False, (409, err_msg)
            parent_ifmap_id = "contrail:" + parent_res_type + ":" + parent_fqn
        else:  # parent is config-root
            parent_ifmap_id = "contrail:config-root:root"

        return True, (escape(ifmap_id), escape(parent_ifmap_id))
Exemple #7
0
    def object_alloc(obj_class, parent_res_type, fq_name):
        """Allocate IF-MAP ID of the resource and its parent."""
        res_type = obj_class.resource_type
        my_fqn = ':'.join(fq_name)
        parent_fqn = ':'.join(fq_name[:-1])

        ifmap_id = 'contrail:%s:%s' % (res_type, my_fqn)
        if parent_fqn:
            if parent_res_type is None:
                err_msg = "Parent: %s type is none for: %s" % (parent_fqn,
                                                               my_fqn)
                return False, (409, err_msg)
            parent_ifmap_id = 'contrail:' + parent_res_type + ':' + parent_fqn
        else:  # parent is config-root
            parent_ifmap_id = 'contrail:config-root:root'

        return True, (escape(ifmap_id), escape(parent_ifmap_id))
Exemple #8
0
    def object_alloc(cls, obj_class, parent_res_type, fq_name):
        res_type = obj_class.resource_type
        my_fqn = ':'.join(fq_name)
        parent_fqn = ':'.join(fq_name[:-1])

        my_imid = 'contrail:%s:%s' % (res_type, my_fqn)
        if parent_fqn:
            if parent_res_type is None:
                err_msg = "Parent: %s type is none for: %s" % (parent_fqn,
                                                               my_fqn)
                return False, (409, err_msg)
            parent_imid = 'contrail:' + parent_res_type + ':' + parent_fqn
        else:  # parent is config-root
            parent_imid = 'contrail:config-root:root'

        # Normalize/escape special chars
        my_imid = escape(my_imid)
        parent_imid = escape(parent_imid)

        return True, (my_imid, parent_imid)
Exemple #9
0
    def object_alloc(cls, obj_class, parent_res_type, fq_name):
        res_type = obj_class.resource_type
        my_fqn = ':'.join(fq_name)
        parent_fqn = ':'.join(fq_name[:-1])

        my_imid = 'contrail:%s:%s' %(res_type, my_fqn)
        if parent_fqn:
            if parent_res_type is None:
                err_msg = "Parent: %s type is none for: %s" % (parent_fqn,
                                                               my_fqn)
                return False, (409, err_msg)
            parent_imid = 'contrail:' + parent_res_type + ':' + parent_fqn
        else: # parent is config-root
            parent_imid = 'contrail:config-root:root'

        # Normalize/escape special chars
        my_imid = escape(my_imid)
        parent_imid = escape(parent_imid)

        return True, (my_imid, parent_imid)
Exemple #10
0
    def _delete_publish(cls, del_root):
        from_name = escape(del_root[0].attrib['name'])
        to_name = None
        if 'filter' in del_root.attrib:
            meta_name = del_root.attrib['filter']
            if len(del_root) == 1:
                link_key = meta_name
            elif len(del_root) == 2:
                to_name = escape(del_root[1].attrib['name'])
                link_key = '%s %s' % (meta_name, to_name)
            else:
                raise Exception("Unknown ifmap delete: %s" %
                                (etree.tostring(del_root)))

            link_keys = [link_key]

        else:  # delete all metadata on this ident or between pair of idents
            if len(del_root) == 1:
                link_keys = cls._graph[from_name]['links'].keys()
            elif len(del_root) == 2:
                to_name = escape(del_root[1].attrib['name'])
                link_keys = []
                if from_name in cls._graph:
                    all_link_keys = cls._graph[from_name]['links'].keys()
                    for link_key in all_link_keys:
                        link_info = cls._graph[from_name]['links'][link_key]
                        if 'other' in link_info:
                            if link_key.split()[1] == to_name:
                                link_keys.append(link_key)
            else:
                raise Exception("Unknown ifmap delete: %s" %
                                (etree.tostring(del_root)))

        subscribe_result = etree.Element('deleteResult')
        for link_key in link_keys:
            subscribe_item = etree.Element('resultItem')
            subscribe_item.extend(deepcopy(del_root))
            link_info = cls._graph[from_name]['links'][link_key]
            # generate id1, id2, meta for poll for the case where
            # del of ident for all metas requested but we have a
            # ref meta to another ident
            if len(del_root) == 1 and 'other' in link_info:
                to_ident_elem = link_info['other']
                subscribe_item.append(to_ident_elem)
            subscribe_item.append(deepcopy(link_info['meta']))
            subscribe_result.append(subscribe_item)
            meta_name = re.sub("{.*}", "contrail:", link_info['meta'][0].tag)
            if 'other' in link_info:
                other_name = escape(link_info['other'].attrib['name'])
                rev_link_key = '%s %s' % (meta_name, from_name)
                if other_name in cls._graph:
                    del cls._graph[other_name]['links'][rev_link_key]
                    if not cls._graph[other_name]['links']:
                        del cls._graph[other_name]
            del cls._graph[from_name]['links'][link_key]

        # delete ident if no links left
        if from_name in cls._graph and not cls._graph[from_name]['links']:
            del cls._graph[from_name]

        if len(subscribe_result) == 0:
            subscribe_item = etree.Element('resultItem')
            subscribe_item.extend(deepcopy(del_root))
            subscribe_result.append(subscribe_item)

        return subscribe_result, (from_name, to_name)
    def _delete_publish(cls, del_root):
        from_name = escape(del_root[0].attrib['name'])
        to_name = None
        if 'filter' in del_root.attrib:
            meta_name = del_root.attrib['filter']
            if len(del_root) == 1:
                link_key = meta_name
            elif len(del_root) == 2:
                to_name = escape(del_root[1].attrib['name'])
                link_key = '%s %s' % (meta_name, to_name)
            else:
                raise Exception("Unknown ifmap delete: %s" %
                                (etree.tostring(del_root)))

            link_keys = [link_key]

        else:  # delete all metadata on this ident or between pair of idents
            if len(del_root) == 1:
                link_keys = cls._graph[from_name]['links'].keys()
            elif len(del_root) == 2:
                to_name = escape(del_root[1].attrib['name'])
                link_keys = []
                if from_name in cls._graph:
                    all_link_keys = cls._graph[from_name]['links'].keys()
                    for link_key in all_link_keys:
                        link_info = cls._graph[from_name]['links'][link_key]
                        if 'other' in link_info:
                            if link_key.split()[1] == to_name:
                                link_keys.append(link_key)
            else:
                raise Exception("Unknown ifmap delete: %s" %
                                (etree.tostring(del_root)))

        subscribe_result = etree.Element('deleteResult')
        for link_key in link_keys:
            subscribe_item = etree.Element('resultItem')
            subscribe_item.extend(deepcopy(del_root))
            link_info = cls._graph[from_name]['links'][link_key]
            # generate id1, id2, meta for poll for the case where
            # del of ident for all metas requested but we have a
            # ref meta to another ident
            if len(del_root) == 1 and 'other' in link_info:
                to_ident_elem = link_info['other']
                subscribe_item.append(to_ident_elem)
            subscribe_item.append(deepcopy(link_info['meta']))
            subscribe_result.append(subscribe_item)
            meta_name = re.sub(
                "{.*}", "contrail:", link_info['meta'][0].tag)
            if 'other' in link_info:
                other_name = escape(link_info['other'].attrib['name'])
                rev_link_key = '%s %s' % (meta_name, from_name)
                if other_name in cls._graph:
                    del cls._graph[other_name]['links'][rev_link_key]
                    if not cls._graph[other_name]['links']:
                        del cls._graph[other_name]
            del cls._graph[from_name]['links'][link_key]

        # delete ident if no links left
        if from_name in cls._graph and not cls._graph[from_name]['links']:
            del cls._graph[from_name]

        if len(subscribe_result) == 0:
            subscribe_item = etree.Element('resultItem')
            subscribe_item.extend(deepcopy(del_root))
            subscribe_result.append(subscribe_item)

        return subscribe_result, (from_name, to_name)
Exemple #12
0
    def _object_set(self, obj_class, ifmap_id, obj_dict, existing_links=None):
        # Properties Metadata
        metadatas = []
        for prop_field in obj_class.prop_fields:
            prop_value = obj_dict.get(prop_field)
            if prop_value is None:
                continue
            # construct object of xsd-type and get its xml repr
            # e.g. virtual_network_properties
            prop_field_types = obj_class.prop_field_types[prop_field]
            is_simple = not prop_field_types['is_complex']
            prop_type = prop_field_types['xsd_type']
            # e.g. virtual-network-properties
            meta_name = obj_class.prop_field_metas[prop_field]
            meta_long_name = 'contrail:%s' % meta_name
            meta_value = ''
            meta_elements = ''

            if prop_field in self.IFMAP_PUBLISH_SKIP_LIST:
                # Field not relevant, skip publishing to IfMap
                if not self.IFMAP_PUBLISH_SKIP_LIST[prop_field]:
                    continue
                # Call the handler fn to generate the relevant fields.
                try:
                    func = getattr(self,
                                   self.IFMAP_PUBLISH_SKIP_LIST[prop_field])
                    meta_elements = func(prop_field, prop_value)
                except AttributeError:
                    log_str = ("%s is marked for partial publish to Ifmap but "
                               "handler not defined" % prop_field)
                    self._log(log_str, level=SandeshLevel.SYS_DEBUG)
                    continue
            elif is_simple:
                meta_value = escape(str(prop_value))
            else:  # complex type
                prop_cls = str_to_class(prop_type, __name__)
                buf = StringIO()
                # perms might be inserted at server as obj.
                # obj construction diff from dict construction.
                if isinstance(prop_value, dict):
                    prop_cls(**prop_value).exportChildren(buf,
                                                          level=1,
                                                          name_=meta_name,
                                                          pretty_print=False)
                elif isinstance(prop_value, list):
                    for elem in prop_value:
                        if isinstance(elem, dict):
                            prop_cls(**elem).exportChildren(buf,
                                                            level=1,
                                                            name_=meta_name,
                                                            pretty_print=False)
                        else:
                            elem.exportChildren(buf,
                                                level=1,
                                                name_=meta_name,
                                                pretty_print=False)
                else:  # object
                    prop_value.exportChildren(buf,
                                              level=1,
                                              name_=meta_name,
                                              pretty_print=False)
                meta_elements = buf.getvalue()
                buf.close()
            meta = Metadata(meta_name,
                            meta_value,
                            {'ifmap-cardinality': 'singleValue'},
                            ns_prefix='contrail',
                            elements=meta_elements)
            # If obj is new (existing metas is none) or
            # if obj does not have this meta (or)
            # or if the meta is different from what we have currently,
            # then update
            if (not existing_links or
                    meta_long_name not in existing_links or
                    ('meta' in existing_links[meta_long_name] and
                     unicode(meta) != existing_links[meta_long_name]['meta'])):
                metadatas.append(meta)
        # end for all property types
        VncIfmapServer.update(ifmap_id, metadatas=metadatas)

        # References Metadata
        for ref_field in obj_class.ref_fields:
            refs = obj_dict.get(ref_field)
            if not refs:
                continue

            for ref in refs:
                ref_fq_name = ref['to']
                ref_fld_types_list = list(obj_class.ref_field_types[ref_field])
                ref_res_type = ref_fld_types_list[0]
                ref_link_type = ref_fld_types_list[1]
                ref_meta = obj_class.ref_field_metas[ref_field]
                ref_ifmap_id = get_ifmap_id_from_fq_name(ref_res_type,
                                                         ref_fq_name)
                ref_data = ref.get('attr')
                if ref_data:
                    buf = StringIO()
                    attr_cls = str_to_class(ref_link_type, __name__)
                    attr_cls(**ref_data).exportChildren(buf,
                                                        level=1,
                                                        name_=ref_meta,
                                                        pretty_print=False)
                    ref_link_xml = buf.getvalue()
                    buf.close()
                else:
                    ref_link_xml = ''
                metadata = Metadata(ref_meta,
                                    '',
                                    {'ifmap-cardinality': 'singleValue'},
                                    ns_prefix='contrail',
                                    elements=ref_link_xml)
                VncIfmapServer.update(ifmap_id, ref_ifmap_id, [metadata])
        # end for all ref types
        return (True, '')
Exemple #13
0
    def object_set(self, obj_class, my_imid, existing_metas, obj_dict):
        update = {}

        # Properties Meta
        for prop_field in obj_class.prop_fields:
            field = obj_dict.get(prop_field)
            if field is None:
                continue
            # construct object of xsd-type and get its xml repr
            # e.g. virtual_network_properties
            prop_field_types = obj_class.prop_field_types[prop_field]
            is_simple = not prop_field_types['is_complex']
            prop_type = prop_field_types['xsd_type']
            # e.g. virtual-network-properties
            prop_meta = obj_class.prop_field_metas[prop_field]

            if prop_field in VncIfmapClient.IFMAP_PUBLISH_SKIP_LIST:
                # Field not relevant, skip publishing to IfMap
                if not VncIfmapClient.IFMAP_PUBLISH_SKIP_LIST[prop_field]:
                    continue
                # Call the handler fn to generate the relevant fields.
                if callable(
                        VncIfmapClient.IFMAP_PUBLISH_SKIP_LIST[prop_field]):
                    prop_xml = VncIfmapClient.IFMAP_PUBLISH_SKIP_LIST[
                        prop_field](prop_field, field)
                    meta = Metadata(prop_meta,
                                    '', {'ifmap-cardinality': 'singleValue'},
                                    ns_prefix='contrail',
                                    elements=prop_xml)
                else:
                    log_str = '%s is marked for partial publish\
                               to Ifmap but handler not defined' % (prop_field)
                    self.config_log(log_str, level=SandeshLevel.SYS_DEBUG)
                    continue
            elif is_simple:
                norm_str = escape(str(field))
                meta = Metadata(prop_meta,
                                norm_str, {'ifmap-cardinality': 'singleValue'},
                                ns_prefix='contrail')
            else:  # complex type
                prop_cls = str_to_class(prop_type, __name__)
                buf = cStringIO.StringIO()
                # perms might be inserted at server as obj.
                # obj construction diff from dict construction.
                if isinstance(field, dict):
                    prop_cls(**field).exportChildren(buf,
                                                     level=1,
                                                     name_=prop_meta,
                                                     pretty_print=False)
                elif isinstance(field, list):
                    for elem in field:
                        if isinstance(elem, dict):
                            prop_cls(**elem).exportChildren(buf,
                                                            level=1,
                                                            name_=prop_meta,
                                                            pretty_print=False)
                        else:
                            elem.exportChildren(buf,
                                                level=1,
                                                name_=prop_meta,
                                                pretty_print=False)
                else:  # object
                    field.exportChildren(buf,
                                         level=1,
                                         name_=prop_meta,
                                         pretty_print=False)
                prop_xml = buf.getvalue()
                buf.close()
                meta = Metadata(prop_meta,
                                '', {'ifmap-cardinality': 'singleValue'},
                                ns_prefix='contrail',
                                elements=prop_xml)

            # If obj is new (existing metas is none) or
            # if obj does not have this prop_meta (or)
            # or if the prop_meta is different from what we have currently,
            # then update
            if (not existing_metas or not prop_meta in existing_metas
                    or ('' in existing_metas[prop_meta]
                        and str(meta) != str(existing_metas[prop_meta]['']))):
                self._update_id_self_meta(update, meta)
        # end for all property types

        # References Meta
        for ref_field in obj_class.ref_fields:
            refs = obj_dict.get(ref_field)
            if not refs:
                continue
            for ref in refs:
                ref_fq_name = ref['to']
                ref_fld_types_list = list(obj_class.ref_field_types[ref_field])
                ref_res_type = ref_fld_types_list[0]
                ref_link_type = ref_fld_types_list[1]
                ref_meta = obj_class.ref_field_metas[ref_field]
                ref_imid = get_ifmap_id_from_fq_name(ref_res_type, ref_fq_name)
                ref_data = ref.get('attr')
                if ref_data:
                    buf = cStringIO.StringIO()
                    attr_cls = str_to_class(ref_link_type, __name__)
                    attr_cls(**ref_data).exportChildren(buf,
                                                        level=1,
                                                        name_=ref_meta,
                                                        pretty_print=False)
                    ref_link_xml = buf.getvalue()
                    buf.close()
                else:
                    ref_link_xml = ''
                meta = Metadata(ref_meta,
                                '', {'ifmap-cardinality': 'singleValue'},
                                ns_prefix='contrail',
                                elements=ref_link_xml)
                self._update_id_pair_meta(update, ref_imid, meta)
        # end for all ref types

        self._publish_update(my_imid, update)
        return (True, '')
Exemple #14
0
    def object_set(self, obj_class, my_imid, existing_metas, obj_dict):
        update = {}

        # Properties Meta
        for prop_field in obj_class.prop_fields:
            field = obj_dict.get(prop_field)
            if field is None:
                continue
            # construct object of xsd-type and get its xml repr
            # e.g. virtual_network_properties
            prop_field_types = obj_class.prop_field_types[prop_field]
            is_simple = not prop_field_types['is_complex']
            prop_type = prop_field_types['xsd_type']
            # e.g. virtual-network-properties
            prop_meta = obj_class.prop_field_metas[prop_field]

            if prop_field in VncIfmapClient.IFMAP_PUBLISH_SKIP_LIST:
                # Field not relevant, skip publishing to IfMap
                if not VncIfmapClient.IFMAP_PUBLISH_SKIP_LIST[prop_field]:
                    continue
                # Call the handler fn to generate the relevant fields.
                if callable(VncIfmapClient.IFMAP_PUBLISH_SKIP_LIST[prop_field]):
                    prop_xml = VncIfmapClient.IFMAP_PUBLISH_SKIP_LIST[prop_field](
                                        prop_field, field)
                    meta = Metadata(prop_meta, '',
                        {'ifmap-cardinality':'singleValue'}, ns_prefix='contrail',
                        elements=prop_xml)
                else:
                    log_str = '%s is marked for partial publish\
                               to Ifmap but handler not defined' %(
                                prop_field)
                    self.config_log(log_str, level=SandeshLevel.SYS_DEBUG)
                    continue
            elif is_simple:
                norm_str = escape(str(field))
                meta = Metadata(prop_meta, norm_str,
                       {'ifmap-cardinality':'singleValue'}, ns_prefix = 'contrail')
            else: # complex type
                prop_cls = str_to_class(prop_type, __name__)
                buf = cStringIO.StringIO()
                # perms might be inserted at server as obj.
                # obj construction diff from dict construction.
                if isinstance(field, dict):
                    prop_cls(**field).exportChildren(
                        buf, level=1, name_=prop_meta, pretty_print=False)
                elif isinstance(field, list):
                    for elem in field:
                        if isinstance(elem, dict):
                            prop_cls(**elem).exportChildren(
                                buf, level=1, name_=prop_meta, pretty_print=False)
                        else:
                            elem.exportChildren(
                                buf, level=1, name_=prop_meta, pretty_print=False)
                else: # object
                    field.exportChildren(
                        buf, level=1, name_=prop_meta, pretty_print=False)
                prop_xml = buf.getvalue()
                buf.close()
                meta = Metadata(prop_meta, '',
                    {'ifmap-cardinality':'singleValue'}, ns_prefix='contrail',
                    elements=prop_xml)

            # If obj is new (existing metas is none) or
            # if obj does not have this prop_meta (or)
            # or if the prop_meta is different from what we have currently,
            # then update
            if (not existing_metas or
                not prop_meta in existing_metas or
                    ('' in existing_metas[prop_meta] and
                    str(meta) != str(existing_metas[prop_meta]['']))):
                self._update_id_self_meta(update, meta)
        # end for all property types

        # References Meta
        for ref_field in obj_class.ref_fields:
            refs = obj_dict.get(ref_field)
            if not refs:
                continue
            for ref in refs:
                ref_fq_name = ref['to']
                ref_fld_types_list = list(
                    obj_class.ref_field_types[ref_field])
                ref_res_type = ref_fld_types_list[0]
                ref_link_type = ref_fld_types_list[1]
                ref_meta = obj_class.ref_field_metas[ref_field]
                ref_imid = get_ifmap_id_from_fq_name(ref_res_type, ref_fq_name)
                ref_data = ref.get('attr')
                if ref_data:
                    buf = cStringIO.StringIO()
                    attr_cls = str_to_class(ref_link_type, __name__)
                    attr_cls(**ref_data).exportChildren(
                        buf, level=1, name_=ref_meta, pretty_print=False)
                    ref_link_xml = buf.getvalue()
                    buf.close()
                else:
                    ref_link_xml = ''
                meta = Metadata(ref_meta, '',
                    {'ifmap-cardinality':'singleValue'}, ns_prefix = 'contrail',
                    elements=ref_link_xml)
                self._update_id_pair_meta(update, ref_imid, meta)
        # end for all ref types

        self._publish_update(my_imid, update)
        return (True, '')
    def _object_set(self, obj_class, ifmap_id, obj_dict, existing_links=None):
        # Properties Metadata
        metadatas = []
        for prop_field in obj_class.prop_fields:
            prop_value = obj_dict.get(prop_field)
            if prop_value is None:
                continue
            # construct object of xsd-type and get its xml repr
            # e.g. virtual_network_properties
            prop_field_types = obj_class.prop_field_types[prop_field]
            is_simple = not prop_field_types["is_complex"]
            prop_type = prop_field_types["xsd_type"]
            # e.g. virtual-network-properties
            meta_name = obj_class.prop_field_metas[prop_field]
            meta_long_name = "contrail:%s" % meta_name
            meta_value = ""
            meta_elements = ""

            if prop_field in self.IFMAP_PUBLISH_SKIP_LIST:
                # Field not relevant, skip publishing to IfMap
                if not self.IFMAP_PUBLISH_SKIP_LIST[prop_field]:
                    continue
                # Call the handler fn to generate the relevant fields.
                try:
                    func = getattr(self, self.IFMAP_PUBLISH_SKIP_LIST[prop_field])
                    meta_elements = func(prop_field, prop_value)
                except AttributeError:
                    log_str = "%s is marked for partial publish to Ifmap but " "handler not defined" % prop_field
                    self._log(log_str, level=SandeshLevel.SYS_DEBUG)
                    continue
            elif is_simple:
                meta_value = escape(str(prop_value))
            else:  # complex type
                prop_cls = str_to_class(prop_type, __name__)
                buf = StringIO()
                # perms might be inserted at server as obj.
                # obj construction diff from dict construction.
                if isinstance(prop_value, dict):
                    prop_cls(**prop_value).exportChildren(buf, level=1, name_=meta_name, pretty_print=False)
                elif isinstance(prop_value, list):
                    for elem in prop_value:
                        if isinstance(elem, dict):
                            prop_cls(**elem).exportChildren(buf, level=1, name_=meta_name, pretty_print=False)
                        else:
                            elem.exportChildren(buf, level=1, name_=meta_name, pretty_print=False)
                else:  # object
                    prop_value.exportChildren(buf, level=1, name_=meta_name, pretty_print=False)
                meta_elements = buf.getvalue()
                buf.close()
            meta = Metadata(
                meta_name,
                meta_value,
                {"ifmap-cardinality": "singleValue"},
                ns_prefix="contrail",
                elements=meta_elements,
            )
            # If obj is new (existing metas is none) or
            # if obj does not have this meta (or)
            # or if the meta is different from what we have currently,
            # then update
            if (
                not existing_links
                or meta_long_name not in existing_links
                or (
                    "meta" in existing_links[meta_long_name] and unicode(meta) != existing_links[meta_long_name]["meta"]
                )
            ):
                metadatas.append(meta)
        # end for all property types
        VncIfmapServer.update(ifmap_id, metadatas=metadatas)

        # References Metadata
        for ref_field in obj_class.ref_fields:
            refs = obj_dict.get(ref_field)
            if not refs:
                continue

            for ref in refs:
                ref_fq_name = ref["to"]
                ref_fld_types_list = list(obj_class.ref_field_types[ref_field])
                ref_res_type = ref_fld_types_list[0]
                ref_link_type = ref_fld_types_list[1]
                ref_meta = obj_class.ref_field_metas[ref_field]
                ref_ifmap_id = get_ifmap_id_from_fq_name(ref_res_type, ref_fq_name)
                ref_data = ref.get("attr")
                if ref_data:
                    buf = StringIO()
                    attr_cls = str_to_class(ref_link_type, __name__)
                    attr_cls(**ref_data).exportChildren(buf, level=1, name_=ref_meta, pretty_print=False)
                    ref_link_xml = buf.getvalue()
                    buf.close()
                else:
                    ref_link_xml = ""
                metadata = Metadata(
                    ref_meta, "", {"ifmap-cardinality": "singleValue"}, ns_prefix="contrail", elements=ref_link_xml
                )
                VncIfmapServer.update(ifmap_id, ref_ifmap_id, [metadata])
        # end for all ref types
        return (True, "")