• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python meta.obj_list_to_dict函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: normalize_nova_secgroup_rules

def normalize_nova_secgroup_rules(rules):
    """Normalize the structure of nova security group rules

    Note that nova uses -1 for non-specific port values, but neutron
    represents these with None.

    :param list rules: A list of security group rule dicts.

    :returns: A list of normalized dicts.
    """
    ret = [{'id': r['id'],
            'direction': 'ingress',
            'ethertype': 'IPv4',
            'port_range_min':
                None if r['from_port'] == -1 else r['from_port'],
            'port_range_max':
                None if r['to_port'] == -1 else r['to_port'],
            'protocol': r['ip_protocol'],
            'remote_ip_prefix': r['ip_range'].get('cidr', None),
            'security_group_id': r['parent_group_id']
            } for r in rules]
    return meta.obj_list_to_dict(ret)
开发者ID:Natrinicle,项目名称:shade,代码行数:22,代码来源:_utils.py


示例17: normalize_keystone_services

def normalize_keystone_services(services):
    """Normalize the structure of keystone services

    In keystone v2, there is a field called "service_type". In v3, it's
    "type". Just make the returned dict have both.

    :param list services: A list of keystone service dicts

    :returns: A list of normalized dicts.
    """
    ret = []
    for service in services:
        service_type = service.get('type', service.get('service_type'))
        new_service = {
            'id': service['id'],
            'name': service['name'],
            'description': service.get('description', None),
            'type': service_type,
            'service_type': service_type,
        }
        ret.append(new_service)
    return meta.obj_list_to_dict(ret)
开发者ID:jhedden,项目名称:shade,代码行数:22,代码来源:_utils.py


示例18: normalize_volumes

def normalize_volumes(volumes):
    ret = []
    for vol in volumes:
        new_vol = vol.copy()
        name = vol.get('name', vol.get('display_name'))
        description = vol.get('description', vol.get('display_description'))
        new_vol['name'] = name
        new_vol['display_name'] = name
        new_vol['description'] = description
        new_vol['display_description'] = description
        # For some reason, cinder v1 uses strings for bools for these fields.
        # Cinder v2 uses booleans.
        for field in ('bootable', 'multiattach'):
            if field in new_vol and isinstance(new_vol[field],
                                               six.string_types):
                if new_vol[field] is not None:
                    if new_vol[field].lower() == 'true':
                        new_vol[field] = True
                    elif new_vol[field].lower() == 'false':
                        new_vol[field] = False
        ret.append(new_vol)
    return meta.obj_list_to_dict(ret)
开发者ID:Natrinicle,项目名称:shade,代码行数:22,代码来源:_utils.py


示例19: 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)

        # 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):
            return meta.obj_list_to_dict(self._result)
        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)
        else:
            return self._result
开发者ID:erickcantwell,项目名称:shade,代码行数:23,代码来源:task_manager.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python meta.obj_to_dict函数代码示例发布时间:2022-05-27
下一篇:
Python meta.get_server_external_ipv4函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap