本文整理汇总了Python中f5_openstack_agent.lbaasv2.drivers.bigip.network_helper.NetworkHelper.add_vlan_to_domain方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkHelper.add_vlan_to_domain方法的具体用法?Python NetworkHelper.add_vlan_to_domain怎么用?Python NetworkHelper.add_vlan_to_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类f5_openstack_agent.lbaasv2.drivers.bigip.network_helper.NetworkHelper
的用法示例。
在下文中一共展示了NetworkHelper.add_vlan_to_domain方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BigipSelfIpManager
# 需要导入模块: from f5_openstack_agent.lbaasv2.drivers.bigip.network_helper import NetworkHelper [as 别名]
# 或者: from f5_openstack_agent.lbaasv2.drivers.bigip.network_helper.NetworkHelper import add_vlan_to_domain [as 别名]
class BigipSelfIpManager(object):
def __init__(self, driver, l2_service, l3_binding):
self.driver = driver
self.l2_service = l2_service
self.l3_binding = l3_binding
self.selfip_manager = BigIPResourceHelper(ResourceType.selfip)
self.network_helper = NetworkHelper()
def _create_bigip_selfip(self, bigip, model):
created = False
if self.selfip_manager.exists(bigip, name=model['name'],
partition=model['partition']):
created = True
else:
try:
self.selfip_manager.create(bigip, model)
created = True
except HTTPError as err:
if (err.response.status_code == 400 and
err.response.text.find(
"must be one of the vlans "
"in the associated route domain") > 0):
try:
self.network_helper.add_vlan_to_domain(
bigip,
name=model['vlan'],
partition=model['partition'])
self.selfip_manager.create(bigip, model)
created = True
except HTTPError as err:
LOG.exception("Error creating selfip %s. "
"Repsponse status code: %s. "
"Response message: %s." % (
model["name"],
err.response.status_code,
err.message))
raise f5_ex.SelfIPCreationException("selfip")
else:
LOG.exception("selfip creation error: %s(%s)" %
(err.message, err.response.status_code))
raise
except Exception as err:
LOG.error("Failed to create selfip")
LOG.exception(err.message)
raise f5_ex.SelfIPCreationException("selfip creation")
return created
def assure_bigip_selfip(self, bigip, service, subnetinfo):
u"""Ensure the BigIP has a selfip address on the tenant subnet."""
network = None
subnet = None
if 'network' in subnetinfo:
network = subnetinfo['network']
if 'subnet' in subnetinfo:
subnet = subnetinfo['subnet']
if not network or not subnet:
LOG.error('Attempted to create selfip and snats '
'for network with not id...')
raise KeyError("network and subnet need to be specified")
tenant_id = service['loadbalancer']['tenant_id']
lb_id = service['loadbalancer']['id']
# If we have already assured this subnet.. return.
# Note this cache is periodically cleared in order to
# force assurance that the configuration is present.
if tenant_id in bigip.assured_tenant_snat_subnets and \
subnet['id'] in bigip.assured_tenant_snat_subnets[tenant_id]:
return True
selfip_address = self._get_bigip_selfip_address(bigip, subnet, lb_id)
if 'route_domain_id' not in network:
LOG.error("network route domain is not set")
raise KeyError()
selfip_address += '%' + str(network['route_domain_id'])
if self.l2_service.is_common_network(network):
network_folder = 'Common'
else:
network_folder = self.driver.service_adapter.\
get_folder_name(service['loadbalancer']['tenant_id'])
# Get the name of the vlan.
(network_name, preserve_network_name) = \
self.l2_service.get_network_name(bigip, network)
netmask = netaddr.IPNetwork(subnet['cidr']).prefixlen
address = selfip_address + ("/%d" % netmask)
model = {
"name": "local-" + bigip.device_name + "-" + subnet['id'],
"address": address,
"vlan": network_name,
"floating": "disabled",
#.........这里部分代码省略.........
示例2: BigipSelfIpManager
# 需要导入模块: from f5_openstack_agent.lbaasv2.drivers.bigip.network_helper import NetworkHelper [as 别名]
# 或者: from f5_openstack_agent.lbaasv2.drivers.bigip.network_helper.NetworkHelper import add_vlan_to_domain [as 别名]
class BigipSelfIpManager(object):
def __init__(self, driver, l2_service, l3_binding):
self.driver = driver
self.l2_service = l2_service
self.l3_binding = l3_binding
self.selfip_manager = BigIPResourceHelper(ResourceType.selfip)
self.network_helper = NetworkHelper()
def create_bigip_selfip(self, bigip, model):
if not model['name']:
return False
LOG.debug("Getting selfip....")
s = bigip.net.selfips.selfip
if s.exists(name=model['name'], partition=model['partition']):
LOG.debug("It exists!!!!")
return True
try:
LOG.debug("Doesn't exist!!!!")
self.selfip_manager.create(bigip, model)
LOG.debug("CREATED!!!!")
except HTTPError as err:
if err.response.status_code is not 400:
raise
if err.response.text.find("must be one of the vlans "
"in the associated route domain") > 0:
self.network_helper.add_vlan_to_domain(
bigip,
name=model['vlan'],
partition=model['partition'])
try:
self.selfip_manager.create(bigip, model)
except HTTPError as err:
LOG.error("Error creating selfip %s. "
"Repsponse status code: %s. Response "
"message: %s." % (model["name"],
err.response.status_code,
err.message))
def assure_bigip_selfip(self, bigip, service, subnetinfo):
network = subnetinfo['network']
if not network:
LOG.error('Attempted to create selfip and snats '
'for network with no id... skipping.')
return
subnet = subnetinfo['subnet']
tenant_id = service['loadbalancer']['tenant_id']
# If we have already assured this subnet.. return.
# Note this cache is periodically cleared in order to
# force assurance that the configuration is present.
if tenant_id in bigip.assured_tenant_snat_subnets and \
subnet['id'] in bigip.assured_tenant_snat_subnets[tenant_id]:
return
selfip_address = self._get_bigip_selfip_address(bigip, subnet)
# FIXME(Rich Browne): it is possible this is not set unless
# use namespaces is true. I think this method is only called
# in the global_routed_mode == False case though. Need to check
# that network['route_domain_id'] exists.
if 'route_domain_id' not in network:
LOG.debug("NETWORK ROUTE DOMAIN NOT SET")
network['route_domain_id'] = "0"
LOG.debug("route domain id: %s" % network['route_domain_id'])
selfip_address += '%' + str(network['route_domain_id'])
LOG.debug("have selfip address: %s" % selfip_address)
if self.l2_service.is_common_network(network):
network_folder = 'Common'
else:
network_folder = self.driver.service_adapter.\
get_folder_name(service['loadbalancer']['tenant_id'])
LOG.debug("getting network name")
(network_name, preserve_network_name) = \
self.l2_service.get_network_name(bigip, network)
LOG.debug("CREATING THE SELFIP--------------------")
netmask = netaddr.IPNetwork(subnet['cidr']).prefixlen
address = selfip_address + ("/%d" % netmask)
model = {
"name": "local-" + bigip.device_name + "-" + subnet['id'],
"address": address,
"vlan": network_name,
"floating": "disabled",
"partition": network_folder
}
LOG.debug("Model: %s" % model)
self.create_bigip_selfip(bigip, model)
# TO DO: we need to only bind the local SelfIP to the
# local device... not treat it as if it was floating
LOG.debug("self ip CREATED!!!!!!")
if self.l3_binding:
self.l3_binding.bind_address(subnet_id=subnet['id'],
ip_address=selfip_address)
#.........这里部分代码省略.........