Skip to content

Commit

Permalink
Merge pull request #382 from maham-nazir-confiz/add-os-disk-id-attribute
Browse files Browse the repository at this point in the history
OS Disk Id Attribute Added to Compute
  • Loading branch information
maham-nazir-confiz committed May 3, 2018
2 parents 5744026 + 7bb414e commit 2760ced
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/fog/azurerm/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Server < Fog::Model
attribute :vm_size
attribute :storage_account_name
attribute :os_disk_name
attribute :os_disk_id
attribute :os_disk_vhd_uri
attribute :os_disk_caching
attribute :publisher
Expand Down Expand Up @@ -46,6 +47,10 @@ def self.parse(vm)
hash['vm_size'] = vm.hardware_profile.vm_size unless vm.hardware_profile.vm_size.nil?
unless vm.storage_profile.nil?
hash['os_disk_name'] = vm.storage_profile.os_disk.name

subscription_id = get_subscription_id(vm.id)
hash['os_disk_id'] = "/subscriptions/#{subscription_id}/resourceGroups/#{hash['resource_group']}/providers/Microsoft.Compute/disks/#{hash['os_disk_name']}"

hash['os_disk_size'] = vm.storage_profile.os_disk.disk_size_gb
if vm.storage_profile.os_disk.vhd.nil?
hash['managed_disk_storage_type'] = vm.storage_profile.os_disk.managed_disk.storage_account_type
Expand Down
4 changes: 4 additions & 0 deletions lib/fog/azurerm/utilities/general.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,7 @@ def resource_not_found?(azure_operation_error)
def get_image_name(id)
id.split('/').last
end

def get_subscription_id(id)
id.split('/')[2]
end
1 change: 1 addition & 0 deletions test/api_stub/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def self.create_linux_virtual_machine_response(compute_client)
},
'osDisk' => {
'name' => 'fog-test-server_os_disk',
'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/fog-test-server_os_disk',
'vhd' => {
'uri' => 'http://storageAccount.blob.core.windows.net/vhds/fog-test-server_os_disk.vhd'
}
Expand Down
8 changes: 8 additions & 0 deletions test/api_stub/requests/compute/virtual_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def self.create_virtual_machine_response(compute_client)
},
"osDisk": {
"name":"myosdisk1",
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
"vhd": {
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
},
Expand Down Expand Up @@ -320,6 +321,7 @@ def self.create_virtual_machine_with_custom_data_response(compute_client)
},
"osDisk": {
"name":"myosdisk1",
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
"vhd": {
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
},
Expand Down Expand Up @@ -397,6 +399,7 @@ def self.create_virtual_machine_from_custom_image_response(compute_client)
},
"osDisk": {
"name":"myosdisk1",
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
"vhd": {
"uri":"https://custimagestorage.blob.core.windows.net/customimage/trusty-server-cloudimg-amd64-disk1.vhd"
},
Expand Down Expand Up @@ -474,6 +477,7 @@ def self.detach_data_disk_from_vm_response(compute_client)
},
"osDisk": {
"name":"myosdisk1",
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
"vhd": {
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
},
Expand Down Expand Up @@ -546,6 +550,7 @@ def self.virtual_machine_response(compute_client)
'osDisk' =>
{
'name' => 'myosdisk1',
'id' => '/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1',
'vhd' =>
{
'uri' => 'http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd'
Expand Down Expand Up @@ -651,6 +656,7 @@ def self.list_virtual_machines_response(compute_client)
},
"osDisk": {
"name":"myosdisk1",
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
"vhd": {
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
},
Expand Down Expand Up @@ -809,6 +815,7 @@ def self.update_virtual_machine_response(compute_client)
},
"osDisk": {
"name":"myosdisk1",
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
"vhd": {
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
},
Expand Down Expand Up @@ -896,6 +903,7 @@ def self.virtual_machine_15_data_disks_response(compute_client)
},
"osDisk": {
"name":"myosdisk1",
"id":"/subscriptions/{subscription-id}/resourceGroups/fog-test-rg/providers/Microsoft.Compute/disks/myosdisk1",
"vhd": {
"uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
},
Expand Down
1 change: 1 addition & 0 deletions test/models/compute/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_model_attributes
:vm_size,
:storage_account_name,
:os_disk_name,
:os_disk_id,
:os_disk_vhd_uri,
:os_disk_caching,
:publisher,
Expand Down

0 comments on commit 2760ced

Please sign in to comment.