class Fog::TrafficManager::AzureRM::Real

This class provides the actual implementation for service calls.

This class provides the actual implementation for service calls.

Real class for Traffic Manager Request

This class provides the actual implementation for service call.

Real class for TrafficManager Request

Real class for TrafficManager Request

Real class for TrafficManager Request

Real class for TrafficManager Request

Real class for TrafficManager Request

This class provides the actual implementation for service calls.

Public Class Methods

new(options) click to toggle source
# File lib/fog/azurerm/traffic_manager.rb, line 32
def initialize(options)
  begin
    require 'azure_mgmt_traffic_manager'
  rescue LoadError => e
    retry if require('rubygems')
    raise e.message
  end

  options[:environment] = 'AzureCloud' if options[:environment].nil?

  credentials = Fog::Credentials::AzureRM.get_credentials(options[:tenant_id], options[:client_id], options[:client_secret], options[:environment])
  telemetry = "fog-azure-rm/#{Fog::AzureRM::VERSION}"
  @traffic_mgmt_client = ::Azure::ARM::TrafficManager::TrafficManagerManagementClient.new(credentials, resource_manager_endpoint_url(options[:environment]))
  @traffic_mgmt_client.subscription_id = options[:subscription_id]
  @traffic_mgmt_client.add_user_agent_information(telemetry)
end

Public Instance Methods

check_traffic_manager_endpoint_exists(resource_group, traffic_manager_profile_name, traffic_manager_end_point, type) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/check_traffic_manager_endpoint_exists.rb, line 6
def check_traffic_manager_endpoint_exists(resource_group, traffic_manager_profile_name, traffic_manager_end_point, type)
  msg = "Checking Traffic Manager Endpoint #{traffic_manager_end_point}"
  Fog::Logger.debug msg
  begin
    @traffic_mgmt_client.endpoints.get(resource_group, traffic_manager_profile_name, type, traffic_manager_end_point)
    Fog::Logger.debug "Traffic Manager Endpoint #{traffic_manager_end_point} exists."
    true
  rescue MsRestAzure::AzureOperationError => e
    if resource_not_found?(e)
      Fog::Logger.debug "Traffic Manager Endpoint #{traffic_manager_end_point} doesn't exist."
      false
    else
      raise_azure_exception(e, msg)
    end
  end
end
check_traffic_manager_profile_exists(resource_group, traffic_manager_profile_name) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/check_traffic_manager_profile_exists.rb, line 6
def check_traffic_manager_profile_exists(resource_group, traffic_manager_profile_name)
  msg = "Checking Traffic Manager Profile #{traffic_manager_profile_name}"
  Fog::Logger.debug msg
  begin
    @traffic_mgmt_client.profiles.get(resource_group, traffic_manager_profile_name)
    Fog::Logger.debug "Traffic Manager Profile #{traffic_manager_profile_name} exists."
    true
  rescue MsRestAzure::AzureOperationError => e
    if resource_not_found?(e)
      Fog::Logger.debug "Traffic Manager Profile #{traffic_manager_profile_name} doesn't exist."
      false
    else
      raise_azure_exception(e, msg)
    end
  end
end
create_or_update_traffic_manager_endpoint(endpoint_hash) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_endpoint.rb, line 6
def create_or_update_traffic_manager_endpoint(endpoint_hash)
  msg = "Creating Traffic Manager Endpoint: #{endpoint_hash[:name]}."
  Fog::Logger.debug msg
  endpoint_parameters = get_endpoint_object(endpoint_hash[:target_resource_id], endpoint_hash[:target], endpoint_hash[:weight], endpoint_hash[:priority], endpoint_hash[:endpoint_location], endpoint_hash[:min_child_endpoints])
  begin
    traffic_manager_endpoint = @traffic_mgmt_client.endpoints.create_or_update(endpoint_hash[:resource_group], endpoint_hash[:traffic_manager_profile_name],
                                                                               endpoint_hash[:type], endpoint_hash[:name], endpoint_parameters)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Traffic Manager Endpoint: #{endpoint_hash[:name]} created successfully."
  traffic_manager_endpoint
end
create_or_update_traffic_manager_profile(profile_hash) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_profile.rb, line 6
def create_or_update_traffic_manager_profile(profile_hash)
  msg = "Creating Traffic Manager Profile: #{profile_hash[:name]}."
  Fog::Logger.debug msg
  profile_parameters = get_profile_object(profile_hash[:traffic_routing_method],
                                          profile_hash[:relative_name],
                                          profile_hash[:ttl],
                                          profile_hash[:protocol],
                                          profile_hash[:port],
                                          profile_hash[:path],
                                          profile_hash[:endpoints],
                                          profile_hash[:tags])
  begin
    traffic_manager_profile = @traffic_mgmt_client.profiles.create_or_update(profile_hash[:resource_group],
                                                                             profile_hash[:name],
                                                                             profile_parameters)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Traffic Manager Profile: #{profile_hash[:name]} created successfully."
  traffic_manager_profile
