class Fog::ApplicationGateway::AzureRM::Real
Real
class for Application Gateway
Service
This class provides the actual implementation for service calls.
Real
class for Application Gateway
Request
Real
class for Application Gateway
Request
Real
class for Application Gateway
Request
Real
class for Application Gateway
Request
Public Class Methods
new(options = {})
click to toggle source
# File lib/fog/azurerm/application_gateway.rb, line 50 def initialize(options = {}) begin require 'azure_mgmt_network' rescue LoadError => e retry if require('rubygems') raise e.message end telemetry = "fog-azure-rm/#{Fog::AzureRM::VERSION}" options[:environment] = 'AzureCloud' if options[:environment].nil? credentials = Fog::Credentials::AzureRM.get_credentials(options[:tenant_id], options[:client_id], options[:client_secret], options[:environment]) @network_client = ::Azure::ARM::Network::NetworkManagementClient.new(credentials, resource_manager_endpoint_url(options[:environment])) @network_client.subscription_id = options[:subscription_id] @network_client.add_user_agent_information(telemetry) @tenant_id = options[:tenant_id] @client_id = options[:client_id] @client_secret = options[:client_secret] @subscription_id = options[:subscription_id] @environment = options[:environment] end
Public Instance Methods
check_ag_exists(resource_group_name, application_gateway_name)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/check_ag_exists.rb, line 6 def check_ag_exists(resource_group_name, application_gateway_name) msg = "Checking Application Gateway: #{application_gateway_name}" Fog::Logger.debug msg begin @network_client.application_gateways.get(resource_group_name, application_gateway_name) Fog::Logger.debug "Application Gateway #{application_gateway_name} exists." true rescue MsRestAzure::AzureOperationError => e if e.body['error']['code'] == 'ResourceNotFound' Fog::Logger.debug "Application Gateway #{application_gateway_name} doesn't exist." false else raise_azure_exception(e, msg) end end end
create_or_update_application_gateway(gateway_params)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 6 def create_or_update_application_gateway(gateway_params) msg = "Creating/Updated Application Gateway: #{gateway_params[:name]} in Resource Group: #{gateway_params[:resource_group]}." Fog::Logger.debug msg gateway = define_application_gateway(gateway_params) begin gateway_obj = @network_client.application_gateways.create_or_update(gateway_params[:resource_group], gateway_params[:name], gateway) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Application Gateway #{gateway_params[:name]} created/updated successfully." gateway_obj end
delete_application_gateway(resource_group, name)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/delete_application_gateway.rb, line 6 def delete_application_gateway(resource_group, name) msg = "Deleting Application_Gateway #{name} from Resource Group #{resource_group}." Fog::Logger.debug msg begin @network_client.application_gateways.delete(resource_group, name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Application Gateway #{name} Deleted Successfully." true end
get_application_gateway(resource_group_name, application_gateway_name)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/get_application_gateway.rb, line 6 def get_application_gateway(resource_group_name, application_gateway_name) msg = "Getting Application Gateway: #{application_gateway_name} in Resource group: #{resource_group_name}" Fog::Logger.debug msg begin application_gateway = @network_client.application_gateways.get(resource_group_name, application_gateway_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Getting application gateway #{application_gateway_name} successfully in Resource Group: #{resource_group_name}" application_gateway end
list_application_gateways(resource_group)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/list_application_gateways.rb, line 6 def list_application_gateways(resource_group) msg = "Getting list of Application-Gateway from Resource Group #{resource_group}." Fog::Logger.debug msg begin gateways = @network_client.application_gateways.list_as_lazy(resource_group) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end gateways.value end
start_application_gateway(resource_group, name)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/start_application_gateway.rb, line 5 def start_application_gateway(resource_group, name) msg = "Starting Application Gateway #{name} in Resource Group #{resource_group}" Fog::Logger.debug msg begin @network_client.application_gateways.start(resource_group, name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Successfully started Application Gateway #{name} in Resource Group #{resource_group}" true end
stop_application_gateway(resource_group, name)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/stop_application_gateway.rb, line 5 def stop_application_gateway(resource_group, name) msg = "Stopping Application Gateway #{name} in Resource Group #{resource_group}" Fog::Logger.debug msg begin @network_client.application_gateways.stop(resource_group, name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Successfully stopped Application Gateway #{name} in Resource Group #{resource_group}" true end
update_sku_attributes(gateway_params, sku_name, sku_capacity)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/update_sku_attributes.rb, line 6 def update_sku_attributes(gateway_params, sku_name, sku_capacity) msg = "Updating sku attributes for #{sku_name}" Fog::Logger.debug msg gateway_params[:sku_name] = sku_name if sku_name gateway_params[:sku_capacity] = sku_capacity if sku_capacity begin gateway = create_or_update_application_gateway(gateway_params) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Sku #{sku_name} updated Successfully" gateway end
update_subnet_id_in_gateway_ip_configuration(gateway_params, subnet_id)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/update_subnet_id_in_gateway_ip_configuration.rb, line 6 def update_subnet_id_in_gateway_ip_configuration(gateway_params, subnet_id) msg = 'Updating Subnet id of IP Configuration' Fog::Logger.debug msg gateway_params[:gateway_ip_configurations].each do |ip_configuration| ip_configuration[:subnet_id] = subnet_id end begin gateway = create_or_update_application_gateway(gateway_params) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug 'IP Configuration updated Successfully' gateway end
Private Instance Methods
define_application_gateway(gateway_params)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 21 def define_application_gateway(gateway_params) application_gateway = Azure::ARM::Network::Models::ApplicationGateway.new application_gateway.name = gateway_params[:name] application_gateway.location = gateway_params[:location] application_gateway.gateway_ipconfigurations = define_gateway_ip_configuration(gateway_params[:gateway_ip_configurations]) if gateway_params[:gateway_ip_configurations] application_gateway.ssl_certificates = define_ssl_certificate(gateway_params[:ssl_certificates]) if gateway_params[:ssl_certificates] application_gateway.frontend_ipconfigurations = define_frontend_ip_configurations(gateway_params[:frontend_ip_configurations]) if gateway_params[:frontend_ip_configurations] application_gateway.frontend_ports = define_frontend_ports(gateway_params[:frontend_ports]) if gateway_params[:frontend_ports] application_gateway.probes = define_probes(gateway_params[:probes]) if gateway_params[:probes] application_gateway.backend_address_pools = define_backend_address_pools(gateway_params[:backend_address_pools]) if gateway_params[:backend_address_pools] application_gateway.backend_http_settings_collection = define_backend_http_settings(gateway_params[:backend_http_settings_list]) if gateway_params[:backend_http_settings_list] application_gateway.http_listeners = define_http_listeners(gateway_params[:http_listeners]) if gateway_params[:http_listeners] application_gateway.url_path_maps = define_url_path_maps(gateway_params[:url_path_maps]) if gateway_params[:url_path_maps] application_gateway.request_routing_rules = define_request_routing_rules(gateway_params[:request_routing_rules]) if gateway_params[:request_routing_rules] gateway_sku = Azure::ARM::Network::Models::ApplicationGatewaySku.new gateway_sku.name = gateway_params[:sku_name] gateway_sku.tier = gateway_params[:sku_tier] gateway_sku.capacity = gateway_params[:sku_capacity] application_gateway.sku = gateway_sku application_gateway end
define_backend_address_pools(backend_address_pools)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 134 def define_backend_address_pools(backend_address_pools) backend_address_pool_arr = [] backend_address_pools.each do |bap| backend_pool = Azure::ARM::Network::Models::ApplicationGatewayBackendAddressPool.new backend_addresses1 = bap[:ip_addresses] addresses = [] backend_addresses1.each do |address| backend_add = Azure::ARM::Network::Models::ApplicationGatewayBackendAddress.new backend_add.ip_address = address[:ipAddress] addresses.push(backend_add) end backend_pool.backend_addresses = addresses backend_pool.name = bap[:name] backend_address_pool_arr.push(backend_pool) end backend_address_pool_arr end
define_backend_http_settings(backend_http_settings_list)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 155 def define_backend_http_settings(backend_http_settings_list) backend_http_setting_arr = [] backend_http_settings_list.each do |http_setting| backend_http_setting = Azure::ARM::Network::Models::ApplicationGatewayBackendHttpSettings.new backend_http_setting.port = http_setting[:port] backend_http_setting.protocol = http_setting[:protocol] backend_http_setting.cookie_based_affinity = http_setting[:cookie_based_affinity] backend_http_setting.request_timeout = http_setting[:request_timeout] if http_setting[:probe] probe = Azure::ARM::Network::Models::Probe.new probe.id = http_setting[:probe] backend_http_setting.probe = probe end backend_http_setting.name = http_setting[:name] backend_http_setting_arr.push(backend_http_setting) end backend_http_setting_arr end
define_frontend_ip_configurations(frontend_ip_configurations)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 77 def define_frontend_ip_configurations(frontend_ip_configurations) frontend_ip_configuration_arr = [] frontend_ip_configurations.each do |fic| frontend_ip_configuration = Azure::ARM::Network::Models::ApplicationGatewayFrontendIPConfiguration.new frontend_ip_configuration.private_ipaddress = fic[:private_ip_address] frontend_ip_configuration.private_ipallocation_method = fic[:private_ip_allocation_method] if fic[:subnet_id] subnet = Azure::ARM::Network::Models::Subnet.new subnet.id = fic[:subnet_id] frontend_ip_configuration.subnet = subnet end unless fic[:public_ip_address_id].nil? pip = Azure::ARM::Network::Models::PublicIPAddress.new pip.id = fic[:public_ip_address_id] frontend_ip_configuration.public_ipaddress = pip end frontend_ip_configuration.name = fic[:name] frontend_ip_configuration_arr.push(frontend_ip_configuration) end frontend_ip_configuration_arr end
define_frontend_ports(frontend_ports)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 104 def define_frontend_ports(frontend_ports) frontend_port_arr = [] frontend_ports.each do |port| frontend_port = Azure::ARM::Network::Models::ApplicationGatewayFrontendPort.new frontend_port.port = port[:port] frontend_port.name = port[:name] frontend_port_arr.push(frontend_port) end frontend_port_arr end
define_gateway_ip_configuration(gateway_ip_configurations)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 46 def define_gateway_ip_configuration(gateway_ip_configurations) gateway_ip_configuration_arr = [] gateway_ip_configurations.each do |ip_configuration| configuration = Azure::ARM::Network::Models::ApplicationGatewayIPConfiguration.new configuration.provisioning_state = ip_configuration[:provisioning_state] if ip_configuration[:subnet_id] subnet = Azure::ARM::Network::Models::Subnet.new subnet.id = ip_configuration[:subnet_id] configuration.subnet = subnet end configuration.name = ip_configuration[:name] gateway_ip_configuration_arr.push(configuration) end gateway_ip_configuration_arr end
define_http_listeners(http_listeners)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 176 def define_http_listeners(http_listeners) http_listener_arr = [] http_listeners.each do |listener| http_listener = Azure::ARM::Network::Models::ApplicationGatewayHttpListener.new http_listener.protocol = listener[:protocol] http_listener.host_name = listener[:host_name] http_listener.require_server_name_indication = listener[:require_server_name_indication] if listener[:frontend_ip_config_id] frontend_ip = Azure::ARM::Network::Models::FrontendIPConfiguration.new frontend_ip.id = listener[:frontend_ip_config_id] http_listener.frontend_ipconfiguration = frontend_ip end if listener[:frontend_port_id] frontend_port = Azure::ARM::Network::Models::ApplicationGatewayFrontendPort.new frontend_port.id = listener[:frontend_port_id] http_listener.frontend_port = frontend_port end if listener[:ssl_certificate_id] ssl_cert = Azure::ARM::Network::Models::ApplicationGatewaySslCertificate.new ssl_cert.id = listener[:ssl_certificate_id] http_listener.ssl_certificate = ssl_cert end http_listener.name = listener[:name] http_listener_arr.push(http_listener) end http_listener_arr end
define_path_rules(path_rules)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 236 def define_path_rules(path_rules) path_rule_arr = [] path_rules.each do |rule| path_rule = Azure::ARM::Network::Models::ApplicationGatewayPathRule.new if rule[:backend_address_pool_id] backend_address_pool = Azure::ARM::Network::Models::BackendAddressPool.new backend_address_pool.id = rule[:backend_address_pool_id] path_rule.backend_address_pool = backend_address_pool end if rule[:backend_http_settings_id] backend_http_setting = Azure::ARM::Network::Models::ApplicationGatewayBackendHttpSettings.new backend_http_setting.id = rule[:backend_http_settings_id] path_rule.backend_http_settings = backend_http_setting end path_urls = rule[:paths] paths = [] path_urls.each do |url| paths.push(url) end path_rule.paths = paths path_rule.name = rule[:name] path_rule_arr.push(path_rule) end path_rule_arr end
define_probes(probes)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 117 def define_probes(probes) probe_arr = [] probes.each do |probe| ag_probe = Azure::ARM::Network::Models::ApplicationGatewayProbe.new ag_probe.protocol = probe[:protocol] ag_probe.host = probe[:host] ag_probe.path = probe[:path] ag_probe.interval = probe[:interval] ag_probe.timeout = probe[:timeout] ag_probe.unhealthy_threshold = probe[:unhealthy_threshold] ag_probe.name = probe[:name] probe_arr.push(ag_probe) end probe_arr end
define_request_routing_rules(request_routing_rules)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 264 def define_request_routing_rules(request_routing_rules) request_routing_rule_arr = [] request_routing_rules.each do |rule| request_routing_rule = Azure::ARM::Network::Models::ApplicationGatewayRequestRoutingRule.new request_routing_rule.rule_type = rule[:type] if rule[:http_listener_id] http_listener = Azure::ARM::Network::Models::ApplicationGatewayHttpListener.new http_listener.id = rule[:http_listener_id] request_routing_rule.http_listener = http_listener end if rule[:backend_address_pool_id] backend_address_pool = Azure::ARM::Network::Models::BackendAddressPool.new backend_address_pool.id = rule[:backend_address_pool_id] request_routing_rule.backend_address_pool = backend_address_pool end if rule[:backend_http_settings_id] backend_http_setting = Azure::ARM::Network::Models::ApplicationGatewayBackendHttpSettings.new backend_http_setting.id = rule[:backend_http_settings_id] request_routing_rule.backend_http_settings = backend_http_setting end request_routing_rule.name = rule[:name] request_routing_rule_arr.push(request_routing_rule) end request_routing_rule_arr end
define_ssl_certificate(ssl_certificates)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 63 def define_ssl_certificate(ssl_certificates) ssl_certificate_arr = [] ssl_certificates.each do |ssl_certificate| certificate = Azure::ARM::Network::Models::ApplicationGatewaySslCertificate.new certificate.data = ssl_certificate[:data] certificate.password = ssl_certificate[:password] certificate.public_cert_data = ssl_certificate[:public_cert_data] certificate.name = ssl_certificate[:name] ssl_certificate_arr.push(ssl_certificate) end ssl_certificate_arr end
define_url_path_maps(url_path_maps)
click to toggle source
# File lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb, line 207 def define_url_path_maps(url_path_maps) url_path_map_arr = [] url_path_maps.each do |map| url_path_map = Azure::ARM::Network::Models::ApplicationGatewayUrlPathMap.new if map[:default_backend_address_pool_id] default_backend_address_pool = Azure::ARM::Network::Models::BackendAddressPool.new default_backend_address_pool.id = map[:default_backend_address_pool_id] url_path_map.default_backend_address_pool = default_backend_address_pool end if map[:default_backend_http_settings_id] default_backend_http_setting = Azure::ARM::Network::Models::ApplicationGatewayBackendHttpSettings.new default_backend_http_setting.id = map[:default_backend_http_settings_id] url_path_map.default_backend_http_settings = default_backend_http_setting end if map[:path_rules] path_rules = map[:path_rules] path_rule_arr = define_path_rules(path_rules) url_path_map.path_rules = path_rule_arr end url_path_map.name = map[:name] url_path_map_arr.push(url_path_map) end url_path_map_arr end