Class: Chef::Provider::AzureLoadBalancer
Instance Method Summary
collapse
#action_handler, #compute_management_client, #network_management_client, #resource_management_client, #storage_management_client, #try_azure_operation
Instance Method Details
#create_or_update_load_balancer ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/chef/provider/azure_load_balancer.rb', line 56
def create_or_update_load_balancer
tags = new_resource.load_balancer_options[:tags]
subinfo = network_management_client.subnets.get(new_resource.resource_group, new_resource.virtual_network, new_resource.subnet_name)
backend_pool = []
new_resource.virtual_machine.each do |ivm|
count = backend_pool.count
backend_pool[count] = Azure::ARM::Network::Models::BackendAddressPool.new
backend_pool[count].name = ivm
end
frontend_ipconf = Azure::ARM::Network::Models::FrontendIPConfiguration.new.tap do |feip|
new_resource.load_balancer_options[:frontend].each do |fendip|
feip.name = fendip[:name]
feip.subnet = subinfo
feip.private_ipallocation_method = fendip[:private_ipallocation_method]
end
end
probe = Azure::ARM::Network::Models::Probe.new.tap do |prb|
new_resource.load_balancer_options[:probes].each do |prbes|
prb.name = prbes[:name]
prb.port = prbes[:port]
prb.protocol = prbes[:protocol]
if prbes[:protocol].casecmp('http')
prb.request_path = prbes[:request_path]
end
prb.interval_in_seconds = prbes[:interval_in_seconds]
prb.number_of_probes = prbes[:number_of_probes]
end
end
lb = Azure::ARM::Network::Models::LoadBalancer.new.tap do |lbinfo|
lbinfo.location = new_resource.location
lbinfo.tags = tags
lbinfo.frontend_ipconfigurations = [frontend_ipconf]
lbinfo.backend_address_pools = backend_pool
lbinfo.probes = [probe]
end
lb_update(lb)
mylb = network_management_client.load_balancers.get(new_resource.resource_group, new_resource.name)
new_resource.virtual_machine.each do |ivm|
vmnic = network_management_client.network_interfaces.get(new_resource.resource_group, ivm)
mylb.backend_address_pools.each do |pool|
next unless pool.name == ivm
vmnic.ip_configurations.first.load_balancer_backend_address_pools = [pool] network_management_client.network_interfaces.create_or_update(new_resource.resource_group, ivm, vmnic)
end
end
frontend_ipconf_sub = MsRestAzure::SubResource.new.tap do |subresource|
subresource.id = network_management_client.load_balancers.get(new_resource.resource_group, new_resource.name).frontend_ipconfigurations.first.id
end
backend_ipconf_sub = MsRestAzure::SubResource.new.tap do |subresource|
subresource.id = mylb.backend_address_pools.first.id
end
probe_sub = MsRestAzure::SubResource.new.tap do |subresource|
subresource.id = network_management_client.load_balancers.get(new_resource.resource_group, new_resource.name).probes.first.id
end
unless new_resource.load_balancer_options[:inboundnat].nil?
inboudnat = Azure::ARM::Network::Models::InboundNatRule.new.tap do |inat|
new_resource.load_balancer_options[:inboundnat].each do |ibnat|
inat.name = ibnat[:name]
inat.frontend_port = ibnat[:frontend_port]
inat.backend_port = ibnat[:backend_port]
inat.protocol = ibnat[:protocol]
inat.enable_floating_ip = ibnat[:enable_floating_ip]
inat.idle_timeout_in_minutes = ibnat[:idle_timeout_in_minutes]
inat.frontend_ipconfiguration = frontend_ipconf_sub
end
end
end
lbrules = Azure::ARM::Network::Models::LoadBalancingRule.new.tap do |lbrs|
new_resource.load_balancer_options[:lbr].each do |lbr|
lbrs.name = lbr[:name]
lbrs.backend_address_pool = backend_ipconf_sub
lbrs.protocol = lbr[:protocol]
lbrs.backend_port = lbr[:backend_port]
lbrs.frontend_port = lbr[:frontend_port]
lbrs.idle_timeout_in_minutes = lbr[:idle_timeout_in_minutes]
lbrs.enable_floating_ip = lbr[:enable_floating_ip]
lbrs.load_distribution = lbr[:load_distribution]
lbrs.frontend_ipconfiguration = frontend_ipconf_sub
lbrs.backend_address_pool = backend_ipconf_sub
lbrs.probe = probe_sub
end
end
lb = Azure::ARM::Network::Models::LoadBalancer.new.tap do |lbinfo|
lbinfo.location = new_resource.location
lbinfo.tags = tags
lbinfo.frontend_ipconfigurations = [frontend_ipconf]
lbinfo.backend_address_pools = backend_pool
unless new_resource.load_balancer_options[:inboundnat].nil?
lbinfo.inbound_nat_rules = [inboudnat]
end
lbinfo.probes = [probe]
lbinfo.load_balancing_rules = [lbrules]
end
lb_update(lb) end
|
#destroy_load_balancer ⇒ Object
44
45
46
47
48
49
|
# File 'lib/chef/provider/azure_load_balancer.rb', line 44
def destroy_load_balancer
action_handler.report_progress 'Destroying Load Balancer...'
try_azure_operation('destroying load balancer') do
network_management_client.load_balancers.delete(new_resource.resource_group, new_resource.name)
end
end
|
#does_load_balancer_exist ⇒ Object
38
39
40
41
42
|
# File 'lib/chef/provider/azure_load_balancer.rb', line 38
def does_load_balancer_exist
try_azure_operation('listing load balancers', true) do
network_management_client.load_balancers.get(new_resource.resource_group, new_resource.name)
end
end
|
#lb_update(lb) ⇒ Object
52
53
54
|
# File 'lib/chef/provider/azure_load_balancer.rb', line 52
def lb_update(lb)
network_management_client.load_balancers.create_or_update(new_resource.resource_group, new_resource.name, lb)
end
|
#whyrun_supported? ⇒ Boolean
8
9
10
|
# File 'lib/chef/provider/azure_load_balancer.rb', line 8
def whyrun_supported?
true
end
|