Skip to content

Commit

Permalink
dns_service: remove dysfunctional quota management code
Browse files Browse the repository at this point in the history
This stopped doing anything useful when quota editing was removed from
Limes back in May.
  • Loading branch information
majewsky committed Sep 12, 2024
1 parent 7ed4acc commit 9b30a29
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 154 deletions.
120 changes: 0 additions & 120 deletions plugins/dns_service/app/controllers/concerns/create_zones_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ def create_zone(zone_name,attributes, domain_id, project_id)
zone.errors.add("Error", "Zone already existing")
return zone
else
adjust_resource_limits(
domain_id, project_id, target_project&.domain_id, target_project&.id
)

pool = cloud_admin.dns_service.find_pool(attributes[:domain_pool])
pool_attrs = pool.read("attributes")
zone = services.dns_service.new_zone(attributes)
Expand Down Expand Up @@ -72,45 +68,6 @@ def find_parent_zone_project(zone_name, source_project_id)
requested_parent_zone_name = requested_parent_zone_name.partition(".").last
end
end

# this method checks the zone and recordset limits of the project
# and increases them if needed.
# If target project is different from this project, the zone has
# to be created in the target project and then transferred to this project.
# For this, the limitis for zone of target project and this project should be checked
# and increased if needed. Additionally, the recordset limits of this project
# should be checked and increased if needed.
def adjust_resource_limits(
source_domain_id,
source_project_id,
target_domain_id,
target_project_id)
# first, get the latests state of the limes data for this project
update_limes_data(source_domain_id,source_project_id)

# update zone limits for this project if needed
check_and_increase_quota(
source_domain_id,
source_project_id,
"zones",
2
)
# update recordset limits for this project if needed
check_and_increase_quota(
source_domain_id,
source_project_id,
"recordsets",
2,
)

# update zone limits for destination project if needed
if target_project_id.present? && (target_project_id != source_project_id)
# first, get the latests state of the limes data for target project
update_limes_data(target_domain_id, target_project_id)
# check and increase zone quota for destination project
check_and_increase_quota(target_domain_id, target_project_id, "zones")
end
end

def transfer_zone_if_needed(zone, source_project_id, target_project_id)
if target_project_id != source_project_id
Expand All @@ -134,81 +91,4 @@ def transfer_zone_if_needed(zone, source_project_id, target_project_id)
return zone_transfer_request.errors
end
end

def check_and_increase_quota(domain_id, project_id, resource, increase = 1)
# get dns quota for resource and target project
dns_resource =
cloud_admin
.resource_management
.find_project(domain_id, project_id, service: "dns", resource: resource)
.resources
.first or raise ActiveRecord::RecordNotFound

# NOTE: dns_resource.usable_quota is quota + burst
if dns_resource.quota == 0 || dns_resource.quota <= dns_resource.usage
if dns_resource.quota < dns_resource.usage
puts "INFO: for project #{project_id} in domain #{domain_id} the usable quota is smaller than usage! Set quota for resource #{resource} to #{dns_resource.usage + increase}"
# special case if usable quota is smaller than usage than adjust new quota to usage plus increase value
dns_resource.quota = dns_resource.usage + increase
else
puts "INFO: increase quota for project #{project_id} in domain #{domain_id} for resource #{resource} by #{increase}"
# standard increase quota plus increase value
dns_resource.quota += increase
end
unless dns_resource.save
# catch error for automatic quota adjustment
dns_resource.errors.each { |k, m| @zone_request.errors.add(k, m) }
else
puts "INFO: wait 3s to be sure that limes could set the quota correctly"
sleep 3
end
end
end

def update_limes_data(domain_id, project_id)
# get last scraped time
current_timestamp = Time.now.to_i
# update limes data synchronously
cloud_admin.resource_management.sync_project_asynchronously(
domain_id,
project_id,
)

scraped_at = current_timestamp
retry_count = 1
while scraped_at.to_i <= current_timestamp && retry_count <= 10
puts "INFO: update limes data for project #{project_id} in domain #{domain_id}, wait 2s to check that update is done"
sleep 3
scraped_at =
begin
cloud_admin
.resource_management
.find_project(domain_id, project_id, service: "dns", resource: "zones")
.services
.first
.scraped_at
rescue StandardError
0
end
puts "INFO: check limes update. retry_count: #{retry_count}; scraped_at_old: #{current_timestamp}; scraped_at_new: #{scraped_at.to_i}"
retry_count += 1
end
end

def get_zone_resource
cloud_admin
.resource_management
.find_project(@scoped_domain_id, @scoped_project_id, service: "dns", resource: "zones",)
.resources
.first or raise ActiveRecord::RecordNotFound
end

def get_recordset_resource
@recordset_resource =
cloud_admin
.resource_management
.find_project(@scoped_domain_id, @scoped_project_id, service: "dns", resource: "recordsets")
.resources
.first or raise ActiveRecord::RecordNotFound
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,6 @@ def new
payload = @inquiry.payload
@zone_request.attributes = payload
@pool = load_pool(@zone_request.domain_pool)

if @inquiry
scraped_at =
begin
cloud_admin
.resource_management
.find_project(
@inquiry.domain_id,
@inquiry.project_id,
service: "dns",
resource: "zones",
)
.services
.first
.scraped_at
rescue StandardError
0
end

# sync if last sync was more than 5 minutes ago
if (Time.now.to_i - scraped_at.to_i) > 300
Thread.new do
cloud_admin.resource_management.sync_project_asynchronously(
@inquiry.domain_id,
@inquiry.project_id,
)
end
end
end
end

def create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ def new
@zone_request = ::DnsService::ZoneRequest.new(nil)
@pools = cloud_admin.dns_service.pools[:items]

@zone_resource = get_zone_resource
@recordset_resource = get_recordset_resource

# this needs to be removed when migration is done
@pools.reject! do |pool|
pool.attributes["attributes"]["label"] == "New External SAP Hosted Zone"
Expand Down Expand Up @@ -66,8 +63,6 @@ def create
render template: "dns_service/request_zone_wizard/create", formats: :js
else
@pools = cloud_admin.dns_service.pools[:items]
@zone_resource = get_zone_resource
@recordset_resource = get_recordset_resource
render action: :new
end
end
Expand Down

0 comments on commit 9b30a29

Please sign in to comment.