def list_convert_with_links(rpc_ports, limit, url=None, fields=None, **kwargs): ports = [] for rpc_port in rpc_ports: try: port = convert_with_links(rpc_port, fields=fields, sanitize=False) except exception.NodeNotFound: # NOTE(dtantsur): node was deleted after we fetched the port # list, meaning that the port was also deleted. Skip it. LOG.debug('Skipping port %s as its node was deleted', rpc_port.uuid) continue except exception.PortgroupNotFound: # NOTE(dtantsur): port group was deleted after we fetched the # port list, it may mean that the port was deleted too, but # we don't know it. Pretend that the port group was removed. LOG.debug('Removing port group UUID from port %s as the port ' 'group was deleted', rpc_port.uuid) rpc_port.portgroup_id = None port = convert_with_links(rpc_port, fields=fields, sanitize=False) ports.append(port) return collection.list_convert_with_links( items=ports, item_name='ports', limit=limit, url=url, fields=fields, sanitize_func=port_sanitize, **kwargs )
def test_list_convert_with_links(self): col = self._generate_collection(3) # build with next link result = collection.list_convert_with_links(col, 'things', 3, url='thing') self.assertEqual( { 'things': col, 'next': 'http://192.0.2.1:5050/v1/thing?limit=3&' 'marker=%s' % col[2]['uuid'] }, result) # build without next link result = collection.list_convert_with_links(col, 'things', 5, url='thing') self.assertEqual({'things': col}, result) # build with a custom sanitize function def sanitize(item, fields): item.pop('name') result = collection.list_convert_with_links(col, 'things', 5, url='thing', sanitize_func=sanitize) self.assertEqual( { 'things': [{ 'uuid': col[0]['uuid'] }, { 'uuid': col[1]['uuid'] }, { 'uuid': col[2]['uuid'] }] }, result) # items in the original collection are also sanitized self.assertEqual(col, result['things'])
def list_convert_with_links(rpc_templates, limit, fields=None, **kwargs): return collection.list_convert_with_links(items=[ convert_with_links(t, fields=fields, sanitize=False) for t in rpc_templates ], item_name='deploy_templates', limit=limit, fields=fields, sanitize_func=template_sanitize, **kwargs)
def list_convert_with_links(rpc_allocations, limit, url=None, fields=None, **kwargs): return collection.list_convert_with_links( items=[convert_with_links(p, fields=fields, sanitize=False) for p in rpc_allocations], item_name='allocations', limit=limit, url=url, fields=fields, sanitize_func=allocation_sanitize, **kwargs )
def list_convert_with_links(rpc_connectors, limit, url=None, fields=None, detail=None, **kwargs): if detail: kwargs['detail'] = detail return collection.list_convert_with_links( items=[convert_with_links(p, fields=fields, sanitize=False) for p in rpc_connectors], item_name='connectors', limit=limit, url=url, fields=fields, sanitize_func=api_utils.sanitize_dict, **kwargs )
def list_convert_with_links(rpc_portgroups, limit, url=None, fields=None, **kwargs): return collection.list_convert_with_links( items=[ convert_with_links(p, fields=fields, sanitize=False) for p in rpc_portgroups ], item_name='portgroups', limit=limit, url=url, fields=fields, sanitize_func=api_utils.sanitize_dict, **kwargs)
def list_convert_with_links(rpc_chassis_list, limit, url=None, fields=None, **kwargs): return collection.list_convert_with_links( items=[ convert_with_links(ch, fields=fields, sanitize=False) for ch in rpc_chassis_list ], item_name='chassis', limit=limit, url=url, fields=fields, sanitize_func=api_utils.sanitize_dict, **kwargs)
def list_convert_with_links(rpc_conductors, limit, url=None, fields=None, **kwargs): return collection.list_convert_with_links( items=[ convert_with_links(c, fields=fields, sanitize=False) for c in rpc_conductors ], item_name='conductors', limit=limit, url=url, fields=fields, key_field='hostname', sanitize_func=api_utils.sanitize_dict, **kwargs)