Skip to content

Commit

Permalink
Novaclient for usage features. Kill openstackx.
Browse files Browse the repository at this point in the history
 * Fixes bug 848403
 * blueprint novaclient-migration
 * Fully removes openstackx
 * Needs https://review.openstack.org/3382 to work for non-admin users

Change-Id: I3e7fcf2f79a92c92c6c66ff0637ed874563496d6
  • Loading branch information
sleepsonthefloor committed Jan 26, 2012
1 parent 166ec2f commit c0a3d85
Show file tree
Hide file tree
Showing 29 changed files with 219 additions and 256 deletions.
2 changes: 1 addition & 1 deletion horizon/horizon/api/base.py
Expand Up @@ -61,7 +61,7 @@ class APIDictWrapper(object):
dictionary, in addition to attribute accesses.
Attribute access is the preferred method of access, to be
consistent with api resource objects from openstackx
consistent with api resource objects from novclient.
"""
def __init__(self, apidict):
self._apidict = apidict
Expand Down
67 changes: 0 additions & 67 deletions horizon/horizon/api/deprecated.py

This file was deleted.

45 changes: 29 additions & 16 deletions horizon/horizon/api/nova.py
Expand Up @@ -28,8 +28,6 @@
from novaclient.v1_1.servers import REBOOT_HARD

from horizon.api.base import *
from horizon.api.deprecated import check_openstackx
from horizon.api.deprecated import extras_api


LOG = logging.getLogger(__name__)
Expand All @@ -41,7 +39,7 @@


class Flavor(APIResourceWrapper):
"""Simple wrapper around openstackx.admin.flavors.Flavor"""
"""Simple wrapper around novaclient.flavors.Flavor"""
_attrs = ['disk', 'id', 'links', 'name', 'ram', 'vcpus']


Expand All @@ -56,7 +54,7 @@ class FloatingIpPool(APIResourceWrapper):


class KeyPair(APIResourceWrapper):
"""Simple wrapper around openstackx.extras.keypairs.Keypair"""
"""Simple wrapper around novaclient.keypairs.Keypair"""
_attrs = ['fingerprint', 'name', 'private_key']


Expand Down Expand Up @@ -99,7 +97,7 @@ def __init__(self, apiresource):


class Server(APIResourceWrapper):
"""Simple wrapper around openstackx.extras.server.Server
"""Simple wrapper around novaclient.server.Server
Preserves the request info so image name can later be retrieved
"""
Expand Down Expand Up @@ -127,15 +125,33 @@ def reboot(self, hardness=REBOOT_HARD):


class Usage(APIResourceWrapper):
"""Simple wrapper around openstackx.extras.usage.Usage"""
_attrs = ['begin', 'instances', 'stop', 'tenant_id',
'total_active_disk_size', 'total_active_instances',
'total_active_ram_size', 'total_active_vcpus', 'total_cpu_usage',
'total_disk_usage', 'total_hours', 'total_ram_usage']
"""Simple wrapper around contrib/simple_usage.py"""
_attrs = ['start', 'server_usages', 'stop', 'tenant_id',
'total_local_gb_usage', 'total_memory_mb_usage',
'total_vcpus_usage', 'total_hours']

@property
def total_active_instances(self):
return sum(1 for s in self.server_usages if s['ended_at'] == None)

@property
def total_active_vcpus(self):
return sum(s['vcpus']\
for s in self.server_usages if s['ended_at'] == None)

@property
def total_active_local_gb(self):
return sum(s['local_gb']\
for s in self.server_usages if s['ended_at'] == None)

@property
def total_active_memory_mb(self):
return sum(s['memory_mb']\
for s in self.server_usages if s['ended_at'] == None)


class SecurityGroup(APIResourceWrapper):
"""Simple wrapper around openstackx.extras.security_groups.SecurityGroup"""
"""Simple wrapper around novaclient.security_groups.SecurityGroup"""
_attrs = ['id', 'name', 'description', 'tenant_id']

@property
Expand Down Expand Up @@ -285,7 +301,6 @@ def server_console_output(request, instance_id, tail_length=None):
length=tail_length)


@check_openstackx
def admin_server_list(request):
return [Server(s, request) for s in novaclient(request).servers.list()]

Expand Down Expand Up @@ -349,14 +364,12 @@ def tenant_quota_defaults(request, tenant_id):
return QuotaSet(novaclient(request).quotas.defaults(tenant_id))


