remove the vif joins, some dead code, and the ability to take in some instances for filtering
This commit is contained in:
parent
8c6c251c80
commit
3771928e67
@ -19,6 +19,7 @@
|
||||
Implementation of SQLAlchemy backend.
|
||||
"""
|
||||
import re
|
||||
import types
|
||||
import warnings
|
||||
|
||||
from nova import block_device
|
||||
@ -927,7 +928,6 @@ def virtual_interface_get(context, vif_id, session=None):
|
||||
vif_ref = session.query(models.VirtualInterface).\
|
||||
filter_by(id=vif_id).\
|
||||
options(joinedload('network')).\
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('fixed_ips')).\
|
||||
first()
|
||||
return vif_ref
|
||||
@ -943,7 +943,6 @@ def virtual_interface_get_by_address(context, address):
|
||||
vif_ref = session.query(models.VirtualInterface).\
|
||||
filter_by(address=address).\
|
||||
options(joinedload('network')).\
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('fixed_ips')).\
|
||||
first()
|
||||
return vif_ref
|
||||
@ -959,7 +958,6 @@ def virtual_interface_get_by_uuid(context, vif_uuid):
|
||||
vif_ref = session.query(models.VirtualInterface).\
|
||||
filter_by(uuid=vif_uuid).\
|
||||
options(joinedload('network')).\
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('fixed_ips')).\
|
||||
first()
|
||||
return vif_ref
|
||||
@ -975,7 +973,6 @@ def virtual_interface_get_by_fixed_ip(context, fixed_ip_id):
|
||||
vif_ref = session.query(models.VirtualInterface).\
|
||||
filter_by(fixed_ip_id=fixed_ip_id).\
|
||||
options(joinedload('network')).\
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('fixed_ips')).\
|
||||
first()
|
||||
return vif_ref
|
||||
@ -992,7 +989,6 @@ def virtual_interface_get_by_instance(context, instance_id):
|
||||
vif_refs = session.query(models.VirtualInterface).\
|
||||
filter_by(instance_id=instance_id).\
|
||||
options(joinedload('network')).\
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('fixed_ips')).\
|
||||
all()
|
||||
return vif_refs
|
||||
@ -1007,7 +1003,6 @@ def virtual_interface_get_by_instance_and_network(context, instance_id,
|
||||
filter_by(instance_id=instance_id).\
|
||||
filter_by(network_id=network_id).\
|
||||
options(joinedload('network')).\
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('fixed_ips')).\
|
||||
first()
|
||||
return vif_ref
|
||||
@ -1023,7 +1018,6 @@ def virtual_interface_get_by_network(context, network_id):
|
||||
vif_refs = session.query(models.VirtualInterface).\
|
||||
filter_by(network_id=network_id).\
|
||||
options(joinedload('network')).\
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('fixed_ips')).\
|
||||
all()
|
||||
return vif_refs
|
||||
@ -1169,7 +1163,6 @@ def _build_instance_get(context, session=None):
|
||||
partial = session.query(models.Instance).\
|
||||
options(joinedload_all('fixed_ips.floating_ips')).\
|
||||
options(joinedload_all('fixed_ips.network')).\
|
||||
options(joinedload('virtual_interfaces')).\
|
||||
options(joinedload_all('security_groups.rules')).\
|
||||
options(joinedload('volumes')).\
|
||||
options(joinedload('metadata')).\
|
||||
@ -1188,10 +1181,6 @@ def instance_get_all(context):
|
||||
session = get_session()
|
||||
return session.query(models.Instance).\
|
||||
options(joinedload_all('fixed_ips.floating_ips')).\
|
||||
options(joinedload_all('virtual_interfaces.network')).\
|
||||
options(joinedload_all(
|
||||
'virtual_interfaces.fixed_ips.floating_ips')).\
|
||||
options(joinedload('virtual_interfaces.instance')).\
|
||||
options(joinedload('security_groups')).\
|
||||
options(joinedload_all('fixed_ips.network')).\
|
||||
options(joinedload('metadata')).\
|
||||
@ -1201,32 +1190,11 @@ def instance_get_all(context):
|
||||
|
||||
|
||||
@require_context
|
||||
def instance_get_all_by_filters(context, filters):
|
||||
def instance_get_all_by_filters(context, filters, instances=None):
|
||||
"""Return instances that match all filters. Deleted instances
|
||||
will be returned by default, unless there's a filter that says
|
||||
otherwise"""
|
||||
|
||||
def _regexp_filter_by_ipv6(instance, filter_re):
|
||||
for interface in instance['virtual_interfaces']:
|
||||
fixed_ipv6 = interface.get('fixed_ipv6')
|
||||
if fixed_ipv6 and filter_re.match(fixed_ipv6):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _regexp_filter_by_ip(instance, filter_re):
|
||||
for interface in instance['virtual_interfaces']:
|
||||
for fixed_ip in interface['fixed_ips']:
|
||||
if not fixed_ip or not fixed_ip['address']:
|
||||
continue
|
||||
if filter_re.match(fixed_ip['address']):
|
||||
return True
|
||||
for floating_ip in fixed_ip.get('floating_ips', []):
|
||||
if not floating_ip or not floating_ip['address']:
|
||||
continue
|
||||
if filter_re.match(floating_ip['address']):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _regexp_filter_by_metadata(instance, meta):
|
||||
inst_metadata = [{node['key']: node['value']} \
|
||||
for node in instance['metadata']]
|
||||
@ -1263,13 +1231,7 @@ def instance_get_all_by_filters(context, filters):
|
||||
|
||||
session = get_session()
|
||||
query_prefix = session.query(models.Instance).\
|
||||
options(joinedload_all('fixed_ips.floating_ips')).\
|
||||
options(joinedload_all('virtual_interfaces.network')).\
|
||||
options(joinedload_all(
|
||||
'virtual_interfaces.fixed_ips.floating_ips')).\
|
||||
options(joinedload('virtual_interfaces.instance')).\
|
||||
options(joinedload('security_groups')).\
|
||||
options(joinedload_all('fixed_ips.network')).\
|
||||
options(joinedload('metadata')).\
|
||||
options(joinedload('instance_type')).\
|
||||
order_by(desc(models.Instance.created_at))
|
||||
@ -1304,7 +1266,15 @@ def instance_get_all_by_filters(context, filters):
|
||||
query_prefix = _exact_match_filter(query_prefix, filter_name,
|
||||
filters.pop(filter_name))
|
||||
|
||||
instances = query_prefix.all()
|
||||
# TODO(jkoelker): This is for ID or UUID compat
|
||||
if instances is None:
|
||||
instances = []
|
||||
elif isinstance(instances, types.StringType):
|
||||
instances = [instance_get_by_uuid(context, instances)]
|
||||
elif isinstance(instances, types.IntType):
|
||||
instances = [instance_get(context, instances)]
|
||||
|
||||
instances.extend(query_prefix.all())
|
||||
|
||||
if not instances:
|
||||
return []
|
||||
@ -1312,8 +1282,7 @@ def instance_get_all_by_filters(context, filters):
|
||||
# Now filter on everything else for regexp matching..
|
||||
# For filters not in the list, we'll attempt to use the filter_name
|
||||
# as a column name in Instance..
|
||||
regexp_filter_funcs = {'ip6': _regexp_filter_by_ipv6,
|
||||
'ip': _regexp_filter_by_ip}
|
||||
regexp_filter_funcs = {}
|
||||
|
||||
for filter_name in filters.iterkeys():
|
||||
filter_func = regexp_filter_funcs.get(filter_name, None)
|
||||
@ -1373,7 +1342,6 @@ def instance_get_all_by_user(context, user_id):
|
||||
session = get_session()
|
||||
return session.query(models.Instance).\
|
||||
options(joinedload_all('fixed_ips.floating_ips')).\
|
||||
options(joinedload('virtual_interfaces')).\
|
||||
options(joinedload('security_groups')).\
|
||||
options(joinedload_all('fixed_ips.network')).\
|
||||
options(joinedload('metadata')).\
|
||||
@ -1388,7 +1356,6 @@ def instance_get_all_by_host(context, host):
|
||||
session = get_session()
|
||||
return session.query(models.Instance).\
|
||||
options(joinedload_all('fixed_ips.floating_ips')).\
|
||||
options(joinedload('virtual_interfaces')).\
|
||||
options(joinedload('security_groups')).\
|
||||
options(joinedload_all('fixed_ips.network')).\
|
||||
options(joinedload('metadata')).\
|
||||
@ -1405,7 +1372,6 @@ def instance_get_all_by_project(context, project_id):
|
||||
session = get_session()
|
||||
return session.query(models.Instance).\
|
||||
options(joinedload_all('fixed_ips.floating_ips')).\
|
||||
options(joinedload('virtual_interfaces')).\
|
||||
options(joinedload('security_groups')).\
|
||||
options(joinedload_all('fixed_ips.network')).\
|
||||
options(joinedload('metadata')).\
|
||||
@ -1421,7 +1387,6 @@ def instance_get_all_by_reservation(context, reservation_id):
|
||||
query = session.query(models.Instance).\
|
||||
filter_by(reservation_id=reservation_id).\
|
||||
options(joinedload_all('fixed_ips.floating_ips')).\
|
||||
options(joinedload('virtual_interfaces')).\
|
||||
options(joinedload('security_groups')).\
|
||||
options(joinedload_all('fixed_ips.network')).\
|
||||
options(joinedload('metadata')).\
|
||||
@ -1438,36 +1403,11 @@ def instance_get_all_by_reservation(context, reservation_id):
|
||||
all()
|
||||
|
||||
|
||||
@require_context
|
||||
def instance_get_by_fixed_ip(context, address):
|
||||
"""Return instance ref by exact match of FixedIP"""
|
||||
fixed_ip_ref = fixed_ip_get_by_address(context, address)
|
||||
return fixed_ip_ref.instance
|
||||
|
||||
|
||||
@require_context
|
||||
def instance_get_by_fixed_ipv6(context, address):
|
||||
"""Return instance ref by exact match of IPv6"""
|
||||
session = get_session()
|
||||
|
||||
# convert IPv6 address to mac
|
||||
mac = ipv6.to_mac(address)
|
||||
|
||||
# get virtual interface
|
||||
vif_ref = virtual_interface_get_by_address(context, mac)
|
||||
|
||||
# look up instance based on instance_id from vif row
|
||||
result = session.query(models.Instance).\
|
||||
filter_by(id=vif_ref['instance_id'])
|
||||
return result
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def instance_get_project_vpn(context, project_id):
|
||||
session = get_session()
|
||||
return session.query(models.Instance).\
|
||||
options(joinedload_all('fixed_ips.floating_ips')).\
|
||||
options(joinedload('virtual_interfaces')).\
|
||||
options(joinedload('security_groups')).\
|
||||
options(joinedload_all('fixed_ips.network')).\
|
||||
options(joinedload('metadata')).\
|
||||
|
Loading…
x
Reference in New Issue
Block a user