Skip to content

Commit

Permalink
merge with trey
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoelker committed Jun 6, 2011
2 parents 0ac076d + 0541829 commit aac234e
Show file tree
Hide file tree
Showing 138 changed files with 6,008 additions and 2,466 deletions.
3 changes: 3 additions & 0 deletions Authors
Expand Up @@ -30,6 +30,7 @@ Gabe Westmaas <gabe.westmaas@rackspace.com>
Hisaharu Ishii <ishii.hisaharu@lab.ntt.co.jp>
Hisaki Ohara <hisaki.ohara@intel.com>
Ilya Alekseyev <ialekseev@griddynamics.com>
Isaku Yamahata <yamahata@valinux.co.jp>
Jason Koelker <jason@koelker.net>
Jay Pipes <jaypipes@gmail.com>
Jesse Andrews <anotherjesse@gmail.com>
Expand Down Expand Up @@ -58,6 +59,7 @@ Mark Washenberger <mark.washenberger@rackspace.com>
Masanori Itoh <itoumsn@nttdata.co.jp>
Matt Dietz <matt.dietz@rackspace.com>
Michael Gundlach <michael.gundlach@rackspace.com>
Mike Scherbakov <mihgen@gmail.com>
Monsyne Dragon <mdragon@rackspace.com>
Monty Taylor <mordred@inaugust.com>
MORITA Kazutaka <morita.kazutaka@gmail.com>
Expand All @@ -83,6 +85,7 @@ Trey Morris <trey.morris@rackspace.com>
Tushar Patil <tushar.vitthal.patil@gmail.com>
Vasiliy Shlykov <vash@vasiliyshlykov.org>
Vishvananda Ishaya <vishvananda@gmail.com>
Vivek Y S <vivek.ys@gmail.com>
William Wolf <throughnothing@gmail.com>
Yoshiaki Tamura <yoshi@midokura.jp>
Youcef Laribi <Youcef.Laribi@eu.citrix.com>
Expand Down
16 changes: 10 additions & 6 deletions bin/nova-manage
Expand Up @@ -53,7 +53,6 @@
CLI interface for nova management.
"""

import datetime
import gettext
import glob
import json
Expand All @@ -78,6 +77,7 @@ from nova import crypto
from nova import db
from nova import exception
from nova import flags
from nova import image
from nova import log as logging
from nova import quota
from nova import rpc
Expand All @@ -97,7 +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.DECLARE('libvirt_type', 'nova.virt.libvirt.connection')
flags.DEFINE_flag(flags.HelpFlag())
flags.DEFINE_flag(flags.HelpshortFlag())
flags.DEFINE_flag(flags.HelpXMLFlag())
Expand Down Expand Up @@ -423,12 +423,16 @@ class ProjectCommands(object):
arguments: project_id [key] [value]"""
ctxt = context.get_admin_context()
if key:
if value.lower() == 'unlimited':
value = None
try:
db.quota_update(ctxt, project_id, key, value)
except exception.ProjectQuotaNotFound:
db.quota_create(ctxt, project_id, key, value)
project_quota = quota.get_quota(ctxt, project_id)
project_quota = quota.get_project_quotas(ctxt, project_id)
for key, value in project_quota.iteritems():
if value is None:
value = 'unlimited'
print '%s: %s' % (key, value)

def remove(self, project_id, user_id):
Expand Down Expand Up @@ -539,7 +543,7 @@ class FloatingIpCommands(object):
for floating_ip in floating_ips:
instance = None
if floating_ip['fixed_ip']:
instance = floating_ip['fixed_ip']['instance']['ec2_id']
instance = floating_ip['fixed_ip']['instance']['hostname']
print "%s\t%s\t%s" % (floating_ip['host'],
floating_ip['address'],
instance)
Expand Down Expand Up @@ -702,7 +706,7 @@ class ServiceCommands(object):
"""Show a list of all running services. Filter by host & service name.
args: [host] [service]"""
ctxt = context.get_admin_context()
now = datetime.datetime.utcnow()
now = utils.utcnow()
services = db.service_get_all(ctxt)
if host:
services = [s for s in services if s['host'] == host]
Expand Down Expand Up @@ -949,7 +953,7 @@ class ImageCommands(object):
"""Methods for dealing with a cloud in an odd state"""

def __init__(self, *args, **kwargs):
self.image_service = utils.import_object(FLAGS.image_service)
self.image_service = image.get_default_image_service()

