fog-azure-rm 0.3.4 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86a3f0c7c485417833dbbad2fad9b5aab150e503
4
- data.tar.gz: 2b323fe0537e530cc54d7a5a1b0e985b387649bb
3
+ metadata.gz: 2b4f2441649c95cccb88036a162a4613332f51aa
4
+ data.tar.gz: 4d1c16d3f1aa6a8c5aec6ea59632de93988b75eb
5
5
  SHA512:
6
- metadata.gz: c60ea047820659f91d09c395f5b7930fbbbaf0d47dfea3e4b0d36c508650add4d5a3a62803a1a516c19f77611fa3055c20a64cff240dd69f2f5a07cbbf24534b
7
- data.tar.gz: 2b9f9a22a6bafd848d8ef9aab6f213fb3768e0bc7fcaea12bd09db444d310fd8f0fb5f1f1bd0b27d787e39253c2dbb4ec923a3162a4f0c2e81594c155b3670e8
6
+ metadata.gz: b421167e3518fd5b39d9eec7b9dcd286b4402eabab895eb0ddea2a7250dcecf5ddf70e12063c92ea1adda850eced455242bd7d5ae49466b99dd7e2e3c616b4cb
7
+ data.tar.gz: 12864d9c4833cd859147bf506559a1d9bc91b4911c66cf823a1d2630af0b1ec73791950d9484e9effdac455460da2c7959ee7ee76cc7fdc18f697f9c30733106
@@ -1,3 +1,15 @@
1
+ ## 0.3.5
2
+
3
+ **Added:**
4
+ - Compute Service - Added platform update domain and platform fault domain propertied in server model
5
+ - Compute Service - Added support to custom image for managed VM
6
+
7
+ **Changed:**
8
+ - Compute Service - Changed required arguments for server create method
9
+
10
+ **Fixed**
11
+ - Compute Service - Fixed issue with creating VM with custom image
12
+
1
13
  ## 0.3.4
2
14
 
3
15
  **Added:**
@@ -41,6 +41,8 @@ module Fog
41
41
  request :list_managed_disks_in_subscription
42
42
  request :revoke_access_to_managed_disk
43
43
  request :grant_access_to_managed_disk
44
+ request :create_generalized_image
45
+ request :delete_generalized_image
44
46
 
45
47
  model_path 'fog/azurerm/models/compute'
46
48
  model :availability_set
@@ -33,13 +33,16 @@ azure_compute_service.servers.check_vm_exists(<Resource Group name>, <VM Name>)
33
33
 
34
34
  ## Create Server
35
35
 
36
- Create a new linux server
37
-
38
36
  **Info:**
39
- Attribute **network_interface_card_ids** is an array of NICs ids. The NIC id at index zero will become primary NIC of this server(virtual machine) by default.
40
37
 
41
- **Info:**
42
- When using **managed_disk_storage_type** you should not pass the **vhd_path** as the managed disk will be used for the OS disk. Also, data disks cannot be attached to a VM which uses managed disks for the OS disk.
38
+ - Attribute **network_interface_card_ids** is an array of NICs ids. The NIC id at index zero will become primary NIC of this server(virtual machine) by default.
39
+ - To create VM with managed OS disk, use the _managed_disk_storage_type_ argument
40
+ - To create VM with unmanaged OS disk, use the _storage_account_name_ argument
41
+
42
+
43
+ ### Virtual Machine (Managed OS Disk)
44
+
45
+ ### Virtual Machine (Managed OS Disk)
43
46
 
44
47
  ```ruby
45
48
  azure_compute_service.servers.create(
@@ -47,7 +50,6 @@ When using **managed_disk_storage_type** you should not pass the **vhd_path** as
47
50
  location: 'West US',
48
51
  resource_group: '<Resource Group Name>',
49
52
  vm_size: 'Basic_A0',
50
- storage_account_name: '<Storage Account Name>',
51
53
  username: '<Username for VM>',
52
54
  password: '<Password for VM>', # Optional, if 'platform' partameter is 'Linux'.
53
55
  disable_password_authentication: false,
@@ -61,12 +63,12 @@ When using **managed_disk_storage_type** you should not pass the **vhd_path** as
61
63
  vhd_path: '<Path of VHD>', # Optional, if you want to create the VM from a custom image.
62
64
  custom_data: 'echo customData', # Optional, if you want to add custom data in this VM.
63
65
  os_disk_caching: Fog::ARM::Compute::Models::CachingTypes::None, # Optional, can be one of None, ReadOnly, ReadWrite
64
- managed_disk_storage_type: Azure::ARM::Compute::Models::StorageAccountTypes::StandardLRS, # Optional, can be StandardLRS or PremiumLRS
66
+ managed_disk_storage_type: Azure::ARM::Compute::Models::StorageAccountTypes::StandardLRS, # Optional if storage_account_name is passed, can be StandardLRS or PremiumLRS
65
67
  os_disk_size: <Disk Size> # Optional, size of the os disk in GB (upto 1023)
66
68
  )
67
69
  ```
68
70
 
69
- Create a new windows server
71
+ ### Virtual Machine (Unmanaged OS Disk)
70
72
 
71
73
  ```ruby
72
74
  azure_compute_service.servers.create(
@@ -87,7 +89,6 @@ Create a new windows server
87
89
  platform: 'Windows',
88
90
  vhd_path: '<Path of VHD>', # Optional, if you want to create the VM from a custom image.
89
91
  custom_data: 'echo customData', # Optional, if you want to add custom data in this VM.
90
- managed_disk_storage_type: Azure::ARM::Compute::Models::StorageAccountTypes::StandardLRS, # Optional, can be StandardLRS or PremiumLRS
91
92
  os_disk_size: <Disk Size> # Optional, size of the os disk in GB (upto 1023)
92
93
  )
93
94
  ```
@@ -33,6 +33,8 @@ module Fog
33
33
  attribute :managed_disk_storage_type
34
34
  attribute :os_disk_size
35
35
  attribute :tags
36
+ attribute :platform_update_domain
37
+ attribute :platform_fault_domain
36
38
 
37
39
  def self.parse(vm)
38
40
  hash = {}
@@ -80,13 +82,19 @@ module Fog
80
82
  hash['availability_set_id'] = vm.availability_set.id unless vm.availability_set.nil?
81
83
  hash['tags'] = vm.tags
82
84
 
85
+ unless vm.instance_view.nil?
86
+ hash['platform_update_domain'] = vm.instance_view.platform_update_domain
87
+ hash['platform_fault_domain'] = vm.instance_view.platform_fault_domain
88
+ end
89
+
83
90
  hash
84
91
  end
85
92
 
86
93
  def save(async = false)
87
- requires :name, :location, :resource_group, :vm_size, :storage_account_name,
88
- :username, :network_interface_card_ids
94
+ requires :name, :location, :resource_group, :vm_size, :username, :network_interface_card_ids
89
95
  requires :publisher, :offer, :sku, :version if vhd_path.nil? && managed_disk_storage_type.nil?
96
+ requires :storage_account_name if managed_disk_storage_type.nil?
97
+ requires :managed_disk_storage_type if storage_account_name.nil?
90
98
 
91
99
  if platform_is_linux?(platform)
92
100
  requires :disable_password_authentication
@@ -0,0 +1,67 @@
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_generalized_image(image_config)
7
+ msg = "Creating/Updating Generalized Image: #{image_config[:vm_name]}-osImage"
8
+ Fog::Logger.debug msg
9
+ image_name = "#{image_config[:vm_name]}-osImage"
10
+ image = setup_image_params(image_config)
11
+ begin
12
+ image_obj = @compute_mgmt_client.images.create_or_update(image_config[:resource_group], image_name, image)
13
+ rescue MsRestAzure::AzureOperationError => e
14
+ raise_azure_exception(e, msg)
15
+ end
16
+ Fog::Logger.debug "Generalized Image #{image_name} created/updated successfully."
17
+ image_obj
18
+ end
19
+
20
+ private
21
+
22
+ def setup_image_params(image_config)
23
+ storage_profile_image = Azure::ARM::Compute::Models::ImageStorageProfile.new
24
+ storage_profile_image.os_disk = create_os_disk_image(image_config)
25
+ image = Azure::ARM::Compute::Models::Image.new
26
+ image.storage_profile = storage_profile_image
27
+ image.location = image_config[:location]
28
+ image
29
+ end
30
+
31
+ def create_os_disk_image(image_config)
32
+ os_disk_image = Azure::ARM::Compute::Models::ImageOSDisk.new
33
+ os_disk_image.os_type = image_config[:platform]
34
+ os_disk_image.os_state = 'Generalized'
35
+ os_disk_image.blob_uri = image_config[:new_vhd_path]
36
+ os_disk_image.caching = Azure::ARM::Compute::Models::CachingTypes::ReadWrite
37
+ os_disk_image
38
+ end
39
+ end
40
+ # This class provides the mock implementation for unit tests.
41
+ class Mock
42
+ def create_generalized_image(*)
43
+ image_obj = {
44
+ 'location' => 'West US',
45
+ 'tags' => {
46
+ 'key' => 'value'
47
+ },
48
+ 'properties' => {
49
+ 'storageProfile' => {
50
+ 'osDisk' => {
51
+ 'osType' => 'Linux',
52
+ 'blobUri' => 'https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd',
53
+ 'osState' => 'generalized',
54
+ 'hostCaching' => 'readwrite',
55
+ 'storageAccountType' => 'Standard_LRS'
56
+ },
57
+ 'provisioningState' => 'Succeeded'
58
+ }
59
+ }
60
+ }
61
+ image_mapper = Azure::ARM::Compute::Models::Image.mapper
62
+ @compute_mgmt_client.deserialize(image_mapper, image_obj, 'result.body')
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -32,7 +32,8 @@ module Fog
32
32
  vm_config[:platform],
