fog-azure-rm 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/fog-azure-rm.gemspec +8 -8
  4. data/lib/fog/azurerm.rb +5 -0
  5. data/lib/fog/azurerm/async_response.rb +36 -0
  6. data/lib/fog/azurerm/compute.rb +15 -1
  7. data/lib/fog/azurerm/constants.rb +6 -0
  8. data/lib/fog/azurerm/docs/compute.md +145 -2
  9. data/lib/fog/azurerm/models/compute/creation_data.rb +21 -0
  10. data/lib/fog/azurerm/models/compute/disk_create_option.rb +16 -0
  11. data/lib/fog/azurerm/models/compute/encryption_settings.rb +29 -0
  12. data/lib/fog/azurerm/models/compute/image_disk_reference.rb +15 -0
  13. data/lib/fog/azurerm/models/compute/managed_disk.rb +77 -0
  14. data/lib/fog/azurerm/models/compute/managed_disks.rb +43 -0
  15. data/lib/fog/azurerm/models/compute/operation_status_response.rb +18 -0
  16. data/lib/fog/azurerm/models/compute/server.rb +12 -7
  17. data/lib/fog/azurerm/models/compute/servers.rb +6 -0
  18. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profile.rb +1 -0
  19. data/lib/fog/azurerm/requests/compute/check_managed_disk_exists.rb +33 -0
  20. data/lib/fog/azurerm/requests/compute/create_or_update_managed_disk.rb +121 -0
  21. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +24 -11
  22. data/lib/fog/azurerm/requests/compute/delete_managed_disk.rb +29 -0
  23. data/lib/fog/azurerm/requests/compute/delete_virtual_machine.rb +1 -1
  24. data/lib/fog/azurerm/requests/compute/get_managed_disk.rb +64 -0
  25. data/lib/fog/azurerm/requests/compute/grant_access_to_managed_disk.rb +30 -0
  26. data/lib/fog/azurerm/requests/compute/list_managed_disks_by_rg.rb +66 -0
  27. data/lib/fog/azurerm/requests/compute/list_managed_disks_in_subscription.rb +66 -0
  28. data/lib/fog/azurerm/requests/compute/revoke_access_to_managed_disk.rb +33 -0
  29. data/lib/fog/azurerm/requests/dns/check_zone_exists.rb +5 -1
  30. data/lib/fog/azurerm/requests/network/check_net_sec_rule_exists.rb +1 -1
  31. data/lib/fog/azurerm/requests/network/check_subnet_exists.rb +1 -1
  32. data/lib/fog/azurerm/utilities/general.rb +13 -10
  33. data/lib/fog/azurerm/version.rb +1 -1
  34. data/test/api_stub.rb +2 -0
  35. data/test/api_stub/models/compute/managed_disk.rb +59 -0
  36. data/test/api_stub/requests/compute/managed_disk.rb +102 -0
  37. data/test/api_stub/requests/compute/virtual_machine.rb +6 -6
  38. data/test/integration/Virtual_network_gateway_connection.rb +0 -6
  39. data/test/integration/application_gateway.rb +1 -1
  40. data/test/integration/credentials/azure.yml +1 -1
  41. data/test/integration/managed_disk.rb +113 -0
  42. data/test/integration/server.rb +39 -1
  43. data/test/integration/traffic_manager.rb +2 -2
  44. data/test/models/compute/test_managed_disk.rb +61 -0
  45. data/test/models/compute/test_managed_disks.rb +68 -0
  46. data/test/models/compute/test_server.rb +7 -1
  47. data/test/models/compute/test_servers.rb +1 -0
  48. data/test/requests/compute/test_check_managed_disk_exists.rb +31 -0
  49. data/test/requests/compute/test_create_or_update_managed_disk.rb +38 -0
  50. data/test/requests/compute/test_create_virtual_machine.rb +27 -0
  51. data/test/requests/compute/test_delete_managed_disk.rb +23 -0
  52. data/test/requests/compute/test_get_managed_disk.rb +24 -0
  53. data/test/requests/compute/test_grant_access_to_managed_disk.rb +26 -0
  54. data/test/requests/compute/test_list_managed_disks_by_rg.rb +24 -0
  55. data/test/requests/compute/test_list_managed_disks_in_subscription.rb +24 -0
  56. data/test/requests/compute/test_revoke_access_to_managed_disk.rb +24 -0
  57. data/test/test_helper.rb +15 -1
  58. metadata +47 -18
@@ -15,7 +15,7 @@ module ApiStub
15
15
  disable_password_authentication: false,
16
16
  ssh_key_path: '/home',
17
17
  ssh_key_data: 'key',