@check_openstackx
def usage_get(request, tenant_id, start, end):
return Usage(extras_api(request).usage.get(tenant_id, start, end))
return Usage(novaclient(request).usage.get(tenant_id, start, end))


@check_openstackx
def usage_list(request, start, end):
return [Usage(u) for u in extras_api(request).usage.list(start, end)]
return [Usage(u) for u in novaclient(request).usage.list(start, end, True)]


def security_group_list(request):
Expand Down
Expand Up @@ -22,7 +22,6 @@
from django.conf import settings
from django.core.urlresolvers import reverse
from glance.common import exception as glance_exception
from openstackx.api import exceptions as api_exceptions
from novaclient import exceptions as novaclient_exceptions
from novaclient.v1_1 import security_group_rules as nova_rules
from mox import IgnoreArg, IsA
Expand Down
Expand Up @@ -22,7 +22,7 @@
from django.contrib import messages
from django.core.urlresolvers import reverse
from glance.common import exception as glance_exception
from openstackx.api import exceptions as api_exceptions
from novaclient import exceptions as novaclient_exceptions
from mox import IgnoreArg, IsA

from horizon import api
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_create_snapshot_get_with_invalid_status(self):

def test_create_get_server_exception(self):
self.mox.StubOutWithMock(api, 'server_get')
exception = api_exceptions.ApiException('apiException')
exception = novaclient_exceptions.ClientException('apiException')
api.server_get(IsA(http.HttpRequest),
str(self.good_server.id)).AndRaise(exception)

Expand Down Expand Up @@ -158,7 +158,7 @@ def test_create_snapshot_post_exception(self):

api.server_get(IsA(http.HttpRequest),
str(self.good_server.id)).AndReturn(self.good_server)
exception = api_exceptions.ApiException('apiException',
exception = novaclient_exceptions.ClientException('apiException',
message='apiException')
api.snapshot_create(IsA(http.HttpRequest),
str(self.good_server.id), SNAPSHOT_NAME).\
Expand Down
Expand Up @@ -30,7 +30,6 @@
from django.utils.translation import ugettext as _
from glance.common import exception as glance_exception
from novaclient import exceptions as novaclient_exceptions
from openstackx.api import exceptions as api_exceptions

from horizon import api
from horizon import exceptions
Expand Down
Expand Up @@ -21,7 +21,7 @@
from django import http
from django.core.urlresolvers import reverse
from mox import IsA
from openstackx.api import exceptions as api_exceptions
from novaclient import exceptions as novaclient_exceptions

from horizon import api
from horizon import test
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_index(self):
def test_index_server_list_exception(self):
self.mox.StubOutWithMock(api, 'server_list')
self.mox.StubOutWithMock(api, 'volume_list')
exception = api_exceptions.ApiException('apiException')
exception = novaclient_exceptions.ClientException('apiException')
api.server_list(IsA(http.HttpRequest)).AndRaise(exception)
api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes)

Expand Down
15 changes: 8 additions & 7 deletions horizon/horizon/dashboards/nova/overview/views.py
Expand Up @@ -58,24 +58,25 @@ def usage(request, tenant_id=None):
exceptions.handle(request,
_('Unable to retrieve usage information.'))

total_ram = 0
ram_unit = "MB"
total_ram = getattr(usage, 'total_active_ram_size', 0)
if total_ram >= 1024:
ram_unit = "GB"
total_ram /= 1024

instances = []
terminated = []

if hasattr(usage, 'instances'):
if hasattr(usage, 'server_usages'):
total_ram = usage.total_active_memory_mb
now = datetime.datetime.now()
for i in usage.instances:
for i in usage.server_usages:
i['uptime_at'] = now - datetime.timedelta(seconds=i['uptime'])
if i['ended_at'] and not show_terminated:
terminated.append(i)
else:
instances.append(i)

if total_ram >= 1024:
ram_unit = "GB"
total_ram /= 1024

if request.GET.get('format', 'html') == 'csv':
template = 'nova/overview/usage.csv'
mimetype = "text/csv"
Expand Down
@@ -1,11 +1,11 @@
Usage Report For Period:,{{datetime_start|date:"b. d Y H:i"}},/,{{datetime_end|date:"b. d Y H:i"}}
Tenant ID:,{{usage.tenant_id}}
Total Active VCPUs:,{{usage.total_active_vcpus}}
CPU-HRs Used:,{{usage.total_cpu_usage}}
Total Active Ram (MB):,{{usage.total_active_ram_size}}
Total Disk Size:,{{usage.total_active_disk_size}}
Total Disk Usage:,{{usage.total_disk_usage}}
CPU-HRs Used:,{{usage.total_vcpus_usage}}
Total Active Ram (MB):,{{usage.total_active_memory_mb}}
Total Disk Size:,{{usage.total_active_local_gb}}
Total Disk Usage:,{{usage.total_local_gb_usage}}

