summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-05-11 06:28:07 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-05-11 06:28:07 -0700
commiteb0619c91b4756d355b7a5cd5c1f16d342f14a6b (patch)
tree9ff60eeffb5581dfb2509e5cae64f5a5cc0de67f /nova/api
parent5f2bfe56cf12d8f45ae24a5c9dd0c99e6c4d0310 (diff)
First cut with tests passing
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/__init__.py3
-rw-r--r--nova/api/openstack/zones.py48
2 files changed, 50 insertions, 1 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py
index 348b70d5b..b743d306b 100644
--- a/nova/api/openstack/__init__.py
+++ b/nova/api/openstack/__init__.py
@@ -98,7 +98,8 @@ class APIRouter(wsgi.Router):
server_members['inject_network_info'] = 'POST'
mapper.resource("zone", "zones", controller=zones.Controller(),
- collection={'detail': 'GET', 'info': 'GET'}),
+ collection={'detail': 'GET', 'info': 'GET',
+ 'select': 'GET',}),
mapper.resource("user", "users", controller=users.Controller(),
collection={'detail': 'GET'})
diff --git a/nova/api/openstack/zones.py b/nova/api/openstack/zones.py
index 227ffecdc..70653dc0e 100644
--- a/nova/api/openstack/zones.py
+++ b/nova/api/openstack/zones.py
@@ -13,6 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
+import json
+import urlparse
+
+from nova import crypto
from nova import db
from nova import flags
from nova import log as logging
@@ -21,6 +25,12 @@ from nova.scheduler import api
FLAGS = flags.FLAGS
+flags.DEFINE_string('build_plan_encryption_key',
+ None,
+ '128bit (hex) encryption key for scheduler build plans.')
+
+
+LOG = logging.getLogger('nova.api.openstack.zones')
def _filter_keys(item, keys):
@@ -41,6 +51,14 @@ def _scrub_zone(zone):
'deleted', 'deleted_at', 'updated_at'))
+def check_encryption_key(func):
+ def wrapped(*args, **kwargs):
+ if not FLAGS.build_plan_encryption_key:
+ raise exception.Error(_("--build_plan_encryption_key not set"))
+ return func(*args, **kwargs)
+ return wrapped
+
+
class Controller(common.OpenstackController):
_serialization_metadata = {
@@ -97,3 +115,33 @@ class Controller(common.OpenstackController):
zone_id = int(id)
zone = api.zone_update(context, zone_id, env["zone"])
return dict(zone=_scrub_zone(zone))
+
+ @check_encryption_key
+ def select(self, req):
+ """Returns a weighted list of costs to create instances
+ of desired capabilities."""
+ ctx = req.environ['nova.context']
+ qs = req.environ['QUERY_STRING']
+ param_dict = urlparse.parse_qs(qs)
+ param_dict.pop("fresh", None)
+ # parse_qs returns a dict where the values are lists,
+ # since query strings can have multiple values for the
+ # same key. We need to convert that to single values.
+ for key in param_dict:
+ param_dict[key] = param_dict[key][0]
+ build_plan = api.select(ctx, specs=param_dict)
+ cooked = self._scrub_build_plan(build_plan)
+ return {"weights": cooked}
+
+ def _scrub_build_plan(self, build_plan):
+ """Remove all the confidential data and return a sanitized
+ version of the build plan. Include an encrypted full version
+ of the weighting entry so we can get back to it later."""
+ encryptor = crypto.encryptor(FLAGS.build_plan_encryption_key)
+ cooked = []
+ for entry in build_plan:
+ json_entry = json.dumps(entry)
+ cipher_text = encryptor(json_entry)
+ cooked.append(dict(weight=entry['weight'],
+ blob=cipher_text))
+ return cooked