本文整理汇总了Python中networking_cisco._i18n._LW函数的典型用法代码示例。如果您正苦于以下问题:Python _LW函数的具体用法?Python _LW怎么用?Python _LW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_LW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _sync_base
def _sync_base(self):
ctx = context.get_admin_context()
# Sync Networks
for network in self.core_plugin.get_networks(ctx):
mech_context = driver_context.NetworkContext(self.core_plugin, ctx,
network)
try:
self.driver.create_network_postcommit(mech_context)
except Exception:
LOG.warning(_LW("Create network postcommit failed for "
"network %s"), network['id'])
# Sync Subnets
for subnet in self.core_plugin.get_subnets(ctx):
mech_context = driver_context.SubnetContext(self.core_plugin, ctx,
subnet)
try:
self.driver.create_subnet_postcommit(mech_context)
except Exception:
LOG.warning(_LW("Create subnet postcommit failed for"
" subnet %s"), subnet['id'])
# Sync Ports (compute/gateway/dhcp)
for port in self.core_plugin.get_ports(ctx):
_, binding = l2_db.get_locked_port_and_binding(ctx.session,
port['id'])
network = self.core_plugin.get_network(ctx, port['network_id'])
mech_context = driver_context.PortContext(self.core_plugin, ctx,
port, network, binding,
[])
try:
self.driver.create_port_postcommit(mech_context)
except Exception:
LOG.warning(_LW("Create port postcommit failed for"
" port %s"), port['id'])
示例2: _maintain_hosting_device_pool
def _maintain_hosting_device_pool(self, context, template):
"""Maintains the pool of hosting devices that are based on <template>.
Ensures that the number of standby hosting devices (essentially
service VMs) is kept at a suitable level so that resource creation is
not slowed down by booting of the hosting device.
:param context: context for this operation
:param template: db object for hosting device template
"""
#TODO(bobmel): Support HA/load-balanced Neutron servers:
#TODO(bobmel): Locking across multiple running Neutron server instances
lock = self._get_template_pool_lock(template['id'])
acquired = lock.acquire(False)
if not acquired:
# pool maintenance for this template already ongoing, so abort
return
try:
# Maintain a pool of approximately 'desired_slots_free' available
# for allocation. Approximately means that
# abs(desired_slots_free-capacity) <= available_slots <=
# desired_slots_free+capacity
capacity = template['slot_capacity']
if capacity == 0:
return
desired = template['desired_slots_free']
available = self._get_total_available_slots(
context, template['id'], capacity)
grow_threshold = abs(desired - capacity)
if available <= grow_threshold:
num_req = int(math.ceil(grow_threshold / (1.0 * capacity)))
num_created = len(self._create_svc_vm_hosting_devices(
context, num_req, template))
if num_created < num_req:
LOG.warning(_LW('Requested %(requested)d instances based '
'on hosting device template %(template)s '
'but could only create %(created)d '
'instances'),
{'requested': num_req,
'template': template['id'],
'created': num_created})
elif available >= desired + capacity:
num_req = int(
math.floor((available - desired) / (1.0 * capacity)))
num_deleted = self._delete_idle_service_vm_hosting_devices(
context, num_req, template)
if num_deleted < num_req:
LOG.warning(_LW('Tried to delete %(requested)d instances '
'based on hosting device template '
'%(template)s but could only delete '
'%(deleted)d instances'),
{'requested': num_req, 'template': template['id'],
'deleted': num_deleted})
finally:
lock.release()
示例3: _router_removed
def _router_removed(self, router_id, deconfigure=True):
"""Operations when a router is removed.
Get the RouterInfo object corresponding to the router in the service
helpers's router_info dict. If deconfigure is set to True,
remove this router's configuration from the hosting device.
:param router_id: id of the router
:param deconfigure: if True, the router's configuration is deleted from
the hosting device.
:return: None
"""
ri = self.router_info.get(router_id)
if ri is None:
LOG.warning(_LW("Info for router %s was not found. "
"Skipping router removal"), router_id)
return
ri.router['gw_port'] = None
ri.router[l3_constants.INTERFACE_KEY] = []
ri.router[l3_constants.FLOATINGIP_KEY] = []
try:
hd = ri.router['hosting_device']
# We proceed to removing the configuration from the device
# only if (a) deconfigure is set to True (default)
# (b) the router's hosting device is reachable.
if (deconfigure and
self._dev_status.is_hosting_device_reachable(hd)):
self._process_router(ri)
driver = self.driver_manager.get_driver(router_id)
driver.router_removed(ri)
self.driver_manager.remove_driver(router_id)
del self.router_info[router_id]
self.removed_routers.discard(router_id)
except cfg_exceptions.DriverException:
LOG.warning(_LW("Router remove for router_id: %s was incomplete. "
"Adding the router to removed_routers list"),
router_id)
self.removed_routers.add(router_id)
# remove this router from updated_routers if it is there. It might
# end up there too if exception was thrown earlier inside
# `_process_router()`
self.updated_routers.discard(router_id)
except ncc_errors.SessionCloseError as e:
LOG.exception(_LE("ncclient Unexpected session close %s"
" while attempting to remove router"), e)
if not self._dev_status.is_hosting_device_reachable(hd):
LOG.debug("Lost connectivity to Hosting Device %s" % hd['id'])
# rely on heartbeat to detect HD state
# and schedule resync when the device comes back
else:
# retry the router removal on the next pass
self.removed_routers.add(router_id)
LOG.debug("Interim connectivity lost to hosting device %s, "
"enqueuing router %s in removed_routers set" %
pp.pformat(hd), router_id)
示例4: get_version
def get_version():
version = 0
try:
pnr = _get_client()
verstr = pnr.get_version()
version = verstr.split()[2]
except cpnr_client.CpnrException:
LOG.warning(_LW("Failed to obtain CPNR version number"))
except StandardError:
LOG.warning(_LW("Failed to parse CPNR version number"))
LOG.debug("CPNR version: %s", version)
return version
示例5: _edit_running_config
def _edit_running_config(self, conf_str, snippet):
conn = self._get_connection()
LOG.info(
_LI("Config generated for [%(device)s] %(snip)s is:%(conf)s " "caller:%(caller)s"),
{"device": self.hosting_device["id"], "snip": snippet, "conf": conf_str, "caller": self.caller_name()},
)
try:
rpc_obj = conn.edit_config(target="running", config=conf_str)
self._check_response(rpc_obj, snippet, conf_str=conf_str)
except Exception as e:
# Here we catch all exceptions caused by REMOVE_/DELETE_ configs
# to avoid config agent to get stuck once it hits this condition.
# This is needed since the current ncclient version (0.4.2)
# generates an exception when an attempt to configure the device
# fails by the device (ASR1K router) but it doesn't provide any
# details about the error message that the device reported.
# With ncclient 0.4.4 version and onwards the exception returns
# also the proper error. Hence this code can be changed when the
# ncclient version is increased.
if re.search(r"REMOVE_|DELETE_", snippet):
LOG.warning(_LW("Pass exception for %s"), snippet)
pass
elif isinstance(e, ncclient.operations.rpc.RPCError):
e_tag = e.tag
e_type = e.type
params = {
"snippet": snippet,
"type": e_type,
"tag": e_tag,
"dev_id": self.hosting_device["id"],
"ip": self._host_ip,
"confstr": conf_str,
}
raise cfg_exc.CSR1kvConfigException(**params)
示例6: release_segment
def release_segment(self, session, segment):
vxlan_vni = segment[api.SEGMENTATION_ID]
inside = any(lo <= vxlan_vni <= hi for lo, hi in self.tunnel_ranges)
with session.begin(subtransactions=True):
query = (session.query(nexus_models_v2.NexusVxlanAllocation).
filter_by(vxlan_vni=vxlan_vni))
if inside:
count = query.update({"allocated": False})
if count:
mcast_row = (
session.query(nexus_models_v2.NexusMcastGroup)
.filter_by(associated_vni=vxlan_vni).first())
session.delete(mcast_row)
LOG.debug("Releasing vxlan tunnel %s to pool",
vxlan_vni)
else:
count = query.delete()
if count:
LOG.debug("Releasing vxlan tunnel %s outside pool",
vxlan_vni)
if not count:
LOG.warning(_LW("vxlan_vni %s not found"), vxlan_vni)
示例7: _delete_port_profile
def _delete_port_profile(self, handle, port_profile, ucsm_ip):
"""Deletes Port Profile from UCS Manager."""
port_profile_dest = (const.PORT_PROFILESETDN + const.VNIC_PATH_PREFIX +
port_profile)
try:
handle.StartTransaction()
# Find port profile on the UCS Manager
p_profile = handle.GetManagedObject(
None,
self.ucsmsdk.VnicProfile.ClassId(),
{self.ucsmsdk.VnicProfile.NAME: port_profile,
self.ucsmsdk.VnicProfile.DN: port_profile_dest})
if not p_profile:
LOG.warning(_LW('UCS Manager network driver did not find '
'Port Profile %s to delete.'),
port_profile)
return
handle.RemoveManagedObject(p_profile)
handle.CompleteTransaction()
except Exception as e:
# Raise a Neutron exception. Include a description of
# the original exception.
raise cexc.UcsmConfigDeleteFailed(config=port_profile,
ucsm_ip=ucsm_ip,
exc=e)
示例8: sanitize_policy_profile_table
def sanitize_policy_profile_table(self):
"""Clear policy profiles from stale VSM."""
db_session = db.get_session()
hosts = config.get_vsm_hosts()
vsm_info = db_session.query(
n1kv_models.PolicyProfile.vsm_ip).distinct()
if vsm_info is None or hosts is None:
return
vsm_ips = [vsm_ip[0] for vsm_ip in vsm_info if vsm_ip[0] not in hosts]
for vsm_ip in vsm_ips:
pprofiles = n1kv_db.get_policy_profiles_by_host(vsm_ip, db_session)
for pprofile in pprofiles:
# Do not delete profile if it is in use and if it
# is the only VSM to have it configured
pp_in_use = n1kv_db.policy_profile_in_use(pprofile['id'],
db_session)
num_vsm_using_pp = db_session.query(
n1kv_models.PolicyProfile).filter_by(
id=pprofile['id']).count()
if (not pp_in_use) or (num_vsm_using_pp > 1):
db_session.delete(pprofile)
db_session.flush()
else:
LOG.warning(_LW('Cannot delete policy profile %s '
'as it is in use.'), pprofile['id'])
示例9: remove_reserved_binding
def remove_reserved_binding(vlan_id, switch_ip, instance_id,
port_id):
"""Removes reserved binding.
This overloads port bindings to support reserved Switch binding
used to maintain the state of a switch so it can be viewed by
all other neutron processes. There's also the case of
a reserved port binding to keep switch information on a given
interface.
The values of these arguments is as follows:
:param vlan_id: 0
:param switch_ip: ip address of the switch
:param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1
: or RESERVED_NEXUS_PORT_DEVICE_ID_R1
:param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE
: port-expected port_id
"""
if not port_id:
LOG.warning(_LW("remove_reserved_binding called with no state"))
return
LOG.debug("remove_reserved_binding called")
session = db.get_session()
binding = _lookup_one_nexus_binding(session=session,
vlan_id=vlan_id,
switch_ip=switch_ip,
instance_id=instance_id,
port_id=port_id)
for bind in binding:
session.delete(bind)
session.flush()
return binding
示例10: _agent_registration
def _agent_registration(self):
"""Register this agent with the server.
This method registers the cfg agent with the neutron server so hosting
devices can be assigned to it. In case the server is not ready to
accept registration (it sends a False) then we retry registration
for `MAX_REGISTRATION_ATTEMPTS` with a delay of
`REGISTRATION_RETRY_DELAY`. If there is no server response or a
failure to register after the required number of attempts,
the agent stops itself.
"""
for attempts in range(MAX_REGISTRATION_ATTEMPTS):
context = n_context.get_admin_context_without_session()
self.send_agent_report(self.agent_state, context)
res = self.devmgr_rpc.register_for_duty(context)
if res is True:
LOG.info(_LI("[Agent registration] Agent successfully "
"registered"))
return
elif res is False:
LOG.warning(_LW("[Agent registration] Neutron server said "
"that device manager was not ready. Retrying "
"in %0.2f seconds "), REGISTRATION_RETRY_DELAY)
time.sleep(REGISTRATION_RETRY_DELAY)
elif res is None:
LOG.error(_LE("[Agent registration] Neutron server said that "
"no device manager was found. Cannot continue. "
"Exiting!"))
raise SystemExit(_("Cfg Agent exiting"))
LOG.error(_LE("[Agent registration] %d unsuccessful registration "
"attempts. Exiting!"), MAX_REGISTRATION_ATTEMPTS)
raise SystemExit(_("Cfg Agent exiting"))
示例11: _delete_resource_port
def _delete_resource_port(self, context, port_id):
try:
self._core_plugin.delete_port(context, port_id)
LOG.debug("Port %s deleted successfully", port_id)
except n_exc.PortNotFound:
LOG.warning(_LW('Trying to delete port:%s, but port is not found'),
port_id)
示例12: delete_hosting_device_resources
def delete_hosting_device_resources(self, context, tenant_id, mgmt_port,
**kwargs):
attempts = 1
port_ids = set(p['id'] for p in kwargs['ports'])
while mgmt_port is not None or port_ids:
if attempts == DELETION_ATTEMPTS:
LOG.warning(_LW('Aborting resource deletion after %d '
'unsuccessful attempts'), DELETION_ATTEMPTS)
return
else:
if attempts > 1:
eventlet.sleep(SECONDS_BETWEEN_DELETION_ATTEMPTS)
LOG.info(_LI('Resource deletion attempt %d starting'),
attempts)
# Remove anything created.
if mgmt_port is not None:
ml = {mgmt_port['id']}
self._delete_resources(context, "management port",
self._core_plugin.delete_port,
n_exc.PortNotFound, ml)
if not ml:
mgmt_port = None
self._delete_resources(context, "trunk port",
self._core_plugin.delete_port,
n_exc.PortNotFound, port_ids)
attempts += 1
self._safe_delete_t1_network(context, tenant_id)
self._safe_delete_t2_network(context, tenant_id)
LOG.info(_LI('Resource deletion succeeded'))
示例13: _sync_base
def _sync_base(self):
ctx = context.get_admin_context()
# Sync Networks
# Unroll to avoid unwanted additions during sync
networks = [x for x in self.core_plugin.get_networks(ctx)]
for network in networks:
if constants.APIC_SYNC_NETWORK == network['name']:
continue
mech_context = driver_context.NetworkContext(
self.core_plugin, ctx, network)
try:
self.driver.create_network_postcommit(mech_context)
except aexc.ReservedSynchronizationName as e:
LOG.debug(e.message)
except Exception as e:
LOG.warning(_LW("Create network postcommit failed for "
"network %(net_id)s: %(message)s"),
net_id=network['id'], message=e.message)
# Sync Subnets
subnets = [x for x in self.core_plugin.get_subnets(ctx)]
for subnet in subnets:
mech_context = driver_context.SubnetContext(self.core_plugin, ctx,
subnet)
try:
self.driver.create_subnet_postcommit(mech_context)
except Exception as e:
LOG.warning(_LW("Create subnet postcommit failed for "
"subnet %(sub_id)s: %(message)s"),
sub_id=subnet['id'], message=e.message)
# Sync Ports (compute/gateway/dhcp)
ports = [x for x in self.core_plugin.get_ports(ctx)]
for port in ports:
binding = l2_db.get_locked_port_and_binding(ctx.session,
port['id'])[1]
levels = l2_db.get_binding_levels(ctx.session, port['id'],
binding.host)
network = self.core_plugin.get_network(ctx, port['network_id'])
mech_context = driver_context.PortContext(self.core_plugin, ctx,
port, network, binding,
levels)
try:
self.driver.create_port_postcommit(mech_context)
except Exception as e:
LOG.warning(_LW("Create port postcommit failed for "
"port %(port_id)s: %(message)s"),
port_id=port['id'], message=e.message)
示例14: format_for_options
def format_for_options(name, value):
name = name.strip()
if type(value) is str:
value = value.strip()
LOG.debug('name = %s value %s', name, value)
if name not in OPTIONS:
LOG.warning(_LW("Unrecognized DHCP options: %s"), name)
return
code, datatype = OPTIONS[name]
try:
value = _format_value(datatype, value)
except Exception:
LOG.warning(_LW("Failed to parse DHCP option: %s"), name)
return
value = ':'.join(value[i:i + 2] for i in range(0, len(value), 2))
LOG.debug('name = %s value %s', name, value)
return value
示例15: format_for_pnr
def format_for_pnr(name, value):
name = name.strip()
value = value.strip()
if name not in OPTIONS:
LOG.warning(_LW("Unrecognized DHCP options: %s"), name)
return None
code, datatype = OPTIONS[name]
return {'number': str(code), 'value': value}