Class: Fog::Sql::AzureRM::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/azurerm/sql.rb,
lib/fog/azurerm/requests/sql/get_database.rb,
lib/fog/azurerm/requests/sql/get_sql_server.rb,
lib/fog/azurerm/requests/sql/list_databases.rb,
lib/fog/azurerm/requests/sql/delete_database.rb,
lib/fog/azurerm/requests/sql/list_sql_servers.rb,
lib/fog/azurerm/requests/sql/delete_sql_server.rb,
lib/fog/azurerm/requests/sql/get_firewall_rule.rb,
lib/fog/azurerm/requests/sql/list_firewall_rules.rb,
lib/fog/azurerm/requests/sql/delete_firewall_rule.rb,
lib/fog/azurerm/requests/sql/check_database_exists.rb,
lib/fog/azurerm/requests/sql/check_sql_server_exists.rb,
lib/fog/azurerm/requests/sql/create_or_update_database.rb,
lib/fog/azurerm/requests/sql/check_firewall_rule_exists.rb,
lib/fog/azurerm/requests/sql/create_or_update_sql_server.rb,
lib/fog/azurerm/requests/sql/create_or_update_firewall_rule.rb

Overview

Real class for Firewall Rule Request

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Real

Returns a new instance of Real.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/azurerm/sql.rb', line 42

def initialize(options)
  begin
    require 'azure_mgmt_sql'
  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])
  @sql_mgmt_client = ::Azure::ARM::SQL::SqlManagementClient.new(credentials, resource_manager_endpoint_url(options[:environment]))
  @sql_mgmt_client.subscription_id = options[:subscription_id]
  telemetry = "fog-azure-rm/#{Fog::AzureRM::VERSION}"
  @sql_mgmt_client.add_user_agent_information(telemetry)
end

Instance Method Details

#check_database_exists(resource_group, server_name, name) ⇒ Object



6
7
8
9
10
# File 'lib/fog/azurerm/requests/sql/check_database_exists.rb', line 6

def check_database_exists(resource_group, server_name, name)
  msg = "Checking SQL Database #{name}"
  Fog::Logger.debug msg
  # This module needs to be updated to azure sdk
end

#check_firewall_rule_exists(resource_group, server_name, rule_name) ⇒ Object



6
7
8
9
10
# File 'lib/fog/azurerm/requests/sql/check_firewall_rule_exists.rb', line 6

def check_firewall_rule_exists(resource_group, server_name, rule_name)
  msg = "Checking Firewall Rule #{rule_name}"
  Fog::Logger.debug msg
  # This module needs to be updated to azure sdk
end

#check_sql_server_exists(resource_group, server_name) ⇒ Object



6
7
8
9
10
# File 'lib/fog/azurerm/requests/sql/check_sql_server_exists.rb', line 6

def check_sql_server_exists(resource_group, server_name)
  msg = "Checking SQL Server #{server_name}"
  Fog::Logger.debug msg
  # This module needs to be updated to azure sdk
end

#create_or_update_database(database_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/azurerm/requests/sql/create_or_update_database.rb', line 6

def create_or_update_database(database_hash)
  msg = "Creating SQL Database: #{database_hash[:name]}."
  Fog::Logger.debug msg
  formatted_database_params = format_database_parameters(database_hash[:location],
                                                         database_hash[:create_mode],
                                                         database_hash[:edition],
                                                         database_hash[:source_database_id],
                                                         database_hash[:collation],
                                                         database_hash[:max_size_bytes],
                                                         database_hash[:requested_service_objective_name],
                                                         database_hash[:elastic_pool_name],
                                                         database_hash[:requested_service_objective_id],
                                                         database_hash[:tags])
  begin
    sql_database = @sql_mgmt_client.databases.create_or_update(database_hash[:resource_group],
                                                               database_hash[:server_name],
                                                               database_hash[:name],
                                                               formatted_database_params)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "SQL Database: #{database_hash[:name]} created successfully."
  sql_database
end

#create_or_update_firewall_rule(firewall_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/azurerm/requests/sql/create_or_update_firewall_rule.rb', line 6

def create_or_update_firewall_rule(firewall_hash)
  msg = "Creating SQL Firewall Rule : #{firewall_hash[:name]}."
  Fog::Logger.debug msg

  begin
    server_firewall_rule = @sql_mgmt_client.servers.create_or_update_firewall_rule(firewall_hash[:resource_group], firewall_hash[:server_name], firewall_hash[:name], format_server_firewall_parameters(firewall_hash[:start_ip], firewall_hash[:end_ip]))
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "SQL Firewall Rule : #{firewall_hash[:name]} created successfully."
  server_firewall_rule
end

#create_or_update_sql_server(server_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/azurerm/requests/sql/create_or_update_sql_server.rb', line 6

