fog-azure-rm 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/fog/azurerm/docs/compute.md +1 -0
- data/lib/fog/azurerm/docs/storage.md +2 -1
- data/lib/fog/azurerm/models/compute/server.rb +4 -1
- data/lib/fog/azurerm/models/storage/storage_accounts.rb +2 -5
- data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +10 -1
- data/lib/fog/azurerm/requests/storage/check_storage_account_exists.rb +10 -4
- data/lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb +16 -5
- data/lib/fog/azurerm/version.rb +1 -1
- data/test/api_stub/requests/storage/storageaccount.rb +1 -1
- data/test/integration/server.rb +2 -1
- data/test/integration/storage_account.rb +2 -3
- data/test/models/compute/test_server.rb +1 -0
- data/test/requests/storage/test_check_storage_account_exists.rb +4 -2
- data/test/requests/storage/test_check_storage_account_name_availability.rb +4 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3506ec3296726b6937f5a7dcb37cd44d1de99be9
|
4
|
+
data.tar.gz: 247976bb6378c17700f6090a81e0a1bdab573533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44c94ae25c0c8388b0e431f542062e896ff9e326e86fcc1e1bf941162437b484149bed747d085856d5f5cbf98e29e5c5fec41a4b5567abb2fb19ef2dc0552a48
|
7
|
+
data.tar.gz: 08d076b807216e3a731840fef407773fec62787daf9792555f9c399fccfefb138e4b635c416d675d82511bf802e937009d1e61ff759e336396161f515a36a0ad
|
data/CHANGELOG.md
CHANGED
@@ -53,6 +53,7 @@ Create a new linux server
|
|
53
53
|
platform: 'Linux',
|
54
54
|
vhd_path: '<Path of VHD>', # Optional, if you want to create the VM from a custom image.
|
55
55
|
custom_data: 'echo customData', # Optional, if you want to add custom data in this VM.
|
56
|
+
os_disk_caching: 'None/ReadOnly/ReadWrite' # Optional, can be one of None, ReadOnly, ReadWrite
|
56
57
|
)
|
57
58
|
```
|
58
59
|
|
@@ -54,9 +54,10 @@ azure_storage_service = Fog::Storage.new(
|
|
54
54
|
## Check Name Availability
|
55
55
|
|
56
56
|
Check Storage Account Name Availability.This operation checks that account name is valid and is not already in use.
|
57
|
+
_Storage Account Type_ is an optional parameter
|
57
58
|
|
58
59
|
```ruby
|
59
|
-
azure_storage_service.storage_accounts.check_name_availability(
|
60
|
+
azure_storage_service.storage_accounts.check_name_availability(<Storage Account name>, <Storage Account Type>)
|
60
61
|
```
|
61
62
|
|
62
63
|
## Check Storage Account Existence
|
@@ -12,6 +12,7 @@ module Fog
|
|
12
12
|
attribute :storage_account_name
|
13
13
|
attribute :os_disk_name
|
14
14
|
attribute :os_disk_vhd_uri
|
15
|
+
attribute :os_disk_caching
|
15
16
|
attribute :publisher
|
16
17
|
attribute :offer
|
17
18
|
attribute :sku
|
@@ -40,6 +41,7 @@ module Fog
|
|
40
41
|
unless vm.storage_profile.nil?
|
41
42
|
hash['os_disk_name'] = vm.storage_profile.os_disk.name
|
42
43
|
hash['os_disk_vhd_uri'] = vm.storage_profile.os_disk.vhd.uri
|
44
|
+
hash['os_disk_caching'] = vm.storage_profile.os_disk.caching
|
43
45
|
unless vm.storage_profile.image_reference.nil?
|
44
46
|
hash['publisher'] = vm.storage_profile.image_reference.publisher
|
45
47
|
hash['offer'] = vm.storage_profile.image_reference.offer
|
@@ -148,7 +150,8 @@ module Fog
|
|
148
150
|
provision_vm_agent: provision_vm_agent,
|
149
151
|
enable_automatic_updates: enable_automatic_updates,
|
150
152
|
custom_data: custom_data,
|
151
|
-
vhd_path: vhd_path
|
153
|
+
vhd_path: vhd_path,
|
154
|
+
os_disk_caching: os_disk_caching
|
152
155
|
}
|
153
156
|
end
|
154
157
|
end
|
@@ -27,11 +27,8 @@ module Fog
|
|
27
27
|
storage_account_fog.merge_attributes(Fog::Storage::AzureRM::StorageAccount.parse(storage_account))
|
28
28
|
end
|
29
29
|
|
30
|
-
def check_name_availability(name)
|
31
|
-
|
32
|
-
params.name = name
|
33
|
-
params.type = 'Microsoft.Storage/storageAccounts'
|
34
|
-
service.check_storage_account_name_availability(params)
|
30
|
+
def check_name_availability(name, type = 'Microsoft.Storage/storageAccounts')
|
31
|
+
service.check_storage_account_name_availability(name, type)
|
35
32
|
end
|
36
33
|
|
37
34
|
def check_storage_account_exists(resource_group_name, storage_account_name)
|
@@ -28,6 +28,7 @@ module Fog
|
|
28
28
|
vm_hash[:sku],
|
29
29
|
vm_hash[:version],
|
30
30
|
vm_hash[:vhd_path],
|
31
|
+
vm_hash[:os_disk_caching],
|
31
32
|
vm_hash[:platform],
|
32
33
|
vm_hash[:resource_group])
|
33
34
|
|
@@ -75,7 +76,7 @@ module Fog
|
|
75
76
|
image_reference
|
76
77
|
end
|
77
78
|
|
78
|
-
def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version, vhd_path, platform, resource_group)
|
79
|
+
def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version, vhd_path, os_disk_caching, platform, resource_group)
|
79
80
|
storage_profile = Azure::ARM::Compute::Models::StorageProfile.new
|
80
81
|
os_disk = Azure::ARM::Compute::Models::OSDisk.new
|
81
82
|
vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
|
@@ -118,6 +119,14 @@ module Fog
|
|
118
119
|
os_disk.name = "#{vm_name}_os_disk"
|
119
120
|
os_disk.vhd = vhd
|
120
121
|
os_disk.create_option = Azure::ARM::Compute::Models::DiskCreateOptionTypes::FromImage
|
122
|
+
os_disk.caching = case os_disk_caching
|
123
|
+
when 'None'
|
124
|
+
Azure::ARM::Compute::Models::CachingTypes::None
|
125
|
+
when 'ReadOnly'
|
126
|
+
Azure::ARM::Compute::Models::CachingTypes::ReadOnly
|
127
|
+
when 'ReadWrite'
|
128
|
+
Azure::ARM::Compute::Models::CachingTypes::ReadWrite
|
129
|
+
end unless os_disk_caching.nil?
|
121
130
|
storage_profile.os_disk = os_disk
|
122
131
|
storage_profile
|
123
132
|
end
|
@@ -7,17 +7,23 @@ module Fog
|
|
7
7
|
msg = "Checking Storage Account: #{storage_account_name}."
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
|
-
@storage_mgmt_client.storage_accounts.get_properties(resource_group_name, storage_account_name)
|
11
|
-
Fog::Logger.debug "Storage Account #{storage_account_name} exists."
|
12
|
-
true
|
10
|
+
storage_account = @storage_mgmt_client.storage_accounts.get_properties(resource_group_name, storage_account_name)
|
13
11
|
rescue MsRestAzure::AzureOperationError => e
|
14
12
|
if e.body['error']['code'] == 'ResourceNotFound'
|
15
13
|
Fog::Logger.debug "Storage Account #{storage_account_name} doesn't exist."
|
16
|
-
false
|
14
|
+
return false
|
17
15
|
else
|
18
16
|
raise_azure_exception(e, msg)
|
19
17
|
end
|
20
18
|
end
|
19
|
+
|
20
|
+
if storage_account.provisioning_state == 'Succeeded'
|
21
|
+
Fog::Logger.debug "Storage Account #{storage_account_name} exists."
|
22
|
+
true
|
23
|
+
else
|
24
|
+
Fog::Logger.debug "Storage Account #{storage_account_name} doesn't exist."
|
25
|
+
false
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
23
29
|
# This class provides the mock implementation.
|
@@ -3,23 +3,34 @@ module Fog
|
|
3
3
|
class AzureRM
|
4
4
|
# This class provides the actual implementation for service calls.
|
5
5
|
class Real
|
6
|
-
def check_storage_account_name_availability(
|
7
|
-
msg = "Checking Name availability: #{
|
6
|
+
def check_storage_account_name_availability(storage_account_name, storage_account_type)
|
7
|
+
msg = "Checking Storage Account Name availability: #{storage_account_name}."
|
8
8
|
Fog::Logger.debug msg
|
9
|
+
|
10
|
+
storage_account_params = create_storage_account_params(storage_account_name, storage_account_type)
|
9
11
|
begin
|
10
|
-
name_available_obj = @storage_mgmt_client.storage_accounts.check_name_availability(
|
12
|
+
name_available_obj = @storage_mgmt_client.storage_accounts.check_name_availability(storage_account_params)
|
11
13
|
rescue MsRestAzure::AzureOperationError => e
|
12
14
|
raise_azure_exception(e, msg)
|
13
15
|
end
|
14
16
|
if name_available_obj.name_available
|
15
|
-
Fog::Logger.debug "Name: #{
|
17
|
+
Fog::Logger.debug "Name: #{storage_account_name} is available."
|
16
18
|
true
|
17
19
|
else
|
18
|
-
Fog::Logger.debug "Name: #{
|
20
|
+
Fog::Logger.debug "Name: #{storage_account_type} is not available."
|
19
21
|
Fog::Logger.debug "Reason: #{name_available_obj.reason}."
|
20
22
|
false
|
21
23
|
end
|
22
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def create_storage_account_params(name, type)
|
29
|
+
params = Azure::ARM::Storage::Models::StorageAccountCheckNameAvailabilityParameters.new
|
30
|
+
params.name = name
|
31
|
+
params.type = type
|
32
|
+
params
|
33
|
+
end
|
23
34
|
end
|
24
35
|
# This class provides the mock implementation for unit tests.
|
25
36
|
class Mock
|
data/lib/fog/azurerm/version.rb
CHANGED
@@ -5,7 +5,7 @@ module ApiStub
|
|
5
5
|
class StorageAccount
|
6
6
|
def self.storage_account_request(storage_mgmt_client)
|
7
7
|
storage_account_hash = {
|
8
|
-
'id' => '/subscriptions
|
8
|
+
'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog_test_rg/providers/Microsoft.Storage/storageAccounts/fog-test-storage-account',
|
9
9
|
'name' => 'fog-test-storage-account',
|
10
10
|
'location' => 'west us',
|
11
11
|
'sku' =>
|
data/test/integration/server.rb
CHANGED
@@ -37,9 +37,8 @@ begin
|
|
37
37
|
###################### Check Storage Account name Availability ######################
|
38
38
|
########################################################################################################################
|
39
39
|
|
40
|
-
storage_account_avail = storage.storage_accounts.check_name_availability('
|
41
|
-
puts 'Storage
|
42
|
-
puts 'Storage account unavailale' unless storage_account_avail
|
40
|
+
storage_account_avail = storage.storage_accounts.check_name_availability('teststorage123')
|
41
|
+
puts storage_account_avail ? 'Storage Account name available' : 'Storage Account name unavailable'
|
43
42
|
|
44
43
|
########################################################################################################################
|
45
44
|
###################### Check Subnet Exists? ######################
|
@@ -11,13 +11,15 @@ class TestCheckStorageAccountExists < Minitest::Test
|
|
11
11
|
|
12
12
|
def test_check_storage_account_exists_success
|
13
13
|
response_body = ApiStub::Requests::Storage::StorageAccount.storage_account_request(@storage_mgmt_client)
|
14
|
+
response_body.provisioning_state = 'Succeeded'
|
14
15
|
@storage_accounts.stub :get_properties, response_body do
|
15
|
-
|
16
|
+
assert_equal @service.check_storage_account_exists('fog_test_rg', 'fog-test-storage-account'), true
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_check_storage_account_exists_failure
|
20
|
-
response =
|
21
|
+
response = ApiStub::Requests::Storage::StorageAccount.storage_account_request(@storage_mgmt_client)
|
22
|
+
response.provisioning_state = 'Failed'
|
21
23
|
@storage_accounts.stub :get_properties, response do
|
22
24
|
assert !@service.check_storage_account_exists('fog_test_rg', 'fogtestsasecond')
|
23
25
|
end
|
@@ -10,35 +10,26 @@ class TestCheckStorageAccountNameAvailability < Minitest::Test
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_check_storage_account_name_availability_success
|
13
|
-
params = Azure::ARM::Storage::Models::StorageAccountCheckNameAvailabilityParameters.new
|
14
|
-
params.name = 'teststorageaccount'
|
15
|
-
params.type = 'Microsoft.Storage/storageAccounts'
|
16
13
|
true_case_response = ApiStub::Requests::Storage::StorageAccount.true_case_for_check_name_availability(@storage_mgmt_client)
|
17
14
|
@storage_accounts.stub :check_name_availability, true_case_response do
|
18
|
-
assert_equal @azure_credentials.check_storage_account_name_availability(
|
15
|
+
assert_equal @azure_credentials.check_storage_account_name_availability('teststorageaccount', 'Microsoft.Storage/storageAccounts'), true
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
22
19
|
def test_check_storage_account_name_availability_failure
|
23
|
-
params = Azure::ARM::Storage::Models::StorageAccountCheckNameAvailabilityParameters.new
|
24
|
-
params.name = 'teststorageaccount'
|
25
|
-
params.type = 'Microsoft.Storage/storageAccounts'
|
26
20
|
false_case_response = ApiStub::Requests::Storage::StorageAccount.false_case_for_check_name_availability(@storage_mgmt_client)
|
27
21
|
@storage_accounts.stub :check_name_availability, false_case_response do
|
28
|
-
assert_equal @azure_credentials.check_storage_account_name_availability(
|
22
|
+
assert_equal @azure_credentials.check_storage_account_name_availability('testname', 'Microsoft.Storage/storageAccounts'), false
|
29
23
|
assert_raises ArgumentError do
|
30
|
-
@azure_credentials.check_storage_account_name_availability
|
24
|
+
@azure_credentials.check_storage_account_name_availability
|
31
25
|
end
|
32
26
|
end
|
33
27
|
end
|
34
28
|
|
35
29
|
def test_check_storage_account_name_availability_exception
|
36
|
-
params = Azure::ARM::Storage::Models::StorageAccountCheckNameAvailabilityParameters.new
|
37
|
-
params.name = 'teststorageaccount'
|
38
|
-
params.type = 'Microsoft.Storage/storageAccounts'
|
39
30
|
raise_exception = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception', 'code' => 'ResourceGroupNotFound' }) }
|
40
31
|
@storage_accounts.stub :check_name_availability, raise_exception do
|
41
|
-
assert_raises(RuntimeError) { @azure_credentials.check_storage_account_name_availability(
|
32
|
+
assert_raises(RuntimeError) { @azure_credentials.check_storage_account_name_availability('teststorageaccount', 'Microsoft.Storage/storageAccounts') }
|
42
33
|
end
|
43
34
|
end
|
44
35
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaffan Chaudhry
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2017-01-
|
17
|
+
date: 2017-01-13 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: rake
|