trunk merge

This commit is contained in:
Sandy Walsh 2011-03-24 12:04:24 -07:00
commit 18eee851d8
21 changed files with 75 additions and 52 deletions

View File

@ -97,6 +97,7 @@ flags.DECLARE('vlan_start', 'nova.network.manager')
flags.DECLARE('vpn_start', 'nova.network.manager')
flags.DECLARE('fixed_range_v6', 'nova.network.manager')
flags.DECLARE('images_path', 'nova.image.local')
flags.DECLARE('libvirt_type', 'nova.virt.libvirt_conn')
flags.DEFINE_flag(flags.HelpFlag())
flags.DEFINE_flag(flags.HelpshortFlag())
flags.DEFINE_flag(flags.HelpXMLFlag())
@ -610,7 +611,7 @@ class ServiceCommands(object):
args: [host] [service]"""
ctxt = context.get_admin_context()
now = datetime.datetime.utcnow()
services = db.service_get_all(ctxt) + db.service_get_all(ctxt, True)
services = db.service_get_all(ctxt)
if host:
services = [s for s in services if s['host'] == host]
if service:

View File

@ -61,10 +61,13 @@ class RequestLogging(wsgi.Middleware):
return rv
def log_request_completion(self, response, request, start):
controller = request.environ.get('ec2.controller', None)
if controller:
controller = controller.__class__.__name__
action = request.environ.get('ec2.action', None)
apireq = request.environ.get('ec2.request', None)
if apireq:
controller = apireq.controller
action = apireq.action
else:
controller = None
action = None
ctxt = request.environ.get('ec2.context', None)
delta = utils.utcnow() - start
seconds = delta.seconds
@ -75,7 +78,7 @@ class RequestLogging(wsgi.Middleware):
microseconds,
request.remote_addr,
request.method,
request.path_info,
"%s%s" % (request.script_name, request.path_info),
controller,
action,
response.status_int,

View File

@ -304,7 +304,7 @@ class AdminController(object):
* Volume (up, down, None)
* Volume Count
"""
services = db.service_get_all(context)
services = db.service_get_all(context, False)
now = datetime.datetime.utcnow()
hosts = []
rv = []

View File

@ -196,7 +196,7 @@ class CloudController(object):
def _describe_availability_zones(self, context, **kwargs):
ctxt = context.elevated()
enabled_services = db.service_get_all(ctxt)
enabled_services = db.service_get_all(ctxt, False)
disabled_services = db.service_get_all(ctxt, True)
available_zones = []
for zone in [service.availability_zone for service
@ -221,7 +221,7 @@ class CloudController(object):
rv = {'availabilityZoneInfo': [{'zoneName': 'nova',
'zoneState': 'available'}]}
services = db.service_get_all(context)
services = db.service_get_all(context, False)
now = datetime.datetime.utcnow()
hosts = []
for host in [service['host'] for service in services]:

View File

@ -14,6 +14,7 @@
# under the License.
import common
import webob.exc
from nova import exception
from nova import flags
@ -51,10 +52,10 @@ class Controller(wsgi.Controller):
raise exception.NotAuthorized(_("Not admin user."))
def index(self, req):
raise faults.Fault(exc.HTTPNotImplemented())
raise faults.Fault(webob.exc.HTTPNotImplemented())
def detail(self, req):
raise faults.Fault(exc.HTTPNotImplemented())
raise faults.Fault(webob.exc.HTTPNotImplemented())
def show(self, req, id):
"""Return data about the given account id"""
@ -69,7 +70,7 @@ class Controller(wsgi.Controller):
def create(self, req):
"""We use update with create-or-update semantics
because the id comes from an external source"""
raise faults.Fault(exc.HTTPNotImplemented())
raise faults.Fault(webob.exc.HTTPNotImplemented())
def update(self, req, id):
"""This is really create or update."""

View File

@ -15,19 +15,19 @@
import base64
import hashlib
import json
import traceback
from xml.dom import minidom
from webob import exc
from xml.dom import minidom
from nova import compute
from nova import context
from nova import exception
from nova import flags
from nova import log as logging
from nova import wsgi
from nova import quota
from nova import utils
from nova import wsgi
from nova.api.openstack import common
from nova.api.openstack import faults
import nova.api.openstack.views.addresses
@ -36,7 +36,6 @@ import nova.api.openstack.views.servers
from nova.auth import manager as auth_manager
from nova.compute import instance_types
from nova.compute import power_state
from nova.quota import QuotaError
import nova.api.openstack
from nova.scheduler import api as scheduler_api
@ -160,8 +159,8 @@ class Controller(wsgi.Controller):
key_data=key_data,
metadata=metadata,
injected_files=injected_files)
except QuotaError as error:
self._handle_quota_errors(error)
except quota.QuotaError as error:
self._handle_quota_error(error)
inst['instance_type'] = flavor_id
inst['image_id'] = requested_image_id
@ -215,7 +214,7 @@ class Controller(wsgi.Controller):
injected_files.append((path, contents))
return injected_files
def _handle_quota_errors(self, error):
def _handle_quota_error(self, error):
"""
Reraise quota errors as api-specific http exceptions
"""
@ -247,7 +246,7 @@ class Controller(wsgi.Controller):
update_dict['admin_pass'] = inst_dict['server']['adminPass']
try:
self.compute_api.set_admin_password(ctxt, id)
except exception.TimeoutException, e:
except exception.TimeoutException:
return exc.HTTPRequestTimeout()
if 'name' in inst_dict['server']:
update_dict['display_name'] = inst_dict['server']['name']

