Example #1
0
def get_memory(instance):
    max_mem = instance['beparams']['maxmem']
    min_mem = instance['beparams']['minmem']
    if max_mem == min_mem:
        return mbformat(max_mem)
    min_mem = mbformat(min_mem)
    max_mem = mbformat(max_mem)
    return "{min} - {max}".format(min=min_mem, max=max_mem)
def get_size(instance):
    if hasattr(instance, "full_flavor"):
        size_string = _("%(name)s | %(RAM)s RAM")
        vals = {'name': instance.full_flavor.name,
                'RAM': sizeformat.mbformat(instance.full_flavor.ram)}
        return size_string % vals
    return _("Not available")
Example #3
0
 def test_usage(self):
     now = timezone.now()
     usage_obj = api.nova.NovaUsage(self.usages.first())
     api.keystone.tenant_list(IsA(http.HttpRequest)) \
                 .AndReturn([self.tenants.list(), False])
     api.nova.usage_list(IsA(http.HttpRequest),
                         datetime.datetime(now.year,
                                           now.month,
                                           now.day, 0, 0, 0, 0),
                         datetime.datetime(now.year,
                                           now.month,
                                           now.day, 23, 59, 59, 0)) \
                                           .AndReturn([usage_obj])
     api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
         .AndReturn(self.limits['absolute'])
     self.mox.ReplayAll()
     res = self.client.get(reverse('horizon:admin:overview:index'))
     self.assertTemplateUsed(res, 'admin/overview/usage.html')
     self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
     self.assertContains(
         res, '<td class="sortable normal_column">test_tenant'
         '</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%.2f</td>'
         '<td class="sortable normal_column">%.2f</td>' %
         (usage_obj.vcpus, usage_obj.disk_gb_hours,
          mbformat(usage_obj.memory_mb), usage_obj.vcpu_hours,
          usage_obj.total_local_gb_usage))
Example #4
0
 def test_usage(self):
     now = timezone.now()
     usage_obj = api.nova.Usage(self.usages.first())
     quotas = self.quota_usages.first()
     api.keystone.tenant_list(IsA(http.HttpRequest), admin=True).AndReturn(self.tenants.list())
     api.usage_list(
         IsA(http.HttpRequest), datetime.datetime(now.year, now.month, 1, 0, 0, 0), Func(usage.almost_now)
     ).AndReturn([usage_obj])
     api.nova.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quotas)
     self.mox.ReplayAll()
     res = self.client.get(reverse("horizon:admin:overview:index"))
     self.assertTemplateUsed(res, "admin/overview/usage.html")
     self.assertTrue(isinstance(res.context["usage"], usage.GlobalUsage))
     self.assertContains(
         res,
         '<td class="sortable normal_column">test_tenant'
         "</td>"
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%.2f</td>'
         '<td class="sortable normal_column">%.2f</td>'
         % (
             usage_obj.vcpus,
             usage_obj.disk_gb_hours,
             mbformat(usage_obj.memory_mb),
             usage_obj.vcpu_hours,
             usage_obj.total_local_gb_usage,
         ),
     )
Example #5
0
 def test_usage(self):
     now = timezone.now()
     usage_obj = api.nova.NovaUsage(self.usages.first())
     api.keystone.tenant_list(IsA(http.HttpRequest)) \
                 .AndReturn([self.tenants.list(), False])
     api.nova.usage_list(IsA(http.HttpRequest),
                         datetime.datetime(now.year,
                                           now.month,
                                           now.day, 0, 0, 0, 0),
                         datetime.datetime(now.year,
                                           now.month,
                                           now.day, 23, 59, 59, 0)) \
                                           .AndReturn([usage_obj])
     api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
         .AndReturn(self.limits['absolute'])
     self.mox.ReplayAll()
     res = self.client.get(reverse('horizon:admin:overview:index'))
     self.assertTemplateUsed(res, 'admin/overview/usage.html')
     self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
     self.assertContains(res,
                         '<td class="sortable normal_column">test_tenant'
                         '</td>'
                         '<td class="sortable normal_column">%s</td>'
                         '<td class="sortable normal_column">%s</td>'
                         '<td class="sortable normal_column">%s</td>'
                         '<td class="sortable normal_column">%.2f</td>'
                         '<td class="sortable normal_column">%.2f</td>' %
                         (usage_obj.vcpus,
                          usage_obj.disk_gb_hours,
                          mbformat(usage_obj.memory_mb),
                          usage_obj.vcpu_hours,
                          usage_obj.total_local_gb_usage))
Example #6
0
 def test_usage(self):
     now = self.override_times()
     usage_obj = api.nova.Usage(self.usages.first())
     api.keystone.tenant_list(IsA(http.HttpRequest), admin=True) \
                 .AndReturn(self.tenants.list())
     api.usage_list(IsA(http.HttpRequest),
                   datetime.datetime(now.year, now.month, 1,
                                     now.hour, now.minute, now.second),
                   datetime.datetime(now.year, now.month, now.day, now.hour,
                                     now.minute, now.second)) \
                   .AndReturn([usage_obj])
     self.mox.ReplayAll()
     res = self.client.get(reverse('horizon:syspanel:overview:index'))
     self.assertTemplateUsed(res, 'syspanel/overview/usage.html')
     self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
     self.assertContains(res,
                         '<td class="sortable">test_tenant</td>'
                         '<td class="sortable">%s</td>'
                         '<td class="sortable">%s</td>'
                         '<td class="sortable">%s</td>'
                         '<td class="sortable">%.2f</td>'
                         '<td class="sortable">%.2f</td>' %
                         (usage_obj.vcpus,
                          usage_obj.disk_gb_hours,
                          mbformat(usage_obj.memory_mb),
                          usage_obj.vcpu_hours,
                          usage_obj.total_local_gb_usage))
Example #7
0
 def test_usage(self):
     now = timezone.now()
     usage_obj = api.nova.Usage(self.usages.first())
     api.keystone.tenant_list(IsA(http.HttpRequest), admin=True) \
                 .AndReturn(self.tenants.list())
     api.usage_list(IsA(http.HttpRequest),
                   datetime.datetime(now.year, now.month, 1, 0, 0, 0),
                   Func(usage.almost_now)) \
                   .AndReturn([usage_obj])
     self.mox.ReplayAll()
     res = self.client.get(reverse('horizon:syspanel:overview:index'))
     self.assertTemplateUsed(res, 'syspanel/overview/usage.html')
     self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
     self.assertContains(res,
                         '<td class="sortable">test_tenant</td>'
                         '<td class="sortable">%s</td>'
                         '<td class="sortable">%s</td>'
                         '<td class="sortable">%s</td>'
                         '<td class="sortable">%.2f</td>'
                         '<td class="sortable">%.2f</td>' %
                         (usage_obj.vcpus,
                          usage_obj.disk_gb_hours,
                          mbformat(usage_obj.memory_mb),
                          usage_obj.vcpu_hours,
                          usage_obj.total_local_gb_usage))
Example #8
0
 def test_usage(self):
     now = timezone.now()
     usage_obj = api.nova.Usage(self.usages.first())
     quotas = self.quota_usages.first()
     api.keystone.tenant_list(IsA(http.HttpRequest), admin=True) \
                 .AndReturn(self.tenants.list())
     api.usage_list(IsA(http.HttpRequest),
                   datetime.datetime(now.year, now.month, 1, 0, 0, 0),
                   Func(usage.almost_now)) \
                   .AndReturn([usage_obj])
     api.nova.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quotas)
     self.mox.ReplayAll()
     res = self.client.get(reverse('horizon:syspanel:overview:index'))
     self.assertTemplateUsed(res, 'syspanel/overview/usage.html')
     self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
     self.assertContains(
         res, '<td class="sortable normal_column">test_tenant'
         '</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%.2f</td>'
         '<td class="sortable normal_column">%.2f</td>' %
         (usage_obj.vcpus, usage_obj.disk_gb_hours,
          mbformat(usage_obj.memory_mb), usage_obj.vcpu_hours,
          usage_obj.total_local_gb_usage))
Example #9
0
def get_instance_size(instance):
    if hasattr(instance, "full_flavor"):
        size_string = _("%(name)s | %(RAM)s RAM")
        vals = {'name': instance.full_flavor.name,
                'RAM': sizeformat.mbformat(instance.full_flavor.ram)}
        return size_string % vals
    return _("Not available")
