Class: Fog::Network::AzureRM::LoadBalancer

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/azurerm/models/network/load_balancer.rb

Overview

LoadBalancer model class for Network Service

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(load_balancer) ⇒ Object

Parameters:

  • load_balancer (Object)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 18

def self.parse(load_balancer)
  hash = {}
  hash['id'] = load_balancer.id
  hash['name'] = load_balancer.name
  hash['location'] = load_balancer.location
  hash['resource_group'] = get_resource_group_from_id(load_balancer.id)
  hash['backend_address_pool_names'] = load_balancer.backend_address_pools.map(&:id) unless load_balancer.backend_address_pools.nil?

  hash['frontend_ip_configurations'] = []
  load_balancer.frontend_ipconfigurations.each do |fic|
    frontend_ip_configuration = Fog::Network::AzureRM::FrontendIPConfiguration.new
    hash['frontend_ip_configurations'] << frontend_ip_configuration.merge_attributes(Fog::Network::AzureRM::FrontendIPConfiguration.parse(fic))
  end unless load_balancer.frontend_ipconfigurations.nil?

  hash['load_balancing_rules'] = []
  load_balancer.load_balancing_rules.each do |lbr|
    load_balancing_rule = Fog::Network::AzureRM::LoadBalangcingRule.new
    hash['load_balancing_rules'] << load_balancing_rule.merge_attributes(Fog::Network::AzureRM::LoadBalangcingRule.parse(lbr))
  end unless load_balancer.load_balancing_rules.nil?

  hash['probes'] = []
  load_balancer.probes.each do |prb|
    prob = Fog::Network::AzureRM::Probe.new
    hash['probes'] << prob.merge_attributes(Fog::Network::AzureRM::Probe.parse(prb))
  end unless load_balancer.probes.nil?

  hash['inbound_nat_rules'] = []
  load_balancer.inbound_nat_rules.each do |inr|
    inbound_nat_rule = Fog::Network::AzureRM::InboundNatRule.new
    hash['inbound_nat_rules'] << inbound_nat_rule.merge_attributes(Fog::Network::AzureRM::InboundNatRule.parse(inr))
  end unless load_balancer.inbound_nat_rules.nil?

  hash['inbound_nat_pools'] = []
  load_balancer.inbound_nat_pools.each do |inp|
    inbound_nat_pool = Fog::Network::AzureRM::InboundNatPool.new
    hash['inbound_nat_pools'] << inbound_nat_pool.merge_attributes(Fog::Network::AzureRM::InboundNatPool.parse(inp))
  end unless load_balancer.inbound_nat_pools.nil?

  hash
end

Instance Method Details

#destroyObject



241
242
243
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 241

def destroy
  service.delete_load_balancer(resource_group, name)
end

#saveObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 59

def save
  requires :name, :location, :resource_group

  validate_frontend_ip_configurations(frontend_ip_configurations) unless frontend_ip_configurations.nil?
  validate_load_balancing_rules(load_balancing_rules) unless load_balancing_rules.nil?
  validate_probes(probes) unless probes.nil?
  validate_inbound_nat_rules(inbound_nat_rules) unless inbound_nat_rules.nil?
  validate_inbound_nat_pools(inbound_nat_pools) unless inbound_nat_pools.nil?

  load_balancer = service.create_load_balancer(name, location, resource_group, frontend_ip_configurations, backend_address_pool_names, load_balancing_rules, probes, inbound_nat_rules, inbound_nat_pools)

  merge_attributes(Fog::Network::AzureRM::LoadBalancer.parse(load_balancer))
end

#validate_frontend_ip_configuration_params(frontend_ip_configuration) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 225

def validate_frontend_ip_configuration_params(frontend_ip_configuration)
  required_params = [
    :name,
    :private_ipallocation_method
  ]
  missing = required_params.select { |p| p unless frontend_ip_configuration.key?(p) }
  if missing.length == 1
    raise(ArgumentError, "#{missing.first} is required for this operation")
  elsif missing.any?
    raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
  end
  unless frontend_ip_configuration.key?(:subnet_id) || frontend_ip_configuration.key?(:public_ipaddress_id)
    raise(ArgumentError, 'subnet_id and public_id can not be empty at the same time.')
  end
end

#validate_frontend_ip_configurations(frontend_ip_configurations) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 207