View File

@ -15,6 +15,7 @@
import common
from nova import db
from nova import flags
from nova import log as logging
from nova import wsgi
@ -69,8 +70,8 @@ class Controller(wsgi.Controller):
zone = dict(name=FLAGS.zone_name)
caps = FLAGS.zone_capabilities
for cap in caps:
key_values = cap.split('=')
zone[key_values[0]] = key_values[1]
key, value = cap.split('=')
zone[key] = value
for item, (min_value, max_value) in items.iteritems():
zone[item] = "%s,%s" % (min_value, max_value)
return dict(zone=zone)

View File

@ -133,7 +133,7 @@ class ComputeManager(manager.SchedulerDependentManager):
self.network_manager = utils.import_object(FLAGS.network_manager)
self.volume_manager = utils.import_object(FLAGS.volume_manager)
super(ComputeManager, self).__init__(service_name="compute",
*args, **kwargs)
*args, **kwargs)
def init_host(self):
"""Do any initialization that needs to be run if this is a

View File

@ -90,7 +90,7 @@ def service_get_by_host_and_topic(context, host, topic):
return IMPL.service_get_by_host_and_topic(context, host, topic)
def service_get_all(context, disabled=False):
def service_get_all(context, disabled=None):
"""Get all services."""
return IMPL.service_get_all(context, disabled)

View File

@ -143,12 +143,15 @@ def service_get(context, service_id, session=None):
@require_admin_context
def service_get_all(context, disabled=False):
def service_get_all(context, disabled=None):
session = get_session()
return session.query(models.Service).\
filter_by(deleted=can_read_deleted(context)).\
filter_by(disabled=disabled).\
all()
query = session.query(models.Service).\
filter_by(deleted=can_read_deleted(context))
if disabled is not None:
query = query.filter_by(disabled=disabled)
return query.all()
@require_admin_context
@ -2209,7 +2212,7 @@ def migration_get(context, id, session=None):
filter_by(id=id).first()
if not result:
raise exception.NotFound(_("No migration found with id %s")
% migration_id)
% id)
return result
@ -2432,6 +2435,7 @@ def zone_create(context, values):
@require_admin_context
def zone_update(context, zone_id, values):
session = get_session()
zone = session.query(models.Zone).filter_by(id=zone_id).first()
if not zone:
raise exception.NotFound(_("No zone with id %(zone_id)s") % locals())

View File

@ -360,4 +360,4 @@ DEFINE_string('node_availability_zone', 'nova',
DEFINE_string('zone_name', 'nova', 'name of this zone')
DEFINE_list('zone_capabilities',
['hypervisor=xenserver;kvm', 'os=linux;windows'],
'Key/Multi-value list representng capabilities of this zone')
'Key/Multi-value list representng capabilities of this zone')

View File

@ -73,7 +73,7 @@ class GlanceImageService(service.BaseImageService):
Returns image with known timestamp fields converted to datetime objects
"""
for attr in ['created_at', 'updated_at', 'deleted_at']:
if image.get(attr) is not None:
if image.get(attr):
image[attr] = self._parse_glance_iso8601_timestamp(image[attr])
return image

View File