Example #10
0
def get_size(instance):
    if hasattr(instance, "full_flavor"):
        size_string = _("%(RAM)s RAM | %(VCPU)s VCPU | %(disk)s Disk")
        vals = {'RAM': sizeformat.mbformat(instance.full_flavor.ram),
                'VCPU': instance.full_flavor.vcpus,
                'disk': sizeformat.diskgbformat(instance.full_flavor.disk)}
        return size_string % vals
    return _("Not available")
Example #11
0
def get_size(instance):
    if hasattr(instance, "full_flavor"):
        size_string = _("%(RAM)s RAM | %(VCPU)s VCPU | %(disk)s Disk")
        vals = {'RAM': sizeformat.mbformat(instance.full_flavor.ram),
                'VCPU': instance.full_flavor.vcpus,
                'disk': sizeformat.diskgbformat(instance.full_flavor.disk)}
        return size_string % vals
    return _("Not available")
Example #12
0
def get_size(instance):
    if hasattr(instance, "full_flavor"):
        size_string = _("%(name)s<br>%(RAM)s RAM<br>%(VCPU)s VCPU"
                        "<br>%(disk)s Disk")
        vals = {'name': instance.full_flavor.name,
                'RAM': sizeformat.mbformat(instance.full_flavor.ram),
                'VCPU': instance.full_flavor.vcpus,
                'disk': sizeformat.diskgbformat(instance.full_flavor.disk)}
        return mark_safe(size_string % vals)
    return _("Not available")
Example #13
0
def get_size(instance):
    if hasattr(instance, 'properties'):
        size_string = _("%(name)s | %(ram)s RAM | %(cpus)s VCPU "
                        "| %(disk)s Disk")
        vals = {'name': instance.properties['id'],
                'ram': sizeformat.mbformat(instance.properties['ram']),
                'cpus': instance.properties['cpus'],
                'disk': sizeformat.diskgbformat(instance.properties['disk'])}
        return size_string % vals
    return _("Not available")
Example #14
0
def get_size(instance):
    if hasattr(instance, "full_flavor"):
        size_string = _("%(name)s | %(RAM)s RAM | %(VCPU)s VCPU " "| %(disk)s Disk")
        vals = {
            "name": instance.full_flavor.name,
            "RAM": sizeformat.mbformat(instance.full_flavor.ram),
            "VCPU": instance.full_flavor.vcpus,
            "disk": sizeformat.diskgbformat(instance.full_flavor.disk),
        }
        return size_string % vals
    return _("Not available")
Example #15
0
    def _test_usage(self, nova_stu_enabled=True):
        self._stub_nova_api_calls(nova_stu_enabled)
        api.nova.extension_supported(
            'SimpleTenantUsage', IsA(http.HttpRequest)) \
            .AndReturn(nova_stu_enabled)
        now = timezone.now()
        usage_obj = api.nova.NovaUsage(self.usages.first())
        api.keystone.tenant_list(IsA(http.HttpRequest)) \
                    .AndReturn([self.tenants.list(), False])

        if nova_stu_enabled:
            api.nova.usage_list(IsA(http.HttpRequest),
                                datetime.datetime(now.year,
                                                  now.month,
                                                  now.day, 0, 0, 0, 0),
                                datetime.datetime(now.year,
                                                  now.month,
                                                  now.day, 23, 59, 59, 0)) \
                .AndReturn([usage_obj])
        api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
            .AndReturn(self.limits['absolute'])
        api.neutron.is_extension_supported(IsA(http.HttpRequest),
                                           'security-group').AndReturn(True)
        api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                           .AndReturn(self.floating_ips.list())
        api.network.security_group_list(IsA(http.HttpRequest)) \
                           .AndReturn(self.q_secgroups.list())
        api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)) \
                           .AndReturn(self.cinder_limits['absolute'])

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:admin:overview:index'))
        self.assertTemplateUsed(res, 'admin/overview/usage.html')
        self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
        self.assertEqual(nova_stu_enabled,
                         res.context['simple_tenant_usage_enabled'])

        usage_table = '<td class="sortable normal_column">test_tenant</td>' \
                      '<td class="sortable normal_column">%s</td>' \
                      '<td class="sortable normal_column">%s</td>' \
                      '<td class="sortable normal_column">%s</td>' \
                      '<td class="sortable normal_column">%.2f</td>' \
                      '<td class="sortable normal_column">%.2f</td>' % \
                      (usage_obj.vcpus,
                       usage_obj.disk_gb_hours,
                       sizeformat.mbformat(usage_obj.memory_mb),
                       usage_obj.vcpu_hours,
                       usage_obj.total_local_gb_usage)

        if nova_stu_enabled:
            self.assertContains(res, usage_table)
        else:
            self.assertNotContains(res, usage_table)