def validate_frontend_ip_configurations(frontend_ip_configurations)
  if frontend_ip_configurations.is_a?(Array)
    if frontend_ip_configurations.any?
      frontend_ip_configurations.each do |frontend_ip_configuration|
        if frontend_ip_configuration.is_a?(Hash)
          validate_frontend_ip_configuration_params(frontend_ip_configuration)
        else
          raise(ArgumentError, ':frontend_ip_configurations must be an Array of Hashes')
        end
      end
    else
      raise(ArgumentError, ':frontend_ip_configurations must not be an empty Array')
    end
  else
    raise(ArgumentError, ':frontend_ip_configurations must be an Array')
  end
end

#validate_inbound_nat_pool_params(inbound_nat_pool) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 191

def validate_inbound_nat_pool_params(inbound_nat_pool)
  required_params = [
    :name,
    :protocol,
    :frontend_port_range_start,
    :frontend_port_range_end,
    :backend_port
  ]
  missing = required_params.select { |p| p unless inbound_nat_pool.key?(p) }
  if missing.length == 1
    raise(ArgumentError, "#{missing.first} is required for this operation")
  elsif missing.any?
    raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
  end
end

#validate_inbound_nat_pools(inbound_nat_pools) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 173

def validate_inbound_nat_pools(inbound_nat_pools)
  if inbound_nat_pools.is_a?(Array)
    if inbound_nat_pools.any?
      inbound_nat_pools.each do |inp|
        if inp.is_a?(Hash)
          validate_inbound_nat_pool_params(inp)
        else
          raise(ArgumentError, ':inbound_nat_pools must be an Array of Hashes')
        end
      end
    else
      raise(ArgumentError, ':inbound_nat_pools must not be an empty Array')
    end
  else
    raise(ArgumentError, ':inbound_nat_pools must be an Array')
  end
end

#validate_inbound_nat_rule_params(inbound_nat_rule) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 158

def validate_inbound_nat_rule_params(inbound_nat_rule)
  required_params = [
    :name,
    :protocol,
    :frontend_port,
    :backend_port
  ]
  missing = required_params.select { |p| p unless inbound_nat_rule.key?(p) }
  if missing.length == 1
    raise(ArgumentError, "#{missing.first} is required for this operation")
  elsif missing.any?
    raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
  end
end

#validate_inbound_nat_rules(inbound_nat_rules) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 140

def validate_inbound_nat_rules(inbound_nat_rules)
  if inbound_nat_rules.is_a?(Array)
    if inbound_nat_rules.any?
      inbound_nat_rules.each do |inr|
        if inr.is_a?(Hash)
          validate_inbound_nat_rule_params(inr)
        else
          raise(ArgumentError, ':inbound_nat_rules must be an Array of Hashes')
        end
      end
    else
      raise(ArgumentError, ':inbound_nat_rules must not be an empty Array')
    end
  else
    raise(ArgumentError, ':inbound_nat_rules must be an Array')
  end
end

#validate_load_balancing_rule_params(load_balancing_rule) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 91

def validate_load_balancing_rule_params(load_balancing_rule)
  required_params = [
    :name,
    :protocol,
    :frontend_port,
    :backend_port
  ]
  missing = required_params.select { |p| p unless load_balancing_rule.key?(p) }
  if missing.length == 1
    raise(ArgumentError, "#{missing.first} is required for this operation")
  elsif missing.any?
    raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
  end
end

#validate_load_balancing_rules(load_balancing_rules) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 73

def validate_load_balancing_rules(load_balancing_rules)
  if load_balancing_rules.is_a?(Array)
    if load_balancing_rules.any?
      load_balancing_rules.each do |lbr|
        if lbr.is_a?(Hash)
          validate_load_balancing_rule_params(lbr)
        else
          raise(ArgumentError, ':load_balancing_rules must be an Array of Hashes')
        end
      end
    else
      raise(ArgumentError, ':load_balancing_rules must not be an empty Array')
    end
  else
    raise(ArgumentError, ':load_balancing_rules must be an Array')
  end
end

#validate_probe_params(probe) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 124

def validate_probe_params(probe)
  required_params = [
    :name,
    :port,
    :request_path,
    :interval_in_seconds,
    :number_of_probes
  ]
  missing = required_params.select { |p| p unless probe.key?(p) }
  if missing.length == 1
    raise(ArgumentError, "#{missing.first} is required for this operation")
  elsif missing.any?
    raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
  end
end

#validate_probes(probes) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fog/azurerm/models/network/load_balancer.rb', line 106

def validate_probes(probes)
  if probes.is_a?(Array)
    if probes.any?
      probes.each do |prb|
        if prb.is_a?(Hash)
          validate_probe_params(prb)
        else
          raise(ArgumentError, ':probes must be an Array of Hashes')
        end
      end
    else
      raise(ArgumentError, ':probes must not be an empty Array')
    end
  else
    raise(ArgumentError, ':probes must be an Array')
  end
end