-
-
Notifications
You must be signed in to change notification settings - Fork 84
Feature/add list virtual machine sizes functionalities #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KevinLoiseau
wants to merge
6
commits into
fog:master
Choose a base branch
from
KevinLoiseau:feature/add_list_virtual_machine_sizes_functionalitie
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
76f40ad
Implement request list_virtual_machine_size
KevinLoiseau a5e93eb
Add VirtualMachineSize model
KevinLoiseau 34d2cb7
Add VirtualMachineSizes collection
KevinLoiseau 6e5e737
Add method all to VirtualMachineSizes
KevinLoiseau d693959
Add documentation about virtual machine size
KevinLoiseau 0285368
Add integration test for virtual machine size
KevinLoiseau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| module Fog | ||
| module Compute | ||
| class AzureRM | ||
| class VirtualMachineSize < Fog::Model | ||
| identity :name | ||
| attribute :max_data_disk_count | ||
| attribute :number_of_cores | ||
| attribute :os_disk_size_in_mb | ||
| attribute :resource_disk_size_in_mb | ||
| attribute :memory_in_mb | ||
|
|
||
| def self.parse(virtual_machine_size) | ||
| get_hash_from_object(virtual_machine_size) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| module Fog | ||
| module Compute | ||
| class AzureRM | ||
| class VirtualMachineSizes < Fog::Collection | ||
| attribute :location | ||
| model Fog::Compute::AzureRM::VirtualMachineSize | ||
|
|
||
| def all | ||
| requires :location | ||
| virtual_machine_sizes = service.list_virtual_machine_sizes(location).map do |virtual_machine_size| | ||
| Fog::Compute::AzureRM::VirtualMachineSize.parse(virtual_machine_size) | ||
| end | ||
| load(virtual_machine_sizes) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
lib/fog/azurerm/requests/compute/list_virtual_machine_sizes.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| module Fog | ||
| module Compute | ||
| class AzureRM | ||
| # Real class for Compute Request | ||
| class Real | ||
| def list_virtual_machine_sizes(location, async = false) | ||
| msg = 'Listing all VirtualMachineSize' | ||
| Fog::Logger.debug msg | ||
| begin | ||
| if async | ||
| response = @compute_mgmt_client.virtual_machine_sizes.list_async(location) | ||
| else | ||
| virtual_machine_sizes = @compute_mgmt_client.virtual_machine_sizes.list(location) | ||
| end | ||
| rescue MsRestAzure::AzureOperationError => e | ||
| raise_azure_exception(e, msg) | ||
| end | ||
| if async | ||
| response | ||
| else | ||
| Fog::Logger.debug 'VirtualMachineSizes listed successfully.' | ||
| virtual_machine_sizes.value | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Mock class for Compute Request | ||
| class Mock | ||
| def list_virtual_machine_sizes(*) | ||
| virtual_machine_sizes = [ | ||
| { | ||
| 'max_data_disk_count' => 1, | ||
| 'memory_in_mb' => 768, | ||
| 'name' => 'Standard_A0', | ||
| 'number_of_cores' => 1, | ||
| 'os_disk_size_in_mb' => 1_047_552, | ||
| 'resource_disk_size_in_mb' => 20_480 | ||
| }, { | ||
| 'max_data_disk_count' => 2, | ||
| 'memory_in_mb' => 1_792, | ||
| 'name' => 'Standard_A1', | ||
| 'number_of_cores' => 1, | ||
| 'os_disk_size_in_mb' => 1_047_552, | ||
| 'resource_disk_size_in_mb' => 71_680 | ||
| }, { | ||
| 'max_data_disk_count' => 4, | ||
| 'memory_in_mb' => 3_584, | ||
| 'name' => 'Standard_A2', | ||
| 'number_of_cores' => 2, | ||
| 'os_disk_size_in_mb' => 1_047_552, | ||
| 'resource_disk_size_in_mb' => 138_240 | ||
| }, { | ||
| 'max_data_disk_count' => 1, | ||
| 'memory_in_mb' => 768, | ||
| 'name' => 'Basic_A0', | ||
| 'number_of_cores' => 1, | ||
| 'os_disk_size_in_mb' => 1_047_552, | ||
| 'resource_disk_size_in_mb' => 20_480 | ||
| } | ||
| ] | ||
| virtual_machine_size_mapper = Azure::ARM::Compute::Models::VirtualMachineSizeListResult.mapper | ||
| @compute_mgmt_client.deserialize(virtual_machine_size_mapper, virtual_machine_sizes, 'result.body').value | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
|
|
||
| module ApiStub | ||
| module Models | ||
| module Compute | ||
| class VirtualMachineSize | ||
| def self.virtual_machine_sizes(sdk_compute_client) | ||
| virtual_machine_sizes = { | ||
| 'value' => [ | ||
| { | ||
| 'max_data_disk_count' => 1, | ||
| 'memory_in_mb' => 768, | ||
| 'name' => 'Standard_A0', | ||
| 'number_of_cores' => 1, | ||
| 'os_disk_size_in_mb' => 1_047_552, | ||
| 'resource_disk_size_in_mb' => 20_480 | ||
| }, | ||
| { | ||
| 'max_data_disk_count' => 2, | ||
| 'memory_in_mb' => 1_792, | ||
| 'name' => 'Standard_A1', | ||
| 'number_of_cores' => 1, | ||
| 'os_disk_size_in_mb' => 1_047_552, | ||
| 'resource_disk_size_in_mb' => 71_680 | ||
| }, | ||
| { | ||
| 'max_data_disk_count' => 4, | ||
| 'memory_in_mb' => 3_584, | ||
| 'name' => 'Standard_A2', | ||
| 'number_of_cores' => 2, | ||
| 'os_disk_size_in_mb' => 1_047_552, | ||
| 'resource_disk_size_in_mb' => 138_240 | ||
| }, | ||
| { | ||
| 'max_data_disk_count' => 1, | ||
| 'memory_in_mb' => 768, | ||
| 'name' => 'Basic_A0', | ||
| 'number_of_cores' => 1, | ||
| 'os_disk_size_in_mb' => 1_047_552, | ||
| 'resource_disk_size_in_mb' => 20_480 | ||
| } | ||
| ] | ||
| } | ||
| virtual_machine_size_mapper = Azure::ARM::Compute::Models::VirtualMachineSizeListResult.mapper | ||
| sdk_compute_client.deserialize(virtual_machine_size_mapper, virtual_machine_sizes, 'result.body').value | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| module ApiStub | ||
| module Requests | ||
| module Compute | ||
| # Mock class for VirtualMachineSize Requests | ||
| class VirtualMachineSize | ||
| def self.list_response(sdk_compute_client) | ||
| body = '{ "value": [{ | ||
| "max_data_disk_count": "1", | ||
| "memory_in_mb": "768", | ||
| "name": "standard_a0", | ||
| "number_of_cores": "1", | ||
| "os_disk_size_in_mb": "1_047_552", | ||
| "resource_disk_size_in_mb": "20_480" | ||
| }, { | ||
| "max_data_disk_count": "2", | ||
| "memory_in_mb": "1_792", | ||
| "name": "Standard_A1", | ||
| "number_of_cores": "1", | ||
| "os_disk_size_in_mb": "1_047_552", | ||
| "resource_disk_size_in_mb": "71_680" | ||
| }, { | ||
| "max_data_disk_count": "4", | ||
| "memory_in_mb": "3_584", | ||
| "name": "Standard_A2", | ||
| "number_of_cores": "2", | ||
| "os_disk_size_in_mb": "1_047_552", | ||
| "resource_disk_size_in_mb": "138_240" | ||
| }, { | ||
| "max_data_disk_count": "1", | ||
| "memory_in_mb": "768", | ||
| "name": "Basic_A0", | ||
| "number_of_cores": "1", | ||
| "os_disk_size_in_mb": "1_047_552", | ||
| "resource_disk_size_in_mb": "20_480" | ||
| }]}' | ||
| mapper = Azure::ARM::Compute::Models::VirtualMachineSizeListResult.mapper | ||
| sdk_compute_client.deserialize(mapper, Fog::JSON.decode(body), 'result.body') | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| require 'fog/azurerm' | ||
| require 'yaml' | ||
|
|
||
| azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) | ||
|
|
||
| compute = Fog::Compute::AzureRM.new( | ||
| tenant_id: azure_credentials['tenant_id'], | ||
| client_id: azure_credentials['client_id'], | ||
| client_secret: azure_credentials['client_secret'], | ||
| subscription_id: azure_credentials['subscription_id'] | ||
| ) | ||
|
|
||
| begin | ||
| ######################################################################################################################## | ||
| ###################### List virtual machine sizes ###################### | ||
| ######################################################################################################################## | ||
|
|
||
| puts 'List of virtual machine sizes:' | ||
| virtual_machine_sizes = compute.virtual_machine_sizes(location: LOCATION) | ||
| virtual_machine_sizes.each do |virtual_machine_size| | ||
| puts "- #{virtual_machine_size.name}" | ||
| end | ||
|
|
||
| puts 'Integration Test for virtual machine size ran successfully!' | ||
| rescue StandardError | ||
| puts 'Integration Test for virtual machine size is failing!' | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| require File.expand_path '../../test_helper', __dir__ | ||
| # Test class for VirtualMachineSize Model | ||
| class TestVirtualMachineSize < Minitest::Test | ||
| def setup | ||
| @service = Fog::Compute::AzureRM.new(credentials) | ||
| @virtual_machine_size = virtual_machine_size(@service) | ||
| end | ||
|
|
||
| def test_model_attributes | ||
| attributes = %i( | ||
| name | ||
| max_data_disk_count | ||
| number_of_cores | ||
| os_disk_size_in_mb | ||
| resource_disk_size_in_mb | ||
| memory_in_mb | ||
| ) | ||
| attributes.each do |attribute| | ||
| assert_respond_to @virtual_machine_size, attribute | ||
| end | ||
| end | ||
|
|
||
| def test_parse_method | ||
| virtual_machine_size_hash = Fog::Compute::AzureRM::VirtualMachineSize.parse(@response) | ||
| @response.instance_variables.each do |attribute| | ||
| assert_equal @response.instance_variable_get(attribute), virtual_machine_size_hash[attribute.to_s.delete('@')] | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| require File.expand_path '../../test_helper', __dir__ | ||
| # Test class for Managed Disk Collection | ||
| class TestVirtualMachineSizes < Minitest::Test | ||
| def setup | ||
| @service = Fog::Compute::AzureRM.new(credentials) | ||
| @virtual_machine_sizes = Fog::Compute::AzureRM::VirtualMachineSizes.new(location: 'location', service: @service) | ||
| @compute_client = @service.instance_variable_get(:@compute_mgmt_client) | ||
| @response = ApiStub::Models::Compute::VirtualMachineSize.virtual_machine_sizes(@compute_client) | ||
| end | ||
|
|
||
| def test_collection_attributes | ||
| assert_respond_to @virtual_machine_sizes, :location | ||
| end | ||
|
|
||
| def test_collection_methods | ||
| methods = %i(all) | ||
| methods.each do |method| | ||
| assert_respond_to @virtual_machine_sizes, method | ||
| end | ||
| end | ||
|
|
||
| def test_all_method_response | ||
| @service.stub :list_virtual_machine_sizes, @response do | ||
| sizes = @virtual_machine_sizes.all | ||
|
|
||
| assert_instance_of Fog::Compute::AzureRM::VirtualMachineSizes, sizes | ||
| assert sizes.size >= 1 | ||
| sizes.each do |size| | ||
| assert_instance_of Fog::Compute::AzureRM::VirtualMachineSize, size | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| require File.expand_path '../../test_helper', __dir__ | ||
| # Test class for List VirtualMachineSizes# | ||
|
|
||
| class TestListVirtualMachineSizes < Minitest::Test | ||
| def setup | ||
| @service = Fog::Compute::AzureRM.new(credentials) | ||
| @client = @service.instance_variable_get(:@compute_mgmt_client) | ||
| @virtual_machine_sizes = @client.virtual_machine_sizes | ||
| end | ||
|
|
||
| def test_list_virtual_machine_sizes_success | ||
| mocked_response = ApiStub::Requests::Compute::VirtualMachineSize.list_response(@client) | ||
| @virtual_machine_sizes.stub :list, mocked_response do | ||
| assert_equal mocked_response.value, @service.list_virtual_machine_sizes('location') | ||
| end | ||
|
|
||
| async_response = Concurrent::Promise.execute { 10 } | ||
| @virtual_machine_sizes.stub :list, async_response do | ||
| assert @service.list_virtual_machine_sizes('location', true) | ||
| end | ||
| end | ||
|
|
||
| def test_list_virtual_machine_sizes_failure | ||
| response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) } | ||
| @virtual_machine_sizes.stub :list, response do | ||
| assert_raises(MsRestAzure::AzureOperationError) { @service.list_virtual_machine_sizes('location') } | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.