From 94f08347682953e7bf55823bac950755c5f1bdc2 Mon Sep 17 00:00:00 2001 From: william fitzgerald Date: Tue, 15 Nov 2016 15:30:42 -0500 Subject: [PATCH] Automate - Remove old Quota classes and Instances. Remove 3 old classes, instances and methods: Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification https://www.pivotaltracker.com/story/show/134385127 --- .../Provisioning/Profile.class/__class__.yaml | 2 +- .../__class__.yaml | 153 --------- .../__methods__/rejected.rb | 7 - .../__methods__/rejected.yaml | 32 -- .../__methods__/validate_quotas.rb | 318 ------------------ .../__methods__/validate_quotas.yaml | 12 - .../default.yaml | 10 - .../Provisioning/Profile.class/__class__.yaml | 10 +- .../__class__.yaml | 33 -- .../__methods__/rejected.rb | 7 - .../__methods__/rejected.yaml | 32 -- .../__methods__/validate_quotas.rb | 1 - .../__methods__/validate_quotas.yaml | 12 - .../default.yaml | 10 - .../Provisioning/Profile.class/__class__.yaml | 2 +- .../__class__.yaml | 153 --------- .../__methods__/rejected.rb | 7 - .../__methods__/rejected.yaml | 32 -- .../__methods__/validate_quotas.rb | 318 ------------------ .../__methods__/validate_quotas.yaml | 12 - .../default.yaml | 10 - ...isionconfiguredsystemrequest_starting.yaml | 4 +- 22 files changed, 8 insertions(+), 1169 deletions(-) delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml delete mode 100644 db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/Profile.class/__class__.yaml b/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/Profile.class/__class__.yaml index c2c95384b8e..7f1e5175684 100644 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/Profile.class/__class__.yaml +++ b/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/Profile.class/__class__.yaml @@ -138,7 +138,7 @@ object: datatype: string priority: 7 owner: - default_value: ProvisionRequestQuotaVerification + default_value: substitute: true message: get_quota_state_machine visibility: diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml b/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml deleted file mode 100644 index 0289d4f745d..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml +++ /dev/null @@ -1,153 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: Factory State Machines - display_name: - name: ProvisionRequestQuotaVerification - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: attribute - name: max_owner_cpu - display_name: Owner - Max CPUs Allowed - datatype: string - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_owner_memory - display_name: Owner - Max Memory Allowed (MB) - datatype: string - priority: 2 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_owner_storage - display_name: Owner - Max Storage Allowed (GB) - datatype: string - priority: 3 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_group_cpu - display_name: Group - Max CPUs Allowed - datatype: string - priority: 4 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_group_memory - display_name: Group - Max Memory Allowed (MB) - datatype: string - priority: 5 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_group_storage - display_name: Group - Max Storage Allowed (GB) - datatype: string - priority: 6 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: state - name: ValidateQuotas - display_name: - datatype: string - priority: 7 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: validate_quotas - on_exit: - on_error: rejected - max_retries: '100' - max_time: diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb b/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb deleted file mode 100644 index 8244358b021..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb +++ /dev/null @@ -1,7 +0,0 @@ -# -# Description: This method runs when the provision request quota validation has failed -# - -# Deny the request -$evm.log('info', "Request denied because of Quota") -$evm.root["miq_request"].deny("admin", "Quota Exceeded") diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml b/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml deleted file mode 100644 index b8b506b427a..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: rejected - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: - - field: - aetype: - name: reason - display_name: - datatype: string - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb b/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb deleted file mode 100644 index 0a4ebc65d21..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb +++ /dev/null @@ -1,318 +0,0 @@ -# -# Description: This method validates the group or owner quotas using the values -# [max_group_cpu, max_group_memory, max_group_storage, max_owner_cpu, max_owner_memory, max_owner_storage] -# from values in the following order: -# 1. In the model -# 2. Group tags - This looks at the Group for the following -# tag values: [quota_max_cpu, quota_max_memory, quota_max_storage] -# 2a. Owner tags - This looks at the User for the following -# tag values: [quota_max_cpu, quota_max_memory, quota_max_storage] -# - -$evm.log("warn", "[DEPRECATION] validate_quotas method will be deprecated. Please use consolidated quota instead.") - -# Initialize Variables -quota_exceeded = false -miq_request = $evm.root['miq_request'] -miq_provision_request = miq_request.resource -user = miq_request.requester -group = user.current_group - -# Specify whether quotas should be managed by group or user -manage_quotas_by_group = true - -# Extract Request Information -vms_in_request = miq_provision_request.get_option(:number_of_vms).to_i -cpu_in_request = miq_provision_request.get_option(:number_of_cpus).to_i -if cpu_in_request.zero? - cpu_in_request = miq_provision_request.get_option(:number_of_sockets).to_i * miq_provision_request.get_option(:cores_per_socket).to_i -end -memory_in_request = miq_provision_request.get_option(:vm_memory).to_i - -# Calculate total CPU based on number of VMs in request -total_cpu_in_request = vms_in_request * cpu_in_request -$evm.log("info", "Total Requested Provisioning vCPUs: #{total_cpu_in_request}") - -# Calculate total Memory based on number of VMs in request -total_memory_in_request = vms_in_request * memory_in_request -total_memory_nice = "%.2fGB" % (total_memory_in_request / 1024) -$evm.log("info", "Total Requested Provisioning Memory: #{total_memory_nice}") - -# Calculate total Storage based on number of VMs in request -vm_size = miq_provision_request.vm_template.provisioned_storage -total_storage_nice = "%.2fGB" % (vm_size * vms_in_request / 1024**3) -$evm.log("info", "Total Requested Provisioning Storage: #{total_storage_nice}") - -if manage_quotas_by_group - # Available check_quota methods [:vms_by_group, :vms_by_owner_and_group] - quota_group = miq_provision_request.check_quota(:vms_by_group, :include_retired_vms => false) - $evm.log("info", "Inspecting quota_group:<#{quota_group.inspect}>") - - ########################## - # - # Group CPU Quota Check - # - ########################## - $evm.log("info", "Beginning Group CPU Quota Check") - $evm.log("info", "Group: <#{group.description}> current CPU usage: <#{quota_group[:cpu]}>") - - max_group_cpu = nil - g_quota_exceeded_reason1 = nil - - # Use value from model unless specified above - max_group_cpu ||= $evm.object['max_group_cpu'] - unless max_group_cpu.nil? - $evm.log("info", "Found quota from model with value <#{max_group_cpu}>") - end - - # Get tag from Group - tag_max_group_cpu = group.tags(:quota_max_cpu).first - unless tag_max_group_cpu.nil? - $evm.log("info", "Found quota from Group <#{group.description}> tag <:quota_max_cpu> with value <#{tag_max_group_cpu}>") - end - - # If group is tagged then override - unless tag_max_group_cpu.nil? - max_group_cpu = tag_max_group_cpu.to_i - $evm.log("info", "Overriding quota from Group <#{group.description}> tag <:quota_max_cpu> with value <#{tag_max_group_cpu}>") - end - - # Validate Group CPU Quota - unless max_group_cpu.blank? - if quota_group && (quota_group[:cpu] + total_cpu_in_request > max_group_cpu.to_i) - $evm.log("info", "CPUs allocated for Group <#{quota_group[:cpu]}> + Requested CPUs <#{total_cpu_in_request}> exceeds Quota Max CPUs <#{max_group_cpu}>") - quota_exceeded = true - g_total_vcpus = quota_group[:cpu] - g_quota_exceeded_reason1 = "Group Allocated vCPUs #{g_total_vcpus} + Requested #{total_cpu_in_request} > Quota #{max_group_cpu}" - end - end - - ########################## - # - # Group Memory Quota Check - # - ########################## - $evm.log("info", "Beginning Group Memory Quota Check") - $evm.log("info", "Group: <#{group.description}> current Memory usage: <#{quota_group[:memory]}>") - - max_group_memory = nil - g_quota_exceeded_reason2 = nil - - # Use value from model unless specified above - max_group_memory ||= $evm.object['max_group_memory'] - unless max_group_memory.nil? - $evm.log("info", "Found quota from model with value:<#{max_group_memory}>") - end - - # Get tag from Group - tag_max_group_memory = group.tags(:quota_max_memory).first - unless tag_max_group_memory.nil? - $evm.log("info", "Found quota from group <#{group.description}> tag with value <#{tag_max_group_memory}>") - end - - # If group is tagged then override - unless tag_max_group_memory.nil? - max_group_memory = tag_max_group_memory.to_i - $evm.log("info", "Overriding quota from group <#{group.description}> tag with value <#{tag_max_group_memory}>") - end - - # Validate Group Memory Quota - unless max_group_memory.blank? - if quota_group && (quota_group[:memory] + total_memory_in_request > max_group_memory.to_i) - $evm.log("info", "Memory allocated for Group <#{quota_group[:memory]}> + Requested Memory <#{total_memory_in_request}> exceeds Quota Max <#{max_group_memory}>") - quota_exceeded = true - g_mem_total_nice = "%.2fGB" % (quota_group[:memory] / 1024) - g_mem_quota_nice = "%.2fGB" % (max_group_memory.to_i / 1024) - g_quota_exceeded_reason2 = "Group Allocated Memory #{g_mem_total_nice} + Requested #{total_memory_nice} > Quota #{g_mem_quota_nice}" - end - end - - ########################## - # - # Group Storage Quota Check - # - ########################## - $evm.log("info", "Beginning Group Storage Quota Check") - $evm.log("info", "Group: <#{group.description}> current Storage usage: <#{quota_group[:allocated_storage]}>") - - max_group_storage = nil - g_quota_exceeded_reason3 = nil - - # Use value from model unless specified above - max_group_storage ||= $evm.object['max_group_storage'] - unless max_group_storage.nil? - $evm.log("info", "Found quota from model with value:<#{max_group_storage}GB>") - end - - # Get tag from Group - tag_max_group_storage = group.tags(:quota_max_storage).first - unless tag_max_group_storage.nil? - $evm.log("info", "Found quota from group <#{group.description}> tag with value <#{tag_max_group_storage}>") - end - - # If group is tagged then override - unless tag_max_group_storage.nil? - max_group_storage = tag_max_group_storage.to_i - $evm.log("info", "Overriding quota from Group <#{group.description}> tag with value <#{tag_max_group_storage}GB> or <#{tag_max_group_storage.to_i * (1024**3)} bytes>") - end - - # Validate Group Storage Quota - unless max_group_storage.blank? - max_group_storage = max_group_storage.to_i - if quota_group && (quota_group[:allocated_storage] + vm_size > max_group_storage.to_i * (1024**3)) - $evm.log("info", "Storage allocated for Group <#{quota_group[:allocated_storage]}> + Requested Storage <#{vm_size}> exceeds Quota Max <#{max_group_storage}>") - quota_exceeded = true - g_stor_total_nice = "%.2fGB" % (quota_group[:allocated_storage] / 1024**3) - g_stor_quota_nice = "%.2fGB" % (max_group_storage) - g_quota_exceeded_reason3 = "Group Allocated Storage #{g_stor_total_nice} + Requested #{total_storage_nice} > Quota #{g_stor_quota_nice}" - end - end - -else - # Available check_quota methods [:vms_by_owner, :vms_by_owner_and_group] - quota_owner = miq_provision_request.check_quota(:vms_by_owner, :include_retired_vms => false) - $evm.log("info", "Inspecting quota_owner:<#{quota_owner.inspect}>") - - ########################## - # - # Owner CPU Quota Check - # - ########################## - $evm.log("info", "Beginning Owner CPU Quota Check") - $evm.log("info", "Owner: <#{user.name}> current CPU usage: <#{quota_owner[:cpu]}>") - - max_owner_cpu = nil - o_quota_exceeded_reason1 = nil - - # Use value from model unless specified above - max_owner_cpu ||= $evm.object['max_owner_cpu'] - unless max_owner_cpu.nil? - $evm.log("info", "Found quota from model with value:<#{max_owner_cpu}>") - end - - # Get tag from Owner - tag_max_owner_cpu = user.tags(:quota_max_cpu).first - unless tag_max_owner_cpu.nil? - $evm.log("info", "Found quota from user <#{user.name}> tag with value <#{tag_max_owner_cpu}>>") - end - - # If owner is tagged then override - unless tag_max_owner_cpu.nil? - max_owner_cpu = tag_max_owner_cpu.to_i - $evm.log("info", "Overriding quota from User <#{user.name}> tag with value <#{tag_max_owner_cpu}>") - end - - # Validate Owner CPU Quota - unless max_owner_cpu.blank? - if quota_owner && (quota_owner[:cpu] + total_cpu_in_request > max_owner_cpu.to_i) - $evm.log("info", "CPUs allocated for Owner <#{quota_owner[:cpu]}> + Requested CPUs <#{total_cpu_in_request}> exceeds Quota Max <#{max_owner_cpu}>") - quota_exceeded = true - o_total_vcpus = quota_owner[:cpu] - o_quota_exceeded_reason1 = "Owner Allocated vCPUs #{o_total_vcpus} + Requested #{total_cpu_in_request} > Quota #{max_owner_cpu}" - end - end - - ########################## - # - # Owner Memory Quota Check - # - ########################## - $evm.log("info", "Beginning Owner Memory Quota Check") - $evm.log("info", "Owner: <#{user.name}> current Memory usage: <#{quota_owner[:memory]}>") - - max_owner_memory = nil - o_quota_exceeded_reason2 = nil - - # Use value from model unless specified above - max_owner_memory ||= $evm.object['max_owner_memory'] - unless max_owner_memory.nil? - $evm.log("info", "Found quota from model with value:<#{max_owner_memory}>") - end - - # Get tag from Owner - tag_max_owner_memory = user.tags(:quota_max_memory).first - unless tag_max_owner_memory.nil? - $evm.log("info", "Found quota from user <#{user.name}> tag with value <#{tag_max_owner_memory}>") - end - - # If owner is tagged then override - unless tag_max_owner_memory.nil? - max_owner_memory = tag_max_owner_memory.to_i - $evm.log("info", "Overriding quota from User <#{user.name}> tag with value <#{tag_max_owner_memory}>") - end - - # Validate Owner Memory Quota - unless max_owner_memory.blank? - if quota_owner && (quota_owner[:memory] + total_memory_in_request > max_owner_memory.to_i) - $evm.log("info", "Memory allocated for Owner <#{quota_owner[:memory]}> + Requested Memory <#{total_memory_in_request}> exceeds Quota Max <#{max_owner_memory}>") - quota_exceeded = true - o_mem_total_nice = "%.2fGB" % (quota_owner[:memory] / 1024) - o_mem_quota_nice = "%.2fGB" % (max_owner_memory.to_i / 1024) - o_quota_exceeded_reason2 = "Owner Allocated Memory #{o_mem_total_nice} + Requested #{total_memory_nice} > Quota #{o_mem_quota_nice}" - end - end - - ########################## - # - # Owner Storage Quota Check - # - ########################## - $evm.log("info", "Beginning Owner Storage Quota Check") - $evm.log("info", "Owner: <#{user.name}> current Storage usage: <#{quota_owner[:allocated_storage]}>") - - max_owner_storage = nil - o_quota_exceeded_reason3 = nil - - # Use value from model unless specified above - max_owner_storage ||= $evm.object['max_owner_storage'] - unless max_owner_storage.nil? - $evm.log("info", "Found quota from model with value:<#{max_owner_storage}GB>") - end - - # Get tag from Owner - tag_max_owner_storage = user.tags(:quota_max_storage).first - unless tag_max_owner_storage.nil? - $evm.log("info", "Found quota from user <#{user.name}> tag with value <#{tag_max_owner_storage}GB> or <#{tag_max_group_storage * (1024**3)} bytes>") - end - - # If owner is tagged then override - unless tag_max_owner_storage.nil? - max_owner_storage = tag_max_owner_storage.to_i - $evm.log("info", "Overriding quota from User <#{user.name}> tag with value <#{tag_max_owner_storage}GB>") - end - - # Validate Owner Storage Quota - unless max_owner_storage.blank? - max_owner_storage = max_owner_storage.to_i - if quota_owner && (quota_owner[:allocated_storage] + vm_size > max_owner_storage.to_i * (1024**3)) - $evm.log("info", "Storage allocated for Owner <#{quota_owner[:allocated_storage]}> + Requested Storage <#{vm_size}> exceeds Quota Max <#{max_owner_storage}>") - quota_exceeded = true - o_stor_total_nice = "%.2fGB" % (quota_owner[:allocated_storage] / 1024**3) - o_stor_quota_nice = "%.2fGB" % (max_owner_storage) - o_quota_exceeded_reason3 = "Owner Allocated Storage #{o_stor_total_nice} + Requested #{total_storage_nice} > Quota #{o_stor_quota_nice}" - end - end -end - -########################## -# -# Quota Exceeded Check -# -########################## -if quota_exceeded == true - msg = "" - # msg += "VMs cannot be provisioned at this time due to the following quota limits: " - msg += "Request denied due to the following quota limits:" - msg += "(#{g_quota_exceeded_reason1}) " unless g_quota_exceeded_reason1.nil? - msg += "(#{g_quota_exceeded_reason2}) " unless g_quota_exceeded_reason2.nil? - msg += "(#{g_quota_exceeded_reason3})" unless g_quota_exceeded_reason3.nil? - msg += "(#{o_quota_exceeded_reason1}) " unless o_quota_exceeded_reason1.nil? - msg += "(#{o_quota_exceeded_reason2}) " unless o_quota_exceeded_reason2.nil? - msg += "(#{o_quota_exceeded_reason3})" unless o_quota_exceeded_reason3.nil? - $evm.log("info", "Inspecting Messge:<#{msg}>") - - miq_provision_request.set_message(msg) - - $evm.root['ae_result'] = 'error' - $evm.object['reason'] = msg -end diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml b/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml deleted file mode 100644 index 05f091e227a..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: validate_quotas - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: [] diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml b/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml deleted file mode 100644 index 44a0f3647fe..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: - name: Default - inherits: - description: - fields: [] diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/Profile.class/__class__.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/Profile.class/__class__.yaml index 5c4a328b2f8..4e8d8627376 100644 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/Profile.class/__class__.yaml +++ b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/Profile.class/__class__.yaml @@ -16,7 +16,7 @@ object: name: get_dialog_name display_name: datatype: string - priority: 4 + priority: 1 owner: default_value: substitute: true @@ -36,7 +36,7 @@ object: name: dialog_name display_name: datatype: string - priority: 6 + priority: 2 owner: default_value: miq_provision_configured_system_foreman_dialogs substitute: true @@ -56,7 +56,7 @@ object: name: auto_approval_state_machine display_name: datatype: string - priority: 7 + priority: 3 owner: default_value: ProvisionRequestApproval substitute: true @@ -76,7 +76,7 @@ object: name: quota_state_machine display_name: datatype: string - priority: 8 + priority: 4 owner: default_value: ProvisionRequestQuotaVerification substitute: true @@ -96,7 +96,7 @@ object: name: state_machine display_name: datatype: string - priority: 9 + priority: 5 owner: default_value: Provision substitute: true diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml deleted file mode 100644 index d155e28bb25..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: Factory State Machines - display_name: - name: ProvisionRequestQuotaVerification - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: state - name: ValidateQuotas - display_name: - datatype: string - priority: 7 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: validate_quotas - on_exit: - on_error: rejected - max_retries: '100' - max_time: diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb deleted file mode 100644 index 8244358b021..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb +++ /dev/null @@ -1,7 +0,0 @@ -# -# Description: This method runs when the provision request quota validation has failed -# - -# Deny the request -$evm.log('info', "Request denied because of Quota") -$evm.root["miq_request"].deny("admin", "Quota Exceeded") diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml deleted file mode 100644 index b8b506b427a..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: rejected - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: - - field: - aetype: - name: reason - display_name: - datatype: string - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb deleted file mode 100644 index 8b137891791..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb +++ /dev/null @@ -1 +0,0 @@ - diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml deleted file mode 100644 index 05f091e227a..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: validate_quotas - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: [] diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml deleted file mode 100644 index d0814f0cfbd..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/Configured_System/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: Default - name: Default - inherits: - description: - fields: [] diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/Profile.class/__class__.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/Profile.class/__class__.yaml index 285451c5f1c..a836db95077 100644 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/Profile.class/__class__.yaml +++ b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/Profile.class/__class__.yaml @@ -158,7 +158,7 @@ object: datatype: string priority: 8 owner: - default_value: ProvisionRequestQuotaVerification + default_value: substitute: true message: get_quota_state_machine visibility: diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml deleted file mode 100644 index 0289d4f745d..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__class__.yaml +++ /dev/null @@ -1,153 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: Factory State Machines - display_name: - name: ProvisionRequestQuotaVerification - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: attribute - name: max_owner_cpu - display_name: Owner - Max CPUs Allowed - datatype: string - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_owner_memory - display_name: Owner - Max Memory Allowed (MB) - datatype: string - priority: 2 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_owner_storage - display_name: Owner - Max Storage Allowed (GB) - datatype: string - priority: 3 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_group_cpu - display_name: Group - Max CPUs Allowed - datatype: string - priority: 4 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_group_memory - display_name: Group - Max Memory Allowed (MB) - datatype: string - priority: 5 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: max_group_storage - display_name: Group - Max Storage Allowed (GB) - datatype: string - priority: 6 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: state - name: ValidateQuotas - display_name: - datatype: string - priority: 7 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: validate_quotas - on_exit: - on_error: rejected - max_retries: '100' - max_time: diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb deleted file mode 100644 index 8244358b021..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.rb +++ /dev/null @@ -1,7 +0,0 @@ -# -# Description: This method runs when the provision request quota validation has failed -# - -# Deny the request -$evm.log('info', "Request denied because of Quota") -$evm.root["miq_request"].deny("admin", "Quota Exceeded") diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml deleted file mode 100644 index b8b506b427a..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/rejected.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: rejected - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: - - field: - aetype: - name: reason - display_name: - datatype: string - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb deleted file mode 100644 index 0a4ebc65d21..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.rb +++ /dev/null @@ -1,318 +0,0 @@ -# -# Description: This method validates the group or owner quotas using the values -# [max_group_cpu, max_group_memory, max_group_storage, max_owner_cpu, max_owner_memory, max_owner_storage] -# from values in the following order: -# 1. In the model -# 2. Group tags - This looks at the Group for the following -# tag values: [quota_max_cpu, quota_max_memory, quota_max_storage] -# 2a. Owner tags - This looks at the User for the following -# tag values: [quota_max_cpu, quota_max_memory, quota_max_storage] -# - -$evm.log("warn", "[DEPRECATION] validate_quotas method will be deprecated. Please use consolidated quota instead.") - -# Initialize Variables -quota_exceeded = false -miq_request = $evm.root['miq_request'] -miq_provision_request = miq_request.resource -user = miq_request.requester -group = user.current_group - -# Specify whether quotas should be managed by group or user -manage_quotas_by_group = true - -# Extract Request Information -vms_in_request = miq_provision_request.get_option(:number_of_vms).to_i -cpu_in_request = miq_provision_request.get_option(:number_of_cpus).to_i -if cpu_in_request.zero? - cpu_in_request = miq_provision_request.get_option(:number_of_sockets).to_i * miq_provision_request.get_option(:cores_per_socket).to_i -end -memory_in_request = miq_provision_request.get_option(:vm_memory).to_i - -# Calculate total CPU based on number of VMs in request -total_cpu_in_request = vms_in_request * cpu_in_request -$evm.log("info", "Total Requested Provisioning vCPUs: #{total_cpu_in_request}") - -# Calculate total Memory based on number of VMs in request -total_memory_in_request = vms_in_request * memory_in_request -total_memory_nice = "%.2fGB" % (total_memory_in_request / 1024) -$evm.log("info", "Total Requested Provisioning Memory: #{total_memory_nice}") - -# Calculate total Storage based on number of VMs in request -vm_size = miq_provision_request.vm_template.provisioned_storage -total_storage_nice = "%.2fGB" % (vm_size * vms_in_request / 1024**3) -$evm.log("info", "Total Requested Provisioning Storage: #{total_storage_nice}") - -if manage_quotas_by_group - # Available check_quota methods [:vms_by_group, :vms_by_owner_and_group] - quota_group = miq_provision_request.check_quota(:vms_by_group, :include_retired_vms => false) - $evm.log("info", "Inspecting quota_group:<#{quota_group.inspect}>") - - ########################## - # - # Group CPU Quota Check - # - ########################## - $evm.log("info", "Beginning Group CPU Quota Check") - $evm.log("info", "Group: <#{group.description}> current CPU usage: <#{quota_group[:cpu]}>") - - max_group_cpu = nil - g_quota_exceeded_reason1 = nil - - # Use value from model unless specified above - max_group_cpu ||= $evm.object['max_group_cpu'] - unless max_group_cpu.nil? - $evm.log("info", "Found quota from model with value <#{max_group_cpu}>") - end - - # Get tag from Group - tag_max_group_cpu = group.tags(:quota_max_cpu).first - unless tag_max_group_cpu.nil? - $evm.log("info", "Found quota from Group <#{group.description}> tag <:quota_max_cpu> with value <#{tag_max_group_cpu}>") - end - - # If group is tagged then override - unless tag_max_group_cpu.nil? - max_group_cpu = tag_max_group_cpu.to_i - $evm.log("info", "Overriding quota from Group <#{group.description}> tag <:quota_max_cpu> with value <#{tag_max_group_cpu}>") - end - - # Validate Group CPU Quota - unless max_group_cpu.blank? - if quota_group && (quota_group[:cpu] + total_cpu_in_request > max_group_cpu.to_i) - $evm.log("info", "CPUs allocated for Group <#{quota_group[:cpu]}> + Requested CPUs <#{total_cpu_in_request}> exceeds Quota Max CPUs <#{max_group_cpu}>") - quota_exceeded = true - g_total_vcpus = quota_group[:cpu] - g_quota_exceeded_reason1 = "Group Allocated vCPUs #{g_total_vcpus} + Requested #{total_cpu_in_request} > Quota #{max_group_cpu}" - end - end - - ########################## - # - # Group Memory Quota Check - # - ########################## - $evm.log("info", "Beginning Group Memory Quota Check") - $evm.log("info", "Group: <#{group.description}> current Memory usage: <#{quota_group[:memory]}>") - - max_group_memory = nil - g_quota_exceeded_reason2 = nil - - # Use value from model unless specified above - max_group_memory ||= $evm.object['max_group_memory'] - unless max_group_memory.nil? - $evm.log("info", "Found quota from model with value:<#{max_group_memory}>") - end - - # Get tag from Group - tag_max_group_memory = group.tags(:quota_max_memory).first - unless tag_max_group_memory.nil? - $evm.log("info", "Found quota from group <#{group.description}> tag with value <#{tag_max_group_memory}>") - end - - # If group is tagged then override - unless tag_max_group_memory.nil? - max_group_memory = tag_max_group_memory.to_i - $evm.log("info", "Overriding quota from group <#{group.description}> tag with value <#{tag_max_group_memory}>") - end - - # Validate Group Memory Quota - unless max_group_memory.blank? - if quota_group && (quota_group[:memory] + total_memory_in_request > max_group_memory.to_i) - $evm.log("info", "Memory allocated for Group <#{quota_group[:memory]}> + Requested Memory <#{total_memory_in_request}> exceeds Quota Max <#{max_group_memory}>") - quota_exceeded = true - g_mem_total_nice = "%.2fGB" % (quota_group[:memory] / 1024) - g_mem_quota_nice = "%.2fGB" % (max_group_memory.to_i / 1024) - g_quota_exceeded_reason2 = "Group Allocated Memory #{g_mem_total_nice} + Requested #{total_memory_nice} > Quota #{g_mem_quota_nice}" - end - end - - ########################## - # - # Group Storage Quota Check - # - ########################## - $evm.log("info", "Beginning Group Storage Quota Check") - $evm.log("info", "Group: <#{group.description}> current Storage usage: <#{quota_group[:allocated_storage]}>") - - max_group_storage = nil - g_quota_exceeded_reason3 = nil - - # Use value from model unless specified above - max_group_storage ||= $evm.object['max_group_storage'] - unless max_group_storage.nil? - $evm.log("info", "Found quota from model with value:<#{max_group_storage}GB>") - end - - # Get tag from Group - tag_max_group_storage = group.tags(:quota_max_storage).first - unless tag_max_group_storage.nil? - $evm.log("info", "Found quota from group <#{group.description}> tag with value <#{tag_max_group_storage}>") - end - - # If group is tagged then override - unless tag_max_group_storage.nil? - max_group_storage = tag_max_group_storage.to_i - $evm.log("info", "Overriding quota from Group <#{group.description}> tag with value <#{tag_max_group_storage}GB> or <#{tag_max_group_storage.to_i * (1024**3)} bytes>") - end - - # Validate Group Storage Quota - unless max_group_storage.blank? - max_group_storage = max_group_storage.to_i - if quota_group && (quota_group[:allocated_storage] + vm_size > max_group_storage.to_i * (1024**3)) - $evm.log("info", "Storage allocated for Group <#{quota_group[:allocated_storage]}> + Requested Storage <#{vm_size}> exceeds Quota Max <#{max_group_storage}>") - quota_exceeded = true - g_stor_total_nice = "%.2fGB" % (quota_group[:allocated_storage] / 1024**3) - g_stor_quota_nice = "%.2fGB" % (max_group_storage) - g_quota_exceeded_reason3 = "Group Allocated Storage #{g_stor_total_nice} + Requested #{total_storage_nice} > Quota #{g_stor_quota_nice}" - end - end - -else - # Available check_quota methods [:vms_by_owner, :vms_by_owner_and_group] - quota_owner = miq_provision_request.check_quota(:vms_by_owner, :include_retired_vms => false) - $evm.log("info", "Inspecting quota_owner:<#{quota_owner.inspect}>") - - ########################## - # - # Owner CPU Quota Check - # - ########################## - $evm.log("info", "Beginning Owner CPU Quota Check") - $evm.log("info", "Owner: <#{user.name}> current CPU usage: <#{quota_owner[:cpu]}>") - - max_owner_cpu = nil - o_quota_exceeded_reason1 = nil - - # Use value from model unless specified above - max_owner_cpu ||= $evm.object['max_owner_cpu'] - unless max_owner_cpu.nil? - $evm.log("info", "Found quota from model with value:<#{max_owner_cpu}>") - end - - # Get tag from Owner - tag_max_owner_cpu = user.tags(:quota_max_cpu).first - unless tag_max_owner_cpu.nil? - $evm.log("info", "Found quota from user <#{user.name}> tag with value <#{tag_max_owner_cpu}>>") - end - - # If owner is tagged then override - unless tag_max_owner_cpu.nil? - max_owner_cpu = tag_max_owner_cpu.to_i - $evm.log("info", "Overriding quota from User <#{user.name}> tag with value <#{tag_max_owner_cpu}>") - end - - # Validate Owner CPU Quota - unless max_owner_cpu.blank? - if quota_owner && (quota_owner[:cpu] + total_cpu_in_request > max_owner_cpu.to_i) - $evm.log("info", "CPUs allocated for Owner <#{quota_owner[:cpu]}> + Requested CPUs <#{total_cpu_in_request}> exceeds Quota Max <#{max_owner_cpu}>") - quota_exceeded = true - o_total_vcpus = quota_owner[:cpu] - o_quota_exceeded_reason1 = "Owner Allocated vCPUs #{o_total_vcpus} + Requested #{total_cpu_in_request} > Quota #{max_owner_cpu}" - end - end - - ########################## - # - # Owner Memory Quota Check - # - ########################## - $evm.log("info", "Beginning Owner Memory Quota Check") - $evm.log("info", "Owner: <#{user.name}> current Memory usage: <#{quota_owner[:memory]}>") - - max_owner_memory = nil - o_quota_exceeded_reason2 = nil - - # Use value from model unless specified above - max_owner_memory ||= $evm.object['max_owner_memory'] - unless max_owner_memory.nil? - $evm.log("info", "Found quota from model with value:<#{max_owner_memory}>") - end - - # Get tag from Owner - tag_max_owner_memory = user.tags(:quota_max_memory).first - unless tag_max_owner_memory.nil? - $evm.log("info", "Found quota from user <#{user.name}> tag with value <#{tag_max_owner_memory}>") - end - - # If owner is tagged then override - unless tag_max_owner_memory.nil? - max_owner_memory = tag_max_owner_memory.to_i - $evm.log("info", "Overriding quota from User <#{user.name}> tag with value <#{tag_max_owner_memory}>") - end - - # Validate Owner Memory Quota - unless max_owner_memory.blank? - if quota_owner && (quota_owner[:memory] + total_memory_in_request > max_owner_memory.to_i) - $evm.log("info", "Memory allocated for Owner <#{quota_owner[:memory]}> + Requested Memory <#{total_memory_in_request}> exceeds Quota Max <#{max_owner_memory}>") - quota_exceeded = true - o_mem_total_nice = "%.2fGB" % (quota_owner[:memory] / 1024) - o_mem_quota_nice = "%.2fGB" % (max_owner_memory.to_i / 1024) - o_quota_exceeded_reason2 = "Owner Allocated Memory #{o_mem_total_nice} + Requested #{total_memory_nice} > Quota #{o_mem_quota_nice}" - end - end - - ########################## - # - # Owner Storage Quota Check - # - ########################## - $evm.log("info", "Beginning Owner Storage Quota Check") - $evm.log("info", "Owner: <#{user.name}> current Storage usage: <#{quota_owner[:allocated_storage]}>") - - max_owner_storage = nil - o_quota_exceeded_reason3 = nil - - # Use value from model unless specified above - max_owner_storage ||= $evm.object['max_owner_storage'] - unless max_owner_storage.nil? - $evm.log("info", "Found quota from model with value:<#{max_owner_storage}GB>") - end - - # Get tag from Owner - tag_max_owner_storage = user.tags(:quota_max_storage).first - unless tag_max_owner_storage.nil? - $evm.log("info", "Found quota from user <#{user.name}> tag with value <#{tag_max_owner_storage}GB> or <#{tag_max_group_storage * (1024**3)} bytes>") - end - - # If owner is tagged then override - unless tag_max_owner_storage.nil? - max_owner_storage = tag_max_owner_storage.to_i - $evm.log("info", "Overriding quota from User <#{user.name}> tag with value <#{tag_max_owner_storage}GB>") - end - - # Validate Owner Storage Quota - unless max_owner_storage.blank? - max_owner_storage = max_owner_storage.to_i - if quota_owner && (quota_owner[:allocated_storage] + vm_size > max_owner_storage.to_i * (1024**3)) - $evm.log("info", "Storage allocated for Owner <#{quota_owner[:allocated_storage]}> + Requested Storage <#{vm_size}> exceeds Quota Max <#{max_owner_storage}>") - quota_exceeded = true - o_stor_total_nice = "%.2fGB" % (quota_owner[:allocated_storage] / 1024**3) - o_stor_quota_nice = "%.2fGB" % (max_owner_storage) - o_quota_exceeded_reason3 = "Owner Allocated Storage #{o_stor_total_nice} + Requested #{total_storage_nice} > Quota #{o_stor_quota_nice}" - end - end -end - -########################## -# -# Quota Exceeded Check -# -########################## -if quota_exceeded == true - msg = "" - # msg += "VMs cannot be provisioned at this time due to the following quota limits: " - msg += "Request denied due to the following quota limits:" - msg += "(#{g_quota_exceeded_reason1}) " unless g_quota_exceeded_reason1.nil? - msg += "(#{g_quota_exceeded_reason2}) " unless g_quota_exceeded_reason2.nil? - msg += "(#{g_quota_exceeded_reason3})" unless g_quota_exceeded_reason3.nil? - msg += "(#{o_quota_exceeded_reason1}) " unless o_quota_exceeded_reason1.nil? - msg += "(#{o_quota_exceeded_reason2}) " unless o_quota_exceeded_reason2.nil? - msg += "(#{o_quota_exceeded_reason3})" unless o_quota_exceeded_reason3.nil? - $evm.log("info", "Inspecting Messge:<#{msg}>") - - miq_provision_request.set_message(msg) - - $evm.root['ae_result'] = 'error' - $evm.object['reason'] = msg -end diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml deleted file mode 100644 index 05f091e227a..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/__methods__/validate_quotas.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: validate_quotas - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: [] diff --git a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml b/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml deleted file mode 100644 index d0814f0cfbd..00000000000 --- a/db/fixtures/ae_datastore/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/ProvisionRequestQuotaVerification.class/default.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: Default - name: Default - inherits: - description: - fields: [] diff --git a/db/fixtures/ae_datastore/ManageIQ/System/Policy.class/miqprovisionconfiguredsystemrequest_starting.yaml b/db/fixtures/ae_datastore/ManageIQ/System/Policy.class/miqprovisionconfiguredsystemrequest_starting.yaml index 71530c6873d..2b4a42f82cf 100644 --- a/db/fixtures/ae_datastore/ManageIQ/System/Policy.class/miqprovisionconfiguredsystemrequest_starting.yaml +++ b/db/fixtures/ae_datastore/ManageIQ/System/Policy.class/miqprovisionconfiguredsystemrequest_starting.yaml @@ -9,6 +9,4 @@ object: description: fields: - rel5: - value: "/Infrastructure/${/#miq_request.resource.ci_type}/Provisioning/Profile/${/#user.normalized_ldap_group}#get_quota_state_machine" - - rel6: - value: "/Infrastructure/${/#miq_request.resource.ci_type}/Provisioning/StateMachines/${/#state_machine}/Default" + value: "/System/CommonMethods/QuotaStatemachine/quota"