当前位置: 首页>>代码示例>>Python>>正文


Python meta.obj_list_to_dict函数代码示例

本文整理汇总了Python中shade.meta.obj_list_to_dict函数的典型用法代码示例。如果您正苦于以下问题:Python obj_list_to_dict函数的具体用法?Python obj_list_to_dict怎么用?Python obj_list_to_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了obj_list_to_dict函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cache_no_cloud_name

    def test_cache_no_cloud_name(self, glance_mock):
        class FakeImage(object):
            status = 'active'
            name = 'None Test Image'

            def __init__(self, id):
                self.id = id

        fi = FakeImage(id=1)
        glance_mock.images.list.return_value = [fi]
        self.cloud.name = None
        self.assertEqual(
            meta.obj_list_to_dict([fi]),
            self.cloud.list_images())
        # Now test that the list was cached
        fi2 = FakeImage(id=2)
        glance_mock.images.list.return_value = [fi, fi2]
        self.assertEqual(
            meta.obj_list_to_dict([fi]),
            self.cloud.list_images())
        # Invalidation too
        self.cloud.list_images.invalidate(self.cloud)
        self.assertEqual(
            meta.obj_list_to_dict([fi, fi2]),
            self.cloud.list_images())
开发者ID:major,项目名称:shade,代码行数:25,代码来源:test_caching.py

示例2: test_list_projects_v2

 def test_list_projects_v2(self, keystone_mock):
     project = fakes.FakeProject('project_a')
     keystone_mock.tenants.list.return_value = [project]
     self.cloud.cloud_config.config['identity_api_version'] = '2'
     self.assertEqual(
         meta.obj_list_to_dict([project]), self.cloud.list_projects())
     project_b = fakes.FakeProject('project_b')
     keystone_mock.tenants.list.return_value = [project, project_b]
     self.assertEqual(
         meta.obj_list_to_dict([project]), self.cloud.list_projects())
     self.cloud.list_projects.invalidate(self.cloud)
     self.assertEqual(
         meta.obj_list_to_dict([project, project_b]),
         self.cloud.list_projects())
开发者ID:major,项目名称:shade,代码行数:14,代码来源:test_caching.py

示例3: wait

    def wait(self, raw):
        self._finished.wait()

        if self._exception:
            six.reraise(type(self._exception), self._exception,
                        self._traceback)

        if raw:
            # Do NOT convert the result.
            return self._result

        # NOTE(Shrews): Since the client API might decide to subclass one
        # of these result types, we use isinstance() here instead of type().
        if (isinstance(self._result, list) or
            isinstance(self._result, types.GeneratorType)):
            return meta.obj_list_to_dict(
                self._result, request_id=self._request_id)
        elif (not isinstance(self._result, bool) and
              not isinstance(self._result, int) and
              not isinstance(self._result, float) and
              not isinstance(self._result, str) and
              not isinstance(self._result, set) and
              not isinstance(self._result, tuple) and
              not isinstance(self._result, types.GeneratorType)):
            return meta.obj_to_dict(self._result, request_id=self._request_id)
        else:
            return self._result
开发者ID:major,项目名称:shade,代码行数:27,代码来源:task_manager.py

示例4: test_search_stacks

 def test_search_stacks(self, mock_heat):
     fake_stacks = [
         fakes.FakeStack('001', 'stack1'),
         fakes.FakeStack('002', 'stack2'),
     ]
     mock_heat.stacks.list.return_value = fake_stacks
     stacks = self.cloud.search_stacks()
     mock_heat.stacks.list.assert_called_once_with()
     self.assertEqual(meta.obj_list_to_dict(fake_stacks), stacks)
开发者ID:jhedden,项目名称:shade,代码行数:9,代码来源:test_stack.py

示例5: normalize_roles

def normalize_roles(roles):
    """Normalize Identity roles."""
    ret = [
        dict(
            id=role.get('id'),
            name=role.get('name'),
        ) for role in roles
    ]
    return meta.obj_list_to_dict(ret)
开发者ID:Natrinicle,项目名称:shade,代码行数:9,代码来源:_utils.py

示例6: test_search_stacks_filters

 def test_search_stacks_filters(self, mock_heat):
     fake_stacks = [
         fakes.FakeStack('001', 'stack1', status='GOOD'),
         fakes.FakeStack('002', 'stack2', status='BAD'),
     ]
     mock_heat.stacks.list.return_value = fake_stacks
     filters = {'stack_status': 'GOOD'}
     stacks = self.cloud.search_stacks(filters=filters)
     mock_heat.stacks.list.assert_called_once_with()
     self.assertEqual(meta.obj_list_to_dict(fake_stacks[:1]), stacks)
开发者ID:jhedden,项目名称:shade,代码行数:10,代码来源:test_stack.py

示例7: normalize_domains

def normalize_domains(domains):
    ret = [
        dict(
            id=domain.get('id'),
            name=domain.get('name'),
            description=domain.get('description'),
            enabled=domain.get('enabled'),
        ) for domain in domains
    ]
    return meta.obj_list_to_dict(ret)
开发者ID:Natrinicle,项目名称:shade,代码行数:10,代码来源:_utils.py

示例8: test_list_nics

    def test_list_nics(self, mock_client):
        port1 = fakes.FakeMachinePort(1, "aa:bb:cc:dd", "node1")
        port2 = fakes.FakeMachinePort(2, "dd:cc:bb:aa", "node2")
        port_list = [port1, port2]
        port_dict_list = meta.obj_list_to_dict(port_list)

        mock_client.port.list.return_value = port_list
        nics = self.cloud.list_nics()

        self.assertTrue(mock_client.port.list.called)
        self.assertEqual(port_dict_list, nics)