33
33
  vm_config[:resource_group],
34
34
  vm_config[:managed_disk_storage_type],
35
- vm_config[:os_disk_size])
35
+ vm_config[:os_disk_size],
36
+ vm_config[:location])
36
37
 
37
38
  virtual_machine.os_profile = if vm_config[:platform].casecmp(WINDOWS).zero?
38
39
  define_windows_os_profile(vm_config[:name],
@@ -62,6 +63,9 @@ module Fog
62
63
  rescue MsRestAzure::AzureOperationError => e
63
64
  raise_azure_exception(e, msg)
64
65
  end
66
+
67
+ is_managed_custom_vm = !vm_config[:vhd_path].nil? && !vm_config[:managed_disk_storage_type].nil?
68
+ delete_generalized_image(vm_config[:resource_group], vm_config[:name]) if is_managed_custom_vm
65
69
  Fog::Logger.debug "Virtual Machine #{vm_config[:name]} Created Successfully." unless async
66
70
  response
67
71
  end
@@ -83,40 +87,18 @@ module Fog
83
87
  image_reference
84
88
  end
85
89
 
86
- def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version, vhd_path, os_disk_caching, platform, resource_group, managed_disk_storage_type, os_disk_size)
90
+ def define_storage_profile(vm_name, storage_account_name, publisher, offer, sku, version, vhd_path, os_disk_caching, platform, resource_group, managed_disk_storage_type, os_disk_size, location)
87
91
  storage_profile = Azure::ARM::Compute::Models::StorageProfile.new
88
- storage_profile.image_reference = image_reference(publisher, offer, sku, version)
92
+ storage_profile.image_reference = image_reference(publisher, offer, sku, version) if vhd_path.nil?
89
93
  os_disk = Azure::ARM::Compute::Models::OSDisk.new
90
94
 
91
- if managed_disk_storage_type.nil?
95
+ new_vhd_path = copy_vhd_to_storage_account(resource_group, storage_account_name, vhd_path) unless vhd_path.nil?
96
+
97
+ if managed_disk_storage_type.nil?
92
98
  vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
93
99
  vhd.uri = get_blob_endpoint(storage_account_name) + "/vhds/#{vm_name}_os_disk.vhd"
94
100
 
95
101
  unless vhd_path.nil?
96
- # Copy if VHD does not exist belongs to same storage account.
97
- vhd_storage_account = (vhd_path.split('/')[2]).split('.')[0]
98
- if storage_account_name != vhd_storage_account
99
- storage_account = @storage_service.storage_accounts.get(resource_group, storage_account_name)
100
- access_key = storage_account.get_access_keys.first.value
101
- storage_data = Fog::Storage::AzureRM.new(provider: 'AzureRM', azure_storage_account_name: storage_account_name, azure_storage_access_key: access_key)
102
- new_time = current_time
103
- container_name = "customvhd#{new_time}"
104
- blob_name = "vhd_image#{new_time}.vhd"
105
- storage_data.directories.create(
106
- key: container_name
107
- )
108
-
109
- storage_data.copy_blob_from_uri(container_name, blob_name, vhd_path)
110
- until storage_data.get_blob_properties(container_name, blob_name).properties[:copy_status] == 'success'
111
- Fog::Logger.debug 'Waiting disk to ready'
112
- sleep(10)
113
- end
114
- new_vhd_path = get_blob_endpoint(storage_account_name) + "/#{container_name}/#{blob_name}"
115
- Fog::Logger.debug "Path:#{new_vhd_path}. | Copy done"
116
- else
117
- new_vhd_path = vhd_path
118
- end
119
-
120
102
  img_vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
121
103
  img_vhd.uri = new_vhd_path
122
104
  os_disk.image = img_vhd
@@ -124,11 +106,33 @@ module Fog
124
106
 
125
107
  os_disk.vhd = vhd
126
108
  else
