`
lynnkong
  • 浏览: 303140 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

【openstack】Quantum关于Port的操作(LinuxBridge)

阅读更多

Quantum关于Port的操作(LinuxBridge)

1      创建port

1.1    流程



 (2012/12/13修正): 为port分配IP时,当没有指定fixed_ip,是从network中选一个有空闲IPsubnet分配IP ,而不是从所有subnet分配。

 

    # 校验fixed_ips的合法性

    def _test_fixed_ips_for_port(self, context, network_id, fixed_ips):

        """Test fixed IPs for port.

 

        Check that configured subnets are valid prior to allocating any

        IPs. Include the subnet_id in the result if only an IP address is

        configured.

 

        :raises: InvalidInput, IpAddressInUse

        """

        fixed_ip_set = []

        for fixed in fixed_ips:

            found = False

            # 如果没有指定subnet

            if 'subnet_id' not in fixed:

                # 如果既没有指定subnet,也没有指定ip_address,抛错

                if 'ip_address' not in fixed:

                    msg = _('IP allocation requires subnet_id or ip_address')

                    raise q_exc.InvalidInput(error_message=msg)

 

                # 如果没有指定subnet,但指定了ip_address

                filter = {'network_id': [network_id]}

                # 找到属于入参network_id的所有subnet

                subnets = self.get_subnets(context, filters=filter)

                for subnet in subnets:

                    # 检查ip_address是否在subnet中,返回subnet_id

                    if QuantumDbPluginV2._check_subnet_ip(subnet['cidr'],

                                                          fixed['ip_address']):

                        found = True

                        subnet_id = subnet['id']

                        break

                # 如果在所有subnet都没有找到,抛错

                if not found:

                    msg = _('IP address %s is not a valid IP for the defined '

                            'networks subnets') % fixed['ip_address']

                    raise q_exc.InvalidInput(error_message=msg)

            # 如果指定了subnet

            else:

                subnet = self._get_subnet(context, fixed['subnet_id'])

                # subnet所属network与入参不一致,抛错

                if subnet['network_id'] != network_id:

                    msg = _('Failed to create port on network %s, '

                            'because fixed_ips included invalid subnet '

                            '%s') % (network_id, fixed['subnet_id'])

                    raise q_exc.InvalidInput(error_message=msg)

                subnet_id = subnet['id']

 

            # 如果指定了ip_address

            if 'ip_address' in fixed:

                # Ensure that the IP's are unique

                # ipallocation表中查找,如果记录已存在,抛错

                if not QuantumDbPluginV2._check_unique_ip(context, network_id,

                                                          subnet_id,

                                                          fixed['ip_address']):

                    raise q_exc.IpAddressInUse(net_id=network_id,

                                               ip_address=fixed['ip_address'])

 

                # Ensure that the IP is valid on the subnet

                # 如果记录不存在,且同时指定了subnetip_address,则判断ip_address是否属于指定的subnet

                if (not found and

                    not QuantumDbPluginV2._check_subnet_ip(

                        subnet['cidr'], fixed['ip_address'])):

                    msg = _('IP address %s is not a valid IP for the defined '

                            'subnet') % fixed['ip_address']

                    raise q_exc.InvalidInput(error_message=msg)

 

                fixed_ip_set.append({'subnet_id': subnet_id,

                                     'ip_address': fixed['ip_address']})

            else:

                fixed_ip_set.append({'subnet_id': subnet_id})

        return fixed_ip_set

2      删除port

2.1    流程



 

3      更新port

3.1    流程



 

4      总结

注意,这里对port的操作中,更新port是需要向下层的agent发送消息处理的,其他操作都只是上层的逻辑操作而已。

 

  • 大小: 31.7 KB
  • 大小: 16.5 KB
  • 大小: 19.6 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics