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,27 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def delete_subnet(resource_group, virtual_network_name, subnet_name)
7
+ Fog::Logger.debug "Deleting Subnet: #{name}..."
8
+ begin
9
+ promise = @network_client.subnets.delete(resource_group, virtual_network_name, subnet_name)
10
+ response = promise.value!
11
+ Fog::Logger.debug "Subnet #{name} deleted successfully."
12
+ response
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Exception deleting Subnet #{subnet_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_subnet(_resource_group, _virtual_network_name, _subnet_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_virtual_network(resource_group_name, name)
7
+ Fog::Logger.debug "Deleting Virtual Network: #{name}..."
8
+ begin
9
+ promise = @network_client.virtual_networks.delete(resource_group_name, name)
10
+ response = promise.value!
11
+ Fog::Logger.debug "Virtual Network #{name} deleted successfully."
12
+ response
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Exception deleting Virtual Network #{name} in Resource Group: #{resource_group_name}. #{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_virtual_network(_resource_group_name, _name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def list_network_interfaces(resource_group)
7
+ Fog::Logger.debug "Getting list of NetworkInterfaces from Resource Group #{resource_group}."
8
+ begin
9
+ promise = @network_client.network_interfaces.list(resource_group)
10
+ response = promise.value!
11
+ result = response.body.value
12
+ return result
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Exception listing Network Interfaces from 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 list_network_interfaces(_resource_group)
23
+ nic = Azure::ARM::Network::Models::NetworkInterface.new
24
+ nic.name = 'fogtestnetworkinterface'
25
+ nic.location = 'West US'
26
+ nic.properties = Azure::ARM::Network::Models::NetworkInterfacePropertiesFormat.new
27
+ [nic]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def list_public_ips(resource_group)
7
+ Fog::Logger.debug "Getting list of PublicIPs from Resource Group #{resource_group}."
8
+ begin
9
+ promise = @network_client.public_ipaddresses.list(resource_group)
10
+ response = promise.value!
11
+ result = response.body.value
12
+ return result
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Exception listing Public IPs from 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 list_public_ips(_resource_group)
23
+ public_ip = Azure::ARM::Network::Models::PublicIPAddress.new
24
+ public_ip.name = 'fogtestpublicip'
25
+ public_ip.location = 'West US'
26
+ public_ip.type = 'Static'
27
+ [public_ip]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ 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 list_subnets(resource_group_name, virtual_network_name)
7
+ begin
8
+ promise = @network_client.subnets.list(resource_group_name, virtual_network_name)
9
+ response = promise.value!
10
+ response.body.value
11
+ rescue MsRestAzure::AzureOperationError => e
12
+ msg = "Exception listing Subnets from Resource Group '#{resource_group}' in Virtal Network #{virtual_network_name}. #{e.body['error']['message']}."
13
+ raise msg
14
+ end
15
+ end
16
+ end
17
+
18
+ # Mock class for Network Request
19
+ class Mock
20
+ def list_subnets(resource_group_name, virtual_network_name)
21
+ subnet = Azure::ARM::Network::Models::Subnet.new
22
+ subnet.id = "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/virtualNetworks/#{virtual_network_name}/subnets/fogtestsubnet"
23
+ subnet.name = 'fogtestsubnet'
24
+ subnet.properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
25
+ [subnet]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ class Real
5
+ def list_virtual_networks
6
+ begin
7
+ response = @network_client.virtual_networks.list_all
8
+ result = response.value!
9
+ result.body.value
10
+ rescue MsRestAzure::AzureOperationError => e
11
+ msg = "Exception listing Virtual Networks. #{e.body['error']['message']}."
12
+ raise msg
13
+ end
14
+ end
15
+ end
16
+
17
+ class Mock
18
+ def list_virtual_networks
19
+ vnet = Azure::ARM::Network::Models::VirtualNetwork.new
20
+ vnet.id = '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-resource-group/providers/Microsoft.Network/virtualNetworks/fogtestvnet'
21
+ vnet.name = 'fogtestvnet'
22
+ vnet.location = 'West US'
23
+ vnet.properties = Azure::ARM::Network::Models::VirtualNetworkPropertiesFormat.new
24
+ [vnet]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ class Real
5
+ def create_resource_group(name, location)
6
+ begin
7
+ Fog::Logger.debug "Creating Resource Group: #{name}."
8
+ rg_properties = ::Azure::ARM::Resources::Models::ResourceGroup.new
9
+ rg_properties.location = location
10
+ promise = @rmc.resource_groups.create_or_update(name, rg_properties)
11
+ result = promise.value!
12
+ Fog::Logger.debug "Resource Group #{name} created successfully."
13
+ result
14
+ rescue MsRestAzure::AzureOperationError => e
15
+ msg = "Exception creating Resource Group #{name}. #{e.body['error']['message']}"
16
+ raise msg
17
+ end
18
+ end
19
+ end
20
+
21
+ class Mock
22
+ def create_resource_group(name, parameters)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ class Real
5
+ def delete_resource_group(name)
6
+ begin
7
+ Fog::Logger.debug "Deleting Resource Group: #{name}."
8
+ promise = @rmc.resource_groups.delete(name)
9
+ result = promise.value!
10
+ Fog::Logger.debug "Resource Group #{name} deleted successfully."
11
+ result
12
+ rescue MsRestAzure::AzureOperationError => e
13
+ msg = "Exception deleting Resource Group #{name}. #{e.body['error']['message']}"
14
+ raise msg
15
+ end
16
+ end
17
+ end
18
+
19
+ class Mock
20
+ def delete_resource_group(name)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ class Real
5
+ def list_resource_groups
6
+ begin
7
+ promise = @rmc.resource_groups.list
8
+ response = promise.value!
9
+ response.body.value
10
+ rescue MsRestAzure::AzureOperationError => e
11
+ msg = "Exception listing Resource Groups. #{e.body['error']['message']}"
12
+ raise msg
13
+ end
14
+ end
15
+ end
16
+
17
+ class Mock
18
+ def list_resource_groups
19
+ resource_group = ::Azure::ARM::Resources::Models::ResourceGroup.new
20
+ resource_group.id = '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-resource-group'
21
+ resource_group.name = 'fog-test-resource-group'
22
+ resource_group.location = 'West US'
23
+ [resource_group]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ def check_storage_account_name_availability(params)
7
+ Fog::Logger.debug "Checking Name availability: #{params.name}."
8
+ begin
9
+ promise = @storage_mgmt_client.storage_accounts.check_name_availability(params)
10
+ result = promise.value!
11
+ name_available_obj = Azure::ARM::Storage::Models::CheckNameAvailabilityResult.serialize_object(result.body)
12
+ if name_available_obj['nameAvailable'] == true
13
+ Fog::Logger.debug "Name: #{params.name} is available."
14
+ return true
15
+ else
16
+ Fog::Logger.debug "Name: #{params.name} is not available."
17
+ Fog::Logger.debug "Reason: #{name_available_obj['reason']}."
18
+ return false
19
+ end
20
+ rescue MsRestAzure::AzureOperationError => e
21
+ msg = "Exception checking name availability: #{e.body['error']['message']}"
22
+ raise msg if e.body['error']['code'] == 'ResourceGroupNotFound'
23
+ end
24
+ end
25
+ end
26
+ # This class provides the mock implementation for unit tests.
27
+ class Mock
28
+ def check_storage_account_name_availability(params)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # rubocop:disable LineLength
2
+ module Fog
3
+ module Storage
4
+ class AzureRM
5
+ # This class provides the actual implemention for service calls.
6
+ class Real
7
+ def create_storage_account(resource_group, name, params)
8
+ Fog::Logger.debug "Creating Storage Account: #{name}."
9
+ begin
10
+ promise = @storage_mgmt_client.storage_accounts.create(resource_group, name, params)
11
+ response = promise.value!
12
+ Fog::Logger.debug "Storage Account created successfully."
13
+ response
14
+ rescue MsRestAzure::AzureOperationError => e
15
+ msg = "Exception creating Storage Account #{name} in Resource Group #{resource_group}. #{e.body['error']['message']}"
16
+ raise msg
17
+ end
18
+ end
19
+ end
20
+ # This class provides the mock implementation for unit tests.
21
+ class Mock
22
+ def create_storage_account(resource_group, name, params)
23
+ storage_acc = {
24
+ name: name,
25
+ location: params.location,
26
+ resource_group: resource_group
27
+ }
28
+ storage_acc
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ # rubocop:disable LineLength
2
+ module Fog
3
+ module Storage
4
+ class AzureRM
5
+ # This class provides the actual implemention for service calls.
6
+ class Real
7
+ def delete_storage_account(resource_group, name)
8
+ Fog::Logger.debug "Deleting Storage Account: #{name}."
9
+ begin
10
+ promise = @storage_mgmt_client.storage_accounts.delete(resource_group, name)
11
+ response = promise.value!
12
+ Fog::Logger.debug "Storage Account #{name} deleted successfully."
13
+ response
14
+ rescue MsRestAzure::AzureOperationError => e
15
+ msg = "Exception deleting Storage Account #{name} in Resource Group #{resource_group}. #{e.body['error']['message']}"
16
+ raise msg
17
+ end
18
+ end
19
+ end
20
+ # This class provides the mock implementation for unit tests.
21
+ class Mock
22
+ def delete_storage_account(resource_group, name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # rubocop:disable LineLength
2
+ module Fog
3
+ module Storage
4
+ class AzureRM
5
+ # This class provides the actual implemention for service calls.
6
+ class Real
7
+ def list_storage_account_for_rg(resource_group)
8
+ begin
9
+ promise = @storage_mgmt_client.storage_accounts.list_by_resource_group(resource_group)
10
+ response = promise.value!
11
+ response.body.value
12
+ rescue MsRestAzure::AzureOperationError => e
13
+ msg = "Exception listing Storage Accounts in Resource Group #{resource_group}. #{e.body['error']['message']}"
14
+ raise msg
15
+ end
16
+ end
17
+ end
18
+ # This class provides the mock implementation for unit tests.
19
+ class Mock
20
+ def list_storage_account_for_rg(resource_group)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ def list_storage_accounts
7
+ begin
8
+ promise = @storage_mgmt_client.storage_accounts.list
9
+ response = promise.value!
10
+ response.body.value
11
+ rescue MsRestAzure::AzureOperationError => e
12
+ msg = "Exception listing Storage Accounts. #{e.body['error']['message']}"
13
+ raise msg
14
+ end
15
+ end
16
+ end
17
+ # This class provides the mock implementation for unit tests.
18
+ class Mock
19
+ def list_storage_accounts
20
+ storage_acc = ::Azure::ARM::Storage::Models::StorageAccount.new
21
+ storage_acc.name = 'fog-test-storage-account'
22
+ storage_acc.location = 'West US'
23
+ [storage_acc]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ require 'fog/azurerm/core'
2
+ require 'fog/azurerm/credentials'
3
+
4
+ module Fog
5
+ module Resources
6
+ class AzureRM < Fog::Service
7
+ requires :tenant_id
8
+ requires :client_id
9
+ requires :client_secret
10
+ requires :subscription_id
11
+
12
+ request_path 'fog/azurerm/requests/resources'
13
+ request :create_resource_group
14
+ request :list_resource_groups
15
+ request :delete_resource_group
16
+
17
+ model_path 'fog/azurerm/models/resources'
18
+ model :resource_group
19
+ collection :resource_groups
20
+
21
+ class Mock
22
+ def initialize(options = {})
23
+ begin
24
+ require 'azure_mgmt_resources'
25
+ rescue LoadError => e
26
+ retry if require('rubygems')
27
+ raise e.message
28
+ end
29
+ end
30
+ end
31
+
32
+ class Real
33
+ def initialize(options)
34
+ begin
35
+ require 'azure_mgmt_resources'
36
+ rescue LoadError => e
37
+ retry if require('rubygems')
38
+ raise e.message
39
+ end
40
+
41
+ credentials = Fog::Credentials::AzureRM.get_credentials(options[:tenant_id], options[:client_id], options[:client_secret])
42
+ @rmc = ::Azure::ARM::Resources::ResourceManagementClient.new(credentials)
43
+ @rmc.subscription_id = options[:subscription_id]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end