Skip to content

Commit 85cb104

Browse files
jeffwarnicaitewk
authored andcommitted
JW Feb28 (#144)
* Fix merge updates * Re get_provision_type, s/provision/request/g; reformat get_request_type; new helper in core * Too much change * add_disk_to_vm: Classify and stdlib process_telemetry_data: state name key typo * add_disk_to_vm: Classify and stdlib process_telemetry_data: state name key typo w_f_vm_ipaddresses: class style w_f_vm_hostname: class style core.rb: add automate_retry() * Add ability for settings to return a (provided) default value. * Add ability for settings to return a (provided) default value. Now with valid logic and error checking! * class format updates Error case emails now back to being errors (somewhere along the line (on_error??) error status was cleared, and thus error detection broke. * yaml's too! * Updates per @itewk * Updates per @itewk (suppress debug now) * miqprovision_update: getting 'prov' is smarter. Drop double dumping of root vmware_drs_cluster_best_fit_with_scope: Move configuration settings to settings.rb settings.rb: defaults & comments TODO: started tracking * Actually send emails in miqprovision_update again * Actually send emails in miqprovision_update again
1 parent 44c6852 commit 85cb104

File tree

5 files changed

+81
-32
lines changed

5 files changed

+81
-32
lines changed

Automate/RedHatConsulting_Utilities/Infrastructure/VM/Provisioning/Email.class/__methods__/miqprovision_update.rb

+11-7
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ def initialize(handle = $evm)
2222

2323
def main
2424
# get the miq_provision task
25-
prov = @handle.root['miq_provision']
26-
log(:info, "Provision:<#{prov.id}> Request:<#{prov.miq_provision_request.id}> Type:<#{prov.type}>") if @DEBUG
27-
log(:info, "prov.attributes => {") if @DEBUG
28-
prov.attributes.sort.each {|k, v| log(:info, "\t#{k} => #{v}")} if @DEBUG
29-
log(:info, "}") if @DEBUG
25+
prov = @handle.root['miq_provision_request'] || @handle.root['miq_provision']
26+
3027
error("miq_provision object not provided") unless prov
3128

3229
# determine to email addresses
@@ -100,7 +97,7 @@ def determine_to_email_addresses(prov)
10097
log(:info, "requester_email => #{requester_email}") if @DEBUG
10198

10299
# get owner email
103-
vm = prov.vm
100+
vm = prov.vm rescue nil
104101
owner = vm.owner unless vm.nil?
105102
owner_email = owner.email unless owner.nil?
106103
owner_email ||= request.options[:owner_email]
@@ -159,7 +156,7 @@ def send_vm_provision_update_email(prov, to, from, update_message, vm_current_pr
159156
status = status.capitalize
160157

161158
# get the VM
162-
vm = prov.vm
159+
vm = prov.vm rescue nil
163160

164161
# get vm name
165162
vm_name = vm.name unless vm.nil?
@@ -226,6 +223,13 @@ def send_vm_provision_update_email(prov, to, from, update_message, vm_current_pr
226223
body += "</table>"
227224
end
228225

226+
# Send email
227+
@handle.log("info", "Sending email to <#{to}> from <#{from}> subject: <#{subject}>") if @DEBUG
228+
@handle.log("info", "Sending email body: #{body}") if @DEBUG
229+
@handle.execute(:send_email, to, from, subject, body)
230+
231+
@handle.log('info', "END: send_vm_provision_update_email") if @DEBUG
232+
229233
end
230234

231235
end

Automate/RedHatConsulting_Utilities/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.rb

+15-22
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,18 @@ module Placement
1919
class VmWareDrsClusterBestFitWithScope
2020
include RedHatConsulting_Utilities::StdLib::Core
2121

22-
STORAGE_MAX_VMS = 0
23-
STORAGE_MAX_PCT_USED = 100
24-
25-
#############################
26-
# Set host sort order here
27-
# options: :active_provioning_memory, :active_provioning_cpu, :current_memory_usage,
28-
# :current_memory_headroom, :current_cpu_usage, :random
29-
#############################
30-
HOST_SORT_ORDER = [:active_provioning_memory, :current_memory_headroom, :random].freeze
31-
32-
#############################
33-
# Set storage sort order here
34-
# options: :active_provisioning_vms, :free_space, :free_space_percentage, :random
35-
#############################
36-
STORAGE_SORT_ORDER = [:active_provisioning_vms, :random].freeze
37-
3822
def initialize(handle = $evm)
3923
@handle = handle
4024
@DEBUG = false
25+
26+
@settings = RedHatConsulting_Utilities::StdLib::Core::Settings.new()
27+
@region = @handle.root['miq_server'].region_number
28+
29+
@STORAGE_MAX_VMS = @settings.get_setting(@region, :placement_storage_max_vms, 0)
30+
@STORAGE_MAX_PCT_USED = @settings.get_setting(@region, :placement_storage_max_pct_used, 100)
31+
32+
@HOST_SORT_ORDER = @settings.get_setting(@region, :placement_host_sort_oprder, [:active_provioning_memory, :current_memory_headroom, :random])
33+
@STORAGE_SORT_ORDER = @settings.get_setting(@region, :placement_storage_sort_oprder, [:free_space, :active_provisioning_vms, :random])
4134
end
4235

4336
def main
@@ -63,12 +56,12 @@ def main
6356

6457
storage_max_vms = @handle.object['storage_max_vms']
6558
storage_max_vms = storage_max_vms.strip.to_i if storage_max_vms.is_a?(String) && !storage_max_vms.strip.empty?
66-
storage_max_vms = STORAGE_MAX_VMS unless storage_max_vms.is_a?(Numeric)
59+
storage_max_vms = @STORAGE_MAX_VMS unless storage_max_vms.is_a?(Numeric)
6760

6861
storage_max_pct_used = @handle.object['storage_max_pct_used']
6962
storage_max_pct_used = storage_max_pct_used.strip.to_i if storage_max_pct_used.is_a?(String) &&
7063
!storage_max_pct_used.strip.empty?
71-
storage_max_pct_used = STORAGE_MAX_PCT_USED unless storage_max_pct_used.is_a?(Numeric)
64+
storage_max_pct_used = @STORAGE_MAX_PCT_USED unless storage_max_pct_used.is_a?(Numeric)
7265
log(:info, "storage_max_vms:<#{storage_max_vms}> storage_max_pct_used:<#{storage_max_pct_used}>")
7366

7467
#############################
@@ -100,7 +93,7 @@ def main
10093
#############################
10194

10295
sort_data = []
103-
log(:info, "Sorted host Order:<#{HOST_SORT_ORDER.inspect}> Results:<#{sort_data.inspect}>")
96+
log(:info, "Sorted host Order:<#{@HOST_SORT_ORDER.inspect}> Results:<#{sort_data.inspect}>")
10497
active_prov_data = prov.check_quota(:active_provisions)
10598
ems.hosts.each do |h|
10699
#############################
@@ -119,7 +112,7 @@ def main
119112
#############################
120113
sort_data << sd = [[], h.name, h]
121114
host_id = h.attributes['id'].to_i
122-
HOST_SORT_ORDER.each do |type|
115+
@HOST_SORT_ORDER.each do |type|
123116
sd[0] << case type
124117
# Multiply values by (-1) to cause larger values to sort first
125118
when :active_provioning_memory
@@ -266,7 +259,7 @@ def main
266259
storages.each_with_index do |s, idx|
267260
sort_data << sd = [[], s.name, idx]
268261
storage_id = s.attributes['id'].to_i
269-
STORAGE_SORT_ORDER.each do |type|
262+
@STORAGE_SORT_ORDER.each do |type|
270263
sd[0] << case type
271264
when :free_space
272265
# Multiply values by (-1) to cause larger values to sort first
@@ -286,7 +279,7 @@ def main
286279
end
287280

288281
sort_data.sort! { |a, b| a[0] <=> b[0] }
289-
log(:info, "Sorted storage Order:<#{STORAGE_SORT_ORDER.inspect}> Results:<#{sort_data.inspect}>")
282+
log(:info, "Sorted storage Order:<#{@STORAGE_SORT_ORDER.inspect}> Results:<#{sort_data.inspect}>")
290283
selected_storage = sort_data.first
291284
log(:info, "Selected Storage: <#{selected_storage}>")
292285
unless selected_storage.nil?

Automate/RedHatConsulting_Utilities/Infrastructure/VM/Provisioning/Placement.class/__methods__/vmware_drs_cluster_best_fit_with_scope.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ object:
1111
location: inline
1212
embedded_methods:
1313
- "/StdLib/Core/Core"
14+
- "/StdLib/Settings/Settings"
1415
options: {}
1516
inputs: []

Automate/RedHatConsulting_Utilities/StdLib/Settings.class/__methods__/settings.rb

+43-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@ module Core
2727
class Settings
2828
SETTINGS = {
2929
global: {
30-
network_lookup_keys: %w(environment), #orderd list of CF tag names to use to lookup vlan names, _ separated
31-
groups_can_order_for: %w(EvmGroup-super_administrator), #list of groups whose members can order services on behalf of others
30+
#orderd list of CF tag names to use to lookup vlan names, _ separated
31+
# This helps build the setting name for VLAN lookups. Format is as:
32+
# network_<template vendor>_key1_key2_..._keyN
33+
# consider the following examples
34+
#
35+
# vmware templates:
36+
# network_lookup_keys: %w(location environment)
37+
# ---> network_vmware_NYC_DEV OR network_vmware_PARIS_QA
38+
# network_lookup_keys: %w(servicelevel location environment)
39+
# ---> network_vmware_GOLD_NYC_DEV OR network_vmware_BRONZE_PARIS_QA
40+
#
41+
network_lookup_keys: %w(environment),
42+
43+
#list of groups whose members can order services on behalf of others
44+
groups_can_order_for: %w(EvmGroup-super_administrator),
45+
3246
vm_auto_start_suppress: true,
3347
},
3448
default: {
@@ -40,7 +54,33 @@ class Settings
4054
retirement_warn: 14.days.to_i,
4155
retirement_max_extensions: 3,
4256

43-
},
57+
#############################
58+
# Options for VM placement logic (for vmware_drs_cluster_best_fit_with_scope)
59+
#
60+
# @TODO: figure out how to have placement_filters here (implies eval(!))
61+
# @TODO: Reconcile RHV placement logic & use same config
62+
#
63+
# storage_max_vms: 0 - ignore
64+
# int - skip datastores with >x VMs
65+
#
66+
# storage_max_pct_used: 100 (default)
67+
# 0-100 - skip datastores with >x % used.
68+
#
69+
# storage_sort_order: ordered array of keys to sort for "best" host
70+
# 0 or more of: :active_provisioning_vms, :free_space, :free_space_percentage, :random
71+
#
72+
# host_sort_order: ordered array of keys to sort for "best" datastore
73+
#
74+
# 0 or more of: :active_provioning_memory, :active_provioning_cpu, :current_memory_usage,
75+
# :current_memory_headroom, :current_cpu_usage, :random
76+
#############################
77+
78+
storage_max_vms: 0,
79+
storage_max_pct_used: 100,
80+
host_sort_order: [:active_provioning_memory, :current_memory_headroom, :random],
81+
storage_sort_order: [:active_provisioning_vms, :random],
82+
83+
},
4484
r901: {
4585
network_vmware: 'dvs_0810_INF_VMS_PRD_HFLEX',
4686
network_vmware_test: 'dvs_0820_Self_Prov_Test(10.43.181.x)',

TODO.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#TODO
2+
3+
# General
4+
* Continue conversion to class style, refactoring out StdLib calls, adding to StdLib
5+
* Migrating configurable options to settings.rb
6+
* Merge VMWware and RHV best fit code
7+
8+
# Settings
9+
* Provide mechanism for eval() settings. Consider placement_filters
10+
* Text template settings. Email!
11+

0 commit comments

Comments
 (0)