本文整理匯總了Python中neutron.extensions.portbindings.HOST_ID屬性的典型用法代碼示例。如果您正苦於以下問題:Python portbindings.HOST_ID屬性的具體用法?Python portbindings.HOST_ID怎麽用?Python portbindings.HOST_ID使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類neutron.extensions.portbindings
的用法示例。
在下文中一共展示了portbindings.HOST_ID屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_update_port_mac
# 需要導入模塊: from neutron.extensions import portbindings [as 別名]
# 或者: from neutron.extensions.portbindings import HOST_ID [as 別名]
def test_update_port_mac(self):
self.check_update_port_mac(
host_arg={portbindings.HOST_ID: 'fake-host'},
arg_list=(portbindings.HOST_ID,),
expected_status=exc.HTTPConflict.code,
expected_error='PortBound')
示例2: create_port_precommit
# 需要導入模塊: from neutron.extensions import portbindings [as 別名]
# 或者: from neutron.extensions.portbindings import HOST_ID [as 別名]
def create_port_precommit(self, context):
if not hasattr(context, 'current'):
return
port = context.current
port_id = port['id']
device_id = port['device_id']
network_id = port['network_id']
tenant_id = port['tenant_id']
host = port[portbindings.HOST_ID]
if hasattr(context, 'top_bound_segment'):
if context.top_bound_segment:
vni = context.top_bound_segment['segmentation_id']
else:
vni = INVALID_VNI
else:
vni = INVALID_VNI
with self.sync_thread_lock:
bridge_name = db.db_get_bridge_name(tenant_id, network_id)
if not bridge_name:
return
for _switch_id in self.switches:
db.db_create_port(tenant_id, network_id, port_id, host,
device_id, bridge_name, _switch_id, vni)
示例3: _is_vm_migrating
# 需要導入模塊: from neutron.extensions import portbindings [as 別名]
# 或者: from neutron.extensions.portbindings import HOST_ID [as 別名]
def _is_vm_migrating(self, context, vlan_segment, orig_vlan_segment):
if not vlan_segment and orig_vlan_segment:
return (context.current.get(portbindings.HOST_ID) !=
context.original.get(portbindings.HOST_ID))
示例4: update_port_postcommit
# 需要導入模塊: from neutron.extensions import portbindings [as 別名]
# 或者: from neutron.extensions.portbindings import HOST_ID [as 別名]
def update_port_postcommit(self, context):
if not hasattr(context, 'current'):
return
port = context.current
port_id = port['id']
network_id = port['network_id']
tenant_id = port['tenant_id']
device_id = port['device_id']
host = port[portbindings.HOST_ID]
if not host:
return
if hasattr(context, 'top_bound_segment'):
if context.top_bound_segment:
vni = context.top_bound_segment['segmentation_id']
else:
vni = INVALID_VNI
else:
vni = INVALID_VNI
with self.sync_thread_lock:
network = db.db_get_network(tenant_id, network_id)
if not network:
return
if context.host != context.original_host:
self._remove_from_switch(context.original, network)
self._add_to_switch(context, network)
with self.sync_thread_lock:
for _switch_id in self.switches:
db_port = db.db_get_port(network_id, port_id, _switch_id, host)
if not db_port:
db.db_create_port(tenant_id, network_id, port_id,
host, device_id,
network.bridge_name, _switch_id, vni)
else:
db.db_update_port(tenant_id, network_id, port_id,
host, device_id,
network.bridge_name, _switch_id, vni)
示例5: _remove_from_switch
# 需要導入模塊: from neutron.extensions import portbindings [as 別名]
# 或者: from neutron.extensions.portbindings import HOST_ID [as 別名]
def _remove_from_switch(self, port, network):
host = port[portbindings.HOST_ID]
port_id = port['id']
for _switch_id in self.switches:
with self.sync_thread_lock:
db_port = db.db_get_port(network.network_id,
port_id,
_switch_id,
host)
if not db_port:
continue
vni = db_port.vni
actions = [
HOSTS_URL.format(
scheme=self.scheme,
base=_switch_id,
port=self.protocol_port,
bridge=network.bridge_name,
vlanid=network.segmentation_id,
host=host
),
]
if (vni != INVALID_VNI) and (network.segmentation_id != vni):
actions.append(
VXLAN_URL.format(
scheme=self.scheme,
base=_switch_id,
port=self.protocol_port,
bridge=network.bridge_name,
vlanid=network.segmentation_id,
vni=vni
)
)
for action in actions:
try:
resp = requests.delete(action)
if resp.status_code != requests.codes.ok:
msg = (_("Error (%(code)s) delete port for %(host)s on"
" switch %(switch_id)s") %
{'code': resp.status_code,
'host': host,
'switch_id': _switch_id})
LOG.info(msg)
except requests.exceptions.RequestException as error:
msg = (_("Error connecting to switch (%(switch_id)s)."
" HTTP Error %(error)s") %
{'switch_id': _switch_id,
'error': error})
LOG.info(msg)
with self.sync_thread_lock:
db.db_delete_port(network.network_id, port_id, _switch_id,
host)
示例6: create
# 需要導入模塊: from neutron.extensions import portbindings [as 別名]
# 或者: from neutron.extensions.portbindings import HOST_ID [as 別名]
def create(self, context, loadbalancer):
"""Create a loadbalancer."""
driver = self.driver
self.loadbalancer = loadbalancer
try:
agent, service = self._schedule_agent_create_service(context)
agent_host = agent['host']
agent_config = agent.get('configurations', {})
LOG.debug("agent configurations: %s" % agent_config)
scheduler = self.driver.scheduler
agent_config_dict = \
scheduler.deserialize_agent_configurations(agent_config)
if not agent_config_dict.get('nova_managed', False):
# Update the port for the VIP to show ownership by this driver
port_data = {
'admin_state_up': True,
'device_owner': 'network:f5lbaasv2',
'status': q_const.PORT_STATUS_ACTIVE
}
port_data[portbindings.HOST_ID] = agent_host
port_data[portbindings.VNIC_TYPE] = "baremetal"
port_data[portbindings.PROFILE] = {}
driver.plugin.db._core_plugin.update_port(
context,
loadbalancer.vip_port_id,
{'port': port_data}
)
else:
LOG.debug("Agent devices are nova managed")
driver.agent_rpc.create_loadbalancer(
context, loadbalancer.to_api_dict(), service, agent_host)
except (lbaas_agentschedulerv2.NoEligibleLbaasAgent,
lbaas_agentschedulerv2.NoActiveLbaasAgent) as e:
LOG.error("Exception: loadbalancer create: %s" % e)
driver.plugin.db.update_status(
context,
models.LoadBalancer,
loadbalancer.id,
plugin_constants.ERROR)
except Exception as e:
LOG.error("Exception: loadbalancer create: %s" % e.message)
raise e
示例7: create_port_on_network
# 需要導入模塊: from neutron.extensions import portbindings [as 別名]
# 或者: from neutron.extensions.portbindings import HOST_ID [as 別名]
def create_port_on_network(self, context, network_id=None,
mac_address=None, name=None, host=None,
device_id=None,
vnic_type=portbindings.VNIC_NORMAL,
binding_profile={}):
"""Create a port on a network."""
ports = []
if network_id and name:
filters = {'name': [name]}
ports = self.driver.plugin.db._core_plugin.get_ports(
context,
filters=filters
)
if not ports:
network = self.driver.plugin.db._core_plugin.get_network(
context,
network_id
)
if not mac_address:
mac_address = attributes.ATTR_NOT_SPECIFIED
if not host:
host = ''
if not name:
name = ''
port_data = {
'tenant_id': network['tenant_id'],
'name': name,
'network_id': network_id,
'mac_address': mac_address,
'admin_state_up': True,
'device_owner': 'network:f5lbaasv2',
'status': neutron_const.PORT_STATUS_ACTIVE,
'fixed_ips': attributes.ATTR_NOT_SPECIFIED
}
if device_id:
port_data['device_id'] = device_id
port_data[portbindings.HOST_ID] = host
port_data[portbindings.VNIC_TYPE] = vnic_type
port_data[portbindings.PROFILE] = binding_profile
extended_attrs = portbindings.EXTENDED_ATTRIBUTES_2_0['ports']
if 'binding:capabilities' in extended_attrs:
port_data['binding:capabilities'] = {'port_filter': False}
port = self.driver.plugin.db._core_plugin.create_port(
context, {'port': port_data})
# Because ML2 marks ports DOWN by default on creation
update_data = {
'status': neutron_const.PORT_STATUS_ACTIVE
}
self.driver.plugin.db._core_plugin.update_port(
context, port['id'], {'port': update_data})
return port
else:
return ports[0]
# return a single active agent to implement cluster wide changes
# which can not efficiently mapped back to a particulare agent