开发者ID:StevenArmstrong,项目名称:shade,代码行数:11,代码来源:test_shade_operator.py

示例9: normalize_groups

def normalize_groups(domains):
    """Normalize Identity groups."""
    ret = [
        dict(
            id=domain.get('id'),
            name=domain.get('name'),
            description=domain.get('description'),
            domain_id=domain.get('domain_id'),
        ) for domain in domains
    ]
    return meta.obj_list_to_dict(ret)
开发者ID:Natrinicle,项目名称:shade,代码行数:11,代码来源:_utils.py

示例10: test_obj_list_to_dict

    def test_obj_list_to_dict(self):
        """Test conversion of a list of objects to a list of dictonaries"""
        class obj0(object):
            value = 0

        class obj1(object):
            value = 1

        list = [obj0, obj1]
        new_list = meta.obj_list_to_dict(list)
        self.assertEqual(new_list[0]['value'], 0)
        self.assertEqual(new_list[1]['value'], 1)
开发者ID:insequent,项目名称:shade,代码行数:12,代码来源:test_meta.py

示例11: wait

 def wait(self):
     self._finished.wait()
     # TODO(mordred): We store the raw requests response if there is
     # one now. So we should probably do an error handler to throw
     # some exceptions if it's not 200
     if self._exception:
         six.reraise(type(self._exception), self._exception,
                     self._traceback)
     if type(self._result) == list:
         return meta.obj_list_to_dict(self._result)
     else:
         return meta.obj_to_dict(self._result)
开发者ID:StevenArmstrong,项目名称:shade,代码行数:12,代码来源:task_manager.py

示例12: normalize_users

def normalize_users(users):
    ret = [
        dict(
            id=user.get('id'),
            email=user.get('email'),
            name=user.get('name'),
            username=user.get('username'),
            default_project_id=user.get('default_project_id',
                                        user.get('tenantId')),
            domain_id=user.get('domain_id'),
            enabled=user.get('enabled'),
        ) for user in users
    ]
    return meta.obj_list_to_dict(ret)
开发者ID:Natrinicle,项目名称:shade,代码行数:14,代码来源:_utils.py

示例13: normalize_nova_secgroups

def normalize_nova_secgroups(groups):
    """Normalize the structure of nova security groups

    This makes security group dicts, as returned from nova, look like the
    security group dicts as returned from neutron. This does not make them
    look exactly the same, but it's pretty close.

    :param list groups: A list of security group dicts.

    :returns: A list of normalized dicts.
    """
    ret = [{'id': g['id'],
            'name': g['name'],
            'description': g['description'],
            'security_group_rules': normalize_nova_secgroup_rules(g['rules'])
            } for g in groups]
    return meta.obj_list_to_dict(ret)
开发者ID:Natrinicle,项目名称:shade,代码行数:17,代码来源:_utils.py

示例14: normalize_neutron_floating_ips

def normalize_neutron_floating_ips(ips):
    """Normalize the structure of Neutron floating IPs

    Unfortunately, not all the Neutron floating_ip attributes are available
    with Nova and not all Nova floating_ip attributes are available with
    Neutron.
    This function extract attributes that are common to Nova and Neutron
    floating IP resource.
    If the whole structure is needed inside shade, shade provides private
    methods that returns "original" objects (e.g.
    _neutron_allocate_floating_ip)

    :param list ips: A list of Neutron floating IPs.

    :returns:
        A list of normalized dicts with the following attributes::

        [
          {
            "id": "this-is-a-floating-ip-id",
            "fixed_ip_address": "192.0.2.10",
            "floating_ip_address": "198.51.100.10",
            "network": "this-is-a-net-or-pool-id",
            "attached": True,
            "status": "ACTIVE"
          }, ...
        ]

    """
    ret = []
    for ip in ips:
        network_id = ip.get('floating_network_id', ip.get('network'))
        ret.append(dict(
            id=ip['id'],
            fixed_ip_address=ip.get('fixed_ip_address'),
            floating_ip_address=ip['floating_ip_address'],
            network=network_id,
            floating_network_id=network_id,
            port_id=ip.get('port_id'),
            router_id=ip.get('router_id'),
            attached=(ip.get('port_id') is not None and
                      ip.get('port_id') != ''),
            status=ip['status'],
        ))
    return meta.obj_list_to_dict(ret)
开发者ID:Natrinicle,项目名称:shade,代码行数:45,代码来源:_utils.py

示例15: setUp

    def setUp(self):
        super(TestFloatingIP, self).setUp()
        config = os_client_config.OpenStackConfig()
        self.client = OpenStackCloud(
            cloud_config=config.get_one_cloud(validate=False))
        self.floating_ips = [
            fakes.FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        self.fake_server = meta.obj_to_dict(
            fakes.FakeServer(
                'server-id', '', 'ACTIVE',
                addresses={u'test_pnztt_net': [{
                    u'OS-EXT-IPS:type': u'fixed',
                    u'addr': '192.0.2.129',
                    u'version': 4,
                    u'OS-EXT-IPS-MAC:mac_addr':
                    u'fa:16:3e:ae:7d:42'}]}))

        self.floating_ip = _utils.normalize_nova_floating_ips(
            meta.obj_list_to_dict(self.floating_ips))[0]
开发者ID:erickcantwell,项目名称:shade,代码行数:21,代码来源:test_floating_ip_nova.py


注:本文中的shade.meta.obj_list_to_dict函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。