end
delete_traffic_manager_endpoint(resource_group, name, traffic_manager_profile_name, type) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/delete_traffic_manager_endpoint.rb, line 6
def delete_traffic_manager_endpoint(resource_group, name, traffic_manager_profile_name, type)
  msg = "Deleting Traffic Manager Endpoint: #{name}."
  Fog::Logger.debug msg
  begin
    @traffic_mgmt_client.endpoints.delete(resource_group, traffic_manager_profile_name, type, name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Traffic Manager Endpoint: #{name} deleted successfully."
  true
end
delete_traffic_manager_profile(resource_group, name) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/delete_traffic_manager_profile.rb, line 6
def delete_traffic_manager_profile(resource_group, name)
  msg = "Deleting Traffic Manager Profile: #{name}."
  Fog::Logger.debug msg
  begin
    @traffic_mgmt_client.profiles.delete(resource_group, name)
    true
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
end
get_traffic_manager_end_point(resource_group, traffic_manager_profile_name, traffic_manager_end_point, type) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/get_traffic_manager_endpoint.rb, line 6
def get_traffic_manager_end_point(resource_group, traffic_manager_profile_name, traffic_manager_end_point, type)
  msg = "Getting Traffic Manager Endpoint: #{traffic_manager_end_point} in Profile: #{traffic_manager_profile_name}."
  Fog::Logger.debug msg
  begin
    endpoint = @traffic_mgmt_client.endpoints.get(resource_group, traffic_manager_profile_name, type, traffic_manager_end_point)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Traffic Manager Endpoint fetched successfully in Resource Group: #{resource_group}"
  endpoint
end
get_traffic_manager_profile(resource_group, traffic_manager_profile_name) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/get_traffic_manager_profile.rb, line 6
def get_traffic_manager_profile(resource_group, traffic_manager_profile_name)
  msg = "Getting Traffic Manager Profile: #{traffic_manager_profile_name} in Resource Group: #{resource_group}..."
  Fog::Logger.debug msg
  begin
    profile = @traffic_mgmt_client.profiles.get(resource_group, traffic_manager_profile_name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Traffic Manager Profile fetched successfully in Resource Group: #{resource_group}"
  profile
end
list_traffic_manager_profiles(resource_group) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/list_traffic_manager_profiles.rb, line 6
def list_traffic_manager_profiles(resource_group)
  msg = "Listing Traffic Manager Profiles in Resource Group: #{resource_group}."
  Fog::Logger.debug msg
  begin
    profiles = @traffic_mgmt_client.profiles.list_all_in_resource_group(resource_group)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Traffic Manager Profiles listed successfully in Resource Group: #{resource_group}"
  profiles.value
end

Private Instance Methods

get_endpoint_object(target_resource_id, target, weight, priority, endpoint_location, min_child_endpoints) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_endpoint.rb, line 22
def get_endpoint_object(target_resource_id, target, weight, priority, endpoint_location, min_child_endpoints)
  endpoint = Azure::ARM::TrafficManager::Models::Endpoint.new
  endpoint.min_child_endpoints = min_child_endpoints
  endpoint.target_resource_id = target_resource_id
  endpoint.endpoint_location = endpoint_location
  endpoint.priority = priority
  endpoint.target = target
  endpoint.weight = weight
  endpoint
end
get_endpoints(endpoints) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_profile.rb, line 42
def get_endpoints(endpoints)
  endpoint_objects = []

  endpoints.each do |endpoint|
    endpoint_object = get_endpoint_object(endpoint[:target_resource_id], endpoint[:target], endpoint[:weight], endpoint[:priority], endpoint[:endpoint_location], endpoint[:min_child_endpoints])
    endpoint_object.name = endpoint[:name]
    endpoint_object.type = "#{ENDPOINT_PREFIX}/#{endpoint[:type]}"
    endpoint_objects.push(endpoint_object)
  end
  endpoint_objects
end
get_profile_object(traffic_routing_method, relative_name, ttl, protocol, port, path, endpoints, tags) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_profile.rb, line 30
def get_profile_object(traffic_routing_method, relative_name, ttl, protocol, port, path, endpoints, tags)
  traffic_manager_profile = Azure::ARM::TrafficManager::Models::Profile.new
  traffic_manager_profile.traffic_routing_method = traffic_routing_method
  traffic_manager_profile.location = GLOBAL

  traffic_manager_profile.dns_config = get_traffic_manager_dns_config(relative_name, ttl)
  traffic_manager_profile.monitor_config = get_traffic_manager_monitor_config(protocol, port, path)
  traffic_manager_profile.endpoints = get_endpoints(endpoints) unless endpoints.nil?
  traffic_manager_profile.tags = tags
  traffic_manager_profile
end
get_traffic_manager_dns_config(relative_name, ttl) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_profile.rb, line 54
def get_traffic_manager_dns_config(relative_name, ttl)
  traffic_manager_dns_config = Azure::ARM::TrafficManager::Models::DnsConfig.new
  traffic_manager_dns_config.relative_name = relative_name
  traffic_manager_dns_config.ttl = ttl
  traffic_manager_dns_config
end
get_traffic_manager_monitor_config(protocol, port, path) click to toggle source
# File lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_profile.rb, line 61
def get_traffic_manager_monitor_config(protocol, port, path)
  traffic_manager_monitor_config = Azure::ARM::TrafficManager::Models::MonitorConfig.new
  traffic_manager_monitor_config.path = path
  traffic_manager_monitor_config.protocol = protocol
  traffic_manager_monitor_config.port = port
  traffic_manager_monitor_config
end