fog-azure-rm 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +9 -0
- data/lib/fog/azurerm/docs/compute.md +1 -1
- data/lib/fog/azurerm/docs/sql.md +39 -0
- data/lib/fog/azurerm/docs/storage.md +89 -2
- data/lib/fog/azurerm/models/application_gateway/gateways.rb +4 -7
- data/lib/fog/azurerm/models/compute/availability_sets.rb +4 -6
- data/lib/fog/azurerm/models/compute/servers.rb +5 -8
- data/lib/fog/azurerm/models/compute/virtual_machine_extensions.rb +0 -3
- data/lib/fog/azurerm/models/dns/record_sets.rb +5 -9
- data/lib/fog/azurerm/models/dns/zones.rb +4 -7
- data/lib/fog/azurerm/models/network/express_route_circuit_authorizations.rb +0 -3
- data/lib/fog/azurerm/models/network/express_route_circuit_peerings.rb +5 -9
- data/lib/fog/azurerm/models/network/express_route_circuits.rb +4 -7
- data/lib/fog/azurerm/models/network/express_route_service_providers.rb +2 -5
- data/lib/fog/azurerm/models/network/load_balancers.rb +4 -7
- data/lib/fog/azurerm/models/network/local_network_gateways.rb +0 -3
- data/lib/fog/azurerm/models/network/network_interfaces.rb +4 -7
- data/lib/fog/azurerm/models/network/network_security_groups.rb +4 -7
- data/lib/fog/azurerm/models/network/network_security_rules.rb +2 -6
- data/lib/fog/azurerm/models/network/public_ips.rb +4 -7
- data/lib/fog/azurerm/models/network/subnets.rb +5 -9
- data/lib/fog/azurerm/models/network/virtual_network_gateway_connections.rb +0 -3
- data/lib/fog/azurerm/models/network/virtual_network_gateways.rb +4 -7
- data/lib/fog/azurerm/models/network/virtual_networks.rb +4 -7
- data/lib/fog/azurerm/models/resources/azure_resources.rb +2 -5
- data/lib/fog/azurerm/models/resources/deployments.rb +4 -7
- data/lib/fog/azurerm/models/resources/resource_groups.rb +4 -7
- data/lib/fog/azurerm/models/sql/firewall_rule.rb +52 -0
- data/lib/fog/azurerm/models/sql/firewall_rules.rb +28 -0
- data/lib/fog/azurerm/models/storage/data_disk.rb +1 -0
- data/lib/fog/azurerm/models/storage/directories.rb +1 -4
- data/lib/fog/azurerm/models/storage/files.rb +1 -4
- data/lib/fog/azurerm/models/storage/recovery_vault.rb +50 -0
- data/lib/fog/azurerm/models/storage/recovery_vaults.rb +27 -0
- data/lib/fog/azurerm/models/storage/storage_account.rb +23 -4
- data/lib/fog/azurerm/models/storage/storage_accounts.rb +5 -7
- data/lib/fog/azurerm/requests/sql/create_or_update_database.rb +4 -4
- data/lib/fog/azurerm/requests/sql/create_or_update_firewall_rule.rb +56 -0
- data/lib/fog/azurerm/requests/sql/create_or_update_sql_server.rb +4 -5
- data/lib/fog/azurerm/requests/sql/delete_database.rb +4 -4
- data/lib/fog/azurerm/requests/sql/delete_firewall_rule.rb +36 -0
- data/lib/fog/azurerm/requests/sql/delete_sql_server.rb +2 -2
- data/lib/fog/azurerm/requests/sql/get_database.rb +2 -2
- data/lib/fog/azurerm/requests/sql/get_firewall_rule.rb +43 -0
- data/lib/fog/azurerm/requests/sql/get_sql_server.rb +2 -2
- data/lib/fog/azurerm/requests/sql/list_databases.rb +2 -2
- data/lib/fog/azurerm/requests/sql/list_firewall_rules.rb +55 -0
- data/lib/fog/azurerm/requests/sql/list_sql_servers.rb +2 -2
- data/lib/fog/azurerm/requests/storage/create_disk.rb +36 -0
- data/lib/fog/azurerm/requests/storage/create_or_update_recovery_vault.rb +54 -0
- data/lib/fog/azurerm/requests/storage/create_storage_account.rb +13 -2
- data/lib/fog/azurerm/requests/storage/delete_disk.rb +5 -9
- data/lib/fog/azurerm/requests/storage/delete_recovery_vault.rb +35 -0
- data/lib/fog/azurerm/requests/storage/disable_backup_protection.rb +60 -0
- data/lib/fog/azurerm/requests/storage/enable_backup_protection.rb +61 -0
- data/lib/fog/azurerm/requests/storage/get_all_backup_jobs.rb +56 -0
- data/lib/fog/azurerm/requests/storage/get_backup_container.rb +53 -0
- data/lib/fog/azurerm/requests/storage/get_backup_item.rb +58 -0
- data/lib/fog/azurerm/requests/storage/get_backup_job_for_vm.rb +53 -0
- data/lib/fog/azurerm/requests/storage/get_backup_protection_policy.rb +64 -0
- data/lib/fog/azurerm/requests/storage/get_recovery_vault.rb +49 -0
- data/lib/fog/azurerm/requests/storage/list_recovery_vaults.rb +48 -0
- data/lib/fog/azurerm/requests/storage/set_recovery_vault_context.rb +36 -0
- data/lib/fog/azurerm/requests/storage/start_backup.rb +54 -0
- data/lib/fog/azurerm/requests/storage/update_storage_account.rb +59 -0
- data/lib/fog/azurerm/sql.rb +9 -0
- data/lib/fog/azurerm/storage.rb +24 -0
- data/lib/fog/azurerm/version.rb +1 -1
- data/rake-script.sh +8 -0
- data/rakefile +11 -3
- data/test/api_stub.rb +4 -0
- data/test/api_stub/models/sql/sql_firewall_rule.rb +22 -0
- data/test/api_stub/models/storage/recovery_vault.rb +23 -0
- data/test/api_stub/requests/sql/firewall_rule.rb +46 -0
- data/test/api_stub/requests/storage/recovery_vault.rb +189 -0
- data/test/api_stub/requests/storage/storageaccount.rb +2 -1
- data/test/integration/container.rb +4 -3
- data/test/integration/data_disk.rb +77 -0
- data/test/integration/express_route_circuit.rb +9 -9
- data/test/integration/server.rb +9 -2
- data/test/integration/sql_server.rb +35 -0
- data/test/integration/storage_account.rb +9 -1
- data/test/models/sql/test_firewall_rule.rb +54 -0
- data/test/models/sql/test_firewall_rules.rb +41 -0
- data/test/models/storage/test_recovery_vault.rb +61 -0
- data/test/models/storage/test_recovery_vaults.rb +47 -0
- data/test/models/storage/test_storage_account.rb +8 -1
- data/test/requests/sql/test_create_or_update_firewall_rule.rb +27 -0
- data/test/requests/sql/test_delete_firewall_rule.rb +34 -0
- data/test/requests/sql/test_get_firewall_rule.rb +35 -0
- data/test/requests/sql/test_list_firewall_rules.rb +35 -0
- data/test/requests/storage/test_create_disk.rb +17 -0
- data/test/requests/storage/test_create_recovery_vault.rb +35 -0
- data/test/requests/storage/test_delete_disk.rb +23 -0
- data/test/requests/storage/test_delete_recovery_vault.rb +34 -0
- data/test/requests/storage/test_disable_backup_protection.rb +52 -0
- data/test/requests/storage/test_enable_backup_protection.rb +66 -0
- data/test/requests/storage/test_get_all_backup_jobs.rb +35 -0
- data/test/requests/storage/test_get_backup_container.rb +35 -0
- data/test/requests/storage/test_get_backup_item.rb +35 -0
- data/test/requests/storage/test_get_backup_job_for_vm.rb +26 -0
- data/test/requests/storage/test_get_backup_protection_policy.rb +35 -0
- data/test/requests/storage/test_get_recovery_vault.rb +35 -0
- data/test/requests/storage/test_list_recovery_vault.rb +35 -0
- data/test/requests/storage/test_set_recovery_vault_context.rb +34 -0
- data/test/requests/storage/test_start_backup.rb +55 -0
- data/test/requests/storage/test_update_storage_account.rb +34 -0
- data/test/smoke_tests/compute/test_resource_group_smoke.rb +34 -24
- data/test/test_helper.rb +26 -0
- metadata +55 -2
@@ -1,12 +1,9 @@
|
|
1
|
-
require 'fog/core/collection'
|
2
|
-
require 'fog/azurerm/models/storage/directory'
|
3
|
-
|
4
1
|
module Fog
|
5
2
|
module Storage
|
6
3
|
class AzureRM
|
7
4
|
# This class is giving implementation of listing containers.
|
8
5
|
class Directories < Fog::Collection
|
9
|
-
model
|
6
|
+
model Directory
|
10
7
|
|
11
8
|
def all(options = { metadata: true })
|
12
9
|
containers = []
|
@@ -1,12 +1,9 @@
|
|
1
|
-
require 'fog/core/collection'
|
2
|
-
require 'fog/azurerm/models/storage/file'
|
3
|
-
|
4
1
|
module Fog
|
5
2
|
module Storage
|
6
3
|
class AzureRM
|
7
4
|
# This class is giving implementation of listing blobs.
|
8
5
|
class Files < Fog::Collection
|
9
|
-
model
|
6
|
+
model File
|
10
7
|
attribute :directory
|
11
8
|
|
12
9
|
def all(options = { metadata: true })
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class is giving implementation of create/save and
|
5
|
+
# delete/destroy for Recovery Vault.
|
6
|
+
class RecoveryVault < Fog::Model
|
7
|
+
attribute :id
|
8
|
+
identity :name
|
9
|
+
attribute :resource_group
|
10
|
+
attribute :location
|
11
|
+
attribute :type
|
12
|
+
attribute :sku_name
|
13
|
+
|
14
|
+
def self.parse(recovery_vault)
|
15
|
+
{
|
16
|
+
id: recovery_vault['id'],
|
17
|
+
name: recovery_vault['name'],
|
18
|
+
resource_group: get_resource_group_from_id(recovery_vault['id']),
|
19
|
+
location: recovery_vault['location'],
|
20
|
+
type: recovery_vault['type'],
|
21
|
+
sku_name: recovery_vault['sku']['name']
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def save
|
26
|
+
requires :name, :location, :resource_group
|
27
|
+
recovery_vault = service.create_or_update_recovery_vault(resource_group, location, name)
|
28
|
+
merge_attributes(RecoveryVault.parse(recovery_vault))
|
29
|
+
end
|
30
|
+
|
31
|
+
def enable_backup_protection(vm_name, vm_resource_group)
|
32
|
+
requires :name, :resource_group
|
33
|
+
service.enable_backup_protection(name, resource_group, vm_name, vm_resource_group)
|
34
|
+
end
|
35
|
+
|
36
|
+
def start_backup(vm_name, vm_resource_group)
|
37
|
+
service.start_backup(resource_group, name, vm_name, vm_resource_group)
|
38
|
+
end
|
39
|
+
|
40
|
+
def disable_backup_protection(vm_name, vm_resource_group)
|
41
|
+
service.disable_backup_protection(name, resource_group, vm_name, vm_resource_group)
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
service.delete_recovery_vault(resource_group, name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class is giving implementation of all/get for Recovery Vaults
|
5
|
+
class RecoveryVaults < Fog::Collection
|
6
|
+
model RecoveryVault
|
7
|
+
attribute :resource_group
|
8
|
+
attribute :name
|
9
|
+
|
10
|
+
def all
|
11
|
+
requires :resource_group
|
12
|
+
recovery_vaults = []
|
13
|
+
service.list_recovery_vaults(resource_group).each do |recovery_vault|
|
14
|
+
recovery_vaults << RecoveryVault.parse(recovery_vault)
|
15
|
+
end
|
16
|
+
load(recovery_vaults)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(resource_group, name)
|
20
|
+
recovery_vault = service.get_recovery_vault(resource_group, name)
|
21
|
+
recovery_vault_obj = RecoveryVault.new(service: service)
|
22
|
+
recovery_vault_obj.merge_attributes(RecoveryVault.parse(recovery_vault))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -5,10 +5,12 @@ module Fog
|
|
5
5
|
# delete/destroy for storage account.
|
6
6
|
class StorageAccount < Fog::Model
|
7
7
|
identity :name
|
8
|
+
attribute :id
|
8
9
|
attribute :location
|
9
10
|
attribute :resource_group
|
10
11
|
attribute :sku_name
|
11
12
|
attribute :replication
|
13
|
+
attribute :encryption
|
12
14
|
|
13
15
|
def self.parse(storage_account)
|
14
16
|
hash = {}
|
@@ -18,6 +20,7 @@ module Fog
|
|
18
20
|
hash['resource_group'] = get_resource_group_from_id(storage_account.id)
|
19
21
|
hash['sku_name'] = storage_account.sku.name.split('_').first
|
20
22
|
hash['replication'] = storage_account.sku.name.split('_').last
|
23
|
+
hash['encryption'] = storage_account.encryption.services.blob.enabled unless storage_account.encryption.nil?
|
21
24
|
hash
|
22
25
|
end
|
23
26
|
|
@@ -29,9 +32,8 @@ module Fog
|
|
29
32
|
self.sku_name = STANDARD_STORAGE if sku_name.nil?
|
30
33
|
self.replication = ALLOWED_STANDARD_REPLICATION.first if replication.nil?
|
31
34
|
validate_sku_name!
|
32
|
-
|
33
|
-
|
34
|
-
merge_attributes(Fog::Storage::AzureRM::StorageAccount.parse(storage_account))
|
35
|
+
storage_account = service.create_storage_account(get_storage_account_arguments)
|
36
|
+
merge_attributes(StorageAccount.parse(storage_account))
|
35
37
|
end
|
36
38
|
|
37
39
|
def get_storage_account_arguments
|
@@ -40,10 +42,19 @@ module Fog
|
|
40
42
|
name: name,
|
41
43
|
sku_name: sku_name,
|
42
44
|
location: location,
|
43
|
-
replication: replication
|
45
|
+
replication: replication,
|
46
|
+
encryption: encryption
|
44
47
|
}
|
45
48
|
end
|
46
49
|
|
50
|
+
def update(storage_account_params)
|
51
|
+
validate_input(storage_account_params)
|
52
|
+
storage_account_params = merge_attributes(storage_account_params).all_attributes
|
53
|
+
|
54
|
+
storage_account = service.update_storage_account(storage_account_params)
|
55
|
+
merge_attributes(StorageAccount.parse(storage_account))
|
56
|
+
end
|
57
|
+
|
47
58
|
def validate_sku_name!
|
48
59
|
case sku_name
|
49
60
|
when STANDARD_STORAGE
|
@@ -63,6 +74,14 @@ module Fog
|
|
63
74
|
service.delete_storage_account(resource_group, name)
|
64
75
|
end
|
65
76
|
|
77
|
+
private
|
78
|
+
|
79
|
+
def validate_input(attr_hash)
|
80
|
+
invalid_attr = [:resource_group, :name, :location, :id]
|
81
|
+
result = invalid_attr & attr_hash.keys
|
82
|
+
raise 'Cannot modify the given attribute' unless result.empty?
|
83
|
+
end
|
84
|
+
|
66
85
|
private :get_storage_account_arguments, :validate_sku_name!
|
67
86
|
end
|
68
87
|
end
|
@@ -1,14 +1,12 @@
|
|
1
|
-
require 'fog/core/collection'
|
2
|
-
require 'fog/azurerm/models/storage/storage_account'
|
3
|
-
|
4
1
|
module Fog
|
5
2
|
module Storage
|
6
3
|
class AzureRM
|
7
4
|
# This class is giving implementation of all/list, get and
|
8
5
|
# check name availability for storage account.
|
9
6
|
class StorageAccounts < Fog::Collection
|
10
|
-
model
|
7
|
+
model StorageAccount
|
11
8
|
attribute :resource_group
|
9
|
+
|
12
10
|
def all
|
13
11
|
accounts = []
|
14
12
|
if !resource_group.nil?
|
@@ -18,15 +16,15 @@ module Fog
|
|
18
16
|
hash_of_storage_accounts = service.list_storage_accounts
|
19
17
|
end
|
20
18
|
hash_of_storage_accounts.each do |account|
|
21
|
-
accounts <<
|
19
|
+
accounts << StorageAccount.parse(account)
|
22
20
|
end
|
23
21
|
load(accounts)
|
24
22
|
end
|
25
23
|
|
26
24
|
def get(resource_group_name, storage_account_name)
|
27
25
|
storage_account = service.get_storage_account(resource_group_name, storage_account_name)
|
28
|
-
storage_account_object =
|
29
|
-
storage_account_object.merge_attributes(
|
26
|
+
storage_account_object = StorageAccount.new(service: service)
|
27
|
+
storage_account_object.merge_attributes(StorageAccount.parse(storage_account))
|
30
28
|
end
|
31
29
|
|
32
30
|
def check_name_availability(name)
|
@@ -7,7 +7,7 @@ module Fog
|
|
7
7
|
msg = "Creating SQL Database: #{database_hash[:name]}."
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{database_hash[:resource_group]}/providers/Microsoft.Sql/servers/#{database_hash[:server_name]}/databases/#{database_hash[:name]}?api-version=2014-04-01-preview"
|
10
|
-
request_parameters =
|
10
|
+
request_parameters = get_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[:restore_point_in_time], database_hash[:source_database_deletion_date], database_hash[:elastic_pool_name], database_hash[:requested_service_objective_id])
|
11
11
|
begin
|
12
12
|
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
13
13
|
response = RestClient.put(
|
@@ -17,8 +17,8 @@ module Fog
|
|
17
17
|
content_type: :json,
|
18
18
|
authorization: token
|
19
19
|
)
|
20
|
-
rescue
|
21
|
-
|
20
|
+
rescue RestClient::Exception => e
|
21
|
+
raise JSON.parse(e.response)['message']
|
22
22
|
end
|
23
23
|
Fog::Logger.debug "SQL Database: #{database_hash[:name]} created successfully."
|
24
24
|
JSON.parse(response)
|
@@ -26,7 +26,7 @@ module Fog
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
def
|
29
|
+
def get_database_parameters(location, create_mode, edition, source_database_id, collation, max_size_bytes, requested_service_objective_name, restore_point_in_time, source_database_deletion_date, elastic_pool_name, requested_service_objective_id)
|
30
30
|
parameters = {}
|
31
31
|
properties = {}
|
32
32
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Fog
|
2
|
+
module Sql
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Firewall Rule Request
|
5
|
+
class Real
|
6
|
+
def create_or_update_firewall_rule(firewall_hash)
|
7
|
+
msg = "Creating SQL Firewall Rule : #{firewall_hash[:name]}."
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
|
10
|
+
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{firewall_hash[:resource_group]}/providers/Microsoft.Sql/servers/#{firewall_hash[:server_name]}/firewallRules/#{firewall_hash[:name]}?api-version=2014-04-01-preview"
|
11
|
+
request_parameters = get_server_firewall_parameters(firewall_hash[:start_ip], firewall_hash[:end_ip])
|
12
|
+
begin
|
13
|
+
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
14
|
+
response = RestClient.put(
|
15
|
+
resource_url,
|
16
|
+
request_parameters.to_json,
|
17
|
+
accept: :json,
|
18
|
+
content_type: :json,
|
19
|
+
authorization: token
|
20
|
+
)
|
21
|
+
rescue RestClient::Exception => e
|
22
|
+
raise JSON.parse(e.response)['message']
|
23
|
+
end
|
24
|
+
Fog::Logger.debug "SQL Firewall Rule : #{firewall_hash[:name]} created successfully."
|
25
|
+
JSON.parse(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def get_server_firewall_parameters(start_ip, end_ip)
|
31
|
+
parameters = {}
|
32
|
+
properties = {}
|
33
|
+
|
34
|
+
properties['startIpAddress'] = start_ip
|
35
|
+
properties['endIpAddress'] = end_ip
|
36
|
+
|
37
|
+
parameters['properties'] = properties
|
38
|
+
|
39
|
+
parameters
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Mock class for Sql Firewall Rule Request
|
44
|
+
class Mock
|
45
|
+
def create_or_update_firewall_rule(*)
|
46
|
+
{
|
47
|
+
'properties' => {
|
48
|
+
'startIpAddress' => '{start-ip-address}',
|
49
|
+
'endIpAddress' => '{end-ip-address}'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -7,7 +7,7 @@ module Fog
|
|
7
7
|
msg = "Creating SQL Server: #{server_hash[:name]}."
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{server_hash[:resource_group]}/providers/Microsoft.Sql/servers/#{server_hash[:name]}?api-version=2014-04-01-preview"
|
10
|
-
request_parameters =
|
10
|
+
request_parameters = get_server_parameters(server_hash[:location], server_hash[:version], server_hash[:administrator_login], server_hash[:administrator_login_password])
|
11
11
|
begin
|
12
12
|
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
13
13
|
response = RestClient.put(
|
@@ -17,9 +17,8 @@ module Fog
|
|
17
17
|
content_type: :json,
|
18
18
|
authorization: token
|
19
19
|
)
|
20
|
-
|
21
|
-
|
22
|
-
raise_azure_exception(e, JSON.parse(e.response)['message'])
|
20
|
+
rescue RestClient::Exception => e
|
21
|
+
raise JSON.parse(e.response)['message']
|
23
22
|
end
|
24
23
|
Fog::Logger.debug "SQL Server: #{server_hash[:name]} created successfully."
|
25
24
|
JSON.parse(response)
|
@@ -27,7 +26,7 @@ module Fog
|
|
27
26
|
|
28
27
|
private
|
29
28
|
|
30
|
-
def
|
29
|
+
def get_server_parameters(location, version, admin_login, admin_password)
|
31
30
|
parameters = {}
|
32
31
|
properties = {}
|
33
32
|
|
@@ -15,11 +15,11 @@ module Fog
|
|
15
15
|
content_type: :json,
|
16
16
|
authorization: token
|
17
17
|
)
|
18
|
-
|
19
|
-
|
20
|
-
rescue MsRestAzure::AzureOperationError => e
|
21
|
-
raise_azure_exception(e, JSON.parse(e.response)['message'])
|
18
|
+
rescue RestClient::Exception => e
|
19
|
+
raise JSON.parse(e.response)['message']
|
22
20
|
end
|
21
|
+
Fog::Logger.debug "SQL Database: #{name} deleted successfully."
|
22
|
+
true
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Fog
|
2
|
+
module Sql
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Sql Firewall Rule Request
|
5
|
+
class Real
|
6
|
+
def delete_firewall_rule(resource_group, server_name, rule_name)
|
7
|
+
msg = "Deleting SQL Firewall Rule: #{rule_name}."
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
|
10
|
+
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Sql/servers/#{server_name}/firewallRules/#{rule_name}?api-version=2014-04-01-preview"
|
11
|
+
begin
|
12
|
+
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
13
|
+
RestClient.delete(
|
14
|
+
resource_url,
|
15
|
+
accept: :json,
|
16
|
+
content_type: :json,
|
17
|
+
authorization: token
|
18
|
+
)
|
19
|
+
Fog::Logger.debug "SQL Firewall Rule: #{rule_name} deleted successfully."
|
20
|
+
true
|
21
|
+
rescue RestClient::Exception => e
|
22
|
+
raise JSON.parse(e.response)['message']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Mock class for Sql Firewall Rule Request
|
28
|
+
class Mock
|
29
|
+
def delete_firewall_rule(*)
|
30
|
+
Fog::Logger.debug 'SQL Firewall Rule {name} from SQL Server {server_name}, Resource group {resource_group} deleted successfully.'
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -17,8 +17,8 @@ module Fog
|
|
17
17
|
)
|
18
18
|
Fog::Logger.debug "SQL Server: #{name} deleted successfully."
|
19
19
|
true
|
20
|
-
rescue
|
21
|
-
|
20
|
+
rescue RestClient::Exception => e
|
21
|
+
raise JSON.parse(e.response)['message']
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -15,8 +15,8 @@ module Fog
|
|
15
15
|
content_type: :json,
|
16
16
|
authorization: token
|
17
17
|
)
|
18
|
-
rescue
|
19
|
-
|
18
|
+
rescue RestClient::Exception => e
|
19
|
+
raise JSON.parse(e.response)['message']
|
20
20
|
end
|
21
21
|
Fog::Logger.debug "Sql Database fetched successfully in Resource Group: #{resource_group}"
|
22
22
|
JSON.parse(response)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Fog
|
2
|
+
module Sql
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Sql Server Firewall Rule Request
|
5
|
+
class Real
|
6
|
+
def get_firewall_rule(resource_group, server_name, rule_name)
|
7
|
+
msg = "Getting Sql Server Firewall Rule: #{rule_name} from SQL Server: #{server_name} in Resource Group: #{resource_group}..."
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Sql/servers/#{server_name}/firewallRules/#{rule_name}?api-version=2014-04-01-preview"
|
10
|
+
begin
|
11
|
+
token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
|
12
|
+
response = RestClient.get(
|
13
|
+
resource_url,
|
14
|
+
accept: :json,
|
15
|
+
content_type: :json,
|
16
|
+
authorization: token
|
17
|
+
)
|
18
|
+
rescue RestClient::Exception => e
|
19
|
+
raise JSON.parse(e.response)['message']
|
20
|
+
end
|
21
|
+
Fog::Logger.debug "Sql Server Firewall Rule fetched successfully from Server: #{server_name}, Resource Group: #{resource_group}"
|
22
|
+
JSON.parse(response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Mock class for Sql Server Firewall Rule Request
|
27
|
+
class Mock
|
28
|
+
def get_firewall_rule(*)
|
29
|
+
{
|
30
|
+
'id' => '{uri-of-firewall-rule}',
|
31
|
+
'name' => '{rule-name}',
|
32
|
+
'type' => '{rule-type}',
|
33
|
+
'location' => '{server-location}',
|
34
|
+
'properties' => {
|
35
|
+
'startIpAddress' => '{start-ip-address}',
|
36
|
+
'endIpAddress' => '{end-ip-address}'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|