test_floating_ips.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:quark 作者: openstack 项目源码 文件源码
def _build_expected_unicorn_request_body(self, floating_ip_address, ports,
                                             actual_body=None):
        if actual_body:
            # Since the port order is non-deterministic, we need to ensure
            # that the order is correct
            actual_port_ids = [endpoint['port']['uuid'] for endpoint in
                               actual_body['floating_ip']['endpoints']]
            reordered_ports = []
            for port_id in actual_port_ids:
                for port in ports:
                    if port['id'] == port_id:
                        reordered_ports.append(port)
            ports = reordered_ports
        endpoints = []
        for port in ports:
            fixed_ips = []
            for fixed_ip in port['fixed_ips']:
                fixed_ips.append({
                    'ip_address': fixed_ip['ip_address'],
                    'version': self.user_subnet['ip_version'],
                    'subnet_id': self.user_subnet['id'],
                    'cidr': self.user_subnet['cidr'],
                    'address_type': 'fixed'
                })
            port_mac = int(netaddr.EUI(port['mac_address'].replace(':', '-')))
            endpoints.append({
                'port': {
                    'uuid': port['id'],
                    'name': port['name'],
                    'network_uuid': port['network_id'],
                    'mac_address': port_mac,
                    'device_id': port['device_id'],
                    'device_owner': port['device_owner'],
                    'fixed_ip': fixed_ips
                },
                'private_ip': port['fixed_ips'][0]['ip_address']
            })
        body = {'public_ip': floating_ip_address,
                'endpoints': endpoints}
        return {'floating_ip': body}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号