fog-azure-rm 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +19 -8
  3. data/LICENSE.md +1 -1
  4. data/README.md +9 -8
  5. data/lib/fog/azurerm/models/compute/availability_set.rb +17 -3
  6. data/lib/fog/azurerm/models/compute/availability_sets.rb +2 -6
  7. data/lib/fog/azurerm/models/compute/server.rb +1 -1
  8. data/lib/fog/azurerm/models/compute/servers.rb +3 -1
  9. data/lib/fog/azurerm/models/dns/record_set.rb +31 -3
  10. data/lib/fog/azurerm/models/dns/record_sets.rb +7 -17
  11. data/lib/fog/azurerm/models/dns/zone.rb +26 -3
  12. data/lib/fog/azurerm/models/dns/zones.rb +8 -6
  13. data/lib/fog/azurerm/models/network/frontend_ip_configuration.rb +32 -0
  14. data/lib/fog/azurerm/models/network/inbound_nat_pool.rb +27 -0
  15. data/lib/fog/azurerm/models/network/inbound_nat_rule.rb +29 -0
  16. data/lib/fog/azurerm/models/network/load_balancer.rb +249 -0
  17. data/lib/fog/azurerm/models/network/load_balancers.rb +27 -0
  18. data/lib/fog/azurerm/models/network/load_balancing_rule.rb +42 -0
  19. data/lib/fog/azurerm/models/network/network_interface.rb +46 -7
  20. data/lib/fog/azurerm/models/network/network_interfaces.rb +2 -8
  21. data/lib/fog/azurerm/models/network/network_security_group.rb +89 -0
  22. data/lib/fog/azurerm/models/network/network_security_groups.rb +27 -0
  23. data/lib/fog/azurerm/models/network/network_security_rule.rb +40 -0
  24. data/lib/fog/azurerm/models/network/probe.rb +29 -0
  25. data/lib/fog/azurerm/models/network/public_ip.rb +32 -4
  26. data/lib/fog/azurerm/models/network/public_ips.rb +2 -8
  27. data/lib/fog/azurerm/models/network/subnet.rb +20 -12
  28. data/lib/fog/azurerm/models/network/subnets.rb +1 -7
  29. data/lib/fog/azurerm/models/network/traffic_manager_end_point.rb +63 -0
  30. data/lib/fog/azurerm/models/network/traffic_manager_end_points.rb +29 -0
  31. data/lib/fog/azurerm/models/network/traffic_manager_profile.rb +59 -0
  32. data/lib/fog/azurerm/models/network/traffic_manager_profiles.rb +24 -0
  33. data/lib/fog/azurerm/models/network/virtual_network.rb +19 -6
  34. data/lib/fog/azurerm/models/network/virtual_networks.rb +4 -9
  35. data/lib/fog/azurerm/models/resources/resource_group.rb +2 -1
  36. data/lib/fog/azurerm/models/resources/resource_groups.rb +1 -9
  37. data/lib/fog/azurerm/models/storage/storage_account.rb +5 -7
  38. data/lib/fog/azurerm/models/storage/storage_accounts.rb +5 -6
  39. data/lib/fog/azurerm/network.rb +30 -0
  40. data/lib/fog/azurerm/requests/compute/create_availability_set.rb +13 -2
  41. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +60 -2
  42. data/lib/fog/azurerm/requests/compute/deallocate_virtual_machine.rb +4 -2
  43. data/lib/fog/azurerm/requests/compute/delete_availability_set.rb +4 -2
  44. data/lib/fog/azurerm/requests/compute/delete_virtual_machine.rb +4 -2
  45. data/lib/fog/azurerm/requests/compute/generalize_virtual_machine.rb +4 -2
  46. data/lib/fog/azurerm/requests/compute/get_virtual_machine.rb +57 -1
  47. data/lib/fog/azurerm/requests/compute/list_availability_sets.rb +16 -1
  48. data/lib/fog/azurerm/requests/compute/list_available_sizes_for_virtual_machine.rb +27 -1
  49. data/lib/fog/azurerm/requests/compute/power_off_virtual_machine.rb +4 -2
  50. data/lib/fog/azurerm/requests/compute/redeploy_virtual_machine.rb +4 -2
  51. data/lib/fog/azurerm/requests/compute/restart_virtual_machine.rb +4 -2
  52. data/lib/fog/azurerm/requests/compute/start_virtual_machine.rb +4 -2
  53. data/lib/fog/azurerm/requests/dns/check_for_zone.rb +16 -17
  54. data/lib/fog/azurerm/requests/dns/create_record_set.rb +80 -37
  55. data/lib/fog/azurerm/requests/dns/create_zone.rb +43 -27
  56. data/lib/fog/azurerm/requests/dns/delete_record_set.rb +17 -19
  57. data/lib/fog/azurerm/requests/dns/delete_zone.rb +16 -19
  58. data/lib/fog/azurerm/requests/dns/get_records_from_record_set.rb +29 -28
  59. data/lib/fog/azurerm/requests/dns/list_record_sets.rb +49 -23
  60. data/lib/fog/azurerm/requests/dns/list_zones.rb +57 -23
  61. data/lib/fog/azurerm/requests/network/check_for_public_ip.rb +3 -1
  62. data/lib/fog/azurerm/requests/network/check_for_virtual_network.rb +4 -2
  63. data/lib/fog/azurerm/requests/network/create_load_balancer.rb +208 -0
  64. data/lib/fog/azurerm/requests/network/create_network_interface.rb +42 -4
  65. data/lib/fog/azurerm/requests/network/create_network_security_group.rb +200 -0
  66. data/lib/fog/azurerm/requests/network/create_public_ip.rb +19 -5
  67. data/lib/fog/azurerm/requests/network/create_subnet.rb +19 -6
  68. data/lib/fog/azurerm/requests/network/create_traffic_manager_endpoint.rb +78 -0
  69. data/lib/fog/azurerm/requests/network/create_traffic_manager_profile.rb +127 -0
  70. data/lib/fog/azurerm/requests/network/create_virtual_network.rb +40 -5
  71. data/lib/fog/azurerm/requests/network/delete_load_balancer.rb +27 -0
  72. data/lib/fog/azurerm/requests/network/delete_network_interface.rb +5 -3
  73. data/lib/fog/azurerm/requests/network/delete_network_security_group.rb +29 -0
  74. data/lib/fog/azurerm/requests/network/delete_public_ip.rb +4 -2
  75. data/lib/fog/azurerm/requests/network/delete_subnet.rb +10 -8
  76. data/lib/fog/azurerm/requests/network/delete_traffic_manager_endpoint.rb +37 -0
  77. data/lib/fog/azurerm/requests/network/delete_traffic_manager_profile.rb +37 -0
  78. data/lib/fog/azurerm/requests/network/delete_virtual_network.rb +8 -6
  79. data/lib/fog/azurerm/requests/network/get_traffic_manager_profile.rb +96 -0
  80. data/lib/fog/azurerm/requests/network/list_load_balancers.rb +31 -0
  81. data/lib/fog/azurerm/requests/network/list_network_interfaces.rb +41 -9
  82. data/lib/fog/azurerm/requests/network/list_network_security_groups.rb +171 -0
  83. data/lib/fog/azurerm/requests/network/list_public_ips.rb +21 -9
  84. data/lib/fog/azurerm/requests/network/list_subnets.rb +34 -11
  85. data/lib/fog/azurerm/requests/network/list_traffic_manager_profiles.rb +98 -0
  86. data/lib/fog/azurerm/requests/network/list_virtual_networks.rb +53 -8
  87. data/lib/fog/azurerm/requests/resources/create_resource_group.rb +11 -2
  88. data/lib/fog/azurerm/requests/resources/delete_resource_group.rb +4 -2
  89. data/lib/fog/azurerm/requests/resources/list_resource_groups.rb +23 -7
  90. data/lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb +2 -0
  91. data/lib/fog/azurerm/requests/storage/create_storage_account.rb +14 -8
  92. data/lib/fog/azurerm/requests/storage/delete_storage_account.rb +4 -3
  93. data/lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb +33 -2
  94. data/lib/fog/azurerm/requests/storage/list_storage_accounts.rb +32 -5
  95. data/lib/fog/azurerm/storage.rb +0 -1
  96. data/lib/fog/azurerm/version.rb +1 -1
  97. metadata +35 -10
@@ -0,0 +1,249 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # LoadBalancer model class for Network Service
5
+ class LoadBalancer < Fog::Model
6
+ identity :name
7
+ attribute :id
8
+ attribute :location
9
+ attribute :resource_group
10
+ attribute :frontend_ip_configurations
11
+ attribute :backend_address_pool_names
12
+ attribute :load_balancing_rules
13
+ attribute :probes
14
+ attribute :inbound_nat_rules
15
+ attribute :inbound_nat_pools
16
+
17
+ # @param [Object] load_balancer
18
+ def self.parse(load_balancer)
19
+ load_balancer_properties = load_balancer['properties']
20
+
21
+ hash = {}
22
+ hash['id'] = load_balancer['id']
23
+ hash['name'] = load_balancer['name']
24
+ hash['location'] = load_balancer['location']
25
+ hash['resource_group'] = load_balancer['id'].split('/')[4]
26
+ hash['backend_address_pool_names'] = load_balancer_properties['backendAddressPools'].map { |item| item['name'] } unless load_balancer_properties['backendAddressPools'].nil?
27
+
28
+ hash['frontend_ip_configurations'] = []
29
+ load_balancer_properties['frontendIPConfigurations'].each do |fic|
30
+ frontend_ip_configuration = Fog::Network::AzureRM::FrontendIPConfiguration.new
31
+ hash['frontend_ip_configurations'] << frontend_ip_configuration.merge_attributes(Fog::Network::AzureRM::FrontendIPConfiguration.parse(fic))
32
+ end unless load_balancer_properties['frontendIPConfigurations'].nil?
33
+
34
+ hash['load_balancing_rules'] = []
35
+ load_balancer_properties['loadBalancingRules'].each do |lbr|
36
+ load_balancing_rule = Fog::Network::AzureRM::LoadBalangcingRule.new
37
+ hash['load_balancing_rules'] << load_balancing_rule.merge_attributes(Fog::Network::AzureRM::LoadBalangcingRule.parse(lbr))
38
+ end unless load_balancer_properties['loadBalancingRules'].nil?
39
+
40
+ hash['probes'] = []
41
+ load_balancer_properties['probes'].each do |prb|
42
+ prob = Fog::Network::AzureRM::Probe.new
43
+ hash['probes'] << prob.merge_attributes(Fog::Network::AzureRM::Probe.parse(prb))
44
+ end unless load_balancer_properties['probes'].nil?
45
+
46
+ hash['inbound_nat_rules'] = []
47
+ load_balancer_properties['inboundNatRules'].each do |inr|
48
+ inbound_nat_rule = Fog::Network::AzureRM::InboundNatRule.new
49
+ hash['inbound_nat_rules'] << inbound_nat_rule.merge_attributes(Fog::Network::AzureRM::InboundNatRule.parse(inr))
50
+ end unless load_balancer_properties['inboundNatRules'].nil?
51
+
52
+ hash['inbound_nat_rules'] = []
53
+ load_balancer_properties['inboundNatPools'].each do |inp|
54
+ inbound_nat_pool = Fog::Network::AzureRM::InboundNatPool.new
55
+ hash['inbound_nat_rules'] << inbound_nat_pool.merge_attributes(Fog::Network::AzureRM::InboundNatPool.parse(inp))
56
+ end unless load_balancer_properties['inboundNatPools'].nil?
57
+
58
+ hash
59
+ end
60
+
61
+ def save
62
+ requires :name, :location, :resource_group
63
+
64
+ validate_frontend_ip_configurations(frontend_ip_configurations) unless frontend_ip_configurations.nil?
65
+ validate_load_balancing_rules(load_balancing_rules) unless load_balancing_rules.nil?
66
+ validate_probes(probes) unless probes.nil?
67
+ validate_inbound_nat_rules(inbound_nat_rules) unless inbound_nat_rules.nil?
68
+ validate_inbound_nat_pools(inbound_nat_pools) unless inbound_nat_pools.nil?
69
+
70
+ 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)
71
+
72
+ merge_attributes(Fog::Network::AzureRM::LoadBalancer.parse(load_balancer))
73
+ end
74
+
75
+ def validate_load_balancing_rules(load_balancing_rules)
76
+ if load_balancing_rules.is_a?(Array)
77
+ if load_balancing_rules.any?
78
+ load_balancing_rules.each do |lbr|
79
+ if lbr.is_a?(Hash)
80
+ validate_load_balancing_rule_params(lbr)
81
+ else
82
+ raise(ArgumentError, ':load_balancing_rules must be an Array of Hashes')
83
+ end
84
+ end
85
+ else
86
+ raise(ArgumentError, ':load_balancing_rules must not be an empty Array')
87
+ end
88
+ else
89
+ raise(ArgumentError, ':load_balancing_rules must be an Array')
90
+ end
91
+ end
92
+
93
+ def validate_load_balancing_rule_params(load_balancing_rule)
94
+ required_params = [
95
+ :name,
96
+ :protocol,
97
+ :frontend_port,
98
+ :backend_port
99
+ ]
100
+ missing = required_params.select { |p| p unless load_balancing_rule.key?(p) }
101
+ if missing.length == 1
102
+ raise(ArgumentError, "#{missing.first} is required for this operation")
103
+ elsif missing.any?
104
+ raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
105
+ end
106
+ end
107
+
108
+ def validate_probes(probes)
109
+ if probes.is_a?(Array)
110
+ if probes.any?
111
+ probes.each do |prb|
112
+ if prb.is_a?(Hash)
113
+ validate_probe_params(prb)
114
+ else
115
+ raise(ArgumentError, ':probes must be an Array of Hashes')
116
+ end
117
+ end
118
+ else
119
+ raise(ArgumentError, ':probes must not be an empty Array')
120
+ end
121
+ else
122
+ raise(ArgumentError, ':probes must be an Array')
123
+ end
124
+ end
125
+
126
+ def validate_probe_params(probe)
127
+ required_params = [
128
+ :name,
129
+ :port,
130
+ :request_path,
131
+ :interval_in_seconds,
132
+ :number_of_probes
133
+ ]
134
+ missing = required_params.select { |p| p unless probe.key?(p) }
135
+ if missing.length == 1
136
+ raise(ArgumentError, "#{missing.first} is required for this operation")
137
+ elsif missing.any?
138
+ raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
139
+ end
140
+ end
141
+
142
+ def validate_inbound_nat_rules(inbound_nat_rules)
143
+ if inbound_nat_rules.is_a?(Array)
144
+ if inbound_nat_rules.any?
145
+ inbound_nat_rules.each do |inr|
146
+ if inr.is_a?(Hash)
147
+ validate_inbound_nat_rule_params(inr)
148
+ else
149
+ raise(ArgumentError, ':inbound_nat_rules must be an Array of Hashes')
150
+ end
151
+ end
152
+ else
153
+ raise(ArgumentError, ':inbound_nat_rules must not be an empty Array')
154
+ end
155
+ else
156
+ raise(ArgumentError, ':inbound_nat_rules must be an Array')
157
+ end
158
+ end
159
+
160
+ def validate_inbound_nat_rule_params(inbound_nat_rule)
161
+ required_params = [
162
+ :name,
163
+ :protocol,
164
+ :frontend_port,
165
+ :backend_port
166
+ ]
167
+ missing = required_params.select { |p| p unless inbound_nat_rule.key?(p) }
168
+ if missing.length == 1
169
+ raise(ArgumentError, "#{missing.first} is required for this operation")
170
+ elsif missing.any?
171
+ raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
172
+ end
173
+ end
174
+
175
+ def validate_inbound_nat_pools(inbound_nat_pools)
176
+ if inbound_nat_pools.is_a?(Array)
177
+ if inbound_nat_pools.any?
178
+ inbound_nat_pools.each do |inp|
179
+ if inp.is_a?(Hash)
180
+ validate_inbound_nat_pool_params(inp)
181
+ else
182
+ raise(ArgumentError, ':inbound_nat_pools must be an Array of Hashes')
183
+ end
184
+ end
185
+ else
186
+ raise(ArgumentError, ':inbound_nat_pools must not be an empty Array')
187
+ end
188
+ else
189
+ raise(ArgumentError, ':inbound_nat_pools must be an Array')
190
+ end
191
+ end
192
+
193
+ def validate_inbound_nat_pool_params(inbound_nat_pool)
194
+ required_params = [
195
+ :name,
196
+ :protocol,
197
+ :frontend_port_range_start,
198
+ :frontend_port_range_end,
199
+ :backend_port
200
+ ]
201
+ missing = required_params.select { |p| p unless inbound_nat_pool.key?(p) }
202
+ if missing.length == 1
203
+ raise(ArgumentError, "#{missing.first} is required for this operation")
204
+ elsif missing.any?
205
+ raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
206
+ end
207
+ end
208
+
209
+ def validate_frontend_ip_configurations(frontend_ip_configurations)
210
+ if frontend_ip_configurations.is_a?(Array)
211
+ if frontend_ip_configurations.any?
212
+ frontend_ip_configurations.each do |frontend_ip_configuration|
213
+ if fic.is_a?(Hash)
214
+ validate_frontend_ip_configuration_params(fic)
215
+ else
216
+ raise(ArgumentError, ':frontend_ip_configurations must be an Array of Hashes')
217
+ end
218
+ end
219
+ else
220
+ raise(ArgumentError, ':frontend_ip_configurations must not be an empty Array')
221
+ end
222
+ else
223
+ raise(ArgumentError, ':frontend_ip_configurations must be an Array')
224
+ end
225
+ end
226
+
227
+ def validate_frontend_ip_configuration_params(frontend_ip_configuration)
228
+ required_params = [
229
+ :name,
230
+ :private_ipallocation_method
231
+ ]
232
+ missing = required_params.select { |p| p unless frontend_ip_configuration.key?(p) }
233
+ if missing.length == 1
234
+ raise(ArgumentError, "#{missing.first} is required for this operation")
235
+ elsif missing.any?
236
+ raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
237
+ end
238
+ unless frontend_ip_configuration.key?(:subnet_id) || frontend_ip_configuration.key?(:public_ipaddress_id)
239
+ raise(ArgumentError, 'subnet_id and public_id can not be empty at the same time.')
240
+ end
241
+ end
242
+
243
+ def destroy
244
+ service.delete_load_balancer(resource_group, name)
245
+ end
246
+ end
247
+ end
248
+ end
249
+ end
@@ -0,0 +1,27 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/azurerm/models/network/load_balancer'
3
+
4
+ module Fog
5
+ module Network
6
+ class AzureRM
7
+ # LoadBalancers collection class for Network Service
8
+ class LoadBalancers < Fog::Collection
9
+ model Fog::Network::AzureRM::LoadBalancer
10
+ attribute :resource_group
11
+
12
+ def all
13
+ requires :resource_group
14
+ load_balancers = []
15
+ service.list_load_balancers(resource_group).each do |load_balancer|
16
+ load_balancers << Fog::Network::AzureRM::LoadBalancer.parse(load_balancer)
17
+ end
18
+ load(load_balancers)
19
+ end
20
+
21
+ def get(identity)
22
+ all.find { |f| f.name == identity }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # LoadBalangcingRule model for Network Service
5
+ class LoadBalangcingRule < Fog::Model
6
+ identity :name
7
+ attribute :id
8
+ attribute :frontend_ip_configuration_id
9
+ attribute :backend_address_pool_id
10
+ attribute :protocol
11
+ attribute :frontend_port
12
+ attribute :backend_port
13
+ attribute :probe_id
14
+ attribute :enable_floating_ip
15
+ attribute :idle_timeout_in_minutes
16
+ attribute :load_distribution
17
+
18
+ def self.parse(load_balancing_rule)
19
+ load_balancing_rule_prop = load_balancing_rule['properties']
20
+ hash = {}
21
+ hash['id'] = load_balancing_rule['id']
22
+ hash['name'] = load_balancing_rule['name']
23
+ unless load_balancing_rule_prop['frontendIPConfiguration'].nil?
24
+ hash['frontend_ip_configuration_id'] = load_balancing_rule_prop['frontendIPConfiguration']['id']
25
+ end
26
+ unless load_balancing_rule_prop['backendAddressPool'].nil?
27
+ hash['backend_address_pool_id'] = load_balancing_rule_prop['backendAddressPool']['id']
28
+ end
29
+
30
+ hash['protocol'] = load_balancing_rule_prop['protocol']
31
+ hash['frontend_port'] = load_balancing_rule_prop['frontendPort']
32
+ hash['backend_port'] = load_balancing_rule_prop['backendPort']
33
+ hash['probe_id'] = load_balancing_rule_prop['probe']['id'] unless load_balancing_rule_prop['probe'].nil?
34
+ hash['enable_floating_ip'] = load_balancing_rule_prop['enableFloatingIP']
35
+ hash['idle_timeout_in_minutes'] = load_balancing_rule_prop['idleTimeoutInMinutes']
36
+ hash['load_distribution'] = load_balancing_rule_prop['loadDistribution']
37
+ hash
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -7,10 +7,52 @@ module Fog
7
7
  attribute :id
