summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-02-18 12:08:35 -0400
committerSandy Walsh <sandy.walsh@rackspace.com>2011-02-18 12:08:35 -0400
commitc884064e7a9af04b2ebdbbb9ee32318a00716412 (patch)
tree34854e36fcf398e3c2f532b4cef317638970789c
parente5d979596ff8c588c7bbe82b7f1cb90de8af041a (diff)
downloadnova-c884064e7a9af04b2ebdbbb9ee32318a00716412.tar.gz
nova-c884064e7a9af04b2ebdbbb9ee32318a00716412.tar.xz
nova-c884064e7a9af04b2ebdbbb9ee32318a00716412.zip
fixups backed on merge comments
-rw-r--r--nova/api/openstack/zones.py30
-rw-r--r--nova/flags.py5
-rw-r--r--nova/scheduler/api.py49
-rw-r--r--nova/scheduler/zone_manager.py15
-rw-r--r--nova/tests/api/openstack/test_zones.py33
5 files changed, 82 insertions, 50 deletions
diff --git a/nova/api/openstack/zones.py b/nova/api/openstack/zones.py
index f75176824..24a4444f7 100644
--- a/nova/api/openstack/zones.py
+++ b/nova/api/openstack/zones.py
@@ -1,4 +1,4 @@
-# Copyright 2010 OpenStack LLC.
+# Copyright 2011 OpenStack LLC.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -20,6 +20,7 @@ from nova import flags
from nova import wsgi
from nova import db
from nova import rpc
+from nova.scheduler.api import API
FLAGS = flags.FLAGS
@@ -49,31 +50,14 @@ class Controller(wsgi.Controller):
"attributes": {
"zone": ["id", "api_url", "name", "capabilities"]}}}
- def _call_scheduler(self, method, context, params=None):
- """Generic handler for RPC calls to the scheduler.
-
- :param params: Optional dictionary of arguments to be passed to the
- scheduler worker
-
- :retval: Result returned by scheduler worker
- """
- if not params:
- params = {}
- queue = FLAGS.scheduler_topic
- kwargs = {'method': method, 'args': params}
- return rpc.call(context, queue, kwargs)
-
def index(self, req):
"""Return all zones in brief"""
- # Ask the ZoneManager in the Scheduler for most recent data.
- items = self._call_scheduler('get_zone_list',
- req.environ['nova.context'])
- for item in items:
- item['api_url'] = item['api_url'].replace('\\/', '/')
-
- # Or fall-back to the database ...
- if len(items) == 0:
+ # Ask the ZoneManager in the Scheduler for most recent data,
+ # or fall-back to the database ...
+ items = API().get_zone_list(req.environ['nova.context'])
+ if not items:
items = db.zone_get_all(req.environ['nova.context'])
+
items = common.limited(items, req)
items = [_exclude_keys(item, ['username', 'password'])
for item in items]
diff --git a/nova/flags.py b/nova/flags.py
index 7e4919d6e..41f01fcd7 100644
--- a/nova/flags.py
+++ b/nova/flags.py
@@ -316,6 +316,5 @@ DEFINE_string('node_availability_zone', 'nova',
'availability zone of this node')
DEFINE_string('zone_name', 'nova', 'name of this zone')
-DEFINE_string('zone_capabilities', 'xen, linux',
- 'comma-delimited list of tags which represent boolean'
- ' capabilities of this zone')
+DEFINE_string('zone_capabilities', 'kypervisor:xenserver;os:linux',
+ 'Key/Value tags which represent capabilities of this zone')
diff --git a/nova/scheduler/api.py b/nova/scheduler/api.py
new file mode 100644
index 000000000..8491bf3a9
--- /dev/null
+++ b/nova/scheduler/api.py
@@ -0,0 +1,49 @@
+# Copyright (c) 2011 Openstack, LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""
+Handles all requests relating to schedulers.
+"""
+
+from nova import flags
+from nova import log as logging
+from nova import rpc
+
+FLAGS = flags.FLAGS
+LOG = logging.getLogger('nova.scheduler.api')
+
+
+class API:
+ """API for interacting with the scheduler."""
+
+ def _call_scheduler(self, method, context, params=None):
+ """Generic handler for RPC calls to the scheduler.
+
+ :param params: Optional dictionary of arguments to be passed to the
+ scheduler worker
+
+ :retval: Result returned by scheduler worker
+ """
+ if not params:
+ params = {}
+ queue = FLAGS.scheduler_topic
+ kwargs = {'method': method, 'args': params}
+ return rpc.call(context, queue, kwargs)
+
+ def get_zone_list(self, context):
+ items = self._call_scheduler('get_zone_list', context)
+ for item in items:
+ item['api_url'] = item['api_url'].replace('\\/', '/')
+ return items
diff --git a/nova/scheduler/zone_manager.py b/nova/scheduler/zone_manager.py
index 3e7c1eba8..783783d06 100644
--- a/nova/scheduler/zone_manager.py
+++ b/nova/scheduler/zone_manager.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 Openstack, LLC.
+# Copyright (c) 2011 Openstack, LLC.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -87,8 +87,8 @@ class ZoneState(object):
def _call_novatools(zone):
"""Call novatools. Broken out for testing purposes."""
- os = novatools.OpenStack(zone.username, zone.password, zone.api_url)
- return os.zones.info()._info
+ client = novatools.OpenStack(zone.username, zone.password, zone.api_url)
+ return client.zones.info()._info
def _poll_zone(zone):
@@ -105,6 +105,7 @@ class ZoneManager(object):
def __init__(self):
self.last_zone_db_check = datetime.min
self.zone_states = {}
+ self.green_pool = GreenPool()
def get_zone_list(self):
"""Return the list of zones we know about."""
@@ -123,20 +124,20 @@ class ZoneManager(object):
self.zone_states[zone.id].update_credentials(zone)
# Cleanup zones removed from db ...
- for zone_id in self.zone_states.keys():
+ keys = self.zone_states.keys() # since we're deleting
+ for zone_id in keys:
if zone_id not in db_keys:
del self.zone_states[zone_id]
def _poll_zones(self, context):
"""Try to connect to each child zone and get update."""
- green_pool = GreenPool()
- green_pool.imap(_poll_zone, self.zone_states.values())
+ self.green_pool.imap(_poll_zone, self.zone_states.values())
def ping(self, context=None):
"""Ping should be called periodically to update zone status."""
diff = datetime.now() - self.last_zone_db_check
if diff.seconds >= FLAGS.zone_db_check_interval:
- logging.debug("Updating zone cache from db.")
+ logging.debug(_("Updating zone cache from db."))
self.last_zone_db_check = datetime.now()
self._refresh_from_db(context)
self._poll_zones(context)
diff --git a/nova/tests/api/openstack/test_zones.py b/nova/tests/api/openstack/test_zones.py
index 65cc1c023..4df7c7feb 100644
--- a/nova/tests/api/openstack/test_zones.py
+++ b/nova/tests/api/openstack/test_zones.py
@@ -1,4 +1,4 @@
-# Copyright 2010 OpenStack LLC.
+# Copyright 2011 OpenStack LLC.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -24,6 +24,7 @@ from nova import context
from nova import flags
from nova.api.openstack import zones
from nova.tests.api.openstack import fakes
+from nova.scheduler.api import API
FLAGS = flags.FLAGS
@@ -31,7 +32,7 @@ FLAGS.verbose = True
def zone_get(context, zone_id):
- return dict(id=1, api_url='http://foo.com', username='bob',
+ return dict(id=1, api_url='http://example.com', username='bob',
password='xxx')
@@ -42,7 +43,7 @@ def zone_create(context, values):
def zone_update(context, zone_id, values):
- zone = dict(id=zone_id, api_url='http://foo.com', username='bob',
+ zone = dict(id=zone_id, api_url='http://example.com', username='bob',
password='xxx')
zone.update(values)
return zone
@@ -52,24 +53,24 @@ def zone_delete(context, zone_id):
pass
-def zone_get_all_scheduler(x, y, z):
+def zone_get_all_scheduler(*args):
return [
- dict(id=1, api_url='http://foo.com', username='bob',
+ dict(id=1, api_url='http://example.com', username='bob',
password='xxx'),
- dict(id=2, api_url='http://blah.com', username='alice',
+ dict(id=2, api_url='http://example.org', username='alice',
password='qwerty')
]
-def zone_get_all_scheduler_empty(x, y, z):
+def zone_get_all_scheduler_empty(*args):
return []
def zone_get_all_db(context):
return [
- dict(id=1, api_url='http://foo.com', username='bob',
+ dict(id=1, api_url='http://example.com', username='bob',
password='xxx'),
- dict(id=2, api_url='http://blah.com', username='alice',
+ dict(id=2, api_url='http://example.org', username='alice',
password='qwerty')
]
@@ -96,8 +97,7 @@ class ZonesTest(unittest.TestCase):
FLAGS.allow_admin_api = self.allow_admin
def test_get_zone_list_scheduler(self):
- self.stubs.Set(zones.Controller, '_call_scheduler',
- zone_get_all_scheduler)
+ self.stubs.Set(API, '_call_scheduler', zone_get_all_scheduler)
req = webob.Request.blank('/v1.0/zones')
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
@@ -106,8 +106,7 @@ class ZonesTest(unittest.TestCase):
self.assertEqual(len(res_dict['zones']), 2)
def test_get_zone_list_db(self):
- self.stubs.Set(zones.Controller, '_call_scheduler',
- zone_get_all_scheduler_empty)
+ self.stubs.Set(API, '_call_scheduler', zone_get_all_scheduler_empty)
self.stubs.Set(nova.db, 'zone_get_all', zone_get_all_db)
req = webob.Request.blank('/v1.0/zones')
res = req.get_response(fakes.wsgi_app())
@@ -122,7 +121,7 @@ class ZonesTest(unittest.TestCase):
res_dict = json.loads(res.body)
self.assertEqual(res_dict['zone']['id'], 1)
- self.assertEqual(res_dict['zone']['api_url'], 'http://foo.com')
+ self.assertEqual(res_dict['zone']['api_url'], 'http://example.com')
self.assertFalse('password' in res_dict['zone'])
self.assertEqual(res.status_int, 200)
@@ -133,7 +132,7 @@ class ZonesTest(unittest.TestCase):
self.assertEqual(res.status_int, 200)
def test_zone_create(self):
- body = dict(zone=dict(api_url='http://blah.zoo', username='fred',
+ body = dict(zone=dict(api_url='http://example.com', username='fred',
password='fubar'))
req = webob.Request.blank('/v1.0/zones')
req.method = 'POST'
@@ -144,7 +143,7 @@ class ZonesTest(unittest.TestCase):
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['zone']['id'], 1)
- self.assertEqual(res_dict['zone']['api_url'], 'http://blah.zoo')
+ self.assertEqual(res_dict['zone']['api_url'], 'http://example.com')
self.assertFalse('username' in res_dict['zone'])
def test_zone_update(self):
@@ -158,7 +157,7 @@ class ZonesTest(unittest.TestCase):
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['zone']['id'], 1)
- self.assertEqual(res_dict['zone']['api_url'], 'http://foo.com')
+ self.assertEqual(res_dict['zone']['api_url'], 'http://example.com')
self.assertFalse('username' in res_dict['zone'])