109
+ unless vhd_path.nil?
110
+ image_obj = create_generalized_image(image_config_params(location, new_vhd_path, platform, resource_group, vm_name))
111
+ storage_profile.image_reference = Azure::ARM::Compute::Models::ImageReference.new
112
+ storage_profile.image_reference.id = image_obj.id
113
+ end
114
+
127
115
  managed_disk = Azure::ARM::Compute::Models::ManagedDiskParameters.new
128
116
  managed_disk.storage_account_type = managed_disk_storage_type
129
117
  os_disk.managed_disk = managed_disk
130
118
  end
131
-
119
+
120
+ storage_profile.os_disk = configure_os_disk_object(os_disk, os_disk_caching, os_disk_size, platform, vm_name)
121
+ storage_profile
122
+ end
123
+
124
+ def image_config_params(location, new_vhd_path, platform, resource_group, vm_name)
125
+ image_config = {
126
+ location: location,
127
+ new_vhd_path: new_vhd_path,
128
+ platform: platform,
129
+ resource_group: resource_group,
130
+ vm_name: vm_name
131
+ }
132
+ image_config
133
+ end
134
+
135
+ def configure_os_disk_object(os_disk, os_disk_caching, os_disk_size, platform, vm_name)
132
136
  os_disk.name = "#{vm_name}_os_disk"
133
137
  os_disk.os_type = platform
134
138
  os_disk.disk_size_gb = os_disk_size unless os_disk_size.nil?
@@ -143,9 +147,31 @@ module Fog
143
147
  Azure::ARM::Compute::Models::CachingTypes::ReadWrite
144
148
  end
145
149
  end
146
-
147
- storage_profile.os_disk = os_disk
148
- storage_profile
150
+ os_disk
151
+ end
152
+
153
+ def copy_vhd_to_storage_account(resource_group, storage_account_name, vhd_path)
154
+ # Copy if VHD does not exist belongs to same storage account.
155
+ vhd_storage_account = (vhd_path.split('/')[2]).split('.')[0]
156
+ if storage_account_name != vhd_storage_account
157
+ storage_account = @storage_service.storage_accounts.get(resource_group, storage_account_name)
158
+ access_key = storage_account.get_access_keys.first.value
159
+ storage_data = Fog::Storage::AzureRM.new(provider: 'AzureRM', azure_storage_account_name: storage_account_name, azure_storage_access_key: access_key)
160
+ new_time = current_time
161
+ container_name = "customvhd#{new_time}"
162
+ blob_name = "vhd_image#{new_time}.vhd"
163
+ storage_data.directories.create(key: container_name)
164
+ storage_data.copy_blob_from_uri(container_name, blob_name, vhd_path)
165
+ until storage_data.get_blob_properties(container_name, blob_name).properties[:copy_status] == 'success'
166
+ Fog::Logger.debug 'Waiting disk to ready'
167
+ sleep(10)
168
+ end
169
+ new_vhd_path = get_blob_endpoint(storage_account_name) + "/#{container_name}/#{blob_name}"
170
+ Fog::Logger.debug "Path:#{new_vhd_path}. | Copy done"
171
+ else
172
+ new_vhd_path = vhd_path
173
+ end
174
+ new_vhd_path
149
175
  end
150
176
 
151
177
  def define_windows_os_profile(vm_name, username, password, provision_vm_agent, enable_automatic_updates, encoded_data)
@@ -153,7 +179,6 @@ module Fog
153
179
  windows_config = Azure::ARM::Compute::Models::WindowsConfiguration.new
154
180
  windows_config.provision_vmagent = provision_vm_agent
155
181
  windows_config.enable_automatic_updates = enable_automatic_updates
156
-
157
182
  os_profile.windows_configuration = windows_config
158
183
  os_profile.computer_name = vm_name
159
184
  os_profile.admin_username = username
@@ -189,7 +214,7 @@ module Fog
189
214
  network_interface_card_ids.each_with_index do |id, index|
190
215
  nic = Azure::ARM::Compute::Models::NetworkInterfaceReference .new
191
216
  nic.id = id
192
- nic.primary = index == PRIMARY_NIC_INDEX ? true : false
217
+ nic.primary = index == PRIMARY_NIC_INDEX
193
218
  network_interface_cards << nic
194
219
  end
