Class: Fog::TrafficManager::AzureRM::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/azurerm/traffic_manager.rb,
lib/fog/azurerm/requests/traffic_manager/get_traffic_manager_profile.rb,
lib/fog/azurerm/requests/traffic_manager/get_traffic_manager_endpoint.rb,
lib/fog/azurerm/requests/traffic_manager/list_traffic_manager_profiles.rb,
lib/fog/azurerm/requests/traffic_manager/delete_traffic_manager_profile.rb,
lib/fog/azurerm/requests/traffic_manager/delete_traffic_manager_endpoint.rb,
lib/fog/azurerm/requests/traffic_manager/check_traffic_manager_profile_exists.rb,
lib/fog/azurerm/requests/traffic_manager/check_traffic_manager_endpoint_exists.rb,
lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_profile.rb,
lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_endpoint.rb

Overview

Real class for Traffic Manager Request

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Real

Returns a new instance of Real.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

Instance Method Details

#check_traffic_manager_endpoint_exists(resource_group, traffic_manager_profile_name, traffic_manager_end_point, type) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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 e.body['code'] == 'NotFound'
      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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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 e.body['error']['code'] == 'ResourceNotFound'
      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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# 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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# 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])
  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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# 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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# 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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# 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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# 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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# 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