18
- network_interface_card_id: 'nic-id',
18
+ network_interface_card_ids: ['nic-id'],
19
19
  availability_set_id: 'as-id',
20
20
  publisher: 'Canonical',
21
21
  offer: 'UbuntuServer',
@@ -39,7 +39,7 @@ module ApiStub
39
39
  disable_password_authentication: nil,
40
40
  ssh_key_path: '/home',
41
41
  ssh_key_data: 'key',
42
- network_interface_card_id: 'nic-id',
42
+ network_interface_card_ids: ['nic-id'],
43
43
  availability_set_id: 'as-id',
44
44
  publisher: 'MicrosoftWindowsServerEssentials',
45
45
  offer: 'WindowsServerEssentials',
@@ -63,7 +63,7 @@ module ApiStub
63
63
  disable_password_authentication: false,
64
64
  ssh_key_path: '/home',
65
65
  ssh_key_data: 'key',
66
- network_interface_card_id: 'nic-id',
66
+ network_interface_card_ids: ['nic-id'],
67
67
  availability_set_id: 'as-id',
68
68
  publisher: 'Canonical',
69
69
  offer: 'UbuntuServer',
@@ -88,7 +88,7 @@ module ApiStub
88
88
  disable_password_authentication: nil,
89
89
  ssh_key_path: '/home',
90
90
  ssh_key_data: 'key',
91
- network_interface_card_id: 'nic-id',
91
+ network_interface_card_ids: ['nic-id'],
92
92
  availability_set_id: 'as-id',
93
93
  publisher: 'MicrosoftWindowsServerEssentials',
94
94
  offer: 'WindowsServerEssentials',
@@ -113,7 +113,7 @@ module ApiStub
113
113
  disable_password_authentication: false,
114
114
  ssh_key_path: '/home',
115
115
  ssh_key_data: 'key',
116
- network_interface_card_id: 'nic-id',
116
+ network_interface_card_ids: ['nic-id'],
117
117
  availability_set_id: 'as-id',
118
118
  platform: 'Linux',
119
119
  provision_vm_agent: nil,
@@ -134,7 +134,7 @@ module ApiStub
134
134
  disable_password_authentication: nil,
135
135
  ssh_key_path: '/home',
136
136
  ssh_key_data: 'key',
137
- network_interface_card_id: 'nic-id',
137
+ network_interface_card_ids: ['nic-id'],
138
138
  availability_set_id: 'as-id',
139
139
  platform: 'Windows',
140
140
  provision_vm_agent: true,
@@ -212,12 +212,6 @@ begin
212
212
  pubip = network.public_ips.get('TestRG-GC', 'mypubip2')
213
213
  pubip.destroy
214
214
 
215
- vnet = network.virtual_networks.get('TestRG-GC', 'testVnet')
216
- vnet.destroy
217
-
218
- vnet = network.virtual_networks.get('TestRG-GC', 'testVnet2')
219
- vnet.destroy
220
-
221
215
  resource_group = resource.resource_groups.get('TestRG-GC')
222
216
  resource_group.destroy
223
217
  rescue
@@ -106,7 +106,7 @@ begin
106
106
  frontend_ports: [
107
107
  {
108
108
  name: 'frontendPort',
109
- port: 443
109
+ port: 65_502
110
110
  }
111
111
  ],
