fix pep8 issues
This commit is contained in:
parent
a05b6f267f
commit
fb0deca7e0
akanda/quantum
db
extensions
plugins
test/functional
@ -78,8 +78,7 @@ class PortForward(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
|
||||
return private_port
|
||||
|
||||
|
||||
class AddressGroup(model_base.BASEV2, models_v2.HasId,
|
||||
models_v2.HasTenant):
|
||||
class AddressGroup(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
|
||||
"""Represents AddressGroup extension"""
|
||||
|
||||
name = sa.Column(sa.String(255), nullable=False, primary_key=True)
|
||||
@ -91,8 +90,7 @@ class AddressGroup(model_base.BASEV2, models_v2.HasId,
|
||||
return name
|
||||
|
||||
|
||||
class AddressEntry(model_base.BASEV2, models_v2.HasId,
|
||||
models_v2.HasTenant):
|
||||
class AddressEntry(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
|
||||
"""Represents (part of) an Address extension"""
|
||||
__tablename__ = 'addressentries'
|
||||
|
||||
|
@ -75,11 +75,11 @@ class AddressEntryResource(_authzbase.ResourceDelegate):
|
||||
try:
|
||||
group = qry.one()
|
||||
except exc.NoResultFound:
|
||||
msg = ("Tenant %(tenant_id) does not have an address "
|
||||
msg = (
|
||||
"Tenant %(tenant_id) does not have an address "
|
||||
"group with id %(group_id)s" %
|
||||
{'tenant_id': tenant_id,
|
||||
'group_id': body.get('group_id'),
|
||||
})
|
||||
{'tenant_id': tenant_id, 'group_id': body.get('group_id')}
|
||||
)
|
||||
raise q_exc.BadRequest(resource='addressentry', msg=msg)
|
||||
if group.name == 'Any':
|
||||
raise q_exc.PolicyNotAuthorized(
|
||||
@ -132,9 +132,12 @@ class Addressentry(object):
|
||||
return "2012-08-02T16:00:00-05:00"
|
||||
|
||||
def get_resources(self):
|
||||
return [extensions.ResourceExtension(
|
||||
return [
|
||||
extensions.ResourceExtension(
|
||||
'dhaddressentry',
|
||||
_authzbase.create_extension(AddressEntryResource()))]
|
||||
_authzbase.create_extension(AddressEntryResource())
|
||||
)
|
||||
]
|
||||
|
||||
def get_actions(self):
|
||||
return []
|
||||
|
@ -47,21 +47,25 @@ class AddressGroupResource(_authzbase.ResourceDelegate):
|
||||
}
|
||||
|
||||
def make_entry_dict(self, addressentry):
|
||||
return {'id': addressentry['id'],
|
||||
return {
|
||||
'id': addressentry['id'],
|
||||
'name': addressentry['name'],
|
||||
'group_id': addressentry['group_id'],
|
||||
'tenant_id': addressentry['tenant_id'],
|
||||
'cidr': addressentry['cidr']}
|
||||
'cidr': addressentry['cidr']
|
||||
}
|
||||
|
||||
def make_dict(self, addressgroup):
|
||||
"""
|
||||
Convert a address model object to a dictionary.
|
||||
"""
|
||||
res = {'id': addressgroup['id'],
|
||||
res = {
|
||||
'id': addressgroup['id'],
|
||||
'name': addressgroup['name'],
|
||||
'tenant_id': addressgroup['tenant_id'],
|
||||
'entries': [self.make_entry_dict(e)
|
||||
for e in addressgroup['entries']]}
|
||||
for e in addressgroup['entries']]
|
||||
}
|
||||
return res
|
||||
|
||||
def create(self, context, tenant_id, body):
|
||||
|
@ -23,7 +23,8 @@ akanda_opts = [
|
||||
cfg.IntOpt('akanda_ipv6_prefix_length',
|
||||
default=64,
|
||||
help='Default length of prefix to pre-assign'),
|
||||
cfg.ListOpt('akanda_allowed_cidr_ranges',
|
||||
cfg.ListOpt(
|
||||
'akanda_allowed_cidr_ranges',
|
||||
default=['10.0.0.8/8', '172.16.0.0/12', '192.168.0.0/16', 'fc00::/7'],
|
||||
help='List of allowed subnet cidrs for non-admin users')
|
||||
]
|
||||
@ -31,7 +32,6 @@ akanda_opts = [
|
||||
cfg.CONF.register_opts(akanda_opts)
|
||||
|
||||
|
||||
|
||||
class NVPQuantumPlugin(nvp.NvpPluginV2, l3_db.L3_NAT_db_mixin):
|
||||
supported_extension_aliases = (
|
||||
nvp.NvpPluginV2.supported_extension_aliases +
|
||||
@ -196,12 +196,14 @@ class NVPQuantumPlugin(nvp.NvpPluginV2, l3_db.L3_NAT_db_mixin):
|
||||
'gateway_ip': attributes.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': attributes.ATTR_NOT_SPECIFIED,
|
||||
'host_routes': attributes.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': attributes.ATTR_NOT_SPECIFIED}
|
||||
'allocation_pools': attributes.ATTR_NOT_SPECIFIED
|
||||
}
|
||||
self.create_subnet(context, {'subnet': create_args})
|
||||
break
|
||||
else:
|
||||
LOG.error('Unable to generate a unique tenant subnet cidr')
|
||||
|
||||
|
||||
def _ipv6_subnet_generator(network_range, prefixlen):
|
||||
# coerce prefixlen to stay within bounds
|
||||
prefixlen = min(128, prefixlen)
|
||||
|
@ -23,7 +23,8 @@ akanda_opts = [
|
||||
cfg.IntOpt('akanda_ipv6_prefix_length',
|
||||
default=64,
|
||||
help='Default length of prefix to pre-assign'),
|
||||
cfg.ListOpt('akanda_allowed_cidr_ranges',
|
||||
cfg.ListOpt(
|
||||
'akanda_allowed_cidr_ranges',
|
||||
default=['10.0.0.8/8', '172.16.0.0/12', '192.168.0.0/16', 'fc00::/7'],
|
||||
help='List of allowed subnet cidrs for non-admin users')
|
||||
]
|
||||
@ -156,9 +157,11 @@ class OVSQuantumPluginV2(ovs_quantum_plugin.OVSQuantumPluginV2):
|
||||
port['fixed_ips'].append({'subnet_id': subnet['id'],
|
||||
'ip_address': subnet['gateway_ip']})
|
||||
|
||||
self.update_port(context.elevated(),
|
||||
self.update_port(
|
||||
context.elevated(),
|
||||
port['id'],
|
||||
{'port': port})
|
||||
{'port': port}
|
||||
)
|
||||
return True
|
||||
|
||||
def _akanda_add_ipv6_subnet(self, context, network):
|
||||
@ -166,7 +169,8 @@ class OVSQuantumPluginV2(ovs_quantum_plugin.OVSQuantumPluginV2):
|
||||
try:
|
||||
subnet_generator = _ipv6_subnet_generator(
|
||||
cfg.CONF.akanda_ipv6_tenant_range,
|
||||
cfg.CONF.akanda_ipv6_prefix_length)
|
||||
cfg.CONF.akanda_ipv6_prefix_length
|
||||
)
|
||||
except:
|
||||
LOG.exception('Unable able to add tenant IPv6 subnet.')
|
||||
return
|
||||
@ -192,7 +196,8 @@ class OVSQuantumPluginV2(ovs_quantum_plugin.OVSQuantumPluginV2):
|
||||
'gateway_ip': attributes.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': attributes.ATTR_NOT_SPECIFIED,
|
||||
'host_routes': attributes.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': attributes.ATTR_NOT_SPECIFIED}
|
||||
'allocation_pools': attributes.ATTR_NOT_SPECIFIED
|
||||
}
|
||||
self.create_subnet(context, {'subnet': create_args})
|
||||
break
|
||||
else:
|
||||
@ -204,7 +209,8 @@ class OVSQuantumPluginV2(ovs_quantum_plugin.OVSQuantumPluginV2):
|
||||
"""
|
||||
for protocol, port, name in DEFAULT_PORT_ALIASES:
|
||||
pa_q = context.session.query(akmodels.PortAlias)
|
||||
pa_q = pa_q.filter_by(tenant_id=context.tenant_id,
|
||||
pa_q = pa_q.filter_by(
|
||||
tenant_id=context.tenant_id,
|
||||
port=port,
|
||||
protocol=protocol,
|
||||
)
|
||||
@ -227,7 +233,8 @@ class OVSQuantumPluginV2(ovs_quantum_plugin.OVSQuantumPluginV2):
|
||||
"""
|
||||
for ag_name, entries in DEFAULT_ADDRESS_GROUPS:
|
||||
ag_q = context.session.query(akmodels.AddressGroup)
|
||||
ag_q = ag_q.filter_by(tenant_id=context.tenant_id,
|
||||
ag_q = ag_q.filter_by(
|
||||
tenant_id=context.tenant_id,
|
||||
name=ag_name,
|
||||
)
|
||||
try:
|
||||
@ -244,7 +251,8 @@ class OVSQuantumPluginV2(ovs_quantum_plugin.OVSQuantumPluginV2):
|
||||
|
||||
for entry_name, cidr in entries:
|
||||
entry_q = context.session.query(akmodels.AddressEntry)
|
||||
entry_q = entry_q.filter_by(group=address_group,
|
||||
entry_q = entry_q.filter_by(
|
||||
group=address_group,
|
||||
name=entry_name,
|
||||
cidr=cidr,
|
||||
)
|
||||
@ -286,7 +294,8 @@ def _ipv6_subnet_generator(network_range, prefixlen):
|
||||
rand_bits = rand.randint(0, max_range)
|
||||
|
||||
candidate_cidr = netaddr.IPNetwork(
|
||||
netaddr.IPAddress(net.value + (rand_bits << prefixlen)))
|
||||
netaddr.IPAddress(net.value + (rand_bits << prefixlen))
|
||||
)
|
||||
candidate_cidr.prefixlen = prefixlen
|
||||
|
||||
yield candidate_cidr
|
||||
|
@ -144,7 +144,7 @@ if __name__ == '__main__':
|
||||
auth_url='http://localhost:5000/v2.0/',
|
||||
auth_strategy='keystone',
|
||||
auth_region='RegionOne')
|
||||
for lister, deleter, obj_type in [
|
||||
resources = [
|
||||
(c.list_portalias, c.delete_portalias, 'portalias'),
|
||||
(c.list_filterrules, c.delete_filterrule, 'filterrule'),
|
||||
(c.list_portforwards, c.delete_portforward, 'portforward'),
|
||||
@ -152,8 +152,9 @@ if __name__ == '__main__':
|
||||
(c.list_addressgroups, c.delete_addressgroup, 'addressgroup'),
|
||||
(c.list_ports, c.delete_port, 'port'),
|
||||
(c.list_subnets, c.delete_subnet, 'subnet'),
|
||||
(c.list_networks, c.delete_network, 'network'),
|
||||
]:
|
||||
(c.list_networks, c.delete_network, 'network')
|
||||
]
|
||||
for lister, deleter, obj_type in resources:
|
||||
print obj_type
|
||||
response = lister()
|
||||
data = response[iter(response).next()]
|
||||
|
Loading…
x
Reference in New Issue
Block a user