def _register(self, container_format, disk_format,
path, owner, name=None, is_public='T',
Expand Down
12 changes: 8 additions & 4 deletions nova/api/direct.py
Expand Up @@ -42,6 +42,7 @@
from nova import flags
from nova import utils
from nova import wsgi
import nova.api.openstack.wsgi


# Global storage for registering modules.
Expand Down Expand Up @@ -251,7 +252,7 @@ def get_method_info(self, context, method):
return self._methods[method]


class ServiceWrapper(wsgi.Controller):
class ServiceWrapper(object):
"""Wrapper to dynamically povide a WSGI controller for arbitrary objects.
With lightweight introspection allows public methods on the object to
Expand All @@ -265,7 +266,7 @@ class ServiceWrapper(wsgi.Controller):
def __init__(self, service_handle):
self.service_handle = service_handle

@webob.dec.wsgify(RequestClass=wsgi.Request)
@webob.dec.wsgify(RequestClass=nova.api.openstack.wsgi.Request)
def __call__(self, req):
arg_dict = req.environ['wsgiorg.routing_args'][1]
action = arg_dict['action']
Expand All @@ -289,8 +290,11 @@ def __call__(self, req):

try:
content_type = req.best_match_content_type()
default_xmlns = self.get_default_xmlns(req)
return self._serialize(result, content_type, default_xmlns)
serializer = {
'application/xml': nova.api.openstack.wsgi.XMLDictSerializer(),
'application/json': nova.api.openstack.wsgi.JSONDictSerializer(),
}[content_type]
return serializer.serialize(result)
except:
raise exception.Error("returned non-serializable type: %s"
% result)
Expand Down
6 changes: 6 additions & 0 deletions nova/api/ec2/__init__.py
Expand Up @@ -327,6 +327,12 @@ def __call__(self, req):
ec2_id = ec2utils.id_to_ec2_id(ex.volume_id, 'vol-%08x')
message = _('Volume %s not found') % ec2_id
return self._error(req, context, type(ex).__name__, message)
except exception.SnapshotNotFound as ex:
LOG.info(_('SnapshotNotFound raised: %s'), unicode(ex),
context=context)
ec2_id = ec2utils.id_to_ec2_id(ex.snapshot_id, 'snap-%08x')
message = _('Snapshot %s not found') % ec2_id
return self._error(req, context, type(ex).__name__, message)
except exception.NotFound as ex:
LOG.info(_('NotFound raised: %s'), unicode(ex), context=context)
return self._error(req, context, type(ex).__name__, unicode(ex))
Expand Down
3 changes: 1 addition & 2 deletions nova/api/ec2/admin.py
Expand Up @@ -21,7 +21,6 @@
"""

import base64
import datetime

from nova import db
from nova import exception
Expand Down Expand Up @@ -305,7 +304,7 @@ def describe_hosts(self, context, **_kwargs):
* Volume Count
"""
services = db.service_get_all(context, False)
now = datetime.datetime.utcnow()
now = utils.utcnow()
hosts = []
rv = []
for host in [service['host'] for service in services]:
Expand Down
90 changes: 72 additions & 18 deletions nova/api/ec2/cloud.py
Expand Up @@ -23,7 +23,6 @@
"""

import base64
import datetime
import IPy
import os
import urllib
Expand Down Expand Up @@ -159,7 +158,7 @@ def get_metadata(self, address):
floating_ip = db.instance_get_floating_address(ctxt,
instance_ref['id'])
ec2_id = ec2utils.id_to_ec2_id(instance_ref['id'])
image_ec2_id = self.image_ec2_id(instance_ref['image_id'])
image_ec2_id = self.image_ec2_id(instance_ref['image_ref'])
data = {
'user-data': base64.b64decode(instance_ref['user_data']),
'meta-data': {
Expand Down Expand Up @@ -235,7 +234,7 @@ def _describe_availability_zones_verbose(self, context, **kwargs):
'zoneState': 'available'}]}

services = db.service_get_all(context, False)
now = datetime.datetime.utcnow()
now = utils.utcnow()
hosts = []
for host in [service['host'] for service in services]:
if not host in hosts:
Expand Down Expand Up @@ -283,14 +282,50 @@ def describe_snapshots(self,
owner=None,
restorable_by=None,
**kwargs):
return {'snapshotSet': [{'snapshotId': 'fixme',
'volumeId': 'fixme',
'status': 'fixme',
'startTime': 'fixme',
'progress': 'fixme',
'ownerId': 'fixme',
'volumeSize': 0,
'description': 'fixme'}]}
if snapshot_id:
snapshots = []
for ec2_id in snapshot_id:
internal_id = ec2utils.ec2_id_to_id(ec2_id)
snapshot = self.volume_api.get_snapshot(
context,
snapshot_id=internal_id)
snapshots.append(snapshot)
else:
snapshots = self.volume_api.get_all_snapshots(context)
snapshots = [self._format_snapshot(context, s) for s in snapshots]
return {'snapshotSet': snapshots}

def _format_snapshot(self, context, snapshot):
s = {}
s['snapshotId'] = ec2utils.id_to_ec2_id(snapshot['id'], 'snap-%08x')
s['volumeId'] = ec2utils.id_to_ec2_id(snapshot['volume_id'],
'vol-%08x')
s['status'] = snapshot['status']
s['startTime'] = snapshot['created_at']
s['progress'] = snapshot['progress']
s['ownerId'] = snapshot['project_id']
s['volumeSize'] = snapshot['volume_size']
s['description'] = snapshot['display_description']

s['display_name'] = snapshot['display_name']
s['display_description'] = snapshot['display_description']
return s

def create_snapshot(self, context, volume_id, **kwargs):
LOG.audit(_("Create snapshot of volume %s"), volume_id,
context=context)
volume_id = ec2utils.ec2_id_to_id(volume_id)
snapshot = self.volume_api.create_snapshot(
context,
volume_id=volume_id,
name=kwargs.get('display_name'),
description=kwargs.get('display_description'))
return self._format_snapshot(context, snapshot)