112
112
  backend_address_pools: [
@@ -2,4 +2,4 @@ client_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
2
2
  client_secret: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3
3
  subscription_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
4
4
  tenant_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
5
- environment: XXXXXXXX
5
+ environment: XXXXXXXX
@@ -0,0 +1,113 @@
1
+ require 'fog/azurerm'
2
+ require 'yaml'
3
+
4
+ ########################################################################################################################
5
+ ###################### Services object required by all actions ######################
6
+ ###################### Keep it Uncommented! ######################
7
+ ########################################################################################################################
8
+
9
+ azure_credentials = YAML.load_file('credentials/azure.yml')
10
+
11
+ rs = Fog::Resources::AzureRM.new(
12
+ tenant_id: azure_credentials['tenant_id'],
13
+ client_id: azure_credentials['client_id'],
14
+ client_secret: azure_credentials['client_secret'],
15
+ subscription_id: azure_credentials['subscription_id'],
16
+ environment: azure_credentials['environment']
17
+ )
18
+
19
+ compute = Fog::Compute::AzureRM.new(
20
+ tenant_id: azure_credentials['tenant_id'],
21
+ client_id: azure_credentials['client_id'],
22
+ client_secret: azure_credentials['client_secret'],
23
+ subscription_id: azure_credentials['subscription_id'],
24
+ environment: azure_credentials['environment']
25
+ )
26
+
27
+ ########################################################################################################################
28
+ ###################### Resource names #####################
29
+ ########################################################################################################################
30
+
31
+ time = current_time
32
+ resource_group_name = "MD-RG-#{time}"
33
+ disk_name = "MD#{time}diskunique"
34
+
35
+ ########################################################################################################################
36
+ ###################### Prerequisites ######################
37
+ ########################################################################################################################
38
+
39
+ begin
40
+ rs.resource_groups.create(
41
+ name: resource_group_name,
42
+ location: LOCATION
43
+ )
44
+
45
+ ########################################################################################################################
46
+ ###################### Check for Managed Disk ######################
47
+ ########################################################################################################################
48
+
49
+ flag = compute.managed_disks.check_managed_disk_exists(resource_group_name, disk_name)
50
+ puts "Managed Disk doesn't exist." unless flag
51
+
52
+ ########################################################################################################################
53
+ ###################### Create Managed Disk ######################
54
+ ########################################################################################################################
55
+
56
+ disk = compute.managed_disks.create(
57
+ name: disk_name,
58
+ location: LOCATION,
59
+ resource_group_name: resource_group_name,
60
+ account_type: 'Premium_LRS',
61
+ disk_size_gb: 1023,
62
+ creation_data: {
63
+ create_option: 'Empty'
64
+ }
65
+ )
66
+ puts "Created managed disk: #{disk.name}"
67
+
68
+ ########################################################################################################################
69
+ ###################### Grant and revoke access ######################
70
+ ########################################################################################################################
71
+
72
+ access_sas = compute.managed_disks.grant_access(resource_group_name, disk_name, 'Read', 1000)
73
+ puts "Access SAS: #{access_sas}"
74
+
75
+ response = compute.managed_disks.revoke_access(resource_group_name, disk_name)
76
+ puts "Revoke Access response: #{response.inspect}"
77
+
78
+ ########################################################################################################################
79
+ ###################### List Managed Disks ######################
80
+ ########################################################################################################################
81
+ puts 'List managed disks:'
82
+ compute.managed_disks(resource_group: resource_group_name).each do |managed_disk|
83
+ puts managed_disk.name
84
+ end
85
+
86
+ ########################################################################################################################
87
+ ###################### List all Managed Disks in a subscription ######################
88
+ ########################################################################################################################
89
+
90
+ puts 'List managed disks in Subscription:'
91
+ compute.managed_disks.each do |m_disk|
92
+ puts m_disk.name
93
+ end
94
+
95
+ ########################################################################################################################
96
+ ###################### Get and Delete Managed Disk ######################
97
+ ########################################################################################################################
98
+
99
+ disk = compute.managed_disks.get(resource_group_name, disk_name)
100
+ puts "Get managed disk: #{disk.inspect}"
101
+ puts "Deleted managed disk: #{disk.destroy}"
102
+
103
+ ########################################################################################################################
104
+ ###################### CleanUp ######################
105
+ ########################################################################################################################
106
+
107
+ rg = rs.resource_groups.get(resource_group_name)
108
+ rg.destroy
109
+ puts 'Integration Test for managed disk ran successfully'
110
+ rescue
111
+ puts 'Integration Test for managed disk is failing'
112
+ resource_group.destroy unless resource_group.nil?
113
+ end
@@ -99,7 +99,7 @@ begin
99
99
  username: 'testuser',
100
100
  password: 'Confiz=123',
101
101
  disable_password_authentication: false,
102
- network_interface_card_id: "/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-VM/providers/Microsoft.Network/networkInterfaces/NetInt",
102
+ network_interface_card_ids: ["/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-VM/providers/Microsoft.Network/networkInterfaces/NetInt"],
103
103
  publisher: 'Canonical',
104
104
  offer: 'UbuntuServer',
105
105
  sku: '14.04.2-LTS',
@@ -110,6 +110,44 @@ begin
110
110
  )
111
111
  puts "Created virtual machine: #{virtual_machine.name}"
112
112
 
