s['id'] = db_subnet.id
self._validate_subnet(context, s, cur_subnet=db_subnet)
- if 'gateway_ip' in s and s['gateway_ip'] is not None:
+ if s.get('gateway_ip') is not None:
allocation_pools = [{'start': p['first_ip'], 'end': p['last_ip']}
for p in db_subnet.allocation_pools]
self._validate_gw_out_of_pools(s["gateway_ip"], allocation_pools)
raise n_exc.BadRequest(resource='floatingip', msg=msg)
internal_subnet_id = None
- if 'fixed_ip_address' in fip and fip['fixed_ip_address']:
+ if fip.get('fixed_ip_address'):
internal_ip_address = fip['fixed_ip_address']
for ip in internal_port['fixed_ips']:
if ip['ip_address'] == internal_ip_address:
def _check_and_get_fip_assoc(self, context, fip, floatingip_db):
port_id = internal_ip_address = router_id = None
- if (('fixed_ip_address' in fip and fip['fixed_ip_address']) and
- not ('port_id' in fip and fip['port_id'])):
+ if fip.get('fixed_ip_address') and not fip.get('port_id'):
msg = _("fixed_ip_address cannot be specified without a port_id")
raise n_exc.BadRequest(resource='floatingip', msg=msg)
- if 'port_id' in fip and fip['port_id']:
+ if fip.get('port_id'):
port_id, internal_ip_address, router_id = self.get_assoc_data(
context,
fip,
ips_to_remove=nsx_floating_ips)
def _get_fip_assoc_data(self, context, fip, floatingip_db):
- if (('fixed_ip_address' in fip and fip['fixed_ip_address']) and
- not ('port_id' in fip and fip['port_id'])):
+ if fip.get('fixed_ip_address') and not fip.get('port_id'):
msg = _("fixed_ip_address cannot be specified without a port_id")
raise n_exc.BadRequest(resource='floatingip', msg=msg)
port_id = internal_ip = router_id = None
- if 'port_id' in fip and fip['port_id']:
+ if fip.get('port_id'):
fip_qry = context.session.query(l3_db.FloatingIP)
port_id, internal_ip, router_id = self.get_assoc_data(
context,
return result
def get_nuage_port_by_id(self, params):
- if 'nuage_fip_id' in params and params['nuage_fip_id'] == '1':
+ if params.get('nuage_fip_id') == '1':
domain_id = uuidutils.generate_uuid()
else:
if 'nuage_router_id' in params:
'dns_nameservers', 'host_routes',
'shared', 'ipv6_ra_mode', 'ipv6_address_mode'):
# Arg must be present and not null (but can be false)
- if arg in kwargs and kwargs[arg] is not None:
+ if kwargs.get(arg) is not None:
data['subnet'][arg] = kwargs[arg]
if ('gateway_ip' in kwargs and
data['router']['admin_state_up'] = admin_state_up
for arg in (('admin_state_up', 'tenant_id') + (arg_list or ())):
# Arg must be present and not empty
- if arg in kwargs and kwargs[arg]:
+ if kwargs.get(arg):
data['router'][arg] = kwargs[arg]
router_req = self.new_create_request('routers', data, fmt)
if set_context and tenant_id:
data[self.gw_resource]['name'] = name
for arg in arg_list or ():
# Arg must be present and not empty
- if arg in kwargs and kwargs[arg]:
+ if kwargs.get(arg):
data[self.gw_resource][arg] = kwargs[arg]
nw_gw_req = self.new_create_request(networkgw.NETWORK_GATEWAYS,
data, fmt)
for arg in (('admin_state_up', 'tenant_id', 'shared') +
(arg_list or ())):
# Arg must be present and not empty
- if arg in kwargs and kwargs[arg]:
+ if kwargs.get(arg):
data['network'][arg] = kwargs[arg]
network_req = self.new_create_request('networks', data, fmt)
if (kwargs.get('set_context') and 'tenant_id' in kwargs):