try:
filters = dict(network_id=[network_id], device_id=[device_id])
ports = plugin.get_ports(context, filters=filters)
- if len(ports):
+ if ports:
# Ensure that fixed_ips cover all dhcp_enabled subnets.
port = ports[0]
for fixed_ip in port['fixed_ips']:
filters = dict(network_id=[network_id], device_id=[device_id])
ports = plugin.get_ports(context, filters=filters)
- if len(ports):
+ if ports:
plugin.delete_port(context, ports[0]['id'])
def release_port_fixed_ip(self, context, **kwargs):
filters = dict(network_id=[network_id], device_id=[device_id])
ports = plugin.get_ports(context, filters=filters)
- if len(ports):
+ if ports:
port = ports[0]
fixed_ips = port.get('fixed_ips', [])
'admin_state_up': True,
'name': ''}})
- if not len(gw_port['fixed_ips']):
+ if not gw_port['fixed_ips']:
self.delete_port(context.elevated(), gw_port['id'],
l3_port_check=False)
msg = (_('No IPs available for external network %s') %
raise q_exc.BadRequest(resource='floatingip', msg=msg)
else:
ips = [ip['ip_address'] for ip in internal_port['fixed_ips']]
- if len(ips) == 0:
+ if not ips:
msg = (_('Cannot add floating IP to port %s that has'
'no fixed IP addresses') % internal_port['id'])
raise q_exc.BadRequest(resource='floatingip', msg=msg)
def _validate_service_defs(data, valid_values=None):
""" Validate the list of service definitions. """
try:
- if len(data) == 0:
+ if not data:
return _("No service type definition was provided. At least a "
"service type definition must be provided")
f_name = _validate_service_defs.__name__
return msg
del svc_def_copy[DRIVER_ATTR]
# Anything left - it should be an error
- if len(svc_def_copy):
+ if svc_def_copy:
msg = (_("Unparseable attributes found in "
"service definition %s") % svc_def)
LOG.error(_("%(f_name)s: %(msg)s"), locals())
def _get_vnic_settings(self, vnic_name):
vnic_settings = self._conn.Msvm_SyntheticEthernetPortSettingData(
ElementName=vnic_name)
- if not len(vnic_settings):
+ if not vnic_settings:
raise HyperVException(msg=_('Vnic not found: %s') % vnic_name)
return vnic_settings[0]
def _get_vswitch(self, vswitch_name):
vswitch = self._conn.Msvm_VirtualSwitch(ElementName=vswitch_name)
- if not len(vswitch):
+ if not vswitch:
raise HyperVException(msg=_('VSwitch not found: %s') %
vswitch_name)
return vswitch[0]
for vswitch_port in vswitch_ports:
lan_endpoints = vswitch_port.associators(
wmi_result_class='Msvm_SwitchLanEndpoint')
- if len(lan_endpoints):
+ if lan_endpoints:
ext_port = lan_endpoints[0].associators(
wmi_result_class='Msvm_ExternalEthernetPort')
if ext_port:
# delete unnessary ofc_tenant
filters = dict(tenant_id=[tenant_id])
nets = super(NECPluginV2, self).get_networks(context, filters=filters)
- if len(nets) == 0:
+ if not nets:
try:
self.ofc.delete_ofc_tenant(context, tenant_id)
except (nexc.OFCException, nexc.OFCConsistencyBroken) as exc:
except q_exc.NetworkNotFound:
continue
pairs.append((c, lswitches))
- if len(pairs) == 0:
+ if not pairs:
raise q_exc.NetworkNotFound(net_id=netw_id)
LOG.debug(_("Returning pairs for network: %s"), pairs)
return pairs
# do not make the case in which switches are found in NVP
# but not in Quantum catastrophic.
- if len(nvp_lswitches):
+ if nvp_lswitches:
LOG.warning(_("Found %s logical switches not bound "
"to Quantum networks. Quantum and NVP are "
"potentially out of sync"), len(nvp_lswitches))
lports.append(quantum_lport)
# do not make the case in which ports are found in NVP
# but not in Quantum catastrophic.
- if len(nvp_lports):
+ if nvp_lports:
LOG.warning(_("Found %s logical ports not bound "
"to Quantum ports. Quantum and NVP are "
"potentially out of sync"), len(nvp_lports))
msg = (_("Network '%s' is not a valid external "
"network") % network_id)
raise q_exc.BadRequest(resource='router', msg=msg)
- if len(ext_net.subnets):
+ if ext_net.subnets:
ext_subnet = ext_net.subnets[0]
nexthop = ext_subnet.gateway_ip
cluster = self._find_target_cluster(router)
msg = (_("Network '%s' is not a valid external "
"network") % network_id)
raise q_exc.BadRequest(resource='router', msg=msg)
- if len(ext_net.subnets):
+ if ext_net.subnets:
ext_subnet = ext_net.subnets[0]
nexthop = ext_subnet.gateway_ip
cluster = self._find_target_cluster(router)
# do not make the case in which routers are found in NVP
# but not in Quantum catastrophic.
- if len(nvp_lrouters):
+ if nvp_lrouters:
LOG.warning(_("Found %s logical routers not bound "
"to Quantum routers. Quantum and NVP are "
"potentially out of sync"), len(nvp_lrouters))
results = nvplib.query_lswitch_lports(
cluster, '*',
filters={'tag': port_id, 'tag_scope': 'q_port_id'})
- if len(results):
+ if results:
ls_port = results[0]
else:
raise nvp_exc.NvpPluginException(
cluster, '*', relations="LogicalPortAttachment",
filters={'tag': port_id, 'tag_scope': 'q_port_id'})
lrouter_port_id = None
- if len(results):
+ if results:
lport = results[0]
attachment_data = lport['_relations'].get('LogicalPortAttachment')
lrouter_port_id = (attachment_data and
print "NVP Default Cluster Name %s" % nvp_opts.default_cluster_name
print "-----------Cluster Options--------------------"
- if not len(clusters_opts):
+ if not clusters_opts:
print "No NVP Clusters detected in nvp.ini!"
exit(1)
clusters, default_cluster = QuantumPlugin.parse_clusters_opts(
params.extend(['%s=%s' % (k, v) for (k, v) in filters.iteritems()])
uri_path = "%s/%s" % (URI_PREFIX, res_path)
non_empty_params = [x for x in params if x is not None]
- if len(non_empty_params):
+ if non_empty_params:
query_string = '&'.join(non_empty_params)
if query_string:
uri_path += "?%s" % query_string
'port_range_max': constants.DHCP_RESPONSE_PORT,
'ip_prefix': '0.0.0.0/0'})
# If there are no ingress rules add bunk rule to drop all ingress traffic
- if not len(rules['logical_port_ingress_rules']):
+ if not rules['logical_port_ingress_rules']:
rules['logical_port_ingress_rules'].append(
{'ethertype': 'IPv4', 'ip_prefix': '127.0.0.1/32'})
try:
self.SECPROF_RESOURCE in res_type or
'gatewayservice' in res_type):
LOG.debug("UUIDS:%s", uuids)
- if len(uuids) > 0:
+ if uuids:
return self._show(res_type, response_file, uuids[0],
relations=relations)
else:
if val_func:
val_func(body_json)
args = [body]
- if len(uuids):
+ if uuids:
args.append(uuids[0])
response = response_template % add_resource(*args)
return response