【openstack】Quantum关于Port的操作(LinuxBridge)
2012-10-25 09:07
441 查看
Quantum关于Port的操作(LinuxBridge)
(2012/12/13修正): 为port分配IP时,当没有指定fixed_ip,是从network中选一个有空闲IP的subnet分配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
# 如果记录不存在,且同时指定了subnet和ip_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
1 创建port
1.1 流程
(2012/12/13修正): 为port分配IP时,当没有指定fixed_ip,是从network中选一个有空闲IP的subnet分配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
# 如果记录不存在,且同时指定了subnet和ip_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发送消息处理的,其他操作都只是上层的逻辑操作而已。相关文章推荐
- 【openstack】Quantum关于network的操作(LinuxBridge)
- 【openstack】Quantum关于Subnet的操作(LinuxBridge)
- Quantum关于network的操作(LinuxBridge)
- 关于VS.Net2005中串口操作说明(C#)(SerialPort组件)
- linux中关于磁盘操作工具fdisk|parted|mk2fs|mke2fs|fsck|badblocks的使用小结
- 【Linux基础学习之一】关于Linux的一些基本操作(linux登陆、口令文件、多终端登陆)
- linux基础——关于chmod用户权限和文件的相关操作
- linux下关于文件操作记录
- linux中关于硬盘分区操作
- 关于Linux下使用expdp和impdp命令对Oracle数据库进行导入和导出操作
- Linux下关于进程的一些操作
- Install and configure Quantum network + Linuxbridge for RHEL6.3 (Folsom release)
- openstack newton linuxbridge 改成 ovs
- linux下关于压缩、解压相关的操作
- Linux下C语言编程入门-6关于重定向操作
- openstack学习之neutron_linuxbridge_agent分析
- 关于Linux下使用expdp和impdp命令对Oracle数据库进行导入和导出操作
- 关于远程操作Linux下的项目和重启tomcat服务
- 关于linux中内核编程中结构体的赋值操作(结构体指定初始化)