def _check_tenant_bill(self, tenant_id): balance = AccountRecord.objects.filter(tenant_id=tenant_id).aggregate( Sum('amount'))['amount__sum'] if not balance: balance = 0 api.admin_api(self.request).quota_sets.update( tenant_id, instances=-int(balance / self.price_list.create_instance_price()))
def handle(self, request, data): api.admin_api(request).flavors.create(data['name'], int(data['memory_mb']), int(data['vcpus']), int(data['disk_gb']), int(data['flavorid'])) messages.success(request, '%s was successfully added to flavors.' % data['name']) return redirect('syspanel_flavors')
def handle(self, request, data): try: service = api.admin_api(request).services.get(data['service']) api.admin_api(request).services.update(data['service'], not service.disabled) if service.disabled: messages.info(request, "Service '%s' has been enabled" % data['name']) else: messages.info(request, "Service '%s' has been disabled" % data['name']) except api_exceptions.ApiException, e: messages.error(request, "Unable to update service '%s': %s" % data['name'], e.message)
def usage(request): (date_start, date_end, datetime_start, datetime_end) = _get_start_and_end_date(request) service_list = [] usage_list = [] max_vcpus = max_gigabytes = 0 if date_start > _current_month(): messages.error(request, 'No data for the selected period') date_end = date_start datetime_end = datetime_start else: try: service_list = api.admin_api(request).services.list() except api_exceptions.ApiException, e: messages.error(request, 'Unable to get service info: %s' % e.message) for service in service_list: if service.type == 'nova-compute': max_vcpus += service.stats['max_vcpus'] max_gigabytes += service.stats['max_gigabytes'] try: usage_list = api.extras_api(request).usage.list(datetime_start, datetime_end) except api_exceptions.ApiException, e: messages.error(request, 'Unable to get usage info: %s' % e.message)
def quotas(request, tenant_id): for f in (UpdateQuotas,): _, handled = f.maybe_handle(request) if handled: return handled quotas = api.admin_api(request).quota_sets.get(tenant_id) quota_set = { 'tenant_id': quotas.id, 'metadata_items': quotas.metadata_items, 'injected_file_content_bytes': quotas.injected_file_content_bytes, 'volumes': quotas.volumes, 'gigabytes': quotas.gigabytes, 'ram': int(quotas.ram) / 100, 'floating_ips': quotas.floating_ips, 'instances': quotas.instances, 'injected_files': quotas.injected_files, 'cores': quotas.cores, } form = UpdateQuotas(initial=quota_set) return render_to_response( 'syspanel_tenant_quotas.html',{ 'form': form, 'tenant_id': tenant_id, 'quotas': quotas, }, context_instance = template.RequestContext(request))
def quotas(request, tenant_id): for f in (UpdateQuotas,): _, handled = f.maybe_handle(request) if handled: return handled quotas = api.admin_api(request).quota_sets.get(tenant_id) quota_set = { "tenant_id": quotas.id, "metadata_items": quotas.metadata_items, "injected_file_content_bytes": quotas.injected_file_content_bytes, "volumes": quotas.volumes, "gigabytes": quotas.gigabytes, "ram": int(quotas.ram) / 100, "floating_ips": quotas.floating_ips, "instances": quotas.instances, "injected_files": quotas.injected_files, "cores": quotas.cores, } form = UpdateQuotas(initial=quota_set) return render_to_response( "syspanel_tenant_quotas.html", {"form": form, "tenant_id": tenant_id, "quotas": quotas}, context_instance=template.RequestContext(request), )
def quotas(request, tenant_id): for f in (UpdateQuotas, ): form, handled = f.maybe_handle(request) if handled: return handled quotas = api.admin_api(request).quota_sets.get(tenant_id) quota_set = { 'tenant_id': quotas.id, 'metadata_items': quotas.metadata_items, 'injected_file_content_bytes': quotas.injected_file_content_bytes, 'volumes': quotas.volumes, 'gigabytes': quotas.gigabytes, 'ram': int(quotas.ram), 'floating_ips': quotas.floating_ips, 'instances': quotas.instances, 'injected_files': quotas.injected_files, 'cores': quotas.cores, } form = UpdateQuotas(initial=quota_set) return render_to_response( 'django_openstack/syspanel/tenants/quotas.html', { 'form': form, 'tenant_id': tenant_id, 'quotas': quotas, }, context_instance=template.RequestContext(request))
def handle(self, request, data): try: api.admin_api(request).quota_sets.update( data["tenant_id"], metadata_items=data["metadata_items"], injected_file_content_bytes=data["injected_file_content_bytes"], volumes=data["volumes"], gigabytes=data["gigabytes"], ram=int(data["ram"]) * 100, floating_ips=data["floating_ips"], instances=data["instances"], injected_files=data["injected_files"], cores=data["cores"], ) messages.success(request, "Quotas for %s were successfully updated." % data["tenant_id"]) except api_exceptions.ApiException, e: messages.error(request, "Unable to update quotas: %s" % e.message)
def index(request): quotas = api.admin_api(request).quota_sets.get(True)._info quotas['ram'] = int(quotas['ram']) / 100 quotas.pop('id') return render_to_response('syspanel_quotas.html',{ 'quotas': quotas, }, context_instance = template.RequestContext(request))
def handle(self, request, data): try: api.admin_api(request).quota_sets.update(data['tenant_id'], metadata_items=data['metadata_items'], injected_file_content_bytes=data['injected_file_content_bytes'], volumes=data['volumes'], gigabytes=data['gigabytes'], ram=int(data['ram']) * 100, floating_ips=data['floating_ips'], instances=data['instances'], injected_files=data['injected_files'], cores=data['cores'], ) messages.success(request, 'Quotas for %s were successfully updated.' % data['tenant_id']) except api_exceptions.ApiException, e: messages.error(request, 'Unable to update quotas: %s' % e.message)
def index(request): for f in (ToggleService,): _, handled = f.maybe_handle(request) if handled: return handled services = [] try: services = api.admin_api(request).services.list() except api_exceptions.ApiException, e: messages.error(request, 'Unable to get service info: %s' % e.message)
def test_get_admin_api(self): self.mox.StubOutClassWithMocks(OSAdmin, "Admin") OSAdmin.Admin(auth_token=TEST_TOKEN, management_url=TEST_URL) self.mox.StubOutWithMock(api, "url_for") api.url_for(IsA(http.HttpRequest), "nova", True).AndReturn(TEST_URL) api.url_for(IsA(http.HttpRequest), "nova", True).AndReturn(TEST_URL) self.mox.ReplayAll() self.assertIsNotNone(api.admin_api(self.request)) self.mox.VerifyAll()
def index(request): for f in (DeleteFlavor,): _, handled = f.maybe_handle(request) if handled: return handled # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above delete_form = DeleteFlavor() flavors = [] try: flavors = api.admin_api(request).flavors.list() except api_exceptions.ApiException, e: messages.error(request, 'Unable to get usage info: %s' % e.message)
def stub_admin_api(self, count=1): self.mox.StubOutWithMock(api, "admin_api") admin_api = self.mox.CreateMock(OSAdmin.Admin) for i in range(count): api.admin_api(IsA(http.HttpRequest)).AndReturn(admin_api) return admin_api
def handle(self, request, data): flavor_id = data['flavorid'] api.admin_api(request).flavors.delete(flavor_id, True) return redirect(request.build_absolute_uri())
def _check_tenant_bill(self,tenant_id): balance = AccountRecord.objects.filter(tenant_id=tenant_id).aggregate(Sum('amount'))['amount__sum'] if not balance: balance = 0 api.admin_api(self.request).quota_sets.update(tenant_id, instances=-int(balance/self.price_list.create_instance_price()))
def _check_tenant_bill(self,tenant_id): balance = AccountRecord.objects.filter(tenant_id=tenant_id).aggregate(Sum('amount'))['amount__sum'] if not balance: balance = 0 api.admin_api(self.request).quota_sets.update(tenant_id, instances=-int(balance/PriceList.CREATE_INSTANCE))