Example #16
0
def get_size(cluster):
    if db_capability.is_vertica_datastore(cluster.datastore['type']):
        return "3"

    if hasattr(cluster, "full_flavor"):
        size_string = _("%(name)s | %(RAM)s RAM | %(instances)s instances")
        vals = {'name': cluster.full_flavor.name,
                'RAM': sizeformat.mbformat(cluster.full_flavor.ram),
                'instances': len(cluster.instances)}
        return size_string % vals
    return _("Not available")
Example #17
0
def get_size(instance):
    if hasattr(instance, 'properties'):
        size_string = _("%(name)s | %(ram)s RAM | %(cpus)s VCPU "
                        "| %(disk)s Disk")
        vals = {
            'name': instance.properties['id'],
            'ram': sizeformat.mbformat(instance.properties['ram']),
            'cpus': instance.properties['cpus'],
            'disk': sizeformat.diskgbformat(instance.properties['disk'])
        }
        return size_string % vals
    return _("Not available")
Example #18
0
def get_size(cluster):
    if db_capability.is_vertica_datastore(cluster.datastore["type"]):
        return "3"

    if hasattr(cluster, "full_flavor"):
        size_string = _("%(name)s | %(RAM)s RAM | %(instances)s instances")
        vals = {
            "name": cluster.full_flavor.name,
            "RAM": sizeformat.mbformat(cluster.full_flavor.ram),
            "instances": len(cluster.instances),
        }
        return size_string % vals
    elif hasattr(cluster, "instances"):
        return "%s instances" % len(cluster.instances)
    return _("Not available")
Example #19
0
def get_memory_used(hypervisor):
    return sizeformat.mbformat(hypervisor.memory_mb_used)
Example #20
0
def get_memory_used(hypervisor):
    return sizeformat.mbformat(hypervisor.memory_mb_used)
Example #21
0
    def _test_usage(self, nova_stu_enabled=True, tenant_deleted=False):
        self._stub_api_calls(nova_stu_enabled)
        api.nova.extension_supported(
            'SimpleTenantUsage', IsA(http.HttpRequest)) \
            .AndReturn(nova_stu_enabled)
        now = timezone.now()
        usage_list = [api.nova.NovaUsage(u) for u in self.usages.list()]
        if tenant_deleted:
            api.keystone.tenant_list(IsA(http.HttpRequest)) \
                .AndReturn([[self.tenants.first()], False])
        else:
            api.keystone.tenant_list(IsA(http.HttpRequest)) \
                .AndReturn([self.tenants.list(), False])

        if nova_stu_enabled:
            api.nova.usage_list(IsA(http.HttpRequest),
                                datetime.datetime(now.year,
                                                  now.month,
                                                  1, 0, 0, 0, 0),
                                datetime.datetime(now.year,
                                                  now.month,
                                                  now.day, 23, 59, 59, 0)) \
                .AndReturn(usage_list)
        api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
            .AndReturn(self.limits['absolute'])
        api.neutron.is_extension_supported(IsA(http.HttpRequest),
                                           'security-group').AndReturn(True)
        api.network.floating_ip_supported(IsA(http.HttpRequest)) \
            .AndReturn(True)
        api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                           .AndReturn(self.floating_ips.list())
        api.network.security_group_list(IsA(http.HttpRequest)) \
                           .AndReturn(self.q_secgroups.list())
        api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)) \
                           .AndReturn(self.cinder_limits['absolute'])

        self.mox.ReplayAll()
        res = self.client.get(reverse('horizon:admin:overview:index'))
        self.assertTemplateUsed(res, 'admin/overview/usage.html')
        self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
        self.assertEqual(nova_stu_enabled,
                         res.context['simple_tenant_usage_enabled'])

        usage_table = encoding.smart_str(u'''
            <tr class="" data-object-id="1" id="global_usage__row__1">
              <td class="sortable normal_column">test_tenant</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%.2f</td>
              <td class="sortable normal_column">%.2f</td>
            </tr>
            ''' % (usage_list[0].vcpus,
                   sizeformat.diskgbformat(usage_list[0].disk_gb_hours),
                   sizeformat.mbformat(usage_list[0].memory_mb),
                   usage_list[0].vcpu_hours,
                   usage_list[0].total_local_gb_usage)
        )

        # test for deleted project
        usage_table_deleted = encoding.smart_str(u'''
            <tr class="" data-object-id="3" id="global_usage__row__3">
              <td class="sortable normal_column">3 (Deleted)</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%.2f</td>
              <td class="sortable normal_column">%.2f</td>
            </tr>
            ''' % (usage_list[1].vcpus,
                   sizeformat.diskgbformat(usage_list[1].disk_gb_hours),
                   sizeformat.mbformat(usage_list[1].memory_mb),
                   usage_list[1].vcpu_hours,
                   usage_list[1].total_local_gb_usage)
        )

        if nova_stu_enabled:
            self.assertContains(res, usage_table, html=True)
            if tenant_deleted:
                self.assertContains(res, usage_table_deleted, html=True)
            else:
                self.assertNotContains(res, usage_table_deleted, html=True)
        else:
            self.assertNotContains(res, usage_table, html=True)
