- 
      
- 
        Save neidiom/ec82c55b6f21fb80075496b4a79b9d14 to your computer and use it in GitHub Desktop. 
Revisions
- 
        gregohardy revised this gist May 2, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ https://github.com/hipchat/hipchat-cli/blob/master/tutorial/README.md 
- 
        gregohardy revised this gist May 2, 2017 . 2 changed files with 64 additions and 0 deletions.There are no files selected for viewingFile renamed without changes.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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ # Test require 'azure_mgmt_compute' require 'azure_mgmt_resources' require 'azure_mgmt_storage' require 'azure' require 'pry' include Azure include Azure::ARM::Compute include Azure::ARM::Compute::Models include Azure::ARM::Resources include Azure::ARM::Resources::Models include Azure::ARM::Storage include Azure::ARM::Storage::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 storage_client = StorageManagementClient.new(credentials) storage_client.subscription_id = subscription_id resources_client = ResourceManagementClient.new(credentials) resources_client.subscription_id = subscription_id vm_management = Azure.vm_management puts "ASM - (Classic)" vms = vm_management.list_virtual_machines puts "Virtual Machines :: Found #{vms.length} active vms" cloud_service = Azure.cloud_service_management all_cloud_services = cloud_service.list_cloud_services services = all_cloud_services.find_all { |x| x.name =~ /CLOUD-/ } puts "Virtual Machines :: Found #{all_cloud_services.length} should delete #{services.length}" storage_management = Azure.storage_management all_storage_accounts = storage_management.list_storage_accounts storage_accounts = all_storage_accounts.find_all { |x| x.label =~ /CLOUD-/ } puts "Storage Accounts :: Found #{all_storage_accounts.length} should delete #{storage_accounts.length}" puts "\nARM - (New)" arm_vms = client.virtual_machines.list_all puts "Virtual Machines :: Found #{arm_vms.value.length} active vms" resource_groups = resources_client.resource_groups.list cloud_rgs = resource_groups.value.find_all { |x| x.name =~ /CLOUD-(.*)-service-/ } puts "Resource Groups :: Found #{resource_groups.value.length} should delete #{cloud_rgs.length}" storage_accounts = storage_client.storage_accounts.list cloud_storage_accounts = storage_accounts.value.find_all { |x| x.name =~ /CLOUD-/ } puts "Storage Accounts :: Found #{storage_accounts.value.length} should delete #{cloud_storage_accounts.length}" 
- 
        gregohardy created this gist May 2, 2017 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,83 @@ require 'azure_mgmt_compute' require 'azure_mgmt_resources' require 'azure_mgmt_storage' require 'azure' include Azure include Azure::ARM::Compute include Azure::ARM::Compute::Models include Azure::ARM::Resources include Azure::ARM::Resources::Models include Azure::ARM::Storage include Azure::ARM::Storage::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 storage_client = StorageManagementClient.new(credentials) storage_client.subscription_id = subscription_id resources_client = ResourceManagementClient.new(credentials) resources_client.subscription_id = subscription_id vm_management = Azure.vm_management puts "ASM - (Classic)" vms = vm_management.list_virtual_machines puts "Virtual Machines :: Found #{vms.length} active vms" cloud_service = Azure.cloud_service_management all_cloud_services = cloud_service.list_cloud_services services = all_cloud_services.find_all { |x| x.name =~ /CLOUD-/ } puts "Virtual Machines :: Found #{all_cloud_services.length} should delete #{services.length}" for service in services puts "Deleting service #{service.name}" cloud_service.delete_cloud_service(service.name) end storage_management = Azure.storage_management all_storage_accounts = storage_management.list_storage_accounts storage_accounts = all_storage_accounts.find_all { |x| x.label =~ /CLOUD-/ } puts "Storage Accounts :: Found #{all_storage_accounts.length} should delete #{storage_accounts.length}" for account in storage_accounts puts "Deleting storage account #{account.label}" storage_management.delete_storage_account(account.name) end puts "\nARM - (New)" arm_vms = client.virtual_machines.list_all puts "Virtual Machines :: Found #{arm_vms.value.length} active vms" resource_groups = resources_client.resource_groups.list cloud_rgs = resource_groups.value.find_all { |x| x.name =~ /CLOUD-(.*)-service-/ } puts "Resource Groups :: Found #{resource_groups.value.length} should delete #{cloud_rgs.length}" for rg in cloud_rgs if rg.provisioning_state == 'Deleting' puts "Deleting #{rg.name}" else puts "Attempting Delete of resource group #{rg.name}" resources_client.resource_groups.begin_delete(rg.name) unless rg.provisioning_state == 'Deleting' end end storage_accounts = storage_client.storage_accounts.list cloud_storage_accounts = storage_accounts.value.find_all { |x| x.name =~ /CLOUD-/ } puts "Storage Accounts :: Found #{storage_accounts.value.length} should delete #{cloud_storage_accounts.length}" for account in cloud_storage_accounts if account.provisioning_state == 'Deleting' puts "Deleting #{account.name}" else puts "Attempting Delete of resource group #{account.name}" storage_client.storage_accounts.begin_delete(account.name) unless account.provisioning_state == 'Deleting' end end