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,21 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ class ResourceGroup < Fog::Model
5
+ identity :name
6
+ attribute :id
7
+ attribute :location
8
+
9
+ def save
10
+ requires :name
11
+ requires :location
12
+ service.create_resource_group(name, location)
13
+ end
14
+
15
+ def destroy
16
+ service.delete_resource_group(name)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/azurerm/models/resources/resource_group'
3
+
4
+ module Fog
5
+ module Resources
6
+ class AzureRM
7
+ class ResourceGroups < Fog::Collection
8
+ model Fog::Resources::AzureRM::ResourceGroup
9
+
10
+ def all
11
+ resource_groups = []
12
+ service.list_resource_groups.each do |rg|
13
+ hash = {}
14
+ rg.instance_variables.each do |var|
15
+ hash[var.to_s.delete('@')] = rg.instance_variable_get(var)
16
+ end
17
+ resource_groups << hash
18
+ end
19
+ load(resource_groups)
20
+ end
21
+
22
+ def get(identity)
23
+ all.find { |f| f.name == identity }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ # rubocop:disable LineLength
2
+ # rubocop:disable MethodLength
3
+ module Fog
4
+ module Storage
5
+ class AzureRM
6
+ # This class is giving implementation of create/save and
7
+ # delete/destroy for storage account.
8
+ class StorageAccount < Fog::Model
9
+ attribute :id
10
+ identity :name
11
+ attribute :type
12
+ attribute :location
13
+ attribute :tags
14
+ attribute :resource_group
15
+ attribute :properties
16
+
17
+ def save
18
+ requires :name
19
+ requires :location
20
+ requires :resource_group
21
+ # Create a model for new storage account.
22
+ properties = Azure::ARM::Storage::Models::StorageAccountPropertiesCreateParameters.new
23
+ properties.account_type = 'Standard_LRS' # This might change in the near future!
24
+
25
+ params = Azure::ARM::Storage::Models::StorageAccountCreateParameters.new
26
+ params.properties = properties
27
+ params.location = location
28
+ service.create_storage_account(resource_group, name, params)
29
+ end
30
+
31
+ def destroy
32
+ service.delete_storage_account(resource_group, name)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,45 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/azurerm/models/storage/storage_account'
3
+ # rubocop:disable LineLength
4
+ # rubocop:disable MethodLength
5
+ # rubocop:disable AbcSize
6
+ module Fog
7
+ module Storage
8
+ class AzureRM
9
+ # This class is giving implementation of all/list, get and
10
+ # check name availability for storage account.
11
+ class StorageAccounts < Fog::Collection
12
+ model Fog::Storage::AzureRM::StorageAccount
13
+ attribute :resource_group
14
+ def all
15
+ accounts = []
16
+ if !resource_group.nil?
17
+ requires :resource_group
18
+ hash_of_storage_accounts = service.list_storage_account_for_rg(resource_group)
19
+ else
20
+ hash_of_storage_accounts = service.list_storage_accounts
21
+ end
22
+ hash_of_storage_accounts.each do |account|
23
+ hash = {}
24
+ account.instance_variables.each do |var|
25
+ hash[var.to_s.delete('@')] = account.instance_variable_get(var)
26
+ end
27
+ accounts << hash
28
+ end
29
+ load(accounts)
30
+ end
31
+
32
+ def get(identity)
33
+ all.find { |f| f.name == identity }
34
+ end
35
+
36
+ def check_name_availability(name)
37
+ params = Azure::ARM::Storage::Models::StorageAccountCheckNameAvailabilityParameters.new
38
+ params.name = name
39
+ params.type = 'Microsoft.Storage/storageAccounts'
40
+ service.check_storage_account_name_availability(params)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,67 @@
1
+ require 'fog/azurerm/core'
2
+
3
+ module Fog
4
+ module Network
5
+ # Fog Service Class for AzureRM
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/network'
13
+ request :create_virtual_network
14
+ request :delete_virtual_network
15
+ request :list_virtual_networks
16
+ request :check_for_virtual_network
17
+ request :create_public_ip
18
+ request :delete_public_ip
19
+ request :list_public_ips
20
+ request :check_for_public_ip
21
+ request :create_subnet
22
+ request :list_subnets
23
+ request :delete_subnet
24
+ request :create_network_interface
25
+ request :delete_network_interface
26
+ request :list_network_interfaces
27
+
28
+ model_path 'fog/azurerm/models/network'
29
+ model :virtual_network
30
+ collection :virtual_networks
31
+ model :public_ip
32
+ collection :public_ips
33
+ model :subnet
34
+ collection :subnets
35
+ model :network_interface
36
+ collection :network_interfaces
37
+
38
+ # Mock class for Network Service
39
+ class Mock
40
+ def initialize(_options = {})
41
+ begin
42
+ require 'azure_mgmt_network'
43
+ rescue LoadError => e
44
+ retry if require('rubygems')
45
+ raise e.message
46
+ end
47
+ end
48
+ end
49
+
50
+ # Real class for Network Service
51
+ class Real
52
+ def initialize(options)
53
+ begin
54
+ require 'azure_mgmt_network'
55
+ rescue LoadError => e
56
+ retry if require('rubygems')
57
+ raise e.message
58
+ end
59
+
60
+ credentials = Fog::Credentials::AzureRM.get_credentials(options[:tenant_id], options[:client_id], options[:client_secret])
61
+ @network_client = ::Azure::ARM::Network::NetworkManagementClient.new(credentials)
62
+ @network_client.subscription_id = options[:subscription_id]
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,45 @@
1
+ # rubocop:disable AbcSize
2
+ # rubocop:disable MethodLength
3
+ module Fog
4
+ module Compute
5
+ class AzureRM
6
+ # This class provides the actual implemention for service calls.
7
+ class Real
8
+ def create_availability_set(resource_group, name, location)
9
+ begin
10
+ Fog::Logger.debug "Creating Availability Set '#{name}' in #{location} region."
11
+ avail_set_props = get_avail_set_properties(location)
12
+ promise = @compute_mgmt_client.availability_sets.create_or_update(resource_group, name, avail_set_props)
13
+ result = promise.value!
14
+ Fog::Logger.debug "Availability Set #{name} created successfully."
15
+ result
16
+ rescue MsRestAzure::AzureOperationError => e
17
+ msg = "Exception creating Availability Set #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
18
+ raise msg
19
+ end
20
+ end
21
+
22
+ # create the properties object for creating availability sets
23
+ def get_avail_set_properties(location)
24
+ avail_set_props =
25
+ Azure::ARM::Compute::Models::AvailabilitySetProperties.new
26
+ # At least two domain faults
27
+ avail_set_props.platform_fault_domain_count = 2
28
+ avail_set_props.platform_update_domain_count = 2
29
+ # At this point we do not have virtual machines to include
30
+ avail_set_props.virtual_machines = []
31
+ avail_set_props.statuses = []
32
+ avail_set = Azure::ARM::Compute::Models::AvailabilitySet.new
33
+ avail_set.location = location
34
+ avail_set.properties = avail_set_props
35
+ avail_set
36
+ end
37
+ end
38
+ # This class provides the mock implementation for unit tests.
39
+ class Mock
40
+ def create_availability_set(resource_group, name, params)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,100 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ class Real
6
+ def create_virtual_machine(name, location, resource_group, vm_size, storage_account_name,
7
+ username, password, disable_password_authentication,
8
+ ssh_key_path, ssh_key_data, network_interface_card_id,
9
+ availability_set_id, publisher, offer, sku, version)
10
+ Fog::Logger.debug "Creating Virtual Machine #{name} in Resource Group #{resource_group}."
11
+ params = Azure::ARM::Compute::Models::VirtualMachine.new
12
+ vm_properties = Azure::ARM::Compute::Models::VirtualMachineProperties.new
13
+
14
+ unless availability_set_id.nil?
15
+ sub_resource = MsRestAzure::SubResource.new
16
+ sub_resource.id = availability_set_id
17
+ vm_properties.availability_set = sub_resource
18
+ end
19
+
20
+ vm_properties.hardware_profile = define_hardware_profile(vm_size)
21
+ vm_properties.storage_profile = define_storage_profile(name, storage_account_name, publisher, offer, sku, version)
22
+ vm_properties.os_profile = define_os_profile(name, username, password, disable_password_authentication, ssh_key_path, ssh_key_data)
23
+ vm_properties.network_profile = define_network_profile(network_interface_card_id)
24
+ params.properties = vm_properties
25
+ params.location = location
26
+ begin
27
+ promise = @compute_mgmt_client.virtual_machines.create_or_update(resource_group, name, params)
28
+ result = promise.value!
29
+ Fog::Logger.debug "Virtual Machine #{name} Created Successfully."
30
+ Azure::ARM::Compute::Models::VirtualMachine.serialize_object(result.body)
31
+ rescue MsRestAzure::AzureOperationError => e
32
+ msg = "Error Creating Virtual Machine '#{name}' in Resource Group '#{resource_group}'. #{e.body['error']['message']}"
33
+ raise msg
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def define_hardware_profile(vm_size)
40
+ hw_profile = Azure::ARM::Compute::Models::HardwareProfile.new
41
+ hw_profile.vm_size = vm_size
42
+ hw_profile
43
+ end
44
+
45
+ def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version)
46
+ storage_profile = Azure::ARM::Compute::Models::StorageProfile.new
47
+ os_disk = Azure::ARM::Compute::Models::OSDisk.new
48
+ vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
49
+ image_reference = Azure::ARM::Compute::Models::ImageReference.new
50
+
51
+ image_reference.publisher = publisher
52
+ image_reference.offer = offer
53
+ image_reference.sku = sku
54
+ image_reference.version = version
55
+ vhd.uri = "http://#{storage_account_name}.blob.core.windows.net/vhds/#{vm_name}_os_disk.vhd"
56
+ os_disk.name = "#{vm_name}_os_disk"
57
+ os_disk.vhd = vhd
58
+ os_disk.create_option = Azure::ARM::Compute::Models::DiskCreateOptionTypes::FromImage
59
+ storage_profile.image_reference = image_reference
60
+ storage_profile.os_disk = os_disk
61
+ storage_profile
62
+ end
63
+
64
+ def define_os_profile(vm_name, username, password, disable_password_authentication, ssh_key_path, ssh_key_data)
65
+ os_profile = Azure::ARM::Compute::Models::OSProfile.new
66
+ linux_config = Azure::ARM::Compute::Models::LinuxConfiguration.new
67
+
68
+ unless ssh_key_path.nil? || ssh_key_data.nil?
69
+ ssh_config = Azure::ARM::Compute::Models::SshConfiguration.new
70
+ ssh_public_key = Azure::ARM::Compute::Models::SshPublicKey.new
71
+ ssh_public_key.path = ssh_key_path
72
+ ssh_public_key.key_data = ssh_key_data
73
+ ssh_config.public_keys = [ssh_public_key]
74
+ linux_config.ssh = ssh_config
75
+ end
76
+
77
+ linux_config.disable_password_authentication = disable_password_authentication
78
+ os_profile.linux_configuration = linux_config
79
+ os_profile.computer_name = vm_name
80
+ os_profile.admin_username = username
81
+ os_profile.admin_password = password
82
+ os_profile
83
+ end
84
+
85
+ def define_network_profile(network_interface_card_id)
86
+ network_profile = Azure::ARM::Compute::Models::NetworkProfile.new
87
+ nic = Azure::ARM::Compute::Models::NetworkInterfaceReference .new
88
+ nic.id = network_interface_card_id
89
+ network_profile.network_interfaces = [nic]
90
+ network_profile
91
+ end
92
+ end
93
+ # This class provides the mock implementation for unit tests.
94
+ class Mock
95
+ def create_virtual_machine
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ def deallocate_virtual_machine(resource_group, name)
7
+ Fog::Logger.debug "Deallocating Virtual Machine #{name} in Resource Group #{resource_group}."
8
+ begin
9
+ promise = @compute_mgmt_client.virtual_machines.deallocate(resource_group, name)
10
+ result = promise.value!
11
+ Fog::Logger.debug "Virtual Machine #{name} Deallocated Successfully."
12
+ result
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Error Deallocating Virtual Machine '#{name}' in Resource Group '#{resource_group}'. #{e.body['error']['message']}"
15
+ raise msg
16
+ end
17
+ end
18
+ end
19
+ # This class provides the mock implementation for unit tests.
20
+ class Mock
21
+ def deallocate_virtual_machine(resource_group, name)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ def delete_availability_set(resource_group, name)
7
+ begin
8
+ Fog::Logger.debug "Deleting Availability Set: #{name}."
9
+ promise = @compute_mgmt_client.availability_sets.delete(resource_group, name)
10
+ result = promise.value!
11
+ Fog::Logger.debug "Availability Set #{name} deleted successfully."
12
+ result
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Exception deleting Availability Set #{name} in Resourse Group #{resource_group}. #{e.body['error']['message']}"
15
+ raise msg
16
+ end
17
+ end
18
+ end
19
+ # This class provides the mock implementation for unit tests.
20
+ class Mock
21
+ def delete_availability_set(resource_group, name)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ def delete_virtual_machine(resource_group, name)
7
+ Fog::Logger.debug "Deleting Virtual Machine #{name} from Resource Group #{resource_group}."
8
+ begin
9
+ promise = @compute_mgmt_client.virtual_machines.delete(resource_group, name)
10
+ result = promise.value!
11
+ Fog::Logger.debug "Virtual Machine #{name} Deleted Successfully."
12
+ result
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Error Deleting Virtual Machine '#{name}' from Resource Group '#{resource_group}'. #{e.body['error']['message']}"
15
+ raise msg
16
+ end
17
+ end
18
+ end
19
+ # This class provides the mock implementation for unit tests.
20
+ class Mock
21
+ def delete_virtual_machine(resource_group, name)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ def generalize_virtual_machine(resource_group, name)
7
+ Fog::Logger.debug "Generalizing Virtual Machine #{name} in Resource Group #{resource_group}."
8
+ begin
9
+ promise = @compute_mgmt_client.virtual_machines.generalize(resource_group, name)
10
+ result = promise.value!
11
+ Fog::Logger.debug "Virtual Machine #{name} Generalized Successfully."
12
+ result
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ msg = "Error Generalizing Virtual Machine '#{name}' in Resource Group '#{resource_group}'. #{e.body['error']['message']}"
15
+ raise msg
16
+ end
17
+ end
18
+ end
19
+ # This class provides the mock implementation for unit tests.
20
+ class Mock
21
+ def generalize_virtual_machine(resource_group, name)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end