Example #22
0
    def _test_usage(self, nova_stu_enabled=True, tenant_deleted=False):
        self._stub_nova_api_calls(nova_stu_enabled)
        api.nova.extension_supported(
            'SimpleTenantUsage', IsA(http.HttpRequest)) \
            .AndReturn(nova_stu_enabled)
        now = timezone.now()
        usage_list = [api.nova.NovaUsage(u) for u in self.usages.list()]
        if tenant_deleted:
            api.keystone.tenant_list(IsA(http.HttpRequest)) \
                .AndReturn([[self.tenants.first()], False])
        else:
            api.keystone.tenant_list(IsA(http.HttpRequest)) \
                .AndReturn([self.tenants.list(), False])

        if nova_stu_enabled:
            api.nova.usage_list(IsA(http.HttpRequest),
                                datetime.datetime(now.year,
                                                  now.month,
                                                  1, 0, 0, 0, 0),
                                datetime.datetime(now.year,
                                                  now.month,
                                                  now.day, 23, 59, 59, 0)) \
                .AndReturn(usage_list)
        api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
            .AndReturn(self.limits['absolute'])
        api.neutron.is_extension_supported(IsA(http.HttpRequest),
                                           'security-group').AndReturn(True)
        api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
                           .AndReturn(self.floating_ips.list())
        api.network.security_group_list(IsA(http.HttpRequest)) \
                           .AndReturn(self.q_secgroups.list())
        api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)) \
                           .AndReturn(self.cinder_limits['absolute'])

        self.mox.ReplayAll()
        res = self.client.get(reverse('horizon:admin:overview:index'))
        self.assertTemplateUsed(res, 'admin/overview/usage.html')
        self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
        self.assertEqual(nova_stu_enabled,
                         res.context['simple_tenant_usage_enabled'])

        usage_table = encoding.smart_str(u'''
            <tr class="" data-object-id="1" id="global_usage__row__1">
              <td class="sortable normal_column">test_tenant</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%.2f</td>
              <td class="sortable normal_column">%.2f</td>
            </tr>
            ''' % (usage_list[0].vcpus,
                   usage_list[0].disk_gb_hours,
                   sizeformat.mbformat(usage_list[0].memory_mb),
                   usage_list[0].vcpu_hours,
                   usage_list[0].total_local_gb_usage)
        )

        # test for deleted project
        usage_table_deleted = encoding.smart_str(u'''
            <tr class="" data-object-id="3" id="global_usage__row__3">
              <td class="sortable normal_column">3 (Deleted)</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%s</td>
              <td class="sortable normal_column">%.2f</td>
              <td class="sortable normal_column">%.2f</td>
            </tr>
            ''' % (usage_list[1].vcpus,
                   usage_list[1].disk_gb_hours,
                   sizeformat.mbformat(usage_list[1].memory_mb),
                   usage_list[1].vcpu_hours,
                   usage_list[1].total_local_gb_usage)
        )

        if nova_stu_enabled:
            self.assertContains(res, usage_table, html=True)
            if tenant_deleted:
                self.assertContains(res, usage_table_deleted, html=True)
            else:
                self.assertNotContains(res, usage_table_deleted, html=True)
        else:
            self.assertNotContains(res, usage_table, html=True)