195
220
 
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ class Real
6
+ def delete_generalized_image(resource_group, vm_name)
7
+ msg = "Deleting Generalized Image: #{vm_name}-osImage"
8
+ Fog::Logger.debug msg
9
+ image_name = "#{vm_name}-osImage"
10
+ begin
11
+ @compute_mgmt_client.images.delete(resource_group, image_name)
12
+ rescue MsRestAzure::AzureOperationError => e
13
+ raise_azure_exception(e, msg)
14
+ end
15
+ Fog::Logger.debug "Generalized Image #{image_name} deleted successfully."
16
+ true
17
+ end
18
+ end
19
+
20
+ # This class provides the mock implementation for unit tests.
21
+ class Mock
22
+ def delete_generalized_image(*)
23
+ Fog::Logger.debug 'Image fog-test-server-osImage from Resource group fog-test-rg deleted successfully.'
24
+ true
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AzureRM
3
- VERSION = '0.3.4'.freeze
3
+ VERSION = '0.3.5'.freeze
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # Module for API Stub
2
2
  module ApiStub
3
3
  module Models
4
+ # Load test Compute models
4
5
  module Compute
5
6
  autoload :Server, File.expand_path('api_stub/models/compute/server', __dir__)
6
7
  autoload :AvailabilitySet, File.expand_path('api_stub/models/compute/availability_set', __dir__)
@@ -8,18 +9,21 @@ module ApiStub
8
9
  autoload :ManagedDisk, File.expand_path('api_stub/models/compute/managed_disk', __dir__)
9
10
  end
10
11
 
12
+ # Load test Resources models
11
13
  module Resources
12
14
  autoload :ResourceGroup, File.expand_path('api_stub/models/resources/resource_group', __dir__)
13
15
  autoload :Deployment, File.expand_path('api_stub/models/resources/deployment', __dir__)
14
16
  autoload :Resource, File.expand_path('api_stub/models/resources/resource', __dir__)
15
17
  end
16
18
 
19
+ # Load test Storage models
17
20
  module Storage
18
21
  autoload :StorageAccount, File.expand_path('api_stub/models/storage/storageaccount', __dir__)
19
22
  autoload :File, ::File.expand_path('api_stub/models/storage/file', __dir__)
20
23
  autoload :Directory, ::File.expand_path('api_stub/models/storage/directory', __dir__)
21
24
  end
22
25
 
26
+ # Load test Network models
23
27
  module Network
24
28
  autoload :PublicIp, File.expand_path('api_stub/models/network/public_ip', __dir__)
25
29
  autoload :Subnet, File.expand_path('api_stub/models/network/subnet', __dir__)
@@ -37,51 +41,61 @@ module ApiStub
37
41
  autoload :LocalNetworkGateway, File.expand_path('api_stub/models/network/local_network_gateway', __dir__)
38
42
  end
39
43
 
44
+ # Load test ApplicationGateway models
40
45
  module ApplicationGateway
41
46
  autoload :Gateway, File.expand_path('api_stub/models/application_gateway/gateway', __dir__)
42
47
  end
43
48
 
49
+ # Load test TrafficManager models
44
50
  module TrafficManager
45
51
  autoload :TrafficManagerEndPoint, File.expand_path('api_stub/models/traffic_manager/traffic_manager_end_point', __dir__)
46
52
  autoload :TrafficManagerProfile, File.expand_path('api_stub/models/traffic_manager/traffic_manager_profile', __dir__)
47
53
  end
48
54
 
55
+ # Load test DNS models
49
56
  module DNS
50
57
  autoload :Zone, File.expand_path('api_stub/models/dns/zone', __dir__)
51
58
  autoload :RecordSet, File.expand_path('api_stub/models/dns/record_set', __dir__)
52
59
  end
53
60
 
61
+ # Load test Sql models
54
62
  module Sql
55
63
  autoload :SqlServer, File.expand_path('api_stub/models/sql/sql_server', __dir__)
56
64
  autoload :SqlDatabase, File.expand_path('api_stub/models/sql/sql_database', __dir__)
57
65
  autoload :SqlFirewallRule, File.expand_path('api_stub/models/sql/sql_firewall_rule', __dir__)
58
66
  end
59
67
 
68
+ # Load test KeyVault models
60
69
  module KeyVault
61
70
  autoload :Vault, File.expand_path('api_stub/models/key_vault/vault', __dir__)
62
71
  end
63
72
  end
64
73
 
65
74
  module Requests
75
+ # Load test Compute requests
66
76
  module Compute
67
77
  autoload :AvailabilitySet, File.expand_path('api_stub/requests/compute/availability_set', __dir__)
68
78
  autoload :VirtualMachine, File.expand_path('api_stub/requests/compute/virtual_machine', __dir__)
69
79
  autoload :VirtualMachineExtension, File.expand_path('api_stub/requests/compute/virtual_machine_extension', __dir__)
70
80
  autoload :ManagedDisk, File.expand_path('api_stub/requests/compute/managed_disk', __dir__)
