Skip to content

Commit

Permalink
merged trunk again
Browse files Browse the repository at this point in the history
  • Loading branch information
tr3buchet committed Jun 3, 2011
2 parents 3db24f7 + 54c341f commit 65e1792
Show file tree
Hide file tree
Showing 69 changed files with 1,157 additions and 346 deletions.
6 changes: 3 additions & 3 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 Down Expand Up @@ -706,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 @@ -953,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
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
20 changes: 12 additions & 8 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 @@ -595,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 @@ -774,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 @@ -899,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 @@ -975,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
5 changes: 2 additions & 3 deletions nova/api/openstack/auth.py
Expand Up @@ -13,9 +13,8 @@
# 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.import datetime
# under the License.

import datetime
import hashlib
import time

Expand Down Expand Up @@ -127,7 +126,7 @@ def authorize_token(self, token_hash):
except exception.NotFound:
return None
if token:
delta = datetime.datetime.utcnow() - token['created_at']
delta = utils.utcnow() - token['created_at']
if delta.days >= 2:
self.db.auth_token_destroy(ctxt, token['token_hash'])
else:
Expand Down
28 changes: 0 additions & 28 deletions nova/api/openstack/common.py
Expand Up @@ -99,34 +99,6 @@ def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit):
return items[start_index:range_end]


def get_image_id_from_image_hash(image_service, context, image_hash):
"""Given an Image ID Hash, return an objectstore Image ID.
image_service - reference to objectstore compatible image service.
context - security context for image service requests.
image_hash - hash of the image ID.
"""

# FIX(sandy): This is terribly inefficient. It pulls all images
# from objectstore in order to find the match. ObjectStore
# should have a numeric counterpart to the string ID.
try:
items = image_service.detail(context)
except NotImplementedError:
items = image_service.index(context)
for image in items:
image_id = image['id']
try:
if abs(hash(image_id)) == int(image_hash):
return image_id
except ValueError:
msg = _("Requested image_id has wrong format: %s,"
"should have numerical format") % image_id
LOG.error(msg)
raise Exception(msg)
raise exception.ImageNotFound(image_id=image_hash)


def get_id_from_href(href):
"""Return the id portion of a url as an int.
Expand Down
2 changes: 1 addition & 1 deletion nova/api/openstack/contrib/__init__.py
Expand Up @@ -13,7 +13,7 @@
# 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.import datetime
# under the License.

"""Contrib contains extensions that are shipped with nova.
Expand Down
3 changes: 2 additions & 1 deletion nova/api/openstack/image_metadata.py
Expand Up @@ -18,6 +18,7 @@
from webob import exc

from nova import flags
from nova import image
from nova import quota
from nova import utils
from nova.api.openstack import faults
Expand All @@ -31,7 +32,7 @@ class Controller(object):
"""The image metadata API controller for the Openstack API"""

def __init__(self):
self.image_service = utils.import_object(FLAGS.image_service)
self.image_service = image.get_default_image_service()

def _get_metadata(self, context, image_id, image=None):
if not image:
Expand Down
22 changes: 8 additions & 14 deletions nova/api/openstack/images.py
Expand Up @@ -18,6 +18,7 @@
from nova import compute
from nova import exception
from nova import flags
import nova.image
from nova import log
from nova import utils
from nova.api.openstack import common
Expand All @@ -40,11 +41,11 @@ def __init__(self, image_service=None, compute_service=None):
:param compute_service: `nova.compute.api:API`
:param image_service: `nova.image.service:BaseImageService`
"""
_default_service = utils.import_object(flags.FLAGS.image_service)
"""
self._compute_service = compute_service or compute.API()
self._image_service = image_service or _default_service
self._image_service = image_service or \
nova.image.get_default_image_service()

def index(self, req):
"""Return an index listing of images available to the request.
Expand Down Expand Up @@ -88,22 +89,16 @@ def show(self, req, id):
"""Return detailed information about a specific image.
:param req: `wsgi.Request` object
:param id: Image identifier (integer)
:param id: Image identifier
"""
context = req.environ['nova.context']

try:
image_id = int(id)
except ValueError:
image = self._image_service.show(context, id)
except (exception.NotFound, exception.InvalidImageRef):
explanation = _("Image not found.")
raise faults.Fault(webob.exc.HTTPNotFound(explanation=explanation))

try:
image = self._image_service.show(context, image_id)
except exception.NotFound:
explanation = _("Image '%d' not found.") % (image_id)
raise faults.Fault(webob.exc.HTTPNotFound(explanation=explanation))

return dict(image=self.get_builder(req).build(image, detail=True))

def delete(self, req, id):
Expand All @@ -112,9 +107,8 @@ def delete(self, req, id):
:param req: `wsgi.Request` object
:param id: Image identifier (integer)
"""
image_id = id
context = req.environ['nova.context']
self._image_service.delete(context, image_id)
self._image_service.delete(context, id)
return webob.exc.HTTPNoContent()

def create(self, req, body):
Expand Down
2 changes: 1 addition & 1 deletion nova/api/openstack/limits.py
Expand Up @@ -11,7 +11,7 @@
# 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.import datetime
# under the License.

"""
Module dedicated functions/classes dealing with rate limiting requests.
Expand Down
2 changes: 1 addition & 1 deletion nova/api/openstack/ratelimiting/__init__.py
Expand Up @@ -13,7 +13,7 @@
# 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.import datetime
# under the License.

"""Rate limiting of arbitrary actions."""

Expand Down

0 comments on commit 65e1792

Please sign in to comment.