113
+ ########################################################################################################################
114
+ ###################### Create Server Async ####################
115
+ ########################################################################################################################
116
+
117
+ async_response = compute.servers.create_async(
118
+ name: 'TestVM',
119
+ location: LOCATION,
120
+ resource_group: 'TestRG-VM',
121
+ vm_size: 'Basic_A0',
122
+ storage_account_name: storage_account_name,
123
+ username: 'testuser',
124
+ password: 'Confiz=123',
125
+ disable_password_authentication: false,
126
+ network_interface_card_ids: ["/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-VM/providers/Microsoft.Network/networkInterfaces/NetInt"],
127
+ publisher: 'Canonical',
128
+ offer: 'UbuntuServer',
129
+ sku: '14.04.2-LTS',
130
+ version: 'latest',
131
+ platform: 'linux',
132
+ custom_data: 'echo customData',
133
+ os_disk_caching: Fog::ARM::Compute::Models::CachingTypes::None
134
+ )
135
+ loop do
136
+ puts async_response.state
137
+
138
+ sleep(2) if async_response.pending?
139
+
140
+ if async_response.fulfilled?
141
+ puts async_response.value.inspect
142
+ break
143
+ end
144
+
145
+ if async_response.rejected?
146
+ puts async_response.reason.inspect
147
+ break
148
+ end
149
+ end
150
+
113
151
  ########################################################################################################################
114
152
  ###################### Attach Data Disk to VM ######################
115
153
  ########################################################################################################################
@@ -80,7 +80,7 @@ begin
80
80
  traffic_manager_profile_name: 'test-tmp',
81
81
  resource_group: 'TestRG-TM',
82
82
  type: 'externalEndpoints',
83
- target: 'test-app.com',
83
+ target: 'test-app1.com',
84
84
  endpoint_location: 'eastus'
85
85
  )
86
86
  puts "Created traffic manager endpoint: #{traffic_manager_end_point.name}"
@@ -93,7 +93,7 @@ begin
93
93
  puts "Get traffic manager endpoint: #{end_point.name}"
94
94
  end_point.update(
95
95
  type: 'externalEndpoints',
96
- target: 'test-app1.com',
96
+ target: 'test-app2.com',
97
97
  endpoint_location: 'centralus'
98
98
  )
99
99
  puts 'Updated traffic manager endpoint'
@@ -0,0 +1,61 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for Managed Disk Model
4
+ class TestManagedDisk < Minitest::Test
5
+ def setup
6
+ @service = Fog::Compute::AzureRM.new(credentials)
7
+ @managed_disk = managed_disk(@service)
8
+ compute_client = @service.instance_variable_get(:@compute_mgmt_client)
9
+ @response = ApiStub::Models::Compute::ManagedDisk.create_managed_disk_response(compute_client)
10
+ end
11
+
12
+ def test_model_methods
13
+ methods = [
14
+ :save,
15
+ :destroy
16
+ ]
17
+ methods.each do |method|
18
+ assert_respond_to @managed_disk, method
19
+ end
20
+ end
21
+
22
+ def test_model_attributes
23
+ attributes = [
24
+ :id,
25
+ :name,
26
+ :type,
27
+ :location,
28
+ :resource_group_name,
29
+ :account_type,
30
+ :time_created,
31
+ :os_type,
32
+ :disk_size_gb,
33
+ :owner_id,
34
+ :provisioning_state,
35
+ :tags,
36
+ :creation_data,
37
+ :encryption_settings
38
+ ]
39
+ attributes.each do |attribute|
40
+ assert_respond_to @managed_disk, attribute
41
+ end
42
+ end
43
+
44
+ def test_save_method_response
45
+ @service.stub :create_or_update_managed_disk, @response do
46
+ assert_instance_of Fog::Compute::AzureRM::ManagedDisk, @managed_disk.save
47
+ end
48
+ end
49
+
50
+ def test_destroy_method_true_response
51
+ @service.stub :delete_managed_disk, true do
52
+ assert @managed_disk.destroy
53
+ end
54
+ end
55
+
56
+ def test_destroy_method_false_response
57
+ @service.stub :delete_managed_disk, false do
58
+ assert !@managed_disk.destroy
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for Managed Disk Collection
4
+ class TestManagedDisks < Minitest::Test
5
+ def setup
6
+ @service = Fog::Compute::AzureRM.new(credentials)
7
+ @managed_disks = Fog::Compute::AzureRM::ManagedDisks.new(resource_group: 'fog-test-rg', service: @service)
8
+ @client = @service.instance_variable_get(:@compute_mgmt_client)
9
+ @managed_disk_list = [ApiStub::Models::Compute::ManagedDisk.create_managed_disk_response(@client)]
10
+ @managed_disk = ApiStub::Models::Compute::ManagedDisk.create_managed_disk_response(@client)
11
+ end
12
+
13
+ def test_collection_methods
14
+ methods = [
15
+ :all,
16
+ :get,
17
+ :check_managed_disk_exists
18
+ ]
19
+ methods.each do |method|
20
+ assert_respond_to @managed_disks, method
21
+ end
22
+ end
23
+
24
+ def test_collection_attributes
25
+ assert_respond_to @managed_disks, :resource_group
26
+ end
27
+
28
+ def test_all_method_response
29
+ @service.stub :list_managed_disks_by_rg, @managed_disk_list do
30
+ assert_instance_of Fog::Compute::AzureRM::ManagedDisks, @managed_disks.all
31
+ assert @managed_disks.all.size >= 1
32
+ @managed_disks.all.each do |disk|
33
+ assert_instance_of Fog::Compute::AzureRM::ManagedDisk, disk
34
+ end
35
+ end
36
+ end
37
+
38
+ def test_get_method_response
39
+ @service.stub :get_managed_disk, @managed_disk do
40
+ assert_instance_of Fog::Compute::AzureRM::ManagedDisk, @managed_disks.get('fog-test-rg', 'fog-test-managed_disk')
41
+ end
42
+ end
43
+
44
+ def test_check_managed_disk_exists_true_case
45
+ @service.stub :check_managed_disk_exists, true do
46
+ assert @managed_disks.check_managed_disk_exists('fog-test-rg', 'fog-test-managed_disk')
47
+ end
48
+ end
49
+
50
+ def test_check_managed_disk_exists_false_case
51
+ @service.stub :check_managed_disk_exists, false do
52
+ assert !@managed_disks.check_managed_disk_exists('fog-test-rg', 'fog-test-managed_disk')
53
+ end
54
+ end
55
+
56
+ def test_grant_access_response
57
+ @service.stub :grant_access_to_managed_disk, 'DUMMY-URI' do
58
+ assert_equal(@managed_disks.grant_access('fog-test-rg', 'fog-test-managed_disk', 'Read', 100), 'DUMMY-URI')
59
+ end
60
+ end
61
+
62
+ def test_revoke_access_response
63
+ response = ApiStub::Models::Compute::ManagedDisk.operation_status_response(@client)
64
+ @service.stub :revoke_access_to_managed_disk, response do
65
+ assert_equal(@managed_disks.revoke_access('fog-test-rg', 'fog-test-managed_disk').status, 'success')
66
+ end
67
+ end
68
+ end
@@ -51,7 +51,7 @@ class TestServer < Minitest::Test
51
51
  :platform,
