Last active
July 29, 2016 15:40
-
-
Save gregohardy/554e552edaa1ac427b2182fc49756fed to your computer and use it in GitHub Desktop.
Azure ARM simple ruby examples
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
$ gem install gem install azure_mgmt_compute | |
$ ruby status.rb | |
There are [1] in this account | |
AZURE VM IDs FOR THIS ACCOUNT | |
============================= | |
/subscriptions/<subscription id###>/resourceGroups/CLOUD-ACCEPTANCE-TESTS/providers/Microsoft.Compute/virtualMachines/CLOUD-3cdbed43 | |
============================= | |
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
require 'azure_mgmt_compute' | |
include Azure::ARM::Compute | |
include Azure::ARM::Compute::Models | |
tenant_id = ENV['AZURE_TENANT_ID'] | |
client_id = ENV['AZURE_CLIENT_ID'] | |
secret = ENV['AZURE_CLIENT_SECRET'] | |
subscription_id = ENV['AZURE_SUBSCRIPTION_ID'] | |
token_provider = MsRestAzure::ApplicationTokenProvider.new(tenant_id, client_id, secret) | |
credentials = MsRest::TokenCredentials.new(token_provider) | |
client = ComputeManagementClient.new(credentials) | |
client.subscription_id = subscription_id | |
result = client.virtual_machines.list_all | |
puts "There are [#{result.length}] in this account\n" | |
puts "AZURE VM IDs FOR THIS ACCOUNT\n" | |
puts "=============================\n" | |
result.each do |x| | |
print x.id | |
end | |
puts "\n=============================\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment