fog-azure-rm 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/fog/azurerm/models/compute/server.rb +5 -0
- data/lib/fog/azurerm/models/resources/azure_resources.rb +8 -0
- data/lib/fog/azurerm/requests/resources/list_resources_in_resource_group.rb +42 -0
- data/lib/fog/azurerm/resources.rb +1 -0
- data/lib/fog/azurerm/utilities/general.rb +4 -0
- data/lib/fog/azurerm/version.rb +1 -1
- data/test/api_stub/models/compute/server.rb +1 -0
- data/test/api_stub/models/resources/resource.rb +17 -0
- data/test/api_stub/requests/compute/virtual_machine.rb +8 -0
- data/test/api_stub/requests/resources/resource.rb +17 -0
- data/test/integration/resource_group.rb +10 -1
- data/test/models/compute/test_server.rb +1 -0
- data/test/models/resources/test_resources.rb +14 -1
- data/test/requests/resources/test_list_resources_in_resource_group.rb +24 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f2643da5f5306d3ff7cc3d7f64ffd012fe8dd62bd3cf751d3b39efb984fab56
|
4
|
+
data.tar.gz: 2698137885445fde6a1378e0e51d988ce735dca45bb78b5cbdc578c17a686831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5dfd85ae82dab94a2ead2195c06776a80c74de916c480c46b88cb07dc5ff8e9ed4fba07f682c281106b59b5704b17bbf0baccc3d485791a1e5249dbc289669a
|
7
|
+
data.tar.gz: 6e4de4154352a2fa6592ae9fdfa8a88ce5f322d4c6d8ef39c6f7cf942df3f85aedccbe00748af26346d0b9cc27f56cf12f25424870f4449c03653b34b42ce1ba
|
data/CHANGELOG.md
CHANGED
@@ -11,6 +11,7 @@ module Fog
|
|
11
11
|
attribute :vm_size
|
12
12
|
attribute :storage_account_name
|
13
13
|
attribute :os_disk_name
|
14
|
+
attribute :os_disk_id
|
14
15
|
attribute :os_disk_vhd_uri
|
15
16
|
attribute :os_disk_caching
|
16
17
|
attribute :publisher
|
@@ -46,6 +47,10 @@ module Fog
|
|
46
47
|
hash['vm_size'] = vm.hardware_profile.vm_size unless vm.hardware_profile.vm_size.nil?
|
47
48
|
unless vm.storage_profile.nil?
|
48
49
|
hash['os_disk_name'] = vm.storage_profile.os_disk.name
|
50
|
+
|
51
|
+
subscription_id = get_subscription_id(vm.id)
|
52
|
+
hash['os_disk_id'] = "/subscriptions/#{subscription_id}/resourceGroups/#{hash['resource_group']}/providers/Microsoft.Compute/disks/#{hash['os_disk_name']}"
|
53
|
+
|
49
54
|
hash['os_disk_size'] = vm.storage_profile.os_disk.disk_size_gb
|
50
55
|
if vm.storage_profile.os_disk.vhd.nil?
|
51
56
|
hash['managed_disk_storage_type'] = vm.storage_profile.os_disk.managed_disk.storage_account_type
|
@@ -26,6 +26,14 @@ module Fog
|
|
26
26
|
def check_azure_resource_exists(resource_id, api_version)
|
27
27
|
service.check_azure_resource_exists(resource_id, api_version)
|
28
28
|
end
|
29
|
+
|
30
|
+
def list_resources_in_resource_group(resource_group_name)
|
31
|
+
resources = []
|
32
|
+
service.list_resources_in_resource_group(resource_group_name).each do |resource|
|
33
|
+
resources.push(Fog::Resources::AzureRM::AzureResource.parse(resource))
|
34
|
+
end
|
35
|
+
load(resources)
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Fog
|
2
|
+
module Resources
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implementation for service calls.
|
5
|
+
class Real
|
6
|
+
def list_resources_in_resource_group(resource_group_name)
|
7
|
+
msg = "Listing Resources in #{resource_group_name}"
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
begin
|
10
|
+
resources = @rmc.resource_groups.list_resources(resource_group_name)
|
11
|
+
rescue MsRestAzure::AzureOperationError => e
|
12
|
+
raise_azure_exception(e, msg)
|
13
|
+
end
|
14
|
+
Fog::Logger.debug "Resources in #{resource_group_name} listed successfully"
|
15
|
+
resources
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# This class provides the mock implementation for unit tests.
|
20
|
+
class Mock
|
21
|
+
def list_resources_in_resource_group(*)
|
22
|
+
resources = {
|
23
|
+
'id' => '/subscriptions/########-####-####-####-############/fog-rg',
|
24
|
+
'name' => 'your-resource-name',
|
25
|
+
'type' => 'providernamespace/resourcetype',
|
26
|
+
'location' => 'westus',
|
27
|
+
'tags' =>
|
28
|
+
{
|
29
|
+
tag_name => tag_value
|
30
|
+
},
|
31
|
+
'plan' =>
|
32
|
+
{
|
33
|
+
'name' => 'free'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
result_mapper = Azure::ARM::Resources::Models::GenericResource.mapper
|
37
|
+
@rmc.deserialize(result_mapper, resources, 'result.body').value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/fog/azurerm/version.rb
CHANGED
@@ -21,6 +21,7 @@ module ApiStub
|
|
21
21
|
},
|
22
22
|
'osDisk' => {
|
23
23
|
'name' => 'fog-test-server_os_disk',
|
24
|
+
'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/fog-test-server_os_disk',
|
24
25
|
'vhd' => {
|
25
26
|
'uri' => 'http://storageAccount.blob.core.windows.net/vhds/fog-test-server_os_disk.vhd'
|
26
27
|
}
|
@@ -37,6 +37,23 @@ module ApiStub
|
|
37
37
|
result_mapper = Azure::ARM::Resources::Models::ResourceListResult.mapper
|
38
38
|
client.deserialize(result_mapper, Fog::JSON.decode(resources), 'result.body').value
|
39
39
|
end
|
40
|
+
|
41
|
+
def self.list_resources_in_resource_group_response(client)
|
42
|
+
resources = '{
|
43
|
+
"id": "/subscriptions/########-####-####-####-############/resourceGroups/{RESOURCE-GROUP}/providers/Microsoft.Network/{PROVIDER-NAME}/{RESOURCE-NAME}",
|
44
|
+
"name": "your-resource-name",
|
45
|
+
"type": "providernamespace/resourcetype",
|
46
|
+
"location": "westus",
|
47
|
+
"tags": {
|
48
|
+
"tag_name": "tag_value"
|
49
|
+
},
|
50
|
+
"plan": {
|
51
|
+
"name": "free"
|
52
|
+
}
|
53
|
+
}'
|
54
|
+
result_mapper = Azure::ARM::Resources::Models::GenericResource.mapper
|
55
|
+
client.deserialize(result_mapper, Fog::JSON.decode(resources), 'result.body')
|
56
|
+
end
|
40
57
|
end
|
41
58
|
end
|
42
59
|
end
|
@@ -243,6 +243,7 @@ module ApiStub
|
|
243
243
|
},
|
244
244
|
"osDisk": {
|
245
245
|
"name":"myosdisk1",
|
246
|
+
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
|
246
247
|
"vhd": {
|
247
248
|
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
|
248
249
|
},
|
@@ -320,6 +321,7 @@ module ApiStub
|
|
320
321
|
},
|
321
322
|
"osDisk": {
|
322
323
|
"name":"myosdisk1",
|
324
|
+
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
|
323
325
|
"vhd": {
|
324
326
|
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
|
325
327
|
},
|
@@ -397,6 +399,7 @@ module ApiStub
|
|
397
399
|
},
|
398
400
|
"osDisk": {
|
399
401
|
"name":"myosdisk1",
|
402
|
+
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
|
400
403
|
"vhd": {
|
401
404
|
"uri":"https://custimagestorage.blob.core.windows.net/customimage/trusty-server-cloudimg-amd64-disk1.vhd"
|
402
405
|
},
|
@@ -474,6 +477,7 @@ module ApiStub
|
|
474
477
|
},
|
475
478
|
"osDisk": {
|
476
479
|
"name":"myosdisk1",
|
480
|
+
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
|
477
481
|
"vhd": {
|
478
482
|
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
|
479
483
|
},
|
@@ -546,6 +550,7 @@ module ApiStub
|
|
546
550
|
'osDisk' =>
|
547
551
|
{
|
548
552
|
'name' => 'myosdisk1',
|
553
|
+
'id' => '/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1',
|
549
554
|
'vhd' =>
|
550
555
|
{
|
551
556
|
'uri' => 'http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd'
|
@@ -651,6 +656,7 @@ module ApiStub
|
|
651
656
|
},
|
652
657
|
"osDisk": {
|
653
658
|
"name":"myosdisk1",
|
659
|
+
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
|
654
660
|
"vhd": {
|
655
661
|
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
|
656
662
|
},
|
@@ -809,6 +815,7 @@ module ApiStub
|
|
809
815
|
},
|
810
816
|
"osDisk": {
|
811
817
|
"name":"myosdisk1",
|
818
|
+
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
|
812
819
|
"vhd": {
|
813
820
|
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
|
814
821
|
},
|
@@ -896,6 +903,7 @@ module ApiStub
|
|
896
903
|
},
|
897
904
|
"osDisk": {
|
898
905
|
"name":"myosdisk1",
|
906
|
+
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
|
899
907
|
"vhd": {
|
900
908
|
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
|
901
909
|
},
|
@@ -39,6 +39,23 @@ module ApiStub
|
|
39
39
|
result_mapper = Azure::ARM::Resources::Models::ResourceListResult.mapper
|
40
40
|
client.deserialize(result_mapper, Fog::JSON.decode(body), 'result.body')
|
41
41
|
end
|
42
|
+
|
43
|
+
def self.list_resources_in_resource_group(client)
|
44
|
+
body = '{
|
45
|
+
"id": "/subscriptions/########-####-####-####-############/resourceGroups/{RESOURCE-GROUP}/providers/Microsoft.Network/{PROVIDER-NAME}/{RESOURCE-NAME}",
|
46
|
+
"name": "your-resource-name",
|
47
|
+
"type": "providernamespace/resourcetype",
|
48
|
+
"location": "westus",
|
49
|
+
"tags": {
|
50
|
+
"tag_name": "tag_value"
|
51
|
+
},
|
52
|
+
"plan": {
|
53
|
+
"name": "free"
|
54
|
+
}
|
55
|
+
}'
|
56
|
+
result_mapper = Azure::ARM::Resources::Models::GenericResource.mapper
|
57
|
+
client.deserialize(result_mapper, Fog::JSON.decode(body), 'result.body')
|
58
|
+
end
|
42
59
|
end
|
43
60
|
end
|
44
61
|
end
|
@@ -17,7 +17,6 @@ resource = Fog::Resources::AzureRM.new(
|
|
17
17
|
resource_group_name = "RG-#{current_time}"
|
18
18
|
|
19
19
|
begin
|
20
|
-
|
21
20
|
########################################################################################################################
|
22
21
|
###################### Check Resource Group Exists? ######################
|
23
22
|
########################################################################################################################
|
@@ -51,6 +50,16 @@ begin
|
|
51
50
|
resource_group = resource_groups.get(resource_group_name)
|
52
51
|
puts "Get resource group: #{resource_group.name}"
|
53
52
|
|
53
|
+
########################################################################################################################
|
54
|
+
###################### Get All Resources in a Resource Group ######################
|
55
|
+
########################################################################################################################
|
56
|
+
|
57
|
+
resources = resource.azure_resources.list_resources_in_resource_group(resource_group_name)
|
58
|
+
puts 'List resources in resource groups:'
|
59
|
+
resources.each do |a_resource|
|
60
|
+
puts a_resource.name
|
61
|
+
end
|
62
|
+
|
54
63
|
########################################################################################################################
|
55
64
|
###################### Destroy Resource Group ######################
|
56
65
|
########################################################################################################################
|
@@ -14,7 +14,8 @@ class TestResources < Minitest::Test
|
|
14
14
|
methods = [
|
15
15
|
:all,
|
16
16
|
:get,
|
17
|
-
:check_azure_resource_exists
|
17
|
+
:check_azure_resource_exists,
|
18
|
+
:list_resources_in_resource_group
|
18
19
|
]
|
19
20
|
methods.each do |method|
|
20
21
|
assert_respond_to @resources, method
|
@@ -49,4 +50,16 @@ class TestResources < Minitest::Test
|
|
49
50
|
assert !@resources.check_azure_resource_exists(@resource_id, '2016-09-01')
|
50
51
|
end
|
51
52
|
end
|
53
|
+
|
54
|
+
def test_list_resources_in_resource_group_method_response
|
55
|
+
client = @service.instance_variable_get(:@rmc)
|
56
|
+
response = [ApiStub::Models::Resources::Resource.list_resources_in_resource_group_response(client)]
|
57
|
+
@service.stub :list_resources_in_resource_group, response do
|
58
|
+
assert_instance_of Fog::Resources::AzureRM::AzureResources, @resources.list_resources_in_resource_group('fog-test-rg')
|
59
|
+
assert @resources.list_resources_in_resource_group('fog-test-rg').size >= 1
|
60
|
+
@resources.list_resources_in_resource_group('fog-test-rg').each do |s|
|
61
|
+
assert_instance_of Fog::Resources::AzureRM::AzureResource, s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
52
65
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Test class for List Resource Groups Request
|
4
|
+
class TestListResources < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@service = Fog::Resources::AzureRM.new(credentials)
|
7
|
+
@client = @service.instance_variable_get(:@rmc)
|
8
|
+
@resources = @client.resource_groups
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_list_resources_in_resource_group_success
|
12
|
+
mocked_response = ApiStub::Requests::Resources::AzureResource.list_resources_in_resource_group(@client)
|
13
|
+
@resources.stub :list_resources, mocked_response do
|
14
|
+
assert_equal @service.list_resources_in_resource_group('fog-test-rg'), mocked_response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_list_resources_in_resource_group_failure
|
19
|
+
response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
|
20
|
+
@resources.stub :list_resources, response do
|
21
|
+
assert_raises(MsRestAzure::AzureOperationError) { @service.list_resources_in_resource_group('fog-test-rg') }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-azure-rm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaffan Chaudhry
|
@@ -18,7 +18,7 @@ authors:
|
|
18
18
|
autorequire:
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
|
-
date: 2018-03
|
21
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: rake
|
@@ -564,6 +564,7 @@ files:
|
|
564
564
|
- lib/fog/azurerm/requests/resources/get_resource_group.rb
|
565
565
|
- lib/fog/azurerm/requests/resources/list_deployments.rb
|
566
566
|
- lib/fog/azurerm/requests/resources/list_resource_groups.rb
|
567
|
+
- lib/fog/azurerm/requests/resources/list_resources_in_resource_group.rb
|
567
568
|
- lib/fog/azurerm/requests/resources/list_tagged_resources.rb
|
568
569
|
- lib/fog/azurerm/requests/resources/tag_resource.rb
|
569
570
|
- lib/fog/azurerm/requests/sql/check_database_exists.rb
|
@@ -965,6 +966,7 @@ files:
|
|
965
966
|
- test/requests/resources/test_get_resource_group.rb
|
966
967
|
- test/requests/resources/test_list_deployments.rb
|
967
968
|
- test/requests/resources/test_list_resource_groups.rb
|
969
|
+
- test/requests/resources/test_list_resources_in_resource_group.rb
|
968
970
|
- test/requests/resources/test_list_tagged_resources.rb
|
969
971
|
- test/requests/resources/test_tag_resource.rb
|
970
972
|
- test/requests/sql/test_create_or_update_database.rb
|