From dd15912d18dda92837a838f3a710c7e6ab206d91 Mon Sep 17 00:00:00 2001 From: CFME Date: Tue, 20 Jun 2017 11:43:37 -0400 Subject: [PATCH] Refactor out utilities to RedHatConsulting_Utilities domain --- .../.manifest.yaml | 4 +- .../Configuration.class/__class__.yaml | 33 -- .../Configuration.class/default.yaml | 10 - .../Placement.class/__class__.yaml | 253 --------------- .../__methods__/vmware_customize.rb | 52 --- .../__methods__/vmware_customize.yaml | 12 - .../vmware_drs_cluster_best_fit_with_scope.rb | 298 ------------------ ...mware_drs_cluster_best_fit_with_scope.yaml | 12 - .../Provisioning/Placement.class/default.yaml | 18 -- .../Methods.class/__class__.yaml | 213 ------------- .../Methods.class/__methods__/start_vm.rb | 47 --- .../Methods.class/__methods__/start_vm.yaml | 12 - .../StateMachines/Methods.class/startvm.yaml | 12 - .../Methods.class/__methods__/set_vm_names.rb | 236 -------------- .../__methods__/set_vm_names.yaml | 12 - .../Methods.class/set_vm_names.yaml | 12 - .../__domain__.yaml | 4 +- 17 files changed, 4 insertions(+), 1236 deletions(-) delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Configuration.class/__class__.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Configuration.class/default.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__class__.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_customize.rb delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_customize.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.rb delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/default.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__class__.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/start_vm.rb delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/start_vm.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/startvm.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_vm_names.rb delete mode 100644 Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_vm_names.yaml delete mode 100644 Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/set_vm_names.yaml diff --git a/Automate/RedHatConsulting_Satellite6/.manifest.yaml b/Automate/RedHatConsulting_Satellite6/.manifest.yaml index 92b75be..7b07db4 100644 --- a/Automate/RedHatConsulting_Satellite6/.manifest.yaml +++ b/Automate/RedHatConsulting_Satellite6/.manifest.yaml @@ -10,11 +10,11 @@ __domain__.yaml: name: Etc/UTC time: *1 updated_on: !ruby/object:ActiveSupport::TimeWithZone - utc: &3 2017-05-25 18:50:00.170633000 Z + utc: &3 2017-06-20 15:16:02.182181000 Z zone: *2 time: *3 size: 309 - sha1: TS3e7eM26Ztsae0DWUyb3+Ud8YI= + sha1: 47moJ5t1tIzi82RhiVFl/MMBMqI= RedHatConsulting_Satellite/System/__namespace__.yaml: created_on: !ruby/object:ActiveSupport::TimeWithZone utc: &4 2017-05-16 13:12:41.294369000 Z diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Configuration.class/__class__.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Configuration.class/__class__.yaml deleted file mode 100644 index 9d0e873..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Configuration.class/__class__.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: - display_name: - name: Configuration - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: attribute - name: vmware_folder - 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/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Configuration.class/default.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Configuration.class/default.yaml deleted file mode 100644 index b3c2f9d..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Configuration.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/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__class__.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__class__.yaml deleted file mode 100644 index 773044d..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__class__.yaml +++ /dev/null @@ -1,253 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: Host and Storage to Provision To - display_name: - name: Placement - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: assertion - name: placement - display_name: - datatype: string - priority: 1 - owner: - default_value: "${/#miq_provision.placement_auto}" - substitute: true - message: "*" - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: attribute - name: vm - display_name: - datatype: vm - 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: host - display_name: - datatype: host - 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: storage - display_name: - datatype: storage - 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: storage_max_vms - display_name: - datatype: integer - 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: storage_max_pct_used - display_name: - datatype: integer - 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: method - name: redhat - display_name: - datatype: string - priority: 7 - owner: - default_value: - substitute: true - message: redhat - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: vmware - display_name: - datatype: string - priority: 8 - owner: - default_value: - substitute: true - message: vmware - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: microsoft - display_name: - datatype: string - priority: 9 - owner: - default_value: - substitute: true - message: microsoft - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: redhat_customize - display_name: - datatype: string - priority: 10 - owner: - default_value: - substitute: true - message: redhat - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: vmware_customize - display_name: - datatype: string - priority: 11 - owner: - default_value: - substitute: true - message: vmware - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: microsoft_customize - display_name: - datatype: string - priority: 12 - owner: - default_value: - substitute: true - message: microsoft - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_customize.rb b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_customize.rb deleted file mode 100644 index 27c1010..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_customize.rb +++ /dev/null @@ -1,52 +0,0 @@ -# Customizes the VMware placement after the intitial placement decisions. -# -# EXPECTED -# EVM ROOT -# miq_provision - VM Provisining request to customize the placement for. -# -@DEBUG = false - -# Log an error and exit. -# -# @param msg Message to error with -def error(msg) - $evm.log(:error, msg) - $evm.root['ae_result'] = 'error' - $evm.root['ae_reason'] = msg.to_s - exit MIQ_STOP -end - -# Get the vm provsining customization configuration. -# -# @return VM provisining configuration -VM_PROVISIONING_CONFIG_URI = 'Infrastructure/VM/Provisioning/Configuration/default' -def get_vm_provisioning_config() - provisioning_config = $evm.instantiate(VM_PROVISIONING_CONFIG_URI) - error("VM Provisioning Configuration not found") if provisioning_config.nil? - - return provisioning_config -end - -begin - # Get provisioning object - prov = $evm.root['miq_provision'] - error('Provisioning request not found') if prov.nil? - $evm.log(:info, "Provision:<#{prov.id}> Request:<#{prov.miq_provision_request.id}> Type:<#{prov.type}>") - $evm.log(:info, "prov.attributes => {") if @DEBUG - prov.attributes.sort.each { |k,v| $evm.log(:info, "\t#{k} => #{v}") } if @DEBUG - $evm.log(:info, "}") if @DEBUG - - # get the datacenter - template = prov.vm_template - datacenter = template.v_owning_datacenter - - # determine cutsomized placement folder - vm_provisioning_config = get_vm_provisioning_config() - vmware_folder = vm_provisioning_config['vmware_folder'] - vsphere_fully_qualified_folder = "#{datacenter}/#{vmware_folder}" - - # update placement folder - $evm.log(:info, "Provisioning object <:placement_folder_name> curent value <#{prov.options[:placement_folder_name].inspect}>") if @DEBUG - prov.set_folder(vsphere_fully_qualified_folder) - $evm.log(:info, "Provisioning object <:placement_folder_name> updated with <#{prov.options[:placement_folder_name].inspect}>") -end diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_customize.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_customize.yaml deleted file mode 100644 index ed9167c..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_customize.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: vmware_customize - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: [] diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.rb b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.rb deleted file mode 100644 index a99eaed..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.rb +++ /dev/null @@ -1,298 +0,0 @@ -# VMware placment logic which chooses placment based on: -# Option 1. DRS cluster tagged with `Provisioning Scope - All` or `Provisioning Scope - USER GROUP` -# A. If multiple DRS clusters are tagged one is picked at random -# B. Storage is filtered by inspecting a random host and the storage must have Multi Host Access -# C. Storage is then picked by using logic from `vmware_best_fit_least_utilized` -# Option 2. If no DRS clusters appropriatlly tagged then check for Hosts tagged with `Provisioning Scope - All` or `Provisioning Scope - USER GROUP` -# A. If multiple Hosts are tagged pick one using logic from `vmware_best_fit_least_utilized` -# B. Storage must be attached to host -# C. Storage must be tagged with `Provisioning Scope - All` or `Provisioning Scope - USER GROUP` -# D. Storage is then picked using logic from `vmware_best_fit_least_utilized` -# -@DEBUG = true - -# Log an error and exit. -# -# @param msg Message to error with -def error(msg) - $evm.log(:error, msg) - $evm.root['ae_result'] = 'error' - $evm.root['ae_reason'] = msg.to_s - exit MIQ_STOP -end - -begin - # Get variables - prov = $evm.root["miq_provision"] - vm = prov.vm_template - error("VM not specified") if vm.nil? - user = prov.miq_request.requester - error("User not specified") if user.nil? - ems = vm.ext_management_system - error("EMS not found for VM:<#{vm.name}>") if ems.nil? - - tags = {} - - # Get Tags that are in scope - # Default is to look for Hosts and Datastores tagged with prov_scope = All or match to Group - normalized_ldap_group = user.normalized_ldap_group.gsub(/\W/,'_') - tags["prov_scope"] = ["all", normalized_ldap_group] - - $evm.log("info", "VM=<#{vm.name}>, Space Required=<#{vm.provisioned_storage}>, group=<#{user.normalized_ldap_group}>") - - ############################# - # STORAGE LIMITATIONS - ############################# - STORAGE_MAX_VMS = 0 - storage_max_vms = $evm.object['storage_max_vms'] - storage_max_vms = storage_max_vms.strip.to_i if storage_max_vms.kind_of?(String) && !storage_max_vms.strip.empty? - storage_max_vms = STORAGE_MAX_VMS unless storage_max_vms.kind_of?(Numeric) - STORAGE_MAX_PCT_USED = 100 - storage_max_pct_used = $evm.object['storage_max_pct_used'] - storage_max_pct_used = storage_max_pct_used.strip.to_i if storage_max_pct_used.kind_of?(String) && !storage_max_pct_used.strip.empty? - storage_max_pct_used = STORAGE_MAX_PCT_USED unless storage_max_pct_used.kind_of?(Numeric) - $evm.log("info", "storage_max_vms:<#{storage_max_vms}> storage_max_pct_used:<#{storage_max_pct_used}>") - - ############################# - # Set host sort order here - # options: :active_provioning_memory, :active_provioning_cpu, :current_memory_usage, - # :current_memory_headroom, :current_cpu_usage, :random - ############################# - HOST_SORT_ORDER = [:active_provioning_memory, :current_memory_headroom, :random] - - ############################# - # Find a DRS-enabled cluster - ############################# - drs_clusters = [] - ems.ems_clusters.each do |c| - if c.drs_enabled - ############################# - # Only consider DRS clusters that have the required tags - ############################# - next unless tags.all? do |key, value| - if value.kind_of?(Array) - value.any? { |v| c.tagged_with?(key, v) } - else - c.tagged_with?(key, value) - end - end - drs_clusters << c - end - end - - # If no tagged DRS clusters search hosts - # else tagged DRS clusters, pick one at random - if drs_clusters.length.zero? - ############################# - # No DRS cluster found - try hosts - ############################# - - evm.log("info", "Sorted host Order:<#{HOST_SORT_ORDER.inspect}> Results:<#{sort_data.inspect}>") - active_prov_data = prov.check_quota(:active_provisions) - sort_data = [] - ems.hosts.each do |h| - ############################# - # Only consider hosts that have the required tags - ############################# - next unless tags.all? do |key, value| - if value.kind_of?(Array) - value.any? { |v| h.tagged_with?(key, v) } - else - h.tagged_with?(key, value) - end - end - - ############################# - # Sort hosts - ############################# - sort_data << sd = [[], h.name, h] - host_id = h.attributes['id'].to_i - HOST_SORT_ORDER.each do |type| - sd[0] << case type - # Multiply values by (-1) to cause larger values to sort first - when :active_provioning_memory - active_prov_data[:active][:memory_by_host_id][host_id] - when :active_provioning_cpu - active_prov_data[:active][:cpu_by_host_id][host_id] - when :current_memory_headroom - h.current_memory_headroom * -1 - when :current_memory_usage - h.current_memory_usage - when :current_cpu_usage - h.current_cpu_usage - when :random - rand(1000) - else 0 - end - end - end - - sort_data.sort! { |a, b| a[0] <=> b[0] } - hosts = sort_data.collect { |sd| sd.pop } - else - ############################# - # Tagged DRS cluster found - pick one at random - ############################# - cluster = drs_clusters.sample - - # Pick a random host on the tagged DRS cluster to then search for - # associated storage tagged with Multi Host Access - # - # NOTE: in the case of using a tagged DRS cluster host tags are ignored since VMware will choose the host - hosts = [cluster.hosts.sample] - end - - ############################# - # Set storage sort order here - # options: :active_provisioning_vms, :free_space, :free_space_percentage, :random - ############################# - STORAGE_SORT_ORDER = [:active_provisioning_vms, :random] - - host = storage = nil - min_registered_vms = nil - hosts.each do |h| - next unless h.power_state == "on" - $evm.log(:info, "evaluating host #{h.name}") if @DEBUG - - nvms = h.vms.length - - ############################# - # Only consider storages that have the required tag categories - ############################# - storages = h.storages.select do |s| - $evm.log(:info, "evaluating storage #{s.name} with tags #{s.tags.inspect} against tags: #{tags.inspect}") if @DEBUG - tags.all? do |key, value| - if value.kind_of?(Array) - value.any? { |v| s.tagged_with?(key, v) } - else - s.tagged_with?(key, value) - end - end - end - - $evm.log("info", "Evaluating storages:<#{storages.collect { |s| s.name }.join(", ")}>") - - # if using a DRS cluster then ensure the selected storage has Multi Host Access enabled - # - # there is an exception if the cluster only has one host in which case having Multi Host Access enabled does not matter - if cluster && cluster.hosts.length > 1 - # NOTE: for whatever reason the multiplehostaccess parameter uses 0/1 instead of true/false for it's value - storages = storages.select { |s| s.multiplehostaccess == 1 } - - error("No storages with Multiple Host Access enabled on a sample host <#{h.name}> from the the selected DRS cluster <#{cluster.name}>.") if storages.empty? - end - - ############################# - # Filter out storages that do not have enough free space for the VM - ############################# - active_prov_data = prov.check_quota(:active_provisions) - storages = storages.select do |s| - storage_id = s.attributes['id'].to_i - actively_provisioned_space = active_prov_data[:active][:storage_by_id][storage_id] - if s.free_space > vm.provisioned_storage + actively_provisioned_space - $evm.log("info", "Active Provision Data inspect: [#{active_prov_data.inspect}]") if @DEBUG - $evm.log("info", "Active provision space requirement: [#{actively_provisioned_space}]") if @DEBUG - $evm.log("info", "Valid Datastore: [#{s.name}], enough free space for VM -- Available: [#{s.free_space}], Needs: [#{vm.provisioned_storage}]") if @DEBUG - true - else - $evm.log("info", "Skipping Datastore:<#{s.name}>, not enough free space for VM:<#{vm.name}>. Available:<#{s.free_space}>, Needs:<#{vm.provisioned_storage}>") - false - end - end - - ############################# - # Filter out storages number of VMs is greater than the max number of VMs allowed per Datastore - ############################# - storages = storages.select do |s| - storage_id = s.attributes['id'].to_i - active_num_vms_for_storage = active_prov_data[:active][:vms_by_storage_id][storage_id].length - if (storage_max_vms == 0) || ((s.vms.size + active_num_vms_for_storage) < storage_max_vms) - true - else - $evm.log("info", "Skipping Datastore:<#{s.name}>, max number of VMs:<#{s.vms.size + active_num_vms_for_storage}> exceeded") - false - end - end - - ############################# - # Filter out storages where percent used will be greater than the max % allowed per Datastore - ############################# - storages = storages.select do |s| - storage_id = s.attributes['id'].to_i - active_pct_of_storage = ((active_prov_data[:active][:storage_by_id][storage_id]) / s.total_space.to_f) * 100 - request_pct_of_storage = (vm.provisioned_storage / s.total_space.to_f) * 100 - - if (storage_max_pct_used == 100) || ((s.v_used_space_percent_of_total + active_pct_of_storage + request_pct_of_storage) < storage_max_pct_used) - true - else - $evm.log("info", "Skipping Datastore:<#{s.name}> percent of used space #{s.v_used_space_percent_of_total + active_pct_of_storage + request_pct_of_storage} exceeded") - false - end - end - - if min_registered_vms.nil? || nvms < min_registered_vms - ############################# - # Sort storage to determine target datastore - ############################# - sort_data = [] - storages.each_with_index do |s, idx| - sort_data << sd = [[], s.name, idx] - storage_id = s.attributes['id'].to_i - STORAGE_SORT_ORDER.each do |type| - sd[0] << case type - when :free_space - # Multiply values by (-1) to cause larger values to sort first - (s.free_space - active_prov_data[:active][:storage_by_id][storage_id]) * -1 - when :free_space_percentage - active_pct_of_storage = ((active_prov_data[:active][:storage_by_id][storage_id]) / s.total_space.to_f) * 100 - s.v_used_space_percent_of_total + active_pct_of_storage - when :active_provioning_vms - active_prov_data[:active][:vms_by_storage_id][storage_id].length - when :random - rand(1000) - else 0 - end - end - end - - sort_data.sort! { |a, b| a[0] <=> b[0] } - $evm.log("info", "Sorted storage Order:<#{STORAGE_SORT_ORDER.inspect}> Results:<#{sort_data.inspect}>") - selected_storage = sort_data.first - unless selected_storage.nil? - selected_idx = selected_storage.last - storage = storages[selected_idx] - host = h - end - - # Stop checking if we have found both host and storage - break if host && storage - end - - end # END - hosts.each - - obj = $evm.object - - # If selected by DRS cluster - # else if selected by host - if cluster - $evm.log("info", "Selected Cluster: <#{cluster.nil? ? "nil" : cluster.name}>") - obj["ems_cluster"] = cluster - prov.set_cluster(cluster) - elsif host - $evm.log("info", "Selected Host: <#{host.nil? ? "nil" : host.name}>") - obj["host"] = host - prov.set_host(host) - end - - $evm.log("info", "Selected Datastore: <#{storage.nil? ? "nil" : storage.name}>") - if storage - obj["storage"] = storage - prov.set_storage(storage) - end - - $evm.log("info", "vm=<#{vm.name}> host=<#{host}> storage=<#{storage}>") - - if (cluster.nil? and host.nil?) or storage.nil? - error("Either {host,cluster} or storage is nil - issue abort.") - end -end diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.yaml deleted file mode 100644 index 338246c..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: vmware_drs_cluster_best_fit_with_scope - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: [] diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/default.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/default.yaml deleted file mode 100644 index d2a5fdd..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/Placement.class/default.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: - name: default - inherits: - description: - fields: - - redhat: - value: redhat_best_fit_cluster - - vmware: - value: vmware_drs_cluster_best_fit_with_scope - - microsoft: - value: microsoft_best_fit_least_utilized - - vmware_customize: - value: vmware_customize diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__class__.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__class__.yaml deleted file mode 100644 index 04df4a8..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__class__.yaml +++ /dev/null @@ -1,213 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: - display_name: - name: Methods - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: relationship - name: common_rel1 - display_name: - datatype: - priority: 1 - owner: - default_value: - substitute: true - message: "*" - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: common_meth1 - display_name: - datatype: string - priority: 2 - owner: - default_value: - substitute: true - message: "*" - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: relationship - name: rel1 - display_name: - datatype: - 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: method - name: execute - display_name: - 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: relationship - name: vmware_rel1 - display_name: - datatype: - priority: 5 - owner: - default_value: - substitute: true - message: vmware - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: vmware_meth1 - display_name: - datatype: string - priority: 6 - owner: - default_value: - substitute: true - message: vmware - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: relationship - name: redhat_rel1 - display_name: - datatype: - priority: 7 - owner: - default_value: - substitute: true - message: redhat - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: redhat_meth1 - display_name: - datatype: string - priority: 8 - owner: - default_value: - substitute: true - message: redhat - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: relationship - name: microsoft_rel1 - display_name: - datatype: string - priority: 9 - owner: - default_value: - substitute: true - message: microsoft - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: method - name: microsoft_meth1 - display_name: - datatype: string - priority: 10 - owner: - default_value: - substitute: true - message: microsoft - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/start_vm.rb b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/start_vm.rb deleted file mode 100644 index 3ec4de6..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/start_vm.rb +++ /dev/null @@ -1,47 +0,0 @@ -# Starts / Powers on VM and then waits for the VM to be in a powerd on state. -# -# EXPECTED -# EVM ROOT -# miq_provision - VM Provisining request contianing the VM to start. -# -# @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/customising_vm_provisioning/chapter.html#_start_vm -# -@DEBUG = false - -# Log an error and exit. -# -# @param msg Message to error with -def error(msg) - $evm.log(:error, msg) - $evm.root['ae_result'] = 'error' - $evm.root['ae_reason'] = msg.to_s - exit MIQ_STOP -end - -begin - # Get provisioning object - prov = $evm.root['miq_provision'] - error('Provisioning request not found') if prov.nil? - $evm.log(:info, "Provision:<#{prov.id}> Request:<#{prov.miq_provision_request.id}> Type:<#{prov.type}>") - $evm.log(:info, "prov.attributes => {") if @DEBUG - prov.attributes.sort.each { |k,v| $evm.log(:info, "\t#{k} => #{v}") } if @DEBUG - $evm.log(:info, "}") if @DEBUG - - # get the VM - vm = prov.vm - error('VM on provisining request not found') if vm.nil? - $evm.log(:info, "vm = #{vm}") if @DEBUG - - $evm.log(:info, "Current VM power state = #{vm.power_state}") - unless vm.power_state == 'on' - vm.start - vm.refresh - $evm.root['ae_result'] = 'retry' - $evm.root['ae_retry_interval'] = '30.seconds' - else - $evm.root['ae_result'] = 'ok' - end -rescue => err - $evm.log(:error, "[#{err}]\n#{err.backtrace.join("\n")}") - $evm.root['ae_result'] = 'error' -end diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/start_vm.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/start_vm.yaml deleted file mode 100644 index f1565fb..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/start_vm.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: start_vm - display_name: StartVM - description: - scope: instance - language: ruby - location: inline - inputs: [] diff --git a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/startvm.yaml b/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/startvm.yaml deleted file mode 100644 index cd46a8e..0000000 --- a/Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/startvm.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: - name: StartVm - inherits: - description: - fields: - - execute: - value: start_vm diff --git a/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_vm_names.rb b/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_vm_names.rb deleted file mode 100644 index fe724d7..0000000 --- a/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_vm_names.rb +++ /dev/null @@ -1,236 +0,0 @@ -# This function takes care of naming a set of VMs with all unique names. -# This function also ensures that there is no other service trying to name VMs -# with the same prefix at the same time to avoid VM name duplication. -# -# EXPECTED -# EVM ROOT -# service_template_provision_task - service task to set the VM names for -# required options: -# dialog -# dialog_vm_prefix - VM name prefix to use when naming VMs. -# -# @see https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/the_service_provisioning_state_machine/chapter.html#_vm_naming_for_services -# @see https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/service_objects/chapter.html -# -@DEBUG = false - -RETRY_INTERVAL = 10 -DEFAULT_SUFFIX_COUNTER_LENGTH = 4 - -# Log an error and exit. -# -# @param msg Message to error with -def error(msg) - $evm.log(:error, msg) - $evm.root['ae_result'] = 'error' - $evm.root['ae_reason'] = msg.to_s - exit MIQ_STOP -end - - -# Calls a user provided block for each grand child of the given parent. -# -# @param parent Parent of grand children to call the given block for -# @block |grand_child_task| Call the given block for each grand child of the given parent -def for_each_grand_child_task(parent) - parent.miq_request_tasks.each do |child_task| - child_task.miq_request_tasks.each do |grand_child_task| - # call block passing grand child MiqProvision - yield grand_child_task - end - end -end - -# Calls a user provided block for each active or pending requests. -# Optionally does not call for the given current request. -# -# @param current_request Optional. Current request to not call the block for. -# @param request_type The type of active or pending requests to iterate over -# @block |active_or_pending_request| Call this block for each active or pending request. -def for_each_active_or_pending_request(current_request = nil, request_type = 'ServiceTemplateProvisionRequest') - $evm.vmdb(:miq_request).all.each do |request| - if ( (request.request_state == 'active' || request.request_state == 'pending') && - (request_type.nil? || request.type == request_type) && - (current_request.nil? || request.id != current_request.id) ) - - # call block passing active/pending request - yield request - end - end -end - -# Given a ServiceTemplateProvisionRequest sets a lock option on that request signifying that the -# given request is doing VM naming with the given VM prefix. -# -# Before claiming the lock will first look for other active ServiceTemplateProvisionRequest that are either actively trying -# to get the lock or actually have the lock. -# -# In the case where any existing active ServiceTemplateProvisionRequest have the lock on the given vm_prefix or are trying -# to get the lock, then the given ServiceTemplateProvisionRequest will not get the lock. The caller of this function is then -# expected to try again. -# -# NOTE 1: This function does its best to approximate how a synchronize would work in Java in that the :vm_naming_lock_attempt option -# is checking to make sure only one thread concurrently attempts to get a lock while the :vm_naming_lock option is the actual lock to claim. -# -# @param current_request Current ServiceTemplateProvisionRequest attempt to get naming lock on given VM prefix -# @param vm_prefix VM naming prefix to get a lock on -# @block Block of code to run if lock is acquired, block not run if lock is not acquired. -# -# @return True if the lock was acquired and given block executed. False if lock not acquired and user block not run. -def with_service_template_provision_request_naming_lock(current_request, vm_prefix) - aquired_lock = false - begin - # set that the given request is trying to get the vm_naming lock - $evm.log(:info, "Set lock attempt: { request_id => '#{current_request.id}', :vm_naming_lock_attempt => '#{vm_prefix}' }") if @DEBUG - current_request.set_option(:vm_naming_lock_attempt, vm_prefix) - - # determine if any active ServiceTemplateProvisionRequests are trying to get a lock or have the lock for the given vm prefix - $evm.log(:info, "Other Active ServiceTemplateProvisionRequests: { current_request_id => #{current_request.id} }") if @DEBUG - existing_lock = false - for_each_active_or_pending_request(current_request) do |request| - request_vm_naming_lock_attempt = request.get_option(:vm_naming_lock_attempt) - request_vm_naming_lock = request.get_option(:vm_naming_lock) - $evm.log(:info, "Found active ServiceTemplateProvisionRequest: { :id => #{request.id}, :vm_naming_lock_attempt => '#{request_vm_naming_lock_attempt}', :vm_naming_lock => '#{request_vm_naming_lock}' }") if @DEBUG - - # if the active ServiceTemplateProvisionRequest is trying to get lock or has lock, then this task can't have it - if ( (!request_vm_naming_lock.nil? && request_vm_naming_lock == vm_prefix) || - (!request_vm_naming_lock_attempt.nil? && request_vm_naming_lock_attempt == vm_prefix) ) - - # found existing request that already has lock - $evm.log(:info, "Found active ServiceTemplateProvisionRequest with lock or attempting to get lock: { request_id => '#{request.id}', :vm_naming_lock_attempt => '#{request_vm_naming_lock_attempt}', :vm_naming_lock => '#{request_vm_naming_lock}' }") if @DEBUG - existing_lock = true - break - end - end - - # if another active ServiceTemplateProvisionRequest already has the lock or is trying to get the lock then can't get lock - # else claim the lock - if existing_lock - $evm.log(:info, "ServiceTemplateProvisionRequest Failed to get lock: { request_id => '#{current_request.id}', :vm_naming_lock => '#{vm_prefix}' }") if @DEBUG - aquired_lock = false - else - begin - $evm.log(:info, "ServiceTemplateProvisionRequest Claim lock: { request_id => '#{current_request.id}', :vm_naming_lock => '#{vm_prefix}' }") if @DEBUG - current_request.set_option(:vm_naming_lock, vm_prefix) - aquired_lock = true - - # yield to the user block - yield - ensure - $evm.log(:info, "ServiceTemplateProvisionRequest Release lock: { request_id => '#{current_request.id}', :vm_naming_lock => '#{vm_prefix}' }") if @DEBUG - current_request.set_option(:vm_naming_lock, nil) - end - end - ensure - $evm.log(:info, "ServiceTemplateProvisionRequest Release lock attempt: { request_id => '#{current_request.id}', :vm_naming_lock_attempt => '#{vm_prefix}' }") if @DEBUG - current_request.set_option(:vm_naming_lock_attempt, nil) - end - - return aquired_lock -end - -# Determines a unique VM name using the given VM name prefix, and optional given domain name, -# avoiding any names already in the given list. -# -# @param vm_prefix VM name prefix for new VM -# @param domain_name Domain name for new VM -# @param used_vm_names List of VM names already used (not already in VMDB) -# @param suffix_counter_length Length of the counter to suffix the prefix with, ex 4 would mean '#{vm_prefix}0000' -def get_vm_name(vm_prefix, domain_name, used_vm_names, suffix_counter_length = DEFAULT_SUFFIX_COUNTER_LENGTH) - counter_max = ("9" * suffix_counter_length).to_i - vm_name = nil - for i in (1..(counter_max+1)) - if i > counter_max - error("Counter exceeded max (#{counter_max}) for prefix (#{vm_prefix})") - else - vm_name = "#{vm_prefix}#{i.to_s.rjust(suffix_counter_length, "0")}" - - # if domain name is given then append it to the VM name - if !domain_name.nil? - vm_name = "#{vm_name}.#{domain_name}" - end - - # determine if VM already exists with generated name - no_existing_vm_in_vmdb = $evm.vmdb('vm_or_template').find_by_name(vm_name).blank? - not_in_used_vm_names = !used_vm_names.include?(vm_name) - $evm.log(:info, "get_vm_name: { vm_name => '#{vm_name}', no_existing_vm_in_vmdb => #{no_existing_vm_in_vmdb}, not_in_used_vm_names => #{not_in_used_vm_names} }") if @DEBUG - - # stop searching if no VM with given name already exists - break if no_existing_vm_in_vmdb && not_in_used_vm_names - end - end - - $evm.log(:info, "get_vm_name: '#{vm_name}'") if @DEBUG - return vm_name -end - -begin - $evm.log(:info, "START - set_vm_names") if @DEBUG - - # get the current ServiceTemplateProvisionTask - task = $evm.root['service_template_provision_task'] - error("$evm.root['service_template_provision_task'] not found") if task.nil? - $evm.log(:info, "Current ServiceTemplateProvisionTask: { :id => '#{task.id}', :miq_request_id => '#{task.miq_request.id}' }") if @DEBUG - - # get the VM name prefix - vm_prefix = task.get_option(:dialog)['dialog_vm_prefix'] - $evm.log(:info, "vm_prefix => '#{vm_prefix}'") if @DEBUG - error("dialog_vm_prefix not found in ServiceTemplateProvisionTask dialog options: { :id => '#{task.id}', :miq_request_id => '#{task.miq_request.id}' }") if vm_prefix.blank? - - # Get the domain name if one is set - domain_name = task.get_option(:dialog)['dialog_domain_name'] - $evm.log(:info, "domain_name => '#{domain_name}'") if @DEBUG - error("dialog_domain_name not found in ServiceTemplateProvisionTask dialog options: { :id => '#{task.id}', :miq_request_id => '#{task.miq_request.id}' }") if domain_name.blank? - - # - # IMPORTANT - # A lock is needed for generating the VM names in the case where two or more services get requested at the same time. - # Without this lock the two or more services could end up giving out the same VM names. - # - current_request = task.miq_request - aquired_lock = with_service_template_provision_request_naming_lock(current_request, vm_prefix) do - used_vm_names = [] - - # get the VM names on all current active requests so as not to conflict with those - $evm.log(:info, "Other Active ServiceTemplateProvisionRequests: { current_task_id => #{task.id}, current_request_id => #{current_request.id} }") if @DEBUG - for_each_active_or_pending_request(current_request) do |request| - $evm.log(:info, "\tActive ServiceTemplateProvisionRequest VM Names: { other_active_request_id => #{request.id} }") if @DEBUG - - for_each_grand_child_task(request) do |grand_child_task| - existing_vm_target_name = grand_child_task.get_option(:vm_target_name) - $evm.log(:info, "\t\tOther Active ServiceTemplateProvisionRequest VM name: { grand_child_task => #{grand_child_task.id}, existing_vm_target_name => '#{existing_vm_target_name}' }") if @DEBUG - - # add the concurrent service request VM name to the list of used vm names so there are no conflicts - used_vm_names.push(existing_vm_target_name) - end - end - - # for each VM request generate a unique name and keep track of the names used in this batch - for_each_grand_child_task(task) do |grand_child_task| - # get the unique vm name - vm_name = get_vm_name(vm_prefix, domain_name, used_vm_names) - used_vm_names.push(vm_name) - - # set the target vm name - grand_child_task.set_option(:vm_target_name, vm_name) - grand_child_task.set_option(:vm_target_hostname, vm_name) - grand_child_task.set_option(:vm_name, vm_name) - - $evm.log(:info, "Set grand_child_task options: { current_request_id => #{current_request.id}, grand_child_task_id => '#{grand_child_task.id}', :vm_target_name => '#{grand_child_task.get_option(:vm_target_name)}', :vm_target_hostname => '#{grand_child_task.get_option(:vm_target_hostname)}' }") - end - end - - # if did not acquire lock then retry after interval - # else done - unless aquired_lock - $evm.log(:info, "Did not acquire VM naming lock '#{vm_prefix}', retry after interval '#{RETRY_INTERVAL}'") - $evm.root['ae_result'] = 'retry' - $evm.root['ae_retry_interval'] = "#{RETRY_INTERVAL}.seconds" - else - $evm.root['ae_result'] = 'ok' - end - - $evm.log(:info, "END - set_vm_names") if @DEBUG -rescue => err - error("[#{err}]\n#{err.backtrace.join("\n")}") -end diff --git a/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_vm_names.yaml b/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_vm_names.yaml deleted file mode 100644 index ffbbb18..0000000 --- a/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_vm_names.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: set_vm_names - display_name: - description: - scope: instance - language: ruby - location: inline - inputs: [] diff --git a/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/set_vm_names.yaml b/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/set_vm_names.yaml deleted file mode 100644 index 5243b42..0000000 --- a/Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/set_vm_names.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: - name: set_vm_names - inherits: - description: - fields: - - execute: - value: set_vm_names diff --git a/Automate/RedHatConsulting_Satellite6/__domain__.yaml b/Automate/RedHatConsulting_Satellite6/__domain__.yaml index 2abef95..443db28 100644 --- a/Automate/RedHatConsulting_Satellite6/__domain__.yaml +++ b/Automate/RedHatConsulting_Satellite6/__domain__.yaml @@ -4,9 +4,9 @@ version: 1.0 object: attributes: name: RedHatConsulting_Satellite6 - description: ManageIQ Automate Domain for integrating with Red Hat Satellite 6 developed by Red Hat Consulting. + description: ManageIQ Automate Domain for integrating with Red Hat Satellite 6 developed by Red Hat Consulting display_name: - priority: 3 + priority: 8 enabled: true tenant_id: 10000000000001 source: user