Skip to content

Instantly share code, notes, and snippets.

@chojayr
Last active August 29, 2015 14:05
Show Gist options
  • Save chojayr/d9ed355cc700c77352c2 to your computer and use it in GitHub Desktop.
Save chojayr/d9ed355cc700c77352c2 to your computer and use it in GitHub Desktop.
azure_brood

azure_brood

Another lame script to create or delete VM on Windows Azure
How to use?
Basically You need to install first the required gem
* azure
* yaml
* json
  • You need to supply the account information on "azure_account.yaml"
---
storage_account_name: ##the storage account name 
storage_access_key: ##storage access key 
management_certificate: ## *.pem location 
subscription_id: ##your account subscription id 
management_endpoint: 'https://management.core.windows.net'
  • Supply the desired VM name on "hostname.yaml"
---
host:
  - my_vm_name01
  - my_vm_name02
  - my_vm_name03
  - my_vm_name04
  - my_vm_name04

Once the gems that required are installed on your system and you provide all the information needed on the yaml file.

  • To deploy vm
$ ruby deploy_azurevm.rb

NOTE: This deploy script will spawn all the VM you supply on the
"hostname.yaml"
  • To list all the VM created
$ ruby list_azurevm.rb
  • To list the available public images
$ ruby image_azurevm.rb
  • To list locations
$ ruby location_azurevm.rb
  • To Delete the VM's included on the hostname.yaml
$ ruby destroy_azurevm.rb
---
storage_account_name: ##the storage account name
storage_access_key: ##storage access key
management_certificate: ## *.pem location
subscription_id: ##your account subscription id
management_endpoint: 'https://management.core.windows.net'
#!/usr/bin/env ruby
##
##
require "azure"
require "yaml"
require "net/http"
require "uri"
require "json"
Azure.configure do |config|
ymlval = YAML.load(open('azure.yaml'))
#2 properties to use Storage
config.storage_account_name = ymlval["storage_account_name"]
config.storage_access_key = ymlval["storage_access_key"]
# 3 properties to use Service Management.
config.management_certificate = ymlval["management_certificate"]
config.subscription_id = ymlval["subscription_id"]
config.management_endpoint = ymlval["management_endpoint"]
end
yml = YAML.load(open('hostname.yaml'))
ymlhost = yml["host"]
ymlhost.each do |vm|
virtual_machine_service = Azure::VirtualMachineManagementService.new
#This is to create VM and to start deployment
params = {
:vm_name => "#{vm}",
:vm_user => 'yourusername',
:image => '0b11de9248dd4d87b18621318e037d37__RightImage-Ubuntu-12.04-x64-v13.4', #sample available image
:password => 'yourpassword',
:location => 'Southeast Asia'
}
option = {
:cloud_service_name => "#{vm}",
:deployment_name => "#{vm}",
:tcp_endpoints => '22,80,8080,8443:443', #ports you need to open
:certificate_file => '/path/to/your/file.pem',
:vm_size => 'Basic_A1'
}
virtual_machine_service.create_virtual_machine(params,option)
end
#!/usr/bin/env ruby
##
##
require "azure"
require "pp"
require "yaml"
require "net/http"
require "uri"
require "json"
Azure.configure do |config|
ymlval = YAML.load(open('azure_account.yaml'))
config.storage_account_name = ymlval["storage_account_name"]
config.storage_access_key = ymlval["storage_access_key"]
config.management_certificate = ymlval["management_certificate"]
config.subscription_id = ymlval["subscription_id"]
config.management_endpoint = ymlval["management_endpoint"]
end
yml = YAML.load(open('hostname.yaml'))
ymlhost = yml["host"]
ymlhost.each do |vm|
virtual_machine_service = Azure::VirtualMachineManagementService.new
virtual_machine_service.delete_virtual_machine("#{vm}")
end
---
host:
- samplename1
- samplename2
- samplename3
- samplename4
#!/usr/bin/env ruby
##
## to list azure vm images available
require "azure"
require "pp"
Azure.configure do |config|
ymlval = YAML.load(open('azure_account.yaml'))
config.storage_account_name = ymlval["storage_account_name"]
config.storage_access_key = ymlval["storage_access_key"]
config.management_certificate = ymlval["management_certificate"]
config.subscription_id = ymlval["subscription_id"]
config.management_endpoint = ymlval["management_endpoint"]
end
virtual_machine_image_service = Azure::VirtualMachineImageManagementService.new
igm = virtual_machine_image_service.list_virtual_machine_images
pp igm
#!/usr/bin/env ruby
##
##
require "azure"
require "yaml"
require "pp"
Azure.configure do |config|
ymlval = YAML.load(open('azure_account.yaml'))
config.storage_account_name = ymlval["storage_account_name"]
config.storage_access_key = ymlval["storage_access_key"]
config.management_certificate = ymlval["management_certificate"]
config.subscription_id = ymlval["subscription_id"]
config.management_endpoint = ymlval["management_endpoint"]
end
virtual_machine_service = Azure::VirtualMachineManagementService.new
vmlist = virtual_machine_service.list_virtual_machines
pp vmlist
#!/usr/bin/env ruby
##
## To list available location
require "azure"
require "yaml"
require "pp"
Azure.configure do |config|
ymlval = YAML.load(open('azure_account.yaml'))
config.storage_account_name = ymlval["storage_account_name"]
config.storage_access_key = ymlval["storage_access_key"]
config.management_certificate = ymlval["management_certificate"]
config.subscription_id = ymlval["subscription_id"]
config.management_endpoint = ymlval["management_endpoint"]
end
base_management = Azure::BaseManagementService.new
baselist = base_management.list_locations
pp baselist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment