fog-azure-rm 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +27 -0
  3. data/CONTRIBUTORS.md +4 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +82 -0
  6. data/lib/fog/azurerm.rb +40 -0
  7. data/lib/fog/azurerm/compute.rb +61 -0
  8. data/lib/fog/azurerm/config.rb +1 -0
  9. data/lib/fog/azurerm/core.rb +12 -0
  10. data/lib/fog/azurerm/credentials.rb +37 -0
  11. data/lib/fog/azurerm/dns.rb +48 -0
  12. data/lib/fog/azurerm/models/compute/availability_set.rb +31 -0
  13. data/lib/fog/azurerm/models/compute/availability_sets.rb +36 -0
  14. data/lib/fog/azurerm/models/compute/server.rb +94 -0
  15. data/lib/fog/azurerm/models/compute/servers.rb +32 -0
  16. data/lib/fog/azurerm/models/dns/record_set.rb +28 -0
  17. data/lib/fog/azurerm/models/dns/record_sets.rb +44 -0
  18. data/lib/fog/azurerm/models/dns/zone.rb +21 -0
  19. data/lib/fog/azurerm/models/dns/zones.rb +30 -0
  20. data/lib/fog/azurerm/models/network/network_interface.rb +34 -0
  21. data/lib/fog/azurerm/models/network/network_interfaces.rb +35 -0
  22. data/lib/fog/azurerm/models/network/public_ip.rb +34 -0
  23. data/lib/fog/azurerm/models/network/public_ips.rb +46 -0
  24. data/lib/fog/azurerm/models/network/subnet.rb +34 -0
  25. data/lib/fog/azurerm/models/network/subnets.rb +37 -0
  26. data/lib/fog/azurerm/models/network/virtual_network.rb +30 -0
  27. data/lib/fog/azurerm/models/network/virtual_networks.rb +42 -0
  28. data/lib/fog/azurerm/models/resources/resource_group.rb +21 -0
  29. data/lib/fog/azurerm/models/resources/resource_groups.rb +28 -0
  30. data/lib/fog/azurerm/models/storage/storage_account.rb +37 -0
  31. data/lib/fog/azurerm/models/storage/storage_accounts.rb +45 -0
  32. data/lib/fog/azurerm/network.rb +67 -0
  33. data/lib/fog/azurerm/requests/compute/create_availability_set.rb +45 -0
  34. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +100 -0
  35. data/lib/fog/azurerm/requests/compute/deallocate_virtual_machine.rb +26 -0
  36. data/lib/fog/azurerm/requests/compute/delete_availability_set.rb +26 -0
  37. data/lib/fog/azurerm/requests/compute/delete_virtual_machine.rb +26 -0
  38. data/lib/fog/azurerm/requests/compute/generalize_virtual_machine.rb +26 -0
  39. data/lib/fog/azurerm/requests/compute/get_virtual_machine.rb +24 -0
  40. data/lib/fog/azurerm/requests/compute/list_availability_sets.rb +24 -0
  41. data/lib/fog/azurerm/requests/compute/list_available_sizes_for_virtual_machine.rb +24 -0
  42. data/lib/fog/azurerm/requests/compute/list_virtual_machines.rb +64 -0
  43. data/lib/fog/azurerm/requests/compute/power_off_virtual_machine.rb +26 -0
  44. data/lib/fog/azurerm/requests/compute/redeploy_virtual_machine.rb +26 -0
  45. data/lib/fog/azurerm/requests/compute/restart_virtual_machine.rb +26 -0
  46. data/lib/fog/azurerm/requests/compute/start_virtual_machine.rb +26 -0
  47. data/lib/fog/azurerm/requests/dns/check_for_zone.rb +39 -0
  48. data/lib/fog/azurerm/requests/dns/create_record_set.rb +61 -0
  49. data/lib/fog/azurerm/requests/dns/create_zone.rb +47 -0
  50. data/lib/fog/azurerm/requests/dns/delete_record_set.rb +38 -0
  51. data/lib/fog/azurerm/requests/dns/delete_zone.rb +38 -0
  52. data/lib/fog/azurerm/requests/dns/get_records_from_record_set.rb +57 -0
  53. data/lib/fog/azurerm/requests/dns/list_record_sets.rb +44 -0
  54. data/lib/fog/azurerm/requests/dns/list_zones.rb +52 -0
  55. data/lib/fog/azurerm/requests/network/check_for_public_ip.rb +27 -0
  56. data/lib/fog/azurerm/requests/network/check_for_virtual_network.rb +27 -0
  57. data/lib/fog/azurerm/requests/network/create_network_interface.rb +52 -0
  58. data/lib/fog/azurerm/requests/network/create_public_ip.rb +28 -0
  59. data/lib/fog/azurerm/requests/network/create_subnet.rb +30 -0
  60. data/lib/fog/azurerm/requests/network/create_virtual_network.rb +80 -0
  61. data/lib/fog/azurerm/requests/network/delete_network_interface.rb +27 -0
  62. data/lib/fog/azurerm/requests/network/delete_public_ip.rb +27 -0
  63. data/lib/fog/azurerm/requests/network/delete_subnet.rb +27 -0
  64. data/lib/fog/azurerm/requests/network/delete_virtual_network.rb +27 -0
  65. data/lib/fog/azurerm/requests/network/list_network_interfaces.rb +32 -0
  66. data/lib/fog/azurerm/requests/network/list_public_ips.rb +32 -0
  67. data/lib/fog/azurerm/requests/network/list_subnets.rb +30 -0
  68. data/lib/fog/azurerm/requests/network/list_virtual_networks.rb +29 -0
  69. data/lib/fog/azurerm/requests/resources/create_resource_group.rb +27 -0
  70. data/lib/fog/azurerm/requests/resources/delete_resource_group.rb +25 -0
  71. data/lib/fog/azurerm/requests/resources/list_resource_groups.rb +28 -0
  72. data/lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb +33 -0
  73. data/lib/fog/azurerm/requests/storage/create_storage_account.rb +33 -0
  74. data/lib/fog/azurerm/requests/storage/delete_storage_account.rb +27 -0
  75. data/lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb +25 -0
  76. data/lib/fog/azurerm/requests/storage/list_storage_accounts.rb +28 -0
  77. data/lib/fog/azurerm/resources.rb +48 -0
  78. data/lib/fog/azurerm/storage.rb +51 -0
  79. data/lib/fog/azurerm/version.rb +5 -0
  80. metadata +278 -0
