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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +19 -8
- data/LICENSE.md +1 -1
- data/README.md +9 -8
- data/lib/fog/azurerm/models/compute/availability_set.rb +17 -3
- data/lib/fog/azurerm/models/compute/availability_sets.rb +2 -6
- data/lib/fog/azurerm/models/compute/server.rb +1 -1
- data/lib/fog/azurerm/models/compute/servers.rb +3 -1
- data/lib/fog/azurerm/models/dns/record_set.rb +31 -3
- data/lib/fog/azurerm/models/dns/record_sets.rb +7 -17
- data/lib/fog/azurerm/models/dns/zone.rb +26 -3
- data/lib/fog/azurerm/models/dns/zones.rb +8 -6
- data/lib/fog/azurerm/models/network/frontend_ip_configuration.rb +32 -0
- data/lib/fog/azurerm/models/network/inbound_nat_pool.rb +27 -0
- data/lib/fog/azurerm/models/network/inbound_nat_rule.rb +29 -0
- data/lib/fog/azurerm/models/network/load_balancer.rb +249 -0
- data/lib/fog/azurerm/models/network/load_balancers.rb +27 -0
- data/lib/fog/azurerm/models/network/load_balancing_rule.rb +42 -0
- data/lib/fog/azurerm/models/network/network_interface.rb +46 -7
- data/lib/fog/azurerm/models/network/network_interfaces.rb +2 -8
- data/lib/fog/azurerm/models/network/network_security_group.rb +89 -0
- data/lib/fog/azurerm/models/network/network_security_groups.rb +27 -0
- data/lib/fog/azurerm/models/network/network_security_rule.rb +40 -0
- data/lib/fog/azurerm/models/network/probe.rb +29 -0
- data/lib/fog/azurerm/models/network/public_ip.rb +32 -4
- data/lib/fog/azurerm/models/network/public_ips.rb +2 -8
- data/lib/fog/azurerm/models/network/subnet.rb +20 -12
- data/lib/fog/azurerm/models/network/subnets.rb +1 -7
- data/lib/fog/azurerm/models/network/traffic_manager_end_point.rb +63 -0
- data/lib/fog/azurerm/models/network/traffic_manager_end_points.rb +29 -0
- data/lib/fog/azurerm/models/network/traffic_manager_profile.rb +59 -0
- data/lib/fog/azurerm/models/network/traffic_manager_profiles.rb +24 -0
- data/lib/fog/azurerm/models/network/virtual_network.rb +19 -6
- data/lib/fog/azurerm/models/network/virtual_networks.rb +4 -9
- data/lib/fog/azurerm/models/resources/resource_group.rb +2 -1
- data/lib/fog/azurerm/models/resources/resource_groups.rb +1 -9
- data/lib/fog/azurerm/models/storage/storage_account.rb +5 -7
- data/lib/fog/azurerm/models/storage/storage_accounts.rb +5 -6
- data/lib/fog/azurerm/network.rb +30 -0
- data/lib/fog/azurerm/requests/compute/create_availability_set.rb +13 -2
- data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +60 -2
- data/lib/fog/azurerm/requests/compute/deallocate_virtual_machine.rb +4 -2
- data/lib/fog/azurerm/requests/compute/delete_availability_set.rb +4 -2
- data/lib/fog/azurerm/requests/compute/delete_virtual_machine.rb +4 -2
- data/lib/fog/azurerm/requests/compute/generalize_virtual_machine.rb +4 -2
- data/lib/fog/azurerm/requests/compute/get_virtual_machine.rb +57 -1
- data/lib/fog/azurerm/requests/compute/list_availability_sets.rb +16 -1
- data/lib/fog/azurerm/requests/compute/list_available_sizes_for_virtual_machine.rb +27 -1
- data/lib/fog/azurerm/requests/compute/power_off_virtual_machine.rb +4 -2
- data/lib/fog/azurerm/requests/compute/redeploy_virtual_machine.rb +4 -2
- data/lib/fog/azurerm/requests/compute/restart_virtual_machine.rb +4 -2
- data/lib/fog/azurerm/requests/compute/start_virtual_machine.rb +4 -2
- data/lib/fog/azurerm/requests/dns/check_for_zone.rb +16 -17
- data/lib/fog/azurerm/requests/dns/create_record_set.rb +80 -37
- data/lib/fog/azurerm/requests/dns/create_zone.rb +43 -27
- data/lib/fog/azurerm/requests/dns/delete_record_set.rb +17 -19
- data/lib/fog/azurerm/requests/dns/delete_zone.rb +16 -19
- data/lib/fog/azurerm/requests/dns/get_records_from_record_set.rb +29 -28
- data/lib/fog/azurerm/requests/dns/list_record_sets.rb +49 -23
- data/lib/fog/azurerm/requests/dns/list_zones.rb +57 -23
- data/lib/fog/azurerm/requests/network/check_for_public_ip.rb +3 -1
- data/lib/fog/azurerm/requests/network/check_for_virtual_network.rb +4 -2
- data/lib/fog/azurerm/requests/network/create_load_balancer.rb +208 -0
- data/lib/fog/azurerm/requests/network/create_network_interface.rb +42 -4
- data/lib/fog/azurerm/requests/network/create_network_security_group.rb +200 -0
- data/lib/fog/azurerm/requests/network/create_public_ip.rb +19 -5
- data/lib/fog/azurerm/requests/network/create_subnet.rb +19 -6
- data/lib/fog/azurerm/requests/network/create_traffic_manager_endpoint.rb +78 -0
- data/lib/fog/azurerm/requests/network/create_traffic_manager_profile.rb +127 -0
- data/lib/fog/azurerm/requests/network/create_virtual_network.rb +40 -5
- data/lib/fog/azurerm/requests/network/delete_load_balancer.rb +27 -0
- data/lib/fog/azurerm/requests/network/delete_network_interface.rb +5 -3
- data/lib/fog/azurerm/requests/network/delete_network_security_group.rb +29 -0
- data/lib/fog/azurerm/requests/network/delete_public_ip.rb +4 -2
- data/lib/fog/azurerm/requests/network/delete_subnet.rb +10 -8
- data/lib/fog/azurerm/requests/network/delete_traffic_manager_endpoint.rb +37 -0
- data/lib/fog/azurerm/requests/network/delete_traffic_manager_profile.rb +37 -0
- data/lib/fog/azurerm/requests/network/delete_virtual_network.rb +8 -6
- data/lib/fog/azurerm/requests/network/get_traffic_manager_profile.rb +96 -0
- data/lib/fog/azurerm/requests/network/list_load_balancers.rb +31 -0
- data/lib/fog/azurerm/requests/network/list_network_interfaces.rb +41 -9
- data/lib/fog/azurerm/requests/network/list_network_security_groups.rb +171 -0
- data/lib/fog/azurerm/requests/network/list_public_ips.rb +21 -9
- data/lib/fog/azurerm/requests/network/list_subnets.rb +34 -11
- data/lib/fog/azurerm/requests/network/list_traffic_manager_profiles.rb +98 -0
- data/lib/fog/azurerm/requests/network/list_virtual_networks.rb +53 -8
- data/lib/fog/azurerm/requests/resources/create_resource_group.rb +11 -2
- data/lib/fog/azurerm/requests/resources/delete_resource_group.rb +4 -2
- data/lib/fog/azurerm/requests/resources/list_resource_groups.rb +23 -7
- data/lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb +2 -0
- data/lib/fog/azurerm/requests/storage/create_storage_account.rb +14 -8
- data/lib/fog/azurerm/requests/storage/delete_storage_account.rb +4 -3
- data/lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb +33 -2
- data/lib/fog/azurerm/requests/storage/list_storage_accounts.rb +32 -5
- data/lib/fog/azurerm/storage.rb +0 -1
- data/lib/fog/azurerm/version.rb +1 -1
- metadata +35 -10
@@ -1,36 +1,33 @@
|
|
1
1
|
module Fog
|
2
2
|
module DNS
|
3
3
|
class AzureRM
|
4
|
+
# Real class for DNS Request
|
4
5
|
class Real
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{dns_resource_group}/providers/Microsoft.Network/dnsZones/#{zone_name}?api-version=2015-05-04-preview"
|
6
|
+
def delete_zone(resource_group, name)
|
7
|
+
Fog::Logger.debug "Deleting Zone #{name} ..."
|
8
|
+
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Network/dnsZones/#{name}?api-version=2015-05-04-preview"
|
9
9
|
begin
|
10
10
|
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
11
11
|
RestClient.delete(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
Fog::Logger.debug "Zone #{
|
12
|
+
resource_url,
|
13
|
+
accept: 'application/json',
|
14
|
+
content_type: 'application/json',
|
15
|
+
authorization: token)
|
16
|
+
Fog::Logger.debug "Zone #{name} deleted successfully."
|
17
17
|
true
|
18
|
-
rescue
|
19
|
-
|
20
|
-
|
21
|
-
body = body['error']
|
22
|
-
msg = "Exception deleting zone: #{body['code']}, #{body['message']}"
|
23
|
-
else
|
24
|
-
msg = "Exception deleting zone: #{body['code']}, #{body['message']}"
|
25
|
-
end
|
18
|
+
rescue Exception => e
|
19
|
+
Fog::Logger.warning "Exception deleting zone #{name} from resource group #{resource_group}"
|
20
|
+
msg = "AzureDns::Zone - Exception is: #{e.message}"
|
26
21
|
raise msg
|
27
22
|
end
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
26
|
+
# Mock class for DNS Request
|
31
27
|
class Mock
|
32
|
-
def delete_zone(
|
33
|
-
|
28
|
+
def delete_zone(_resource_group, _name)
|
29
|
+
Fog::Logger.debug "Zone #{_name} deleted successfully."
|
30
|
+
return true
|
34
31
|
end
|
35
32
|
end
|
36
33
|
end
|
@@ -1,44 +1,40 @@
|
|
1
1
|
module Fog
|
2
2
|
module DNS
|
3
3
|
class AzureRM
|
4
|
+
# Real class for DNS Request
|
4
5
|
class Real
|
5
|
-
def get_records_from_record_set(
|
6
|
-
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{
|
7
|
-
Fog::Logger.debug "Getting all records from RecordSet #{
|
6
|
+
def get_records_from_record_set(resource_group, name, zone_name, record_type)
|
7
|
+
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Network/dnsZones/#{zone_name}/#{record_type}/#{name}?api-version=2015-05-04-preview"
|
8
|
+
Fog::Logger.debug "Getting all records from RecordSet #{name} of type '#{record_type}' in zone #{zone_name}"
|
8
9
|
|
9
|
-
existing_records =
|
10
|
+
existing_records = []
|
10
11
|
begin
|
11
12
|
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
12
13
|
dns_response = RestClient.get(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
resource_url,
|
15
|
+
accept: 'application/json',
|
16
|
+
content_type: 'application/json',
|
17
|
+
authorization: token
|
17
18
|
)
|
18
19
|
rescue Exception => e
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
Fog::Logger.warning "Exception trying to get existing #{record_type} records for the record set: #{record_set_name}"
|
24
|
-
msg = "AzureDns::RecordSet - Exception is: #{e.message}"
|
25
|
-
raise msg
|
26
|
-
end
|
20
|
+
Fog::Logger.warning "Exception trying to get existing #{record_type} records for the record set: #{name}"
|
21
|
+
msg = "AzureDns::RecordSet - Exception is: #{e.message}"
|
22
|
+
raise msg
|
27
23
|
end
|
28
24
|
|
29
25
|
begin
|
30
26
|
dns_hash = JSON.parse(dns_response)
|
31
27
|
case record_type
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
when 'A'
|
29
|
+
dns_hash['properties']['ARecords'].each do |record|
|
30
|
+
Fog::Logger.debug "AzureDns:RecordSet - A record is: #{record}"
|
31
|
+
existing_records.push(record['ipv4Address'])
|
32
|
+
end
|
33
|
+
when 'CNAME'
|
34
|
+
Fog::Logger.debug "AzureDns:RecordSet - CNAME record is: #{dns_hash['properties']['CNAMERecord']['cname']}"
|
35
|
+
existing_records.push(dns_hash['properties']['CNAMERecord']['cname'])
|
40
36
|
end
|
41
|
-
|
37
|
+
existing_records
|
42
38
|
rescue Exception => e
|
43
39
|
Fog::Logger.warning "Exception trying to parse response: #{dns_response}"
|
44
40
|
msg = "AzureDns::RecordSet - Exception is: #{e.message}"
|
@@ -47,11 +43,16 @@ module Fog
|
|
47
43
|
end
|
48
44
|
end
|
49
45
|
|
46
|
+
# Mock class for DNS Request
|
50
47
|
class Mock
|
51
|
-
def get_records_from_record_set(
|
52
|
-
|
48
|
+
def get_records_from_record_set(_resource_group, _name, _zone_name, _record_type)
|
49
|
+
[
|
50
|
+
"1.2.3.4",
|
51
|
+
"1.2.3.5",
|
52
|
+
"1.2.3.6"
|
53
|
+
]
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
57
|
-
end
|
58
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Fog
|
2
2
|
module DNS
|
3
3
|
class AzureRM
|
4
|
+
# Real class for DNS Request
|
4
5
|
class Real
|
5
|
-
def list_record_sets(
|
6
|
-
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{
|
6
|
+
def list_record_sets(resource_group, zone_name)
|
7
|
+
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Network/dnsZones/#{zone_name}/recordsets?api-version=2015-05-04-preview"
|
7
8
|
begin
|
8
9
|
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
9
10
|
dns_response = RestClient.get(
|
@@ -11,34 +12,59 @@ module Fog
|
|
11
12
|
accept: 'application/json',
|
12
13
|
content_type: 'application/json',
|
13
14
|
authorization: token)
|
14
|
-
|
15
|
-
|
16
|
-
rescue
|
17
|
-
|
18
|
-
|
19
|
-
body = body['error']
|
20
|
-
msg = "Exception fetching record_sets: #{body['code']}, #{body['message']}"
|
21
|
-
else
|
22
|
-
msg = "Exception fetching record_sets: #{body['code']}, #{body['message']}"
|
23
|
-
end
|
15
|
+
parsed_zone = JSON.parse(dns_response)
|
16
|
+
parsed_zone['value']
|
17
|
+
rescue Exception => e
|
18
|
+
Fog::Logger.warning "Exception listing recordsets in zone #{zone_name} in resource group #{resource_group}"
|
19
|
+
msg = "AzureDns::RecordSet - Exception is: #{e.message}"
|
24
20
|
raise msg
|
25
21
|
end
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
25
|
+
# Mock class for DNS Request
|
29
26
|
class Mock
|
30
|
-
def list_record_sets(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
27
|
+
def list_record_sets(_resource_group, _zone_name)
|
28
|
+
[
|
29
|
+
{
|
30
|
+
"id"=>"/subscriptions/########-####-####-####-############/resourceGroups/#{_resource_group}/providers/Microsoft.Network/dnszones/#{_zone_name}/A/test_record",
|
31
|
+
"name"=>"test_record",
|
32
|
+
"type"=>"Microsoft.Network/dnszones/A",
|
33
|
+
"etag"=>"7f159cb1-653d-4920-bc03-153c700412a2",
|
34
|
+
"location"=>"global",
|
35
|
+
"properties"=>
|
36
|
+
{
|
37
|
+
"metadata"=>nil,
|
38
|
+
"fqdn"=>"test_record.#{_zone_name}.",
|
39
|
+
"TTL"=>60,
|
40
|
+
"ARecords"=>
|
41
|
+
[
|
42
|
+
{
|
43
|
+
"ipv4Address"=>"1.2.3.4"
|
44
|
+
}
|
45
|
+
]
|
46
|
+
}
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"id"=>"/subscriptions/########-####-####-####-############/resourceGroups/#{_resource_group}/providers/Microsoft.Network/dnszones/#{_zone_name}/CNAME/test_record1",
|
50
|
+
"name"=>"test_record1",
|
51
|
+
"type"=>"Microsoft.Network/dnszones/CNAME",
|
52
|
+
"etag"=>"cc5ceb6e-16ad-4a5f-bbd7-9bc31c12d0cf",
|
53
|
+
"location"=>"global",
|
54
|
+
"properties"=>
|
55
|
+
{
|
56
|
+
"metadata"=>nil,
|
57
|
+
"fqdn"=>"test_record1.#{_zone_name}.",
|
58
|
+
"TTL"=>60,
|
59
|
+
"CNAMERecord"=>
|
60
|
+
{
|
61
|
+
"cname"=>"1.2.3.4"
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
]
|
40
66
|
end
|
41
67
|
end
|
42
68
|
end
|
43
69
|
end
|
44
|
-
end
|
70
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Fog
|
2
2
|
module DNS
|
3
3
|
class AzureRM
|
4
|
+
# Real class for DNS Request
|
4
5
|
class Real
|
5
6
|
def list_zones
|
6
7
|
zone_hash_array = []
|
7
8
|
@resources.resource_groups.each do |rg|
|
8
9
|
list_zones_by_rg(rg.name).each do |zone_hash|
|
9
|
-
zone_hash['resource_group'] = rg.name
|
10
10
|
zone_hash_array << zone_hash
|
11
11
|
end
|
12
12
|
end
|
@@ -15,38 +15,72 @@ module Fog
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def list_zones_by_rg(
|
19
|
-
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{
|
18
|
+
def list_zones_by_rg(resource_group)
|
19
|
+
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Network/dnsZones?api-version=2015-05-04-preview"
|
20
20
|
begin
|
21
21
|
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
22
22
|
dns_response = RestClient.get(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
rescue
|
30
|
-
|
31
|
-
|
32
|
-
body = body['error']
|
33
|
-
msg = "Exception fetching zones: #{body['code']}, #{body['message']}"
|
34
|
-
else
|
35
|
-
msg = "Exception fetching zones: #{body['code']}, #{body['message']}"
|
36
|
-
end
|
23
|
+
resource_url,
|
24
|
+
accept: 'application/json',
|
25
|
+
content_type: 'application/json',
|
26
|
+
authorization: token)
|
27
|
+
parsed_zone = JSON.parse(dns_response)
|
28
|
+
parsed_zone['value']
|
29
|
+
rescue Exception => e
|
30
|
+
Fog::Logger.warning "Exception listing zones in resource group #{resource_group}"
|
31
|
+
msg = "AzureDns::RecordSet - Exception is: #{e.message}"
|
37
32
|
raise msg
|
38
33
|
end
|
39
34
|
end
|
40
35
|
end
|
41
36
|
|
37
|
+
# Mock class for DNS Request
|
42
38
|
class Mock
|
43
39
|
def list_zones
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
[
|
41
|
+
{
|
42
|
+
"id"=>"/subscriptions/########-####-####-####-############/resourceGroups/fog_test_rg/providers/Microsoft.Network/dnszones/testfog1.com",
|
43
|
+
"name"=>"testfog1.com",
|
44
|
+
"type"=>"Microsoft.Network/dnszones",
|
45
|
+
"etag"=> "00000002-0000-0000-76c2-f7ad90b5d101",
|
46
|
+
"location"=>"global",
|
47
|
+
"tags"=>{},
|
48
|
+
"properties"=>
|
49
|
+
{
|
50
|
+
"maxNumberOfRecordSets"=>5000,
|
51
|
+
"nameServers"=>
|
52
|
+
[
|
53
|
+
"ns1-05.azure-dns.com.",
|
54
|
+
"ns2-05.azure-dns.net.",
|
55
|
+
"ns3-05.azure-dns.org.",
|
56
|
+
"ns4-05.azure-dns.info."
|
57
|
+
],
|
58
|
+
"numberOfRecordSets"=>2,
|
59
|
+
"parentResourceGroupName"=>"fog_test_rg"
|
60
|
+
}
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"id"=>"/subscriptions/########-####-####-####-############/resourceGroups/fog_test_rg/providers/Microsoft.Network/dnszones/testfog.com",
|
64
|
+
"name"=>"testfog.com",
|
65
|
+
"type"=>"Microsoft.Network/dnszones",
|
66
|
+
"etag"=>"00000002-0000-0000-4215-c21c8fb5d101",
|
67
|
+
"location"=>"global",
|
68
|
+
"tags"=>{},
|
69
|
+
"properties"=>
|
70
|
+
{
|
71
|
+
"maxNumberOfRecordSets"=>5000,
|
72
|
+
"nameServers"=>
|
73
|
+
[
|
74
|
+
"ns1-02.azure-dns.com.",
|
75
|
+
"ns2-02.azure-dns.net.",
|
76
|
+
"ns3-02.azure-dns.org.",
|
77
|
+
"ns4-02.azure-dns.info."
|
78
|
+
],
|
79
|
+
"numberOfRecordSets"=>2,
|
80
|
+
"parentResourceGroupName"=>"fog_test_rg"
|
81
|
+
}
|
82
|
+
}
|
83
|
+
]
|
50
84
|
end
|
51
85
|
end
|
52
86
|
end
|
@@ -18,7 +18,9 @@ module Fog
|
|
18
18
|
|
19
19
|
# Mock class for Network Request
|
20
20
|
class Mock
|
21
|
-
def check_for_public_ip(
|
21
|
+
def check_for_public_ip(resource_group, name)
|
22
|
+
Fog::Logger.debug "Public IP #{name} from Resource group #{resource_group} is available."
|
23
|
+
return true
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -3,7 +3,7 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# Mock class for Network Request
|
5
5
|
class Real
|
6
|
-
def check_for_virtual_network(
|
6
|
+
def check_for_virtual_network(resource_group, name)
|
7
7
|
begin
|
8
8
|
promise = @network_client.virtual_networks.get(resource_group, name)
|
9
9
|
promise.value!
|
@@ -18,7 +18,9 @@ module Fog
|
|
18
18
|
|
19
19
|
# Mock class for Network Request
|
20
20
|
class Mock
|
21
|
-
def check_for_virtual_network(
|
21
|
+
def check_for_virtual_network(resource_group, name)
|
22
|
+
Fog::Logger.debug "Virtual Network #{name} from Resource group #{resource_group} is available."
|
23
|
+
return true
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
module Fog
|
2
|
+
module Network
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Network Request
|
5
|
+
class Real
|
6
|
+
def create_load_balancer(name, location, resource_group, frontend_ip_configurations, backend_address_pool_names, load_balancing_rules, probes, inbound_nat_rules, inbound_nat_pools)
|
7
|
+
Fog::Logger.debug "Creating Load-Balancer: #{name}..."
|
8
|
+
load_balancer = define_load_balancer(name, location, frontend_ip_configurations, backend_address_pool_names, load_balancing_rules, probes, inbound_nat_rules, inbound_nat_pools)
|
9
|
+
begin
|
10
|
+
promise = @network_client.load_balancers.create_or_update(resource_group, name, load_balancer)
|
11
|
+
result = promise.value!
|
12
|
+
Fog::Logger.debug "Load-Balancer #{name} created successfully."
|
13
|
+
Azure::ARM::Network::Models::LoadBalancer.serialize_object(result.body)
|
14
|
+
rescue MsRestAzure::AzureOperationError => e
|
15
|
+
msg = "Exception creating Load-Balancer #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
|
16
|
+
raise msg
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def define_load_balancer(name, location, frontend_ip_configurations, backend_address_pool_names, load_balancing_rules, probes, inbound_nat_rules, inbound_nat_pools)
|
23
|
+
lb_props = Azure::ARM::Network::Models::LoadBalancerPropertiesFormat.new
|
24
|
+
|
25
|
+
if frontend_ip_configurations
|
26
|
+
frontend_ip_configuration_arr = define_frontend_ip_configurations(frontend_ip_configurations)
|
27
|
+
lb_props.frontend_ipconfigurations = []
|
28
|
+
lb_props.frontend_ipconfigurations = frontend_ip_configuration_arr
|
29
|
+
end
|
30
|
+
|
31
|
+
if backend_address_pool_names
|
32
|
+
lb_props.backend_address_pools = []
|
33
|
+
backend_address_pool_names.each do |bap|
|
34
|
+
backend_pool = Azure::ARM::Network::Models::BackendAddressPool.new
|
35
|
+
backend_pool.name = bap
|
36
|
+
lb_props.backend_address_pools.push(backend_pool)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if load_balancing_rules
|
41
|
+
lb_props.load_balancing_rules = []
|
42
|
+
load_balancing_rule_arr = define_load_balancing_rule(load_balancing_rules)
|
43
|
+
lb_props.load_balancing_rules = load_balancing_rule_arr
|
44
|
+
end
|
45
|
+
|
46
|
+
if probes
|
47
|
+
lb_props.probes = []
|
48
|
+
probe_arr = define_probe(probes)
|
49
|
+
lb_props.probes = probe_arr
|
50
|
+
end
|
51
|
+
|
52
|
+
if inbound_nat_rules
|
53
|
+
lb_props.inbound_nat_rules = []
|
54
|
+
inbound_nat_rule_arr = define_inbound_nat_rule(inbound_nat_rules)
|
55
|
+
lb_props.inbound_nat_rules = inbound_nat_rule_arr
|
56
|
+
end
|
57
|
+
|
58
|
+
if inbound_nat_pools
|
59
|
+
lb_props.inbound_nat_pools = []
|
60
|
+
inbound_nat_pool_arr = define_inbound_nat_pool(inbound_nat_pools)
|
61
|
+
lb_props.inbound_nat_pools = inbound_nat_pool_arr
|
62
|
+
end
|
63
|
+
|
64
|
+
load_balancer = Azure::ARM::Network::Models::LoadBalancer.new
|
65
|
+
load_balancer.name = name
|
66
|
+
load_balancer.location = location
|
67
|
+
load_balancer.properties = lb_props
|
68
|
+
|
69
|
+
load_balancer
|
70
|
+
end
|
71
|
+
|
72
|
+
def define_inbound_nat_pool(inbound_nat_pools)
|
73
|
+
inbound_nat_pool_arr = []
|
74
|
+
inbound_nat_pools.each do |inp|
|
75
|
+
inbound_nat_pool = Azure::ARM::Network::Models::InboundNatPool.new
|
76
|
+
inbound_nat_pool_prop = Azure::ARM::Network::Models::InboundNatPoolPropertiesFormat.new
|
77
|
+
|
78
|
+
unless inp[:frontend_ip_configuration_id].nil?
|
79
|
+
frontend_ipconfigurations = Azure::ARM::Network::Models::FrontendIPConfiguration.new
|
80
|
+
frontend_ipconfigurations.id = inp[:frontend_ip_configuration_id]
|
81
|
+
inbound_nat_pool_prop.frontend_ipconfiguration = frontend_ipconfigurations
|
82
|
+
end
|
83
|
+
|
84
|
+
inbound_nat_pool_prop.protocol = inp[:protocol]
|
85
|
+
inbound_nat_pool_prop.frontend_port_range_start = inp[:frontend_port_range_start]
|
86
|
+
inbound_nat_pool_prop.frontend_port_range_end = inp[:frontend_port_range_end]
|
87
|
+
inbound_nat_pool_prop.backend_port = inp[:backend_port]
|
88
|
+
|
89
|
+
inbound_nat_pool.name = inp[:name]
|
90
|
+
inbound_nat_pool.properties = inbound_nat_pool_prop
|
91
|
+
inbound_nat_pool_arr.push(inbound_nat_pool)
|
92
|
+
end
|
93
|
+
inbound_nat_pool_arr
|
94
|
+
end
|
95
|
+
|
96
|
+
def define_inbound_nat_rule(inbound_nat_rules)
|
97
|
+
inbound_nat_rule_arr = []
|
98
|
+
inbound_nat_rules.each do |inr|
|
99
|
+
inbound_nat_rule = Azure::ARM::Network::Models::InboundNatRule.new
|
100
|
+
inbound_nat_rule_prop = Azure::ARM::Network::Models::InboundNatRulePropertiesFormat.new
|
101
|
+
|
102
|
+
unless inr[:frontend_ip_configuration_id].nil?
|
103
|
+
frontend_ipconfigurations = Azure::ARM::Network::Models::FrontendIPConfiguration.new
|
104
|
+
frontend_ipconfigurations.id = inr[:frontend_ip_configuration_id]
|
105
|
+
inbound_nat_rule_prop.frontend_ipconfiguration = frontend_ipconfigurations
|
106
|
+
end
|
107
|
+
inbound_nat_rule_prop.protocol = inr[:protocol]
|
108
|
+
inbound_nat_rule_prop.frontend_port = inr[:frontend_port]
|
109
|
+
inbound_nat_rule_prop.backend_port = inr[:backend_port]
|
110
|
+
|
111
|
+
inbound_nat_rule.name = inr[:name]
|
112
|
+
inbound_nat_rule.properties = inbound_nat_rule_prop
|
113
|
+
inbound_nat_rule_arr.push(inbound_nat_rule)
|
114
|
+
end
|
115
|
+
inbound_nat_rule_arr
|
116
|
+
end
|
117
|
+
|
118
|
+
def define_probe(probes)
|
119
|
+
probe_arr = []
|
120
|
+
probes.each do |prb|
|
121
|
+
probe = Azure::ARM::Network::Models::Probe.new
|
122
|
+
probe_prop = Azure::ARM::Network::Models::ProbePropertiesFormat.new
|
123
|
+
|
124
|
+
probe_prop.protocol = prb[:protocol]
|
125
|
+
probe_prop.port = prb[:port]
|
126
|
+
probe_prop.interval_in_seconds = prb[:interval_in_seconds]
|
127
|
+
probe_prop.number_of_probes = prb[:number_of_probes]
|
128
|
+
probe_prop.request_path = prb[:request_path]
|
129
|
+
|
130
|
+
probe.name = prb[:name]
|
131
|
+
probe.properties = probe_prop
|
132
|
+
probe_arr.push(probe)
|
133
|
+
end
|
134
|
+
probe_arr
|
135
|
+
end
|
136
|
+
|
137
|
+
def define_load_balancing_rule(load_balancing_rules)
|
138
|
+
load_balancing_rule_arr = []
|
139
|
+
load_balancing_rules.each do |lbr|
|
140
|
+
load_balancing_rule = Azure::ARM::Network::Models::LoadBalancingRule.new
|
141
|
+
load_balancing_rule_prop = Azure::ARM::Network::Models::LoadBalancingRulePropertiesFormat.new
|
142
|
+
|
143
|
+
load_balancing_rule_prop.protocol = lbr[:protocol]
|
144
|
+
load_balancing_rule_prop.load_distribution = lbr[:load_distribution]
|
145
|
+
load_balancing_rule_prop.idle_timeout_in_minutes = lbr[:idle_timeout_in_minutes]
|
146
|
+
load_balancing_rule_prop.frontend_port = lbr[:frontend_port]
|
147
|
+
load_balancing_rule_prop.backend_port = lbr[:backend_port]
|
148
|
+
load_balancing_rule_prop.enable_floating_ip = lbr[:enable_floating_ip]
|
149
|
+
|
150
|
+
unless lbr[:frontend_ip_configuration_id].nil?
|
151
|
+
frontend_ipconfigurations = Azure::ARM::Network::Models::FrontendIPConfiguration.new
|
152
|
+
frontend_ipconfigurations.id = lbr[:frontend_ip_configuration_id]
|
153
|
+
load_balancing_rule_prop.frontend_ipconfiguration = frontend_ipconfigurations
|
154
|
+
end
|
155
|
+
|
156
|
+
unless lbr[:backend_address_pool_id].nil?
|
157
|
+
backend_address_pool = Azure::ARM::Network::Models::BackendAddressPool.new
|
158
|
+
backend_address_pool.id = lbr[:backend_address_pool_id]
|
159
|
+
load_balancing_rule_prop.backend_address_pool = backend_address_pool
|
160
|
+
end
|
161
|
+
|
162
|
+
unless lbr[:probe_id].nil?
|
163
|
+
probe = Azure::ARM::Network::Models::Probe.new
|
164
|
+
probe.id = lbr[:probe_id]
|
165
|
+
load_balancing_rule_prop.probe = probe
|
166
|
+
end
|
167
|
+
|
168
|
+
load_balancing_rule.name = lbr[:name]
|
169
|
+
load_balancing_rule.properties = load_balancing_rule_prop
|
170
|
+
load_balancing_rule_arr.push(load_balancing_rule)
|
171
|
+
end
|
172
|
+
load_balancing_rule_arr
|
173
|
+
end
|
174
|
+
|
175
|
+
def define_frontend_ip_configurations(frontend_ip_configurations)
|
176
|
+
frontend_ip_configuration_arr = []
|
177
|
+
frontend_ip_configurations.each do |fic|
|
178
|
+
frontend_ip_configuration = Azure::ARM::Network::Models::FrontendIPConfiguration.new
|
179
|
+
frontend_ip_configuration_prop = Azure::ARM::Network::Models::FrontendIPConfigurationPropertiesFormat.new
|
180
|
+
frontend_ip_configuration_prop.private_ipaddress = fic[:private_ipaddress]
|
181
|
+
frontend_ip_configuration_prop.private_ipallocation_method = fic[:private_ipallocation_method]
|
182
|
+
unless fic[:subnet_id].nil?
|
183
|
+
snet = Azure::ARM::Network::Models::Subnet.new
|
184
|
+
snet.id = fic[:subnet_id]
|
185
|
+
frontend_ip_configuration_prop.subnet = snet
|
186
|
+
end
|
187
|
+
unless fic[:public_ipaddress_id].nil?
|
188
|
+
pip = Azure::ARM::Network::Models::PublicIPAddress.new
|
189
|
+
pip.id = fic[:public_ipaddress_id]
|
190
|
+
frontend_ip_configuration_prop.public_ipaddress = pip
|
191
|
+
end
|
192
|
+
|
193
|
+
frontend_ip_configuration.name = fic[:name]
|
194
|
+
frontend_ip_configuration.properties = frontend_ip_configuration_prop
|
195
|
+
frontend_ip_configuration_arr.push(frontend_ip_configuration)
|
196
|
+
end
|
197
|
+
frontend_ip_configuration_arr
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# Mock class for Network Request
|
202
|
+
class Mock
|
203
|
+
def create_load_balancer(_name, _location, _resource_group, _frontend_ip_configuration_name, _subnet_id, _private_ip_address, _private_ip_allocation_method, _public_ip_address_id, _backend_address_pool_names, _load_balancing_rules, _probes, _inbound_nat_rules, _inbound_nat_pools)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|