81
+ autoload :GeneralizedImage, File.expand_path('api_stub/requests/compute/generalized_image', __dir__)
71
82
  end
72
83
 
84
+ # Load test Resources requests
73
85
  module Resources
74
86
  autoload :ResourceGroup, File.expand_path('api_stub/requests/resources/resource_group', __dir__)
75
87
  autoload :Deployment, File.expand_path('api_stub/requests/resources/deployment', __dir__)
76
88
  autoload :AzureResource, File.expand_path('api_stub/requests/resources/resource', __dir__)
77
89
  end
78
90
 
91
+ # Load test Storage requests
79
92
  module Storage
80
93
  autoload :StorageAccount, File.expand_path('api_stub/requests/storage/storageaccount', __dir__)
81
94
  autoload :File, ::File.expand_path('api_stub/requests/storage/file', __dir__)
82
95
  autoload :Directory, ::File.expand_path('api_stub/requests/storage/directory', __dir__)
83
96
  end
84
97
 
98
+ # Load test Network requests
85
99
  module Network
86
100
  autoload :PublicIp, File.expand_path('api_stub/requests/network/public_ip', __dir__)
87
101
  autoload :Subnet, File.expand_path('api_stub/requests/network/subnet', __dir__)
@@ -99,26 +113,31 @@ module ApiStub
99
113
  autoload :LocalNetworkGateway, File.expand_path('api_stub/requests/network/local_network_gateway', __dir__)
100
114
  end
101
115
 
116
+ # Load test ApplicationGateway requests
102
117
  module ApplicationGateway
103
118
  autoload :Gateway, File.expand_path('api_stub/requests/application_gateway/gateway', __dir__)
104
119
  end
105
120
 
121
+ # Load test TrafficManager requests
106
122
  module TrafficManager
107
123
  autoload :TrafficManagerEndPoint, File.expand_path('api_stub/requests/traffic_manager/traffic_manager_endpoint', __dir__)
108
124
  autoload :TrafficManagerProfile, File.expand_path('api_stub/requests/traffic_manager/traffic_manager_profile', __dir__)
109
125
  end
110
126
 
127
+ # Load test DNS requests
111
128
  module DNS
112
129
  autoload :Zone, File.expand_path('api_stub/requests/dns/zone', __dir__)
113
130
  autoload :RecordSet, File.expand_path('api_stub/requests/dns/record_set', __dir__)
114
131
  end
115
132
 
133
+ # Load test Sql requests
116
134
  module Sql
117
135
  autoload :SqlServer, File.expand_path('api_stub/requests/sql/sql_server', __dir__)
118
136
  autoload :SqlDatabase, File.expand_path('api_stub/requests/sql/database', __dir__)
119
137
  autoload :FirewallRule, File.expand_path('api_stub/requests/sql/firewall_rule', __dir__)
120
138
  end
121
139
 
140
+ # Load test KeyVault requests
122
141
  module KeyVault
123
142
  autoload :Vault, File.expand_path('api_stub/requests/key_vault/vault', __dir__)
124
143
  end
@@ -0,0 +1,41 @@
1
+ module ApiStub
2
+ module Requests
3
+ module Compute
4
+ # Mock class for Virtual Machine Requests
5
+ class GeneralizedImage
6
+ def self.generalized_image_params
7
+ {
8
+ resource_group: 'fog-test-rg',
9
+ vm_name: 'fog-test-server',
10
+ location: 'westus',
11
+ platform: 'Linux',
12
+ new_vhd_path: 'https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd'
13
+ }
14
+ end
15
+
16
+ def self.create_generalized_image(compute_client)
17
+ body = {
18
+ 'location' => 'West US',
19
+ 'tags' => {
20
+ 'key' => 'value'
21
+ },
22
+ 'properties' => {
23
+ 'storageProfile' => {
24
+ 'osDisk' => {
25
+ 'osType' => 'Linux',
26
+ 'blobUri' => 'https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd',
27
+ 'osState' => 'generalized',
28
+ 'hostCaching' => 'readwrite',
29
+ 'storageAccountType' => 'Standard_LRS'
30
+ },
31
+ 'provisioningState' => 'Succeeded'
32
+ }
33
+ }
34
+ }
35
+ image_mapper = Azure::ARM::Compute::Models::Image.mapper
36
+ compute_client.deserialize(image_mapper, body, 'result.body')
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -79,6 +79,15 @@ begin
79
79
  private_ip_allocation_method: Fog::ARM::Network::Models::IPAllocationMethod::Dynamic
80
80
  )
81
81
 