@@ -0,0 +1,57 @@
1
+ module Fog
2
+ module DNS
3
+ class AzureRM
4
+ class Real
5
+ def get_records_from_record_set(record_set_name, dns_resource_group, zone_name, record_type)
6
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{dns_resource_group}/providers/Microsoft.Network/dnsZones/#{zone_name}/#{record_type}/#{record_set_name}?api-version=2015-05-04-preview"
7
+ Fog::Logger.debug "Getting all records from RecordSet #{record_set_name} of type '#{record_type}' in zone #{zone_name}"
8
+
9
+ existing_records = Array.new
10
+ begin
11
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
12
+ dns_response = RestClient.get(
13
+ resource_url,
14
+ accept: 'application/json',
15
+ content_type: 'application/json',
16
+ authorization: token
17
+ )
18
+ rescue Exception => e
19
+ if e.http_code == 404
20
+ Fog::Logger.warning 'AzureDns::RecordSet - 404 code, record set does not exist. returning empty array'
21
+ return existing_records
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
27
+ end
28
+
29
+ begin
30
+ dns_hash = JSON.parse(dns_response)
31
+ case record_type
32
+ when 'A'
33
+ dns_hash['properties']['ARecords'].each do |record|
34
+ Fog::Logger.debug "AzureDns:RecordSet - A record is: #{record}"
35
+ existing_records.push(record['ipv4Address'])
36
+ end
37
+ when 'CNAME'
38
+ Fog::Logger.debug "AzureDns:RecordSet - CNAME record is: #{dns_hash['properties']['CNAMERecord']['cname']}"
39
+ existing_records.push(dns_hash['properties']['CNAMERecord']['cname'])
40
+ end
41
+ return existing_records
42
+ rescue Exception => e
43
+ Fog::Logger.warning "Exception trying to parse response: #{dns_response}"
44
+ msg = "AzureDns::RecordSet - Exception is: #{e.message}"
45
+ raise msg
46
+ end
47
+ end
48
+ end
49
+
50
+ class Mock
51
+ def get_records_from_record_set(record_set_name, dns_resource_group, zone_name, record_type)
52
+
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module DNS
3
+ class AzureRM
4
+ class Real
5
+ def list_record_sets(dns_resource_group, zone_name)
6
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{dns_resource_group}/providers/Microsoft.Network/dnsZones/#{zone_name}/recordsets?api-version=2015-05-04-preview"
7
+ begin
8
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
9
+ dns_response = RestClient.get(
10
+ resource_url,
11
+ accept: 'application/json',
12
+ content_type: 'application/json',
13
+ authorization: token)
14
+ response_hash = JSON.parse(dns_response)
15
+ response_hash['value']
16
+ rescue RestClient::Exception => e
17
+ body = JSON.parse(e.http_body)
18
+ if body.key?('error')
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
24
+ raise msg
25
+ end
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def list_record_sets(dns_resource_group, zone_name)
31
+ rset = {
32
+ :name => 'fogtestrecordset',
33
+ :resource_group => 'fog-test-resource-group',
34
+ :zone_name => 'fogtestzone.com',
35
+ :records => ['1.2.3.4', '1.2.3.3'],
36
+ :type => 'A',
37
+ :ttl => 60
38
+ }
39
+ [rset]
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,52 @@
1
+ module Fog
2
+ module DNS
3
+ class AzureRM
4
+ class Real
5
+ def list_zones
6
+ zone_hash_array = []
7
+ @resources.resource_groups.each do |rg|
8
+ list_zones(rg.name).each do |zone_hash|
9
+ zone_hash['resource_group'] = rg.name
10
+ zone_hash_array << zone_hash
11
+ end
12
+ end
13
+ zone_hash_array
14
+ end
15
+
16
+ def list_zones(dns_resource_group)
17
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{dns_resource_group}/providers/Microsoft.Network/dnsZones?api-version=2015-05-04-preview"
18
+ begin
19
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
20
+ dns_response = RestClient.get(
21
+ resource_url,
22
+ accept: 'application/json',
23
+ content_type: 'application/json',
24
+ authorization: token)
25
+ response_hash = JSON.parse(dns_response)
26
+ response_hash['value']
27
+ rescue RestClient::Exception => e
28
+ body = JSON.parse(e.http_body)
29
+ if body.key?('error')
30
+ body = body['error']
31
+ msg = "Exception fetching zones: #{body['code']}, #{body['message']}"
32
+ else
33
+ msg = "Exception fetching zones: #{body['code']}, #{body['message']}"
34
+ end
35
+ raise msg
36
+ end
37
+ end
38
+ end
39
+
40
+ class Mock
41
+ def list_zones
42
+ zone = {
43
+ id: '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-resource-group/Microsoft.Network/dnszones/fogtestzone.com',
44
+ name: 'fogtestzone.com',
45
+ resource_group: 'fog-test-resource-group'
46
+ }
47
+ [zone]
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Mock class for Network Request
5
+ class Real
6
+ def check_for_public_ip(resource_group, name)
7
+ begin
8
+ promise = @network_client.public_ipaddresses.get(resource_group, name)
9
+ promise.value!
10
+ return true
11
+ rescue MsRestAzure::AzureOperationError => e
12
+ msg = "Exception checking name availability: #{e.body['error']['message']}"
13
+ raise msg if e.body['error']['code'] == 'ResourceGroupNotFound'
14
+ return false if e.body['error']['code'] == 'ResourceNotFound'
15
+ return true
16
+ end
17
+ end
18
+ end
19
+
20
+ # Mock class for Network Request
21
+ class Mock
22
+ def check_for_public_ip(_resource_group, _name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Mock class for Network Request
5
+ class Real
6
+ def check_for_virtual_network(name, resource_group)
7
+ begin
8
+ promise = @network_client.virtual_networks.get(resource_group, name)
9
+ promise.value!
10
+ return true
11
+ rescue MsRestAzure::AzureOperationError => e
12
+ msg = "Exception checking name availability: #{e.body['error']['message']}"
13
+ raise msg if e.body['error']['code'] == 'ResourceGroupNotFound'
14
+ return false if e.body['error']['code'] == 'ResourceNotFound'
15
+ return true
16
+ end
17
+ end
18
+ end
19
+
20
+ # Mock class for Network Request
21
+ class Mock
22
+ def check_for_virtual_network(_name, _resource_group)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,52 @@
1
+
2
+ module Fog
3
+ module Network
4
+ class AzureRM
5
+ # Real class for Network Request
6
+ class Real
7
+ def create_network_interface(name, location, resource_group, subnet_id, ip_config_name, prv_ip_alloc_method)
8
+ network_interface = define_network_interface(name, location, subnet_id, ip_config_name, prv_ip_alloc_method)
9
+ begin
10
+ promise = @network_client.network_interfaces.create_or_update(resource_group, name, network_interface)
11
+ promise.value!
12
+ rescue MsRestAzure::AzureOperationError => e
13
+ msg = "Exception creating Network Interface #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
14
+ raise msg
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def define_network_interface(name, location, subnet_id, ip_config_name, prv_ip_alloc_method)
21
+ subnet = Azure::ARM::Network::Models::Subnet.new
22
+ subnet.id = subnet_id
23
+
24
+ ip_configs_props = Azure::ARM::Network::Models::NetworkInterfaceIPConfigurationPropertiesFormat.new
25
+ ip_configs_props.private_ipallocation_method = prv_ip_alloc_method
26
+ ip_configs_props.subnet = subnet
27
+
28
+ ip_configs = Azure::ARM::Network::Models::NetworkInterfaceIPConfiguration.new
29
+ ip_configs.name = ip_config_name
30
+ ip_configs.properties = ip_configs_props
31
+
32
+ nic_props = Azure::ARM::Network::Models::NetworkInterfacePropertiesFormat.new
33
+ nic_props.ip_configurations = [ip_configs]
34
+
35
+ network_interface = Azure::ARM::Network::Models::NetworkInterface.new
36
+ network_interface.name = name
37
+ network_interface.location = location
38
+ network_interface.properties = nic_props
39
+
40
+ network_interface
41
+ end
42
+ end
43
+
44
+ # Mock class for Network Request
45
+ class Mock
46
+ def create_network_interface(name, location, resource_group, subnet_id, ip_configs_name, prv_ip_alloc_method)
47
+
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def create_public_ip(resource_group, name, public_ip)
7
+ Fog::Logger.debug "Creating PublicIP #{name} in Resource Group #{resource_group}."
8
+ begin
9
+ promise = @network_client.public_ipaddresses.create_or_update(resource_group, name, public_ip)
10
+ response = promise.value!
11
+ result = response.body
12
+ Fog::Logger.debug "PublicIP #{name} Created Successfully!"
13
+ return result
14
+ rescue MsRestAzure::AzureOperationError => e
15
+ msg = "Exception creating Public IP #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
16
+ raise msg
17
+ end
18
+ end
19
+ end
20
+
21
+ # Mock class for Network Request
22
+ class Mock
23
+ def create_public_ip(resource_group, name, public_ip)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def create_subnet(resource_group, virtual_network_name, subnet_name, addressPrefix)
7
+ subnet_properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
8
+ subnet_properties.address_prefix = addressPrefix unless addressPrefix.nil?
9
+
10
+ subnet = Azure::ARM::Network::Models::Subnet.new
11
+ subnet.name = subnet_name
12
+ subnet.properties = subnet_properties
13
+ begin
14
+ promise = @network_client.subnets.create_or_update(resource_group, virtual_network_name, subnet_name, subnet)
15
+ promise.value!
16
+ rescue MsRestAzure::AzureOperationError => e
17
+ msg = "Exception creating Subnet #{subnet_name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
18
+ raise msg
19
+ end
20
+ end
21
+ end
22
+
23
+ # Mock class for Network Request
24
+ class Mock
25
+ def create_subnet(_resource_group, _virtual_network_name, _subnet_name, _addressPrefix)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,80 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ class Real
5
+ def create_virtual_network(name, location, resource_group_name, dns_list, subnet_address_list, network_address_list)
6
+ virtual_network = define_vnet_object(location, name, network_address_list, dns_list, subnet_address_list)
7
+ begin
8
+ promise = @network_client.virtual_networks.create_or_update(resource_group_name, name, virtual_network)
9
+ promise.value!
10
+ rescue MsRestAzure::AzureOperationError => e
11
+ msg = "Exception creating Virtual Network #{name} in Resource Group: #{resource_group_name}. #{e.body['error']['message']}"
12
+ raise msg
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def define_vnet_object(location, network_name, network_address_list, dns_list, subnet_address_list)
19
+ virtual_network = Azure::ARM::Network::Models::VirtualNetwork.new
20
+ virtual_network.location = location
21
+ virtual_network_properties = Azure::ARM::Network::Models::VirtualNetworkPropertiesFormat.new
22
+
23
+ if network_address_list.nil?
24
+ address_space = Azure::ARM::Network::Models::AddressSpace.new
25
+ address_space.address_prefixes = ['10.2.0.0/16']
26
+ virtual_network_properties.address_space = address_space
27
+ else
28
+ network_address_list = network_address_list.split(',')
29
+ na_list = []
30
+ (0...network_address_list.length).each do |i|
31
+ na_list.push(network_address_list[i].strip)
32
+ end
33
+ address_space = Azure::ARM::Network::Models::AddressSpace.new
34
+ address_space.address_prefixes = na_list
35
+ virtual_network_properties.address_space = address_space
36
+ end
37
+
38
+ unless dns_list.nil?
39
+ dns_list = dns_list.split(',')
40
+ ns_list = []
41
+ (0...dns_list.length).each do |i|
42
+ ns_list.push(dns_list[i].strip)
43
+ end
44
+ dhcp_options = Azure::ARM::Network::Models::DhcpOptions.new
45
+ dhcp_options.dns_servers = ns_list unless ns_list.nil?
46
+ virtual_network_properties.dhcp_options = dhcp_options
47
+ end
48
+
49
+ unless subnet_address_list.nil?
50
+ subnet_address_list = subnet_address_list.split(',')
51
+ sub_nets = define_subnet_objects(network_name, subnet_address_list)
52
+ virtual_network_properties.subnets = sub_nets
53
+ end
54
+
55
+ virtual_network.properties = virtual_network_properties
56
+ virtual_network
57
+ end
58
+
59
+ def define_subnet_objects(network_name, subnet_address_list)
60
+ sub_nets = []
61
+ (0...subnet_address_list.length).each do |i|
62
+ subnet_properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
63
+ subnet_properties.address_prefix = subnet_address_list[i].strip
64
+
65
+ subnet = Azure::ARM::Network::Models::Subnet.new
66
+ subnet.name = 'subnet_' + i.to_s + '_' + network_name
67
+ subnet.properties = subnet_properties
68
+ sub_nets.push(subnet)
69
+ end
70
+ sub_nets
71
+ end
72
+ end
73
+
74
+ class Mock
75
+ def create_virtual_network(_name, _location, _dns_list, _subnet_address_list, _network_address_list, _resource_group_name)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def delete_network_interface(resource_group, name)
7
+ Fog::Logger.debug "Deleting NetworkInterface #{name} from Resource Group #{resource_group}."
8
+ begin
9
+ promise = @network_client.network_interfaces.delete(resource_group, name)
10
+ response = promise.value!
11
+ Fog::Logger.debug "NetworkInterface #{name} Deleted Successfully."
12
+ response
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Exception deleting Network Interface #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
15
+ raise msg
16
+ end
17
+ end
18
+ end
19
+
20
+ # Mock class for Network Request
21
+ class Mock
22
+ def delete_network_interface(_resource_group, _name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def delete_public_ip(resource_group, name)
7
+ Fog::Logger.debug "Deleting PublicIP #{name} from Resource Group #{resource_group}."
8
+ begin
9
+ promise = @network_client.public_ipaddresses.delete(resource_group, name)
10
+ response = promise.value!
11
+ Fog::Logger.debug "PublicIP #{name} Deleted Successfully."
12
+ response
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Exception deleting Public IP #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
15
+ raise msg
16
+ end
17
+ end
18
+ end
19
+
20
+ # Mock class for Network Request
21
+ class Mock
22
+ def delete_public_ip(_resource_group, _name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end