diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index fc0947e8b4ea..9a3c535a5c43 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -30,9 +30,7 @@ import sys import traceback from dateutil import parser as dateutil_parser -import decorator from keystoneauth1 import exceptions as ks_exc -import netaddr from neutronclient.common import exceptions as neutron_client_exc from oslo_config import cfg from oslo_db import exception as db_exc @@ -40,7 +38,6 @@ from oslo_log import log as logging import oslo_messaging as messaging from oslo_serialization import jsonutils from oslo_utils import encodeutils -from oslo_utils import importutils from oslo_utils import uuidutils import prettytable import six @@ -67,20 +64,15 @@ from nova.objects import instance as instance_obj from nova.objects import instance_mapping as instance_mapping_obj from nova.objects import quotas as quotas_obj from nova.objects import virtual_interface as virtual_interface_obj -from nova import quota from nova import rpc from nova.scheduler.client import report from nova.scheduler import utils as scheduler_utils -from nova import utils from nova import version from nova.virt import ironic CONF = nova.conf.CONF - LOG = logging.getLogger(__name__) -QUOTAS = quota.QUOTAS - # Keep this list sorted and one entry per line for readability. _EXTRA_DEFAULT_LOG_LEVELS = ['oslo_concurrency=INFO', 'oslo_db=INFO', @@ -106,268 +98,6 @@ def mask_passwd_in_url(url): return urlparse.urlunparse(new_parsed) -class FloatingIpCommands(object): - """Class for managing floating IP.""" - - # TODO(stephenfin): Remove these when we remove cells v1 - description = ('DEPRECATED: Floating IP commands are deprecated since ' - 'nova-network is deprecated in favor of Neutron. The ' - 'floating IP commands will be removed in an upcoming ' - 'release.') - - @staticmethod - def address_to_hosts(addresses): - """Iterate over hosts within an address range. - - If an explicit range specifier is missing, the parameter is - interpreted as a specific individual address. - """ - try: - return [netaddr.IPAddress(addresses)] - except ValueError: - net = netaddr.IPNetwork(addresses) - if net.size < 4: - reason = _("/%s should be specified as single address(es) " - "not in cidr format") % net.prefixlen - raise exception.InvalidInput(reason=reason) - elif net.size >= 1000000: - # NOTE(dripton): If we generate a million IPs and put them in - # the database, the system will slow to a crawl and/or run - # out of memory and crash. This is clearly a misconfiguration. - reason = _("Too many IP addresses will be generated. Please " - "increase /%s to reduce the number generated." - ) % net.prefixlen - raise exception.InvalidInput(reason=reason) - else: - return net.iter_hosts() - - @args('--ip_range', metavar='', help='IP range') - @args('--pool', metavar='', help='Optional pool') - @args('--interface', metavar='', help='Optional interface') - def create(self, ip_range, pool=None, interface=None): - """Creates floating IPs for zone by range.""" - admin_context = context.get_admin_context() - if not pool: - pool = CONF.default_floating_pool - if not interface: - interface = CONF.public_interface - - ips = [{'address': str(address), 'pool': pool, 'interface': interface} - for address in self.address_to_hosts(ip_range)] - try: - db.floating_ip_bulk_create(admin_context, ips, want_result=False) - except exception.FloatingIpExists as exc: - # NOTE(simplylizz): Maybe logging would be better here - # instead of printing, but logging isn't used here and I - # don't know why. - print('error: %s' % exc) - return 1 - - @args('--ip_range', metavar='', help='IP range') - def delete(self, ip_range): - """Deletes floating IPs by range.""" - admin_context = context.get_admin_context() - - ips = ({'address': str(address)} - for address in self.address_to_hosts(ip_range)) - db.floating_ip_bulk_destroy(admin_context, ips) - - @args('--host', metavar='', help='Host') - def list(self, host=None): - """Lists all floating IPs (optionally by host). - - Note: if host is given, only active floating IPs are returned - """ - ctxt = context.get_admin_context() - try: - if host is None: - floating_ips = db.floating_ip_get_all(ctxt) - else: - floating_ips = db.floating_ip_get_all_by_host(ctxt, host) - except exception.NoFloatingIpsDefined: - print(_("No floating IP addresses have been defined.")) - return - for floating_ip in floating_ips: - instance_uuid = None - if floating_ip['fixed_ip_id']: - fixed_ip = db.fixed_ip_get(ctxt, floating_ip['fixed_ip_id']) - instance_uuid = fixed_ip['instance_uuid'] - - print("%s\t%s\t%s\t%s\t%s" % (floating_ip['project_id'], - floating_ip['address'], - instance_uuid, - floating_ip['pool'], - floating_ip['interface'])) - - -@decorator.decorator -def validate_network_plugin(f, *args, **kwargs): - """Decorator to validate the network plugin.""" - if utils.is_neutron(): - print(_("ERROR: Network commands are not supported when using the " - "Neutron API. Use python-neutronclient instead.")) - return 2 - return f(*args, **kwargs) - - -class NetworkCommands(object): - """Class for managing networks.""" - - # TODO(stephenfin): Remove these when we remove cells v1 - description = ('DEPRECATED: Network commands are deprecated since ' - 'nova-network is deprecated in favor of Neutron. The ' - 'network commands will be removed in an upcoming release.') - - @validate_network_plugin - @args('--label', metavar='