2017-02-09 16:47:46 +00:00
|
|
|
|
|
|
|
require_relative '../azure_conn'
|
|
|
|
require 'azure_mgmt_compute'
|
|
|
|
|
|
|
|
require_relative 'resource_groups'
|
|
|
|
|
|
|
|
class Helpers
|
2017-02-20 13:51:41 +00:00
|
|
|
|
|
|
|
attr_reader :azure, :client, :resource_group
|
|
|
|
|
|
|
|
def initialize
|
2017-02-09 16:47:46 +00:00
|
|
|
# Azure connection
|
2017-02-20 13:51:41 +00:00
|
|
|
@azure = AzureConnection.new
|
2017-02-09 16:47:46 +00:00
|
|
|
|
2017-02-20 13:51:41 +00:00
|
|
|
@client = Azure::ARM::Compute::ComputeManagementClient.new(azure.connection)
|
2017-02-09 16:47:46 +00:00
|
|
|
client.subscription_id = azure.subscription_id
|
|
|
|
|
2017-02-20 13:51:41 +00:00
|
|
|
@resource_group = ResourceGroups.new(azure)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Retrive the specified resource group
|
|
|
|
#
|
|
|
|
# == Returns:
|
|
|
|
# Object representing the resource group
|
|
|
|
#
|
|
|
|
def get_resource_group(rg_name)
|
|
|
|
resource_group.get(rg_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_resources(rg_name)
|
|
|
|
resource_group.get_resources(rg_name)
|
|
|
|
end
|
2017-02-09 16:47:46 +00:00
|
|
|
|
2017-02-20 13:51:41 +00:00
|
|
|
# Retrieve the named virtual machine from Azure
|
|
|
|
#
|
|
|
|
# == Returns:
|
|
|
|
# Object representing the VM in Azure
|
|
|
|
#
|
|
|
|
def get_vm(name, rg_name)
|
|
|
|
|
|
|
|
# Ensure that the resource group exists
|
|
|
|
unless resource_group.exists(rg_name)
|
|
|
|
raise "The Resource group cannot be found: #{rg_name}"
|
2017-02-09 16:47:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# get a vm from the named resource group
|
|
|
|
begin
|
|
|
|
client.virtual_machines.get(rg_name, name)
|
|
|
|
rescue => e
|
|
|
|
e.error_message
|
|
|
|
end
|
|
|
|
end
|
2017-02-17 17:25:30 +00:00
|
|
|
end
|