82
+ network.network_interfaces.create(
83
+ name: 'NetInt2',
84
+ resource_group: 'TestRG-CustomVM',
85
+ location: LOCATION,
86
+ subnet_id: "/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-CustomVM/providers/Microsoft.Network/virtualNetworks/testVnet/subnets/mysubnet",
87
+ ip_configuration_name: 'testIpConfiguration',
88
+ private_ip_allocation_method: Fog::ARM::Network::Models::IPAllocationMethod::Dynamic
89
+ )
90
+
82
91
  ########################################################################################################################
83
92
  ###################### Create Server ######################
84
93
  ########################################################################################################################
@@ -94,17 +103,41 @@ begin
94
103
  disable_password_authentication: false,
95
104
  network_interface_card_ids: ["/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-CustomVM/providers/Microsoft.Network/networkInterfaces/NetInt"],
96
105
  platform: 'linux',
97
- vhd_path: 'https://custimagestorage.blob.core.windows.net/newcustomvhd/trusty-server-cloudimg-amd64-disk1-zeeshan.vhd'
106
+ vhd_path: 'https://myblob.blob.core.windows.net/vhds/myvhd.vhd'
107
+ )
108
+ puts "Created custom image un-managed virtual machine: #{custom_image_virtual_machine.name}"
109
+
110
+ ########################################################################################################################
111
+ ################# Create Managed Server ###################
112
+ ########################################################################################################################
113
+
114
+ custom_image_virtual_machine_managed = compute.servers.create(
115
+ name: 'TestVM-Managed',
116
+ location: LOCATION,
117
+ resource_group: 'TestRG-CustomVM',
118
+ vm_size: 'Basic_A0',
119
+ storage_account_name: storage_account_name,
120
+ username: 'testuser',
121
+ password: 'Confiz=123',
122
+ disable_password_authentication: false,
123
+ network_interface_card_ids: ["/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-CustomVM/providers/Microsoft.Network/networkInterfaces/NetInt2"],
124
+ platform: 'linux',
125
+ vhd_path: 'https://myblob.blob.core.windows.net/vhds/myvhd.vhd',
126
+ managed_disk_storage_type: Azure::ARM::Compute::Models::StorageAccountTypes::StandardLRS
98
127
  )
99
- puts "Created custom image virtual machine: #{custom_image_virtual_machine.name}"
128
+ puts "Created custom image managed virtual machine: #{custom_image_virtual_machine_managed.name}"
100
129
 
101
130
  ########################################################################################################################
102
131
  ###################### Get and Delete Server ######################
103
132
  ########################################################################################################################
104
133
 
105
134
  custom_image_virtual_machine = compute.servers.get('TestRG-CustomVM', 'TestVM')
106
- puts "Get custom image virtual machine: #{custom_image_virtual_machine.name}"
107
- puts "Deleted custom image virtual machine: #{custom_image_virtual_machine.destroy}"
135
+ puts "Get custom image un-managed virtual machine: #{custom_image_virtual_machine.name}"
136
+ puts "Deleted custom image un-managed virtual machine: #{custom_image_virtual_machine.destroy}"
137
+
138
+ custom_image_virtual_machine_managed = compute.servers.get('TestRG-CustomVM', 'TestVM-Managed')
139
+ puts "Get custom image managed virtual machine: #{custom_image_virtual_machine_managed.name}"
140
+ puts "Deleted custom image managed virtual machine: #{custom_image_virtual_machine_managed.destroy}"
108
141
 
109
142
  ########################################################################################################################
110
143
  ###################### CleanUp ######################
@@ -113,6 +146,9 @@ begin
113
146
  nic = network.network_interfaces.get('TestRG-CustomVM', 'NetInt')
114
147
  nic.destroy
115
148
 
149
+ nic = network.network_interfaces.get('TestRG-CustomVM', 'NetInt2')
150
+ nic.destroy
151
+
116
152
  vnet = network.virtual_networks.get('TestRG-CustomVM', 'testVnet')
117
153
  vnet.destroy
118
154
 
@@ -57,7 +57,9 @@ class TestServer < Minitest::Test
57
57
  :availability_set_id,
58
58
  :managed_disk_storage_type,
59
59
  :os_disk_size,
60
- :tags
60
+ :tags,
61
+ :platform_update_domain,
62
+ :platform_fault_domain
61
63
  ]
62
64
  attributes.each do |attribute|
63
65
  assert_respond_to @server, attribute
@@ -0,0 +1,27 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for Create Virtual Machine Request
4
+ class TestCreateGeneralizedImage < Minitest::Test
5
+ def setup
6
+ @service = Fog::Compute::AzureRM.new(credentials)
7
+ compute_client = @service.instance_variable_get(:@compute_mgmt_client)
8
+ @image = compute_client.images
9
+ @response = ApiStub::Requests::Compute::GeneralizedImage.create_generalized_image(compute_client)
10
+ @input_params = ApiStub::Requests::Compute::GeneralizedImage.generalized_image_params
11
+ end
12
+
13
+ def test_create_generalized_image_success
14
+ @image.stub :create_or_update, @response do
15
+ assert_equal @service.create_generalized_image(@input_params), @response
16
+ end
17
+ end
18
+
19
+ def test_create_generalized_image_failure
20
+ response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
21
+ @image.stub :create_or_update, response do
22
+ assert_raises RuntimeError do
23
+ @service.create_generalized_image(@input_params)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for Delete Virtual Machine Request
4
+ class TestDeleteGeneralizedImage < Minitest::Test
5
+ def setup
6
+ @service = Fog::Compute::AzureRM.new(credentials)
7
+ compute_client = @service.instance_variable_get(:@compute_mgmt_client)
8
+ @generalized_image = compute_client.images
9
+ end
10
+
11
+ def test_delete_generalized_image_success
12
+ @generalized_image.stub :delete, true do
13
+ assert @service.delete_generalized_image('fog-test-rg', 'fog-test-server-osImage')
14
+ end
15
+ end
16
+
17
+ def test_delete_generalized_image_failure
18
+ response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
19
+ @generalized_image.stub :delete, response do
20
+ assert_raises(RuntimeError) { @service.delete_generalized_image('fog-test-rg', 'fog-test-server-osImage') }
21
+ end
22
+ end
23
+ 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.3.4
4
+ version: 0.3.5
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: 2017-10-02 00:00:00.000000000 Z
21
+ date: 2017-10-11 00:00:00.000000000 Z
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
24
  name: rake
@@ -406,11 +406,13 @@ files:
406
406
  - lib/fog/azurerm/requests/compute/check_vm_extension_exists.rb
407
407
  - lib/fog/azurerm/requests/compute/check_vm_status.rb
408
408
  - lib/fog/azurerm/requests/compute/create_availability_set.rb
409
+ - lib/fog/azurerm/requests/compute/create_generalized_image.rb
409
410
  - lib/fog/azurerm/requests/compute/create_or_update_managed_disk.rb
410
411
  - lib/fog/azurerm/requests/compute/create_or_update_vm_extension.rb
411
412
  - lib/fog/azurerm/requests/compute/create_virtual_machine.rb
412
413
  - lib/fog/azurerm/requests/compute/deallocate_virtual_machine.rb
413
414
  - lib/fog/azurerm/requests/compute/delete_availability_set.rb
415
+ - lib/fog/azurerm/requests/compute/delete_generalized_image.rb
414
416
  - lib/fog/azurerm/requests/compute/delete_managed_disk.rb
415
417
  - lib/fog/azurerm/requests/compute/delete_virtual_machine.rb
416
418
  - lib/fog/azurerm/requests/compute/delete_vm_extension.rb
@@ -659,6 +661,7 @@ files:
659
661
  - test/api_stub/models/traffic_manager/traffic_manager_profile.rb
660
662
  - test/api_stub/requests/application_gateway/gateway.rb
661
663
  - test/api_stub/requests/compute/availability_set.rb
664
+ - test/api_stub/requests/compute/generalized_image.rb
662
665
  - test/api_stub/requests/compute/managed_disk.rb
663
666
  - test/api_stub/requests/compute/virtual_machine.rb
664
667
  - test/api_stub/requests/compute/virtual_machine_extension.rb
@@ -802,11 +805,13 @@ files:
802
805
  - test/requests/compute/test_check_vm_exists.rb
803
806
  - test/requests/compute/test_check_vm_extension_exists.rb
804
807
  - test/requests/compute/test_create_availability_set.rb
808
+ - test/requests/compute/test_create_generalized_image.rb
805
809
  - test/requests/compute/test_create_or_update_managed_disk.rb
806
810
  - test/requests/compute/test_create_virtual_machine.rb
807
811
  - test/requests/compute/test_create_vm_extension.rb
808
812
  - test/requests/compute/test_deallocate_virtual_machine.rb
809
813
  - test/requests/compute/test_delete_availability_set.rb
814
+ - test/requests/compute/test_delete_generalized_image.rb
810
815
  - test/requests/compute/test_delete_managed_disk.rb
811
816
  - test/requests/compute/test_delete_virtual_machine.rb
812
817
  - test/requests/compute/test_detach_data_disk_from_vm.rb