def create_or_update_sql_server(server_hash)
  msg = "Creating SQL Server: #{server_hash[:name]}."
  Fog::Logger.debug msg
  formatted_server_params = format_server_parameters(server_hash[:location],
                                                     server_hash[:version],
                                                     server_hash[:administrator_login],
                                                     server_hash[:administrator_login_password],
                                                     server_hash[:tags])
  begin
    sql_server = @sql_mgmt_client.servers.create_or_update(server_hash[:resource_group],
                                                           server_hash[:name],
                                                           formatted_server_params)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "SQL Server: #{server_hash[:name]} created successfully."
  sql_server
end

#delete_database(resource_group, server_name, name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/azurerm/requests/sql/delete_database.rb', line 6

def delete_database(resource_group, server_name, name)
  msg = "Deleting SQL Database: #{name}."
  Fog::Logger.debug msg
  begin
    @sql_mgmt_client.databases.delete(resource_group, server_name, name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "SQL Database: #{name} deleted successfully."
  true
end

#delete_firewall_rule(resource_group, server_name, rule_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/azurerm/requests/sql/delete_firewall_rule.rb', line 6

def delete_firewall_rule(resource_group, server_name, rule_name)
  msg = "Deleting SQL Firewall Rule: #{rule_name}."
  Fog::Logger.debug msg

  begin
    @sql_mgmt_client.servers.delete_firewall_rule(resource_group, server_name, rule_name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "SQL Firewall Rule: #{rule_name} deleted successfully."
  true
end

#delete_sql_server(resource_group, name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/azurerm/requests/sql/delete_sql_server.rb', line 6

def delete_sql_server(resource_group, name)
  msg = "Deleting SQL Server: #{name}."
  Fog::Logger.debug msg

  begin
    @sql_mgmt_client.servers.delete(resource_group, name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "SQL Server: #{name} deleted successfully."
  true
end

#get_database(resource_group, server_name, name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/azurerm/requests/sql/get_database.rb', line 6

def get_database(resource_group, server_name, name)
  msg = "Getting Sql Database: #{name} in Resource Group: #{resource_group}."
  Fog::Logger.debug msg

  begin
    database = @sql_mgmt_client.databases.get(resource_group, server_name, name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Sql Database fetched successfully in Resource Group: #{resource_group}"
  database
end

#get_firewall_rule(resource_group, server_name, rule_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/azurerm/requests/sql/get_firewall_rule.rb', line 6

def get_firewall_rule(resource_group, server_name, rule_name)
  msg = "Getting Sql Server Firewall Rule: #{rule_name} from SQL Server: #{server_name} in Resource Group: #{resource_group}..."
  Fog::Logger.debug msg

  begin
    firewall_rule = @sql_mgmt_client.servers.get_firewall_rule(resource_group, server_name, rule_name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Sql Server Firewall Rule fetched successfully from Server: #{server_name}, Resource Group: #{resource_group}"
  firewall_rule
end

#get_sql_server(resource_group, server_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/azurerm/requests/sql/get_sql_server.rb', line 6

def get_sql_server(resource_group, server_name)
  msg = "Getting Sql Server: #{server_name} in Resource Group: #{resource_group}..."
  Fog::Logger.debug msg
  begin
    sql_server = @sql_mgmt_client.servers.get_by_resource_group(resource_group, server_name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Sql Server fetched successfully in Resource Group: #{resource_group}"
  sql_server
end

#list_databases(resource_group, server_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/azurerm/requests/sql/list_databases.rb', line 6

def list_databases(resource_group, server_name)
  msg = "Listing Sql Databases in Resource Group: #{resource_group}."
  Fog::Logger.debug msg
  begin
    databases = @sql_mgmt_client.databases.list_by_server(resource_group, server_name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Sql Databases listed successfully in Resource Group: #{resource_group}"
  databases
end

#list_firewall_rules(resource_group, server_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/azurerm/requests/sql/list_firewall_rules.rb', line 6

def list_firewall_rules(resource_group, server_name)
  msg = "Listing Sql Server Firewall rules on server: #{server_name} in Resource Group: #{resource_group}."
  Fog::Logger.debug msg

  begin
    firewall_rules = @sql_mgmt_client.servers.list_firewall_rules(resource_group, server_name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Sql Server Firewall Rules listed successfully on server: #{server_name} in Resource Group: #{resource_group}"
  firewall_rules
end

#list_sql_servers(resource_group) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/azurerm/requests/sql/list_sql_servers.rb', line 6

def list_sql_servers(resource_group)
  msg = "Listing Sql Servers in Resource Group: #{resource_group}."
  Fog::Logger.debug msg
  begin
    servers = @sql_mgmt_client.servers.list_by_resource_group(resource_group)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Sql Servers listed successfully in Resource Group: #{resource_group}"
  servers
end