def delete_snapshot(self, context, snapshot_id, **kwargs):
snapshot_id = ec2utils.ec2_id_to_id(snapshot_id)
self.volume_api.delete_snapshot(context, snapshot_id=snapshot_id)
return True

def describe_key_pairs(self, context, key_name=None, **kwargs):
key_pairs = db.key_pair_get_all_by_user(context, context.user_id)
Expand Down Expand Up @@ -559,7 +594,7 @@ def get_console_output(self, context, instance_id, **kwargs):
instance_id = ec2utils.ec2_id_to_id(ec2_id)
output = self.compute_api.get_console_output(
context, instance_id=instance_id)
now = datetime.datetime.utcnow()
now = utils.utcnow()
return {"InstanceId": ec2_id,
"Timestamp": now,
"output": base64.b64encode(output)}
Expand Down Expand Up @@ -619,16 +654,30 @@ def _format_volume(self, context, volume):
'volumeId': v['volumeId']}]
else:
v['attachmentSet'] = [{}]
if volume.get('snapshot_id') != None:
v['snapshotId'] = ec2utils.id_to_ec2_id(volume['snapshot_id'],
'snap-%08x')
else:
v['snapshotId'] = None

v['display_name'] = volume['display_name']
v['display_description'] = volume['display_description']
return v

def create_volume(self, context, size, **kwargs):
LOG.audit(_("Create volume of %s GB"), size, context=context)
def create_volume(self, context, **kwargs):
size = kwargs.get('size')
if kwargs.get('snapshot_id') != None:
snapshot_id = ec2utils.ec2_id_to_id(kwargs['snapshot_id'])
LOG.audit(_("Create volume from snapshot %s"), snapshot_id,
context=context)
else:
snapshot_id = None
LOG.audit(_("Create volume of %s GB"), size, context=context)

volume = self.volume_api.create(
context,
size=size,
snapshot_id=snapshot_id,
name=kwargs.get('display_name'),
description=kwargs.get('display_description'))
# TODO(vish): Instance should be None at db layer instead of
Expand Down Expand Up @@ -724,13 +773,13 @@ def _format_instances(self, context, instance_id=None, **kwargs):
instances = self.compute_api.get_all(context, **kwargs)
for instance in instances:
if not context.is_admin:
if instance['image_id'] == str(FLAGS.vpn_image_id):
if instance['image_ref'] == str(FLAGS.vpn_image_id):
continue
i = {}
instance_id = instance['id']
ec2_id = ec2utils.id_to_ec2_id(instance_id)
i['instanceId'] = ec2_id
i['imageId'] = self.image_ec2_id(instance['image_id'])
i['imageId'] = self.image_ec2_id(instance['image_ref'])
i['instanceState'] = {
'code': instance['state'],
'name': instance['state_description']}
Expand Down Expand Up @@ -849,7 +898,7 @@ def run_instances(self, context, **kwargs):
instances = self.compute_api.create(context,
instance_type=instance_types.get_instance_type_by_name(
kwargs.get('instance_type', None)),
image_id=self._get_image(context, kwargs['image_id'])['id'],
image_href=self._get_image(context, kwargs['image_id'])['id'],
min_count=int(kwargs.get('min_count', max_count)),
max_count=max_count,
kernel_id=kwargs.get('kernel_id'),
Expand Down Expand Up @@ -925,7 +974,12 @@ def _image_type(image_type):
def image_ec2_id(image_id, image_type='ami'):
"""Returns image ec2_id using id and three letter type."""
template = image_type + '-%08x'
return ec2utils.id_to_ec2_id(int(image_id), template=template)
try:
return ec2utils.id_to_ec2_id(int(image_id), template=template)
except ValueError:
#TODO(wwolf): once we have ec2_id -> glance_id mapping
# in place, this wont be necessary
return "ami-00000000"

def _get_image(self, context, ec2_id):
try:
Expand Down
11 changes: 10 additions & 1 deletion nova/api/ec2/metadatarequesthandler.py
Expand Up @@ -23,6 +23,7 @@

from nova import log as logging
from nova import flags
from nova import utils
from nova import wsgi
from nova.api.ec2 import cloud

Expand Down Expand Up @@ -71,7 +72,15 @@ def __call__(self, req):
remote_address = req.remote_addr
if FLAGS.use_forwarded_for:
remote_address = req.headers.get('X-Forwarded-For', remote_address)
meta_data = cc.get_metadata(remote_address)
try:
meta_data = cc.get_metadata(remote_address)
except Exception:
LOG.exception(_('Failed to get metadata for ip: %s'),
remote_address)
msg = _('An unknown error has occurred. '
'Please try your request again.')
exc = webob.exc.HTTPInternalServerError(explanation=unicode(msg))
return exc
if meta_data is None:
LOG.error(_('Failed to get metadata for ip: %s'), remote_address)
raise webob.exc.HTTPNotFound()
Expand Down

0 comments on commit aac234e

Please sign in to comment.