8
8
  attribute :location
9
9
  attribute :resource_group
10
- attribute :subnet_id
10
+ attribute :virtual_machine_id
11
+ attribute :mac_address
12
+ attribute :network_security_group_id
11
13
  attribute :ip_configuration_name
14
+ attribute :ip_configuration_id
15
+ attribute :subnet_id
12
16
  attribute :private_ip_allocation_method
13
- attribute :properties
17
+ attribute :private_ip_address
18
+ attribute :public_ip_address_id
19
+ attribute :load_balancer_backend_address_pools_ids
20
+ attribute :load_balancer_inbound_nat_rules_ids
21
+ attribute :dns_servers
22
+ attribute :applied_dns_servers
23
+ attribute :internal_dns_name_label
24
+ attribute :internal_fqd
25
+
26
+ def self.parse(nic)
27
+ nic_properties = nic['properties']
28
+ nic_ip_configuration = nic['properties']['ipConfigurations'][0]
29
+ hash = {}
30
+ hash['id'] = nic['id']
31
+ hash['name'] = nic['name']
32
+ hash['location'] = nic['location']
33
+ hash['resource_group'] = nic['id'].split('/')[4]
34
+ hash['virtual_machine_id'] = nic_properties['virtualMachine']['id'] unless nic_properties['virtualMachine'].nil?
35
+ hash['mac_address'] = nic_properties['macAddress'] unless nic_properties['macAddress'].nil?
36
+ hash['network_security_group_id'] = nic_properties['networkSecurityGroup']['id'] unless nic_properties['networkSecurityGroup'].nil?
37
+
38
+ unless nic_ip_configuration.nil?
39
+ nic_ip_configuration_properties = nic_ip_configuration['properties']
40
+ hash['ip_configuration_name'] = nic_ip_configuration['name']
41
+ hash['ip_configuration_id'] = nic_ip_configuration['id']
42
+ hash['subnet_id'] = nic_ip_configuration_properties['subnet']['id'] unless nic_ip_configuration_properties['subnet'].nil?
43
+ hash['private_ip_allocation_method'] = nic_ip_configuration_properties['privateIPAllocationMethod']
44
+ hash['private_ip_address'] = nic_ip_configuration_properties['privateIPAddress']
45
+ hash['public_ip_address_id'] = nic_ip_configuration_properties['publicIPAddress']['id'] unless nic_ip_configuration_properties['publicIPAddress'].nil?
46
+ hash['load_balancer_backend_address_pools_ids'] = nic_ip_configuration_properties['loadBalancerBackendAddressPools'].map{ |item| item['id'] } unless nic_ip_configuration_properties['loadBalancerBackendAddressPools'].nil?
47
+ hash['load_balancer_inbound_nat_rules_ids'] = nic_ip_configuration_properties['loadBalancerInboundNatRules'].map{ |item| item['id'] } unless nic_ip_configuration_properties['loadBalancerInboundNatRules'].nil?
48
+ end
49
+
50
+ hash['dns_servers'] = nic_properties['dnsSettings']['dnsServers']
51
+ hash['applied_dns_servers'] = nic_properties['appliedDnsServers']
52
+ hash['internal_dns_name_label'] = nic_properties['internalDnsNameLabel']
53
+ hash['internal_fqd'] = nic_properties['internalFqd']
54
+ hash
55
+ end
14
56
 
