Skip to content

Commit

Permalink
remove all remaining usages of the old @quota_data mechanism
Browse files Browse the repository at this point in the history
These were partially already broken because Juno plugins do not see
@quota_data, or they are utterly superfluous because there is no action
the user can take to mitigate low quota anyway.
  • Loading branch information
majewsky committed Sep 12, 2024
1 parent 666a7e5 commit f78b9dc
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 107 deletions.
30 changes: 0 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,36 +375,6 @@ Available attributes:
- `exception_id` (default is request uuid)
- `warning` (default false. If true a warning page is rendered instead of error page)
## Display Quota Data
If the variable `@quota_data` is set the view will display all data inside this variable.
### How to set @quota_data
This will load quota data from the database and update the usage attribute.
```ruby
@quota_data = services.resource_management.quota_data(
current_user.domain_id || current_user.project_domain_id,
current_user.project_id,[
{service_type: 'compute', resource_name: 'instances', usage: @instances.length},
{service_type: 'compute', resource_name: 'cores', usage: cores},
{service_type: 'compute', resource_name: 'ram', usage: ram}
])
```
Same example but without updating the usage attribute. It just loads the values from the database. Note that the database is not always up to date.
```ruby
@quota_data = services.resource_management.quota_data(
current_user.domain_id || current_user.project_domain_id,
current_user.project_id,[
{service_type: 'compute', resource_name: 'instances'},
{service_type: 'compute', resource_name: 'cores'},
{service_type: 'compute', resource_name: 'ram'}
])
```
## Pagination
### Controller
Expand Down
5 changes: 0 additions & 5 deletions app/views/layouts/modal.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
- else
= "#{action_name.capitalize} #{controller.controller_name.singularize.humanize}"

- if @quota_data and @quota_data.length>0
.info-text
%i.monitoring-icon
= "Remaining Quota: #{@quota_data.collect(&:available_as_display_string).join(', ')}"

= yield

= yield :javascripts
24 changes: 0 additions & 24 deletions plugins/compute/app/controllers/compute/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,6 @@ def tags
end

def new
# get usage from db
@quota_data = []
if current_user.is_allowed?("access_to_project")
@quota_data =
services.resource_management.quota_data(
current_user.domain_id || current_user.project_domain_id,
current_user.project_id,
[
{ service_type: :compute, resource_name: :instances },
{ service_type: :compute, resource_name: :cores },
{ service_type: :compute, resource_name: :ram },
],
)
end

@instance = services.compute.new_server
@flavors = services.compute.flavors
@images = services.image.all_images
Expand Down Expand Up @@ -682,15 +667,6 @@ def reset_status
end

def new_snapshot
@quota_data =
services.resource_management.quota_data(
@scoped_domain_id,
@scoped_project_id,
[{ service_type: :"object-store", resource_name: :capacity }],
)
@quota = @quota_data.select { |q| q.name == :capacity }.first
@free_capa = @quota.quota - @quota.usage
@free_capa = @free_capa / 1024 / 1024
@action_from_show = params[:action_from_show] == "true" || false
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@
- if current_user.is_allowed?("compute:image_admin") && current_user.is_allowed?("object_storage:container_create")
= simple_form_for :snapshot, url: plugin('compute').create_image_instance_path(id:params[:id], action_from_show:@action_from_show), method: :put, remote: request.xhr?, html: {data: {modal: true}, class: 'form-horizontal' }, wrapper: :horizontal_form do |f|
%div{class: modal? ? 'modal-body' : ''}
- if !@quota
.alert.alert-danger
Server image snapshots are stored in your object storage. Your remaining object storage quota is not available. You can request storage
= link_to 'here', "#{plugin('resources').v2_project_path()}#/storage", {target: "_blank"}
- if @free_capa <= 5120
.alert.alert-warning
Server image snapshots are stored in your object storage. Your remaining object storage quota is low. You can request more
= link_to 'here', "#{plugin('resources').v2_project_path()}#/storage", {target: "_blank"}
= f.input :name, icon_hint: 'A snapshot is an image which preserves the disk state of a running instance.'

%div.buttons{class: modal? ? 'modal-footer' : ''}
- if modal?
%button.btn.btn-default{type:"button", data: {dismiss:"modal"}, aria: {label: "Cancel"}} Cancel
- else
= link_to "Cancel", instances_url(), class: 'btn btn-default'
- if @quota
= button_tag "Create Snapshot", { class: 'btn btn-primary pull-right', data: { disable_with: "Please wait..." } }
= button_tag "Create Snapshot", { class: 'btn btn-primary pull-right', data: { disable_with: "Please wait..." } }
- else
%div{class: modal? ? 'modal-body' : ''}
.alert.alert-info
Expand Down
4 changes: 0 additions & 4 deletions plugins/compute/spec/controllers/instances_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
allow_any_instance_of(ServiceLayer::ComputeService).to receive(
:usage,
).and_return(double("usage", instances: 1, ram: 2, cores: 4))

allow_any_instance_of(ServiceLayer::ResourceManagementService).to receive(
:quota_data,
).and_return([])
end

describe "GET 'index'" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class RoutersController < DashboardController
def index
################# NEW
@routers = []
@quota_data = []

if current_user.is_allowed?("context_is_cloud_network_admin")
@routers =
Expand Down Expand Up @@ -139,15 +138,6 @@ def show
end

def new
@quota_data = []
if current_user.is_allowed?("access_to_project")
@quota_data =
services.resource_management.quota_data(
current_user.domain_id || current_user.project_domain_id,
current_user.project_id,
[{ service_type: :network, resource_name: :routers }],
)
end
# build new router object (no api call done yet!)
@router = services.networking.new_router("admin_state_up" => true)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ def bgp_vpns
end

def security_groups
@quota_data = []
return unless current_user.is_allowed?("access_to_project")

@quota_data =
services.resource_management.quota_data(
current_user.domain_id || current_user.project_domain_id,
current_user.project_id,
[
{ service_type: :network, resource_name: :security_groups },
{ service_type: :network, resource_name: :security_group_rules },
],
)
end

def ports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
allow_any_instance_of(ServiceLayer::NetworkingService).to receive(
:elektron,
).and_return(double("elektron", service: @networking_service))

allow_any_instance_of(ServiceLayer::ResourceManagementService).to receive(
:quota_data,
).and_return([])
end

describe "GET 'index'" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
allow_any_instance_of(ServiceLayer::NetworkingService).to receive(
:elektron,
).and_return(double("elektron", service: double("network").as_null_object))

allow_any_instance_of(ServiceLayer::ResourceManagementService).to receive(
:quota_data,
).and_return([])
end

describe "GET 'index'" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
allow_any_instance_of(ServiceLayer::NetworkingService).to receive(
:networks,
).and_return []

allow_any_instance_of(ServiceLayer::ResourceManagementService).to receive(
:quota_data,
).and_return([])
end

describe "GET 'index'" do
Expand Down

0 comments on commit f78b9dc

Please sign in to comment.