Module: PuppetX::IntechWIFI::Autoscaling_Rules
- Defined in:
- lib/puppet_x/intechwifi/autoscaling_rules.rb
Class Method Summary collapse
- .base_lc_name(name) ⇒ Object
- .encode_code_value(value) ⇒ Object
- .encode_index(value) ⇒ Object
- .extract_code_value(letter) ⇒ Object
- .get_load_balancer(name, region, &aws_command) ⇒ Object
- .index(name) ⇒ Object
- .is_valid_lc_name?(basename, potential_match) ⇒ Boolean
Class Method Details
.base_lc_name(name) ⇒ Object
30 31 32 33 |
# File 'lib/puppet_x/intechwifi/autoscaling_rules.rb', line 30 def self.base_lc_name(name) result = name result = name.slice(0, name.length - 6) if (/_=[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]=$/ =~ name) end |
.encode_code_value(value) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/puppet_x/intechwifi/autoscaling_rules.rb', line 56 def self.encode_code_value value output = (value + 48).chr.to_s if value < 10 output = (value + 55).chr.to_s if value > 9 and value < 37 output =(value + 61).chr.to_s if value >35 and value < 62 output end |
.encode_index(value) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/puppet_x/intechwifi/autoscaling_rules.rb', line 39 def self.encode_index(value) output = [] while value > 0 value, m = value.divmod(62) output = [ encode_code_value(m) ] << output end output = ["00", output].flatten.join[-3..-1] "_=#{output}=" end |
.extract_code_value(letter) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/puppet_x/intechwifi/autoscaling_rules.rb', line 49 def self.extract_code_value letter ord = letter.ord - 48 ord = ord -7 if ord > 9 ord = ord - 9 if ord > 35 ord end |
.get_load_balancer(name, region, &aws_command) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/puppet_x/intechwifi/autoscaling_rules.rb', line 63 def self.get_load_balancer( name, region, &aws_command) args = [ 'autoscaling', 'describe-load-balancer-target-groups', '--region', region, '--auto-scaling-group-name', name ] result = JSON.parse(aws_command.call(args.flatten))["LoadBalancerTargetGroups"] raise PuppetX::IntechWIFI::Exceptions::NotFoundError, name if result.length == 0 raise PuppetX::IntechWIFI::Exceptions::MultipleMatchesError, name if result.length > 1 # Multiple matches result.map{|data| /^arn:aws:elasticloadbalancing:[a-z\-0-9]+:[0-9]+:targetgroup\/([0-9a-z\-]+)\/[0-9a-f]+$/.match(data['LoadBalancerTargetGroupARN'])[1] }[0] rescue PuppetX::IntechWIFI::Exceptions::NotFoundError => e nil end |
.index(name) ⇒ Object
35 36 37 |
# File 'lib/puppet_x/intechwifi/autoscaling_rules.rb', line 35 def self.index(name) name[-4..-2].split("").map{|c| extract_code_value(c)}.reduce(0){ |memo, v| memo * 62 + v } end |
.is_valid_lc_name?(basename, potential_match) ⇒ Boolean
26 27 28 |
# File 'lib/puppet_x/intechwifi/autoscaling_rules.rb', line 26 def self.is_valid_lc_name?(basename, potential_match) !(/^#{basename}_=[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]=$/ =~ potential_match).nil? end |