@ -59,6 +59,8 @@ from nova.scheduler import api
FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.manager')
class Manager(base.Base):
def __init__(self, host=None, db_driver=None):
@ -83,6 +85,7 @@ class SchedulerDependentManager(Manager):
should derive from this class. Otherwise they can derive from
manager.Manager directly. Updates are only sent after
update_service_capabilities is called with non-None values."""
def __init__(self, host=None, db_driver=None, service_name="undefined"):
self.last_capabilities = None
self.service_name = service_name
@ -95,7 +98,7 @@ class SchedulerDependentManager(Manager):
def periodic_tasks(self, context=None):
"""Pass data back to the scheduler at a periodic interval"""
if self.last_capabilities:
logging.debug(_("Notifying Schedulers of capabilities ..."))
LOG.debug(_("Notifying Schedulers of capabilities ..."))
api.update_service_capabilities(context, self.service_name,
self.host, self.last_capabilities)

View File

@ -1,3 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
@ -210,10 +212,7 @@ class IptablesManager(object):
"""
def __init__(self, execute=None):
if not execute:
if FLAGS.fake_network:
self.execute = lambda *args, **kwargs: ('', '')
else:
self.execute = utils.execute
self.execute = _execute
else:
self.execute = execute
@ -352,9 +351,6 @@ class IptablesManager(object):
return new_filter
iptables_manager = IptablesManager()
def metadata_forward():
"""Create forwarding rule for metadata"""
iptables_manager.ipv4['nat'].add_rule("PREROUTING",
@ -767,3 +763,6 @@ def _ip_bridge_cmd(action, params, device):
cmd.extend(params)
cmd.extend(['dev', device])
return cmd
iptables_manager = IptablesManager()

View File

@ -219,8 +219,8 @@ class FanoutAdapterConsumer(AdapterConsumer):
self.queue = "%s_fanout_%s" % (topic, unique)
self.durable = False
LOG.info(_("Created '%(exchange)s' fanout exchange "
"with '%(key)s' routing key"),
dict(exchange=self.exchange, key=self.routing_key))
"with '%(key)s' routing key"),
dict(exchange=self.exchange, key=self.routing_key))
super(FanoutAdapterConsumer, self).__init__(connection=connection,
topic=topic, proxy=proxy)

View File

@ -80,7 +80,7 @@ def get_zone_capabilities(context, service=None):
"""Returns a dict of key, value capabilities for this zone,
or for a particular class of services running in this zone."""
return _call_scheduler('get_zone_capabilities', context=context,
params=dict(service=service))
params=dict(service=service))
def update_service_capabilities(context, service_name, host, capabilities):

View File

@ -356,8 +356,8 @@ class ISCSITestCase(DriverTestCase):
tid = db.volume_get_iscsi_target_num(self.context, volume_id_list[0])
self.mox.StubOutWithMock(self.volume.driver, '_execute')
self.volume.driver._execute("sudo", "ietadm", "--op", "show",
"--tid=%(tid)d" % locals()
).AndRaise(exception.ProcessExecutionError())
"--tid=%(tid)d" % locals()).AndRaise(
exception.ProcessExecutionError())
self.mox.ReplayAll()
self.assertRaises(exception.ProcessExecutionError,

View File

@ -96,7 +96,7 @@ class ZoneManagerTestCase(test.TestCase):
zm.update_service_capabilities("svc10", "host1", dict(a=99, b=99))
caps = zm.get_zone_capabilities(self, None)
self.assertEquals(caps, dict(svc1_a=(2, 20), svc1_b=(3, 30),
svc10_a=(99, 99), svc10_b=(99, 99)))
svc10_a=(99, 99), svc10_b=(99, 99)))
zm.update_service_capabilities("svc1", "host3", dict(c=5))
caps = zm.get_zone_capabilities(self, None)

View File

@ -171,10 +171,6 @@ def execute(*cmd, **kwargs):
stdout=stdout,
stderr=stderr,
cmd=' '.join(cmd))
# NOTE(termie): this appears to be necessary to let the subprocess
# call clean something up in between calls, without
# it two execute calls in a row hangs the second one
greenthread.sleep(0)
return result
except ProcessExecutionError:
if not attempts:
@ -183,6 +179,11 @@ def execute(*cmd, **kwargs):
LOG.debug(_("%r failed. Retrying."), cmd)
if delay_on_retry:
greenthread.sleep(random.randint(20, 200) / 100.0)
finally:
# NOTE(termie): this appears to be necessary to let the subprocess
# call clean something up in between calls, without
# it two execute calls in a row hangs the second one
greenthread.sleep(0)
def ssh_execute(ssh, cmd, process_input=None,

View File

@ -344,7 +344,7 @@ class FakeConnection(driver.ComputeDriver):
Note that this function takes an instance ID, not a
compute.service.Instance, so that it can be called by compute.monitor.
"""
return [0L, 0L, 0L, 0L, null]
return [0L, 0L, 0L, 0L, None]
def interface_stats(self, instance_name, iface_id):
"""

View File

@ -1008,7 +1008,18 @@ class LibvirtConnection(driver.ComputeDriver):
"""
return self._conn.getVersion()
# NOTE(justinsb): getVersion moved between libvirt versions
# Trying to do be compatible with older versions is a lost cause
# But ... we can at least give the user a nice message
method = getattr(self._conn, 'getVersion', None)
if method is None:
raise exception.Error(_("libvirt version is too old"
" (does not support getVersion)"))
# NOTE(justinsb): If we wanted to get the version, we could:
# method = getattr(libvirt, 'getVersion', None)
# NOTE(justinsb): This would then rely on a proper version check
return method()
def get_cpu_info(self):
"""Get cpuinfo information.