ID,Name,UserId,VCPUs,RamMB,DiskGB,Flavor,Usage(Hours),Uptime(Seconds),State
{% for instance in usage.instances %}{{instance.id}},{{instance.name|addslashes}},{{instance.user_id|addslashes}},{{instance.vcpus|addslashes}},{{instance.ram_size|addslashes}},{{instance.disk_size|addslashes}},{{instance.flavor|addslashes}},{{instance.hours}},{{instance.uptime}},{{instance.state|capfirst|addslashes}}
ID,Name,VCPUs,RamMB,DiskGB,Usage(Hours),Uptime(Seconds),State
{% for server_usage in usage.server_usages %}{{server_usage.id}},{{server_usage.name|addslashes}},{{server_usage.vcpus|addslashes}},{{server_usage.memory_mb|addslashes}},{{server_usage.local_gb|addslashes}},{{server_usage.hours}},{{server_usage.uptime}},{{server_usage.state|capfirst|addslashes}}
{% endfor %}
Expand Up @@ -8,13 +8,13 @@

{% block dash_main %}

{% if usage.instances %}
{% if usage.server_usages %}
<div id="usage">
<div class="usage_block first">
<h3>CPU</h3>
<ul>
<li><span class="quantity">{{ usage.total_active_vcpus|default:0 }}</span><span class="unit">Cores</span> Active</li>
<li><span class="quantity">{{ usage.total_cpu_usage|floatformat|default:0 }}</span><span class="unit">CPU-HR</span> Used</li>
<li><span class="quantity">{{ usage.total_vcpus_usage|floatformat|default:0 }}</span><span class="unit">CPU-HR</span> Used</li>
</ul>
</div>

Expand All @@ -28,8 +28,8 @@ <h3>RAM</h3>
<div class="usage_block last">
<h3>Disk</h3>
<ul>
<li><span class="quantity">{{ usage.total_active_disk_size|default:0 }}</span><span class="unit">GB</span> Active</li>
<li><span class="quantity">{{ usage.total_disk_usage|floatformat|default:0 }}</span><span class="unit">GB-HR</span> Used</li>
<li><span class="quantity">{{ usage.total_active_local_gb|default:0 }}</span><span class="unit">GB</span> Active</li>
<li><span class="quantity">{{ usage.total_local_gb|floatformat|default:0 }}</span><span class="unit">GB-HR</span> Used</li>
</ul>
</div>
</div>
Expand All @@ -49,7 +49,6 @@ <h3>Server Usage Summary</h3>
<table class="table table-striped table-bordered">
<tr id='headings'>
<th>{% trans "Name" %}</th>
<th>{% trans "User" %}</th>
<th>{% trans "Size" %}</th>
<th>{% trans "Uptime" %}</th>
<th>{% trans "State" %}</th>
Expand All @@ -62,8 +61,7 @@ <h3>Server Usage Summary</h3>
<tr class="{% cycle 'odd' 'even' %}">
{% endif %}
<td>{{ instance.name }}</td>
<td>{{ instance.user_id }}</td>
<td>{{ instance.ram_size|mbformat }} Ram | {{ instance.vcpus }} VCPU | {{ instance.disk_size }}GB Disk</td>
<td>{{ instance.memory_mb|mbformat }} Ram | {{ instance.vcpus }} VCPU | {{ instance.local_gb }}GB Disk</td>
<td>{{ instance.uptime_at|timesince }}</td>
<td>{{ instance.state|lower|capfirst }}</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion horizon/horizon/dashboards/syspanel/flavors/forms.py
Expand Up @@ -32,7 +32,7 @@


class CreateFlavor(forms.SelfHandlingForm):
#flavorid is required because of openstackx
# flavorid is required in novaclient
flavor_id = forms.IntegerField(label=_("Flavor ID"))
name = forms.CharField(max_length="25", label=_("Name"))
vcpus = forms.CharField(max_length="5", label=_("VCPUs"))
Expand Down

0 comments on commit c0a3d85

Please sign in to comment.