15
57
  def save
16
58
  requires :name
@@ -19,11 +61,8 @@ module Fog
19
61
  requires :subnet_id
20
62
  requires :ip_configuration_name
21
63
  requires :private_ip_allocation_method
22
-
23
- Fog::Logger.debug "Creating Network Interface Card: #{name}..."
24
- network_interface = service.create_network_interface(name, location, resource_group, subnet_id, ip_configuration_name, private_ip_allocation_method)
25
- Fog::Logger.debug "Network Interface #{name} created successfully."
26
- network_interface
64
+ network_interface = service.create_network_interface(resource_group, name, location, subnet_id, ip_configuration_name, private_ip_allocation_method)
65
+ merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(network_interface))
27
66
  end
28
67
 
29
68
  def destroy
@@ -12,14 +12,8 @@ module Fog
12
12
  def all
13
13
  requires :resource_group
14
14
  network_interfaces = []
15
- network_interface_list = service.list_network_interfaces(resource_group)
16
- network_interface_list.each do |nic|
17
- hash = {}
18
- nic.instance_variables.each do |var|
19
- hash[var.to_s.delete('@')] = nic.instance_variable_get(var)
20
- end
21
- hash['resource_group'] = resource_group
22
- network_interfaces << hash
15
+ service.list_network_interfaces(resource_group).each do |nic|
16
+ network_interfaces << Fog::Network::AzureRM::NetworkInterface.parse(nic)
23
17
  end
24
18
  load(network_interfaces)
25
19
  end
@@ -0,0 +1,89 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Subnet model for Network Security Group
5
+ class NetworkSecurityGroup < Fog::Model
6
+ identity :name
7
+ attribute :id
8
+ attribute :resource_group
9
+ attribute :location
10
+ attribute :network_interfaces_ids
11
+ attribute :subnets_ids
12
+ attribute :security_rules
13
+ attribute :default_security_rules
14
+
15
+ def self.parse(nsg)
16
+ hash = {}
17
+ hash['id'] = nsg['id']
18
+ hash['name'] = nsg['name']
19
+ hash['resource_group'] = nsg['id'].split('/')[4]
20
+ hash['location'] = nsg['location']
21
+ hash['network_interfaces_ids'] = nsg['properties']['networkInterfaces'].map { |item| item['id'] } unless nsg['properties']['networkInterfaces'].nil?
22
+ hash['subnets_ids'] = nsg['properties']['subnets'].map { |item| item['id'] } unless nsg['properties']['subnets'].nil?
23
+ hash['security_rules'] = []
24
+ hash['default_security_rules'] = []
25
+
26
+ nsg['properties']['securityRules'].each do |sr|
27
+ security_rule = Fog::Network::AzureRM::NetworkSecurityRule.new
28
+ hash['security_rules'] << security_rule.merge_attributes(Fog::Network::AzureRM::NetworkSecurityRule.parse(sr))
29
+ end unless nsg['properties']['securityRules'].nil?
30
+
31
+ nsg['properties']['defaultSecurityRules'].each do |dsr|
32
+ security_rule = Fog::Network::AzureRM::NetworkSecurityRule.new
33
+ hash['default_security_rules'] << security_rule.merge_attributes(Fog::Network::AzureRM::NetworkSecurityRule.parse(dsr))
34
+ end
35
+
36
+ hash
37
+ end
38
+
39
+ def save
40
+ requires :name, :location, :resource_group
41
+
42
+ validate_security_rules(security_rules) unless security_rules.nil?
43
+ nsg = service.create_network_security_group(resource_group, name, location, security_rules)
44
+ merge_attributes(Fog::Network::AzureRM::NetworkSecurityGroup.parse(nsg))
45
+ end
46
+
47
+ def destroy
48
+ service.delete_network_security_group(resource_group, name)
49
+ end
50
+
51
+ private
52
+
53
+ def validate_security_rules(security_rules)
54
+ if security_rules.is_a?(Array)
55
+ security_rules.each do |sr|
56
+ if sr.is_a?(Hash)
57
+ validate_security_rule_params(sr)
58
+ else
59
+ raise(ArgumentError, ':security_rules must be an Array of Hashes')
60
+ end
61
+ end
62
+ else
63
+ raise(ArgumentError, ':security_rules must be an Array')
64
+ end
65
+ end
66
+
67
+ def validate_security_rule_params(nsr)
68
+ required_params = [
69
+ :name,
70
+ :protocol,
71
+ :source_port_range,
72
+ :destination_port_range,
73
+ :source_address_prefix,
74
+ :destination_address_prefix,
75
+ :access,
76
+ :priority,
77
+ :direction
78
+ ]
79
+ missing = required_params.select { |p| p unless nsr.key?(p) }
80
+ if missing.length == 1
81
+ raise(ArgumentError, "#{missing.first} is required for this operation")
82
+ elsif missing.any?
83
+ raise(ArgumentError, "#{missing[0...-1].join(', ')} and #{missing[-1]} are required for this operation")
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end