fog-azure-rm 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37e9a15cf8f593c6eca92fddd5099c18d219f0be
4
- data.tar.gz: 49fae3451340031eea99a48be0ab7eaef088ac04
3
+ metadata.gz: 3506ec3296726b6937f5a7dcb37cd44d1de99be9
4
+ data.tar.gz: 247976bb6378c17700f6090a81e0a1bdab573533
5
5
  SHA512:
6
- metadata.gz: c7163130df668fe82cc2c517a51b826085f931328afd5c8b72da34aa5baacbfc8ba45a38062e51985df74e20991663f633d69cf16a3b071e8a62af06936d0089
7
- data.tar.gz: 4b1203a28c2ca1f24b2f269fdb9b0b9256d26fcf90ef2cf6fa47b12e7d74d6c9d923fcff8ffd4938c81e341a821985c7409c2e6d4db3607cf34f324ebfe5f215
6
+ metadata.gz: 44c94ae25c0c8388b0e431f542062e896ff9e326e86fcc1e1bf941162437b484149bed747d085856d5f5cbf98e29e5c5fec41a4b5567abb2fb19ef2dc0552a48
7
+ data.tar.gz: 08d076b807216e3a731840fef407773fec62787daf9792555f9c399fccfefb138e4b635c416d675d82511bf802e937009d1e61ff759e336396161f515a36a0ad
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2.1
2
+
3
+ **Changed:**
4
+ - Compute Service - Added new parameter to create virtual machine request
5
+
1
6
  ## 0.2.0
2
7
 
3
8
  **Added:**
@@ -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('<Storage Account name>')
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
- params = Azure::ARM::Storage::Models::StorageAccountCheckNameAvailabilityParameters.new
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(params)
7
- msg = "Checking Name availability: #{params.name}."
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(params)
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: #{params.name} is available."
17
+ Fog::Logger.debug "Name: #{storage_account_name} is available."
16
18
  true
17
19
  else
18
- Fog::Logger.debug "Name: #{params.name} is not available."
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
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AzureRM
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
5
5
  end
@@ -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/67f2116d-4ea2-4c6c-b20a-f92183dbe3cb/resourceGroups/fog_test_rg/providers/Microsoft.Storage/storageAccounts/fogtestsasecond',
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' =>
@@ -105,7 +105,8 @@ begin
105
105
  sku: '14.04.2-LTS',
106
106
  version: 'latest',
107
107
  platform: 'linux',
108
- custom_data: 'echo customData'
108
+ custom_data: 'echo customData',
109
+ os_disk_caching: 'None'
109
110
  )
110
111
  puts "Created virtual machine: #{virtual_machine.name}"
111
112
 
@@ -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('test-storage')
41
- puts 'Storage account available' if storage_account_avail
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? ######################
@@ -37,6 +37,7 @@ class TestServer < Minitest::Test
37
37
  :storage_account_name,
38
38
  :os_disk_name,
39
39
  :os_disk_vhd_uri,
40
+ :os_disk_caching,
40
41
  :publisher,
41
42
  :offer,
42
43
  :sku,
@@ -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
- assert @service.check_storage_account_exists('fog_test_rg', 'fogtestsasecond')
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 = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception', 'code' => 'ResourceNotFound' }) }
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(params), true
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(params), false
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(params, 'wrong arg')
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(params) }
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.0
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-12 00:00:00.000000000 Z
17
+ date: 2017-01-13 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: rake