52
52
  :provision_vm_agent,
53
53
  :enable_automatic_updates,
54
- :network_interface_card_id,
54
+ :network_interface_card_ids,
55
55
  :availability_set_id
56
56
  ]
57
57
  attributes.each do |attribute|
@@ -64,6 +64,12 @@ class TestServer < Minitest::Test
64
64
  @service.stub :create_virtual_machine, response do
65
65
  assert_instance_of Fog::Compute::AzureRM::Server, @server.save
66
66
  end
67
+
68
+ # Async
69
+ async_response = Concurrent::Promise.execute { 10 }
70
+ @service.stub :create_virtual_machine, async_response do
71
+ assert_instance_of Concurrent::Promise, @server.save(true)
72
+ end
67
73
  end
68
74
 
69
75
  def test_save_method_response_for_windows_vm
@@ -12,6 +12,7 @@ class TestServers < Minitest::Test
12
12
  def test_collection_methods
13
13
  methods = [
14
14
  :all,
15
+ :create_async,
15
16
  :get,
16
17
  :check_vm_exists
17
18
  ]
@@ -0,0 +1,31 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for Check Managed Disk Exists Request
4
+ class TestCheckManagedDiskExists < Minitest::Test
5
+ def setup
6
+ @service = Fog::Compute::AzureRM.new(credentials)
7
+ @client = @service.instance_variable_get(:@compute_mgmt_client)
8
+ @managed_disks = @client.disks
9
+ end
10
+
11
+ def test_check_managed_disk_exists_success
12
+ mocked_response = ApiStub::Requests::Compute::ManagedDisk.get_managed_disk_response(@client)
13
+ @managed_disks.stub :get, mocked_response do
14
+ assert @service.check_managed_disk_exists('myrg1', 'mydisk1')
15
+ end
16
+ end
17
+
18
+ def test_check_managed_disk_exists_failure
19
+ response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception', 'code' => 'ResourceNotFound' }) }
20
+ @managed_disks.stub :get, response do
21
+ assert !@service.check_managed_disk_exists('myrg1', 'mydisk1')
22
+ end
23
+ end
24
+
25
+ def test_check_managed_disk_exists_exception
26
+ response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception', 'code' => 'ResourceGroupNotFound' }) }
27
+ @managed_disks.stub :get, response do
28
+ assert_raises(RuntimeError) { @service.check_managed_disk_exists('myrg1', 'mydisk1') }
29
+ end
30
+ end
31
+ end