From 6fd9d326d97b24ee203b0cf3074074864283178d Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Mon, 12 Mar 2012 13:55:21 -0400 Subject: Nuke some unused SQL api calls. Fixes LP bug #953235. Change-Id: Iafb33a74397a9037c31718018275d3a7d064f59b --- nova/db/api.py | 73 ------------------- nova/db/sqlalchemy/api.py | 181 ---------------------------------------------- 2 files changed, 254 deletions(-) (limited to 'nova') diff --git a/nova/db/api.py b/nova/db/api.py index 9d4fae11e..6a2fbbadd 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -134,15 +134,6 @@ def service_get_all_compute_sorted(context): return IMPL.service_get_all_compute_sorted(context) -def service_get_all_network_sorted(context): - """Get all network services sorted by network count. - - :returns: a list of (Service, network_count) tuples. - - """ - return IMPL.service_get_all_network_sorted(context) - - def service_get_all_volume_sorted(context): """Get all volume services sorted by volume count. @@ -184,11 +175,6 @@ def compute_node_get_all(context): return IMPL.compute_node_get_all(context) -def compute_node_get_for_service(context, service_id): - """Get all computeNodes.""" - return IMPL.compute_node_get_for_service(context, service_id) - - def compute_node_create(context, values): """Create a computeNode from the values dictionary.""" return IMPL.compute_node_create(context, values) @@ -206,11 +192,6 @@ def compute_node_get_by_host(context, host): return IMPL.compute_node_get_by_host(context, host) -def compute_node_capacity_find(context, minimum_ram_mb, minimum_disk_gb): - return IMPL.compute_node_capacity_find(context, minimum_ram_mb, - minimum_disk_gb) - - def compute_node_utilization_update(context, host, free_ram_mb_delta=0, free_disk_gb_delta=0, work_delta=0, vm_delta=0): return IMPL.compute_node_utilization_update(context, host, @@ -505,11 +486,6 @@ def virtual_interface_create(context, values): return IMPL.virtual_interface_create(context, values) -def virtual_interface_update(context, vif_id, values): - """Update a virtual interface record in the database.""" - return IMPL.virtual_interface_update(context, vif_id, values) - - def virtual_interface_get(context, vif_id): """Gets a virtual interface from the table,""" return IMPL.virtual_interface_get(context, vif_id) @@ -538,11 +514,6 @@ def virtual_interface_get_by_instance_and_network(context, instance_id, network_id) -def virtual_interface_get_by_network(context, network_id): - """Gets all virtual interfaces on network.""" - return IMPL.virtual_interface_get_by_network(context, network_id) - - def virtual_interface_delete(context, vif_id): """Delete virtual interface record from the database.""" return IMPL.virtual_interface_delete(context, vif_id) @@ -576,11 +547,6 @@ def instance_destroy(context, instance_id): return IMPL.instance_destroy(context, instance_id) -def instance_stop(context, instance_id): - """Stop the instance or raise if it does not exist.""" - return IMPL.instance_stop(context, instance_id) - - def instance_get_by_uuid(context, uuid): """Get an instance or raise if it does not exist.""" return IMPL.instance_get_by_uuid(context, uuid) @@ -617,11 +583,6 @@ def instance_get_active_by_window_joined(context, begin, end=None, project_id) -def instance_get_all_by_user(context, user_id): - """Get all instances.""" - return IMPL.instance_get_all_by_user(context, user_id) - - def instance_get_all_by_project(context, project_id): """Get all instance belonging to a project.""" return IMPL.instance_get_all_by_project(context, project_id) @@ -770,16 +731,6 @@ def network_count(context): return IMPL.network_count(context) -def network_count_allocated_ips(context, network_id): - """Return the number of allocated non-reserved ips in the network.""" - return IMPL.network_count_allocated_ips(context, network_id) - - -def network_count_available_ips(context, network_id): - """Return the number of available ips in the network.""" - return IMPL.network_count_available_ips(context, network_id) - - def network_count_reserved_ips(context, network_id): """Return the number of reserved ips in the network.""" return IMPL.network_count_reserved_ips(context, network_id) @@ -814,11 +765,6 @@ def network_disassociate(context, network_id): return IMPL.network_disassociate(context, network_id) -def network_disassociate_all(context): - """Disassociate all networks from projects.""" - return IMPL.network_disassociate_all(context) - - def network_get(context, network_id): """Get an network or raise if it does not exist.""" return IMPL.network_get(context, network_id) @@ -1182,11 +1128,6 @@ def security_group_destroy(context, security_group_id): return IMPL.security_group_destroy(context, security_group_id) -def security_group_destroy_all(context): - """Deletes a security group.""" - return IMPL.security_group_destroy_all(context) - - #################### @@ -1231,11 +1172,6 @@ def provider_fw_rule_get_all(context): return IMPL.provider_fw_rule_get_all(context) -def provider_fw_rule_get_all_by_cidr(context, cidr): - """Get all provider-level firewall rules.""" - return IMPL.provider_fw_rule_get_all_by_cidr(context, cidr) - - def provider_fw_rule_destroy(context, rule_id): """Delete a provider firewall rule from the database.""" return IMPL.provider_fw_rule_destroy(context, rule_id) @@ -1362,10 +1298,6 @@ def project_get_networks(context, project_id, associate=True): return IMPL.project_get_networks(context, project_id, associate) -def project_get_networks_v6(context, project_id): - return IMPL.project_get_networks_v6(context, project_id) - - ################### @@ -1537,11 +1469,6 @@ def bw_usage_get_by_macs(context, macs, start_period): return IMPL.bw_usage_get_by_macs(context, macs, start_period) -def bw_usage_get_all_by_filters(context, filters): - """Return bandwidth usage that matches all filters.""" - return IMPL.bw_usage_get_all_by_filters(context, filters) - - def bw_usage_update(context, mac, start_period, diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index e0d6647da..99600b70e 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -348,24 +348,6 @@ def service_get_all_compute_sorted(context): label) -@require_admin_context -def service_get_all_network_sorted(context): - session = get_session() - with session.begin(): - topic = 'network' - label = 'network_count' - subq = model_query(context, models.Network.host, - func.count(models.Network.id).label(label), - session=session, read_deleted="no").\ - group_by(models.Network.host).\ - subquery() - return _service_get_all_topic_subquery(context, - session, - topic, - subq, - label) - - @require_admin_context def service_get_all_volume_sorted(context): session = get_session() @@ -431,21 +413,6 @@ def compute_node_get(context, compute_id, session=None): return result -@require_admin_context -def compute_node_get_by_service(context, service_id, session=None): - if not session: - session = get_session() - - result = model_query(context, models.ComputeNode, session=session).\ - filter_by(service_id=service_id).\ - first() - - if not result: - raise exception.ComputeHostNotFound(host="ServiceID=%s" % service_id) - - return result - - @require_admin_context def compute_node_get_all(context, session=None): return model_query(context, models.ComputeNode, session=session).\ @@ -453,14 +420,6 @@ def compute_node_get_all(context, session=None): all() -@require_admin_context -def compute_node_get_for_service(context, service_id): - return model_query(context, models.ComputeNode).\ - options(joinedload('service')).\ - filter_by(service_id=service_id).\ - first() - - def _get_host_utilization(context, host, ram_mb, disk_gb): """Compute the current utilization of a given host.""" instances = instance_get_all_by_host(context, host) @@ -529,23 +488,6 @@ def compute_node_get_by_host(context, host): return node.first() -# Note: these operations use with_lockmode() ... so this will only work -# reliably with engines that support row-level locking -# (postgres, mysql+innodb and above). - -def compute_node_capacity_find(context, minimum_ram_mb, minimum_disk_gb): - """Get all enabled hosts with enough ram and disk.""" - session = get_session() - with session.begin(): - return session.query(models.ComputeNode).\ - options(joinedload('service')).\ - filter(models.ComputeNode.free_ram_mb >= minimum_ram_mb).\ - filter(models.ComputeNode.free_disk_gb >= minimum_disk_gb).\ - filter(models.Service.disabled == False).\ - filter_by(deleted=False).\ - with_lockmode('update').all() - - def compute_node_utilization_update(context, host, free_ram_mb_delta=0, free_disk_gb_delta=0, work_delta=0, vm_delta=0): """Update a specific ComputeNode entry by a series of deltas. @@ -1205,21 +1147,6 @@ def virtual_interface_create(context, values): return vif_ref -@require_context -def virtual_interface_update(context, vif_id, values): - """Update a virtual interface record in the database. - - :param vif_id: = id of virtual interface to update - :param values: = values to update - """ - session = get_session() - with session.begin(): - vif_ref = virtual_interface_get(context, vif_id, session=session) - vif_ref.update(values) - vif_ref.save(session=session) - return vif_ref - - @require_context def _virtual_interface_query(context, session=None): return model_query(context, models.VirtualInterface, session=session, @@ -1286,18 +1213,6 @@ def virtual_interface_get_by_instance_and_network(context, instance_id, return vif_ref -@require_admin_context -def virtual_interface_get_by_network(context, network_id): - """Gets all virtual_interface on network. - - :param network_id: = network to retrieve vifs for - """ - vif_refs = _virtual_interface_query(context).\ - filter_by(network_id=network_id).\ - all() - return vif_refs - - @require_context def virtual_interface_delete(context, vif_id): """Delete virtual interface record from the database. @@ -1418,24 +1333,6 @@ def instance_destroy(context, instance_id): return instance_ref -@require_context -def instance_stop(context, instance_id): - session = get_session() - with session.begin(): - session.query(models.Instance).\ - filter_by(id=instance_id).\ - update({'host': None, - 'vm_state': vm_states.STOPPED, - 'task_state': None, - 'updated_at': literal_column('updated_at')}) - session.query(models.SecurityGroupInstanceAssociation).\ - filter_by(instance_id=instance_id).\ - update({'updated_at': literal_column('updated_at')}) - session.query(models.InstanceMetadata).\ - filter_by(instance_id=instance_id).\ - update({'updated_at': literal_column('updated_at')}) - - @require_context def instance_get_by_uuid(context, uuid, session=None): result = _build_instance_get(context, session=session).\ @@ -1627,11 +1524,6 @@ def _instance_get_all_query(context, project_only=False): options(joinedload('instance_type')) -@require_admin_context -def instance_get_all_by_user(context, user_id): - return _instance_get_all_query(context).filter_by(user_id=user_id).all() - - @require_admin_context def instance_get_all_by_host(context, host): return _instance_get_all_query(context).filter_by(host=host).all() @@ -1990,21 +1882,6 @@ def _network_ips_query(context, network_id): filter_by(network_id=network_id) -@require_admin_context -def network_count_allocated_ips(context, network_id): - return _network_ips_query(context, network_id).\ - filter_by(allocated=True).\ - count() - - -@require_admin_context -def network_count_available_ips(context, network_id): - return _network_ips_query(context, network_id).\ - filter_by(allocated=False).\ - filter_by(reserved=False).\ - count() - - @require_admin_context def network_count_reserved_ips(context, network_id): return _network_ips_query(context, network_id).\ @@ -2046,14 +1923,6 @@ def network_disassociate(context, network_id): 'host': None}) -@require_admin_context -def network_disassociate_all(context): - session = get_session() - session.query(models.Network).\ - update({'project_id': None, - 'updated_at': literal_column('updated_at')}) - - @require_context def network_get(context, network_id, session=None): result = model_query(context, models.Network, session=session, @@ -2921,21 +2790,6 @@ def security_group_destroy(context, security_group_id): 'updated_at': literal_column('updated_at')}) -@require_context -def security_group_destroy_all(context, session=None): - if not session: - session = get_session() - with session.begin(): - session.query(models.SecurityGroup).\ - update({'deleted': True, - 'deleted_at': utils.utcnow(), - 'updated_at': literal_column('updated_at')}) - session.query(models.SecurityGroupIngressRule).\ - update({'deleted': True, - 'deleted_at': utils.utcnow(), - 'updated_at': literal_column('updated_at')}) - - ################### @@ -3010,13 +2864,6 @@ def provider_fw_rule_get_all(context): return model_query(context, models.ProviderFirewallRule).all() -@require_admin_context -def provider_fw_rule_get_all_by_cidr(context, cidr): - return model_query(context, models.ProviderFirewallRule).\ - filter_by(cidr=cidr).\ - all() - - @require_admin_context def provider_fw_rule_destroy(context, rule_id): session = get_session() @@ -3248,11 +3095,6 @@ def project_get_networks(context, project_id, associate=True): return result -@require_context -def project_get_networks_v6(context, project_id): - return project_get_networks(context, project_id) - - ################### @@ -3755,29 +3597,6 @@ def bw_usage_get_by_macs(context, macs, start_period): all() -@require_context -def bw_usage_get_all_by_filters(context, filters): - """Return bandwidth usage that matches all filters.""" - - session = get_session() - query_prefix = session.query(models.BandwidthUsage).\ - order_by(desc(models.BandwidthUsage.created_at)) - - # Make a copy of the filters dictionary to use going forward, as we'll - # be modifying it and we shouldn't affect the caller's use of it. - filters = filters.copy() - - # Filters for exact matches that we can do along with the SQL query. - exact_match_filter_names = ["instance_id", "mac", - "start_period", "last_refreshed", "bw_in", "bw_out"] - - # Filter the query - query_prefix = exact_filter(query_prefix, models.BandwidthUsage, - filters, exact_match_filter_names) - - return query_prefix.all() - - @require_context def bw_usage_update(context, mac, -- cgit