Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Autoload #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Or install it yourself as:
## Usage

You can use this gem against the Microsoft Azure Resource Manager Services in the cloud. Of course, to use the Microsoft Azure Resource Manager Services in the cloud, you need to first [create a Microsoft Azure account](http://www.azure.com/en-us/pricing/free-trial/).
* Set 'LOCATION' constant based on the Azure cloud you are using in [config.rb] (https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/config.rb) file. By default it will be 'eastus'.
* Set 'AzureRm::Config.location' based on the Azure cloud you are using in an initializer. By default it will be 'eastus'.

### Authentication

Expand Down
11 changes: 1 addition & 10 deletions lib/fog/azurerm.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
require 'ms_rest_azure'
require 'azure/core/http/http_error'
require 'erb'
require 'fog/azurerm/config'
require 'fog/azurerm/constants'
require 'fog/azurerm/utilities/general'
require 'fog/azurerm/version'
require 'fog/core'
require 'fog/json'
require 'fog/azurerm/models/compute/caching_types'
require 'fog/azurerm/models/compute/disk_create_option_types'
require 'fog/azurerm/models/network/ipallocation_method'
require 'fog/azurerm/models/network/security_rule_access'
require 'fog/azurerm/models/network/security_rule_direction'
require 'fog/azurerm/models/network/security_rule_protocol'
require 'fog/azurerm/models/storage/sku_name'
require 'fog/azurerm/models/storage/sku_tier'
require 'fog/azurerm/models/storage/kind'

module Fog
# Autoload Module for Credentials
Expand Down Expand Up @@ -71,6 +61,7 @@ module KeyVault
# Autoload Module for Response::Asynchronous
module AzureRM
autoload :AsyncResponse, File.expand_path('azurerm/async_response', __dir__)
autoload :Config, File.expand_path('azurerm/config', __dir__)
end

# Main AzureRM fog Provider Module
Expand Down
12 changes: 11 additions & 1 deletion lib/fog/azurerm/config.rb
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
LOCATION = 'eastus'.freeze
module AzureRM
class Config
def self.location
@location || 'eastus'.freeze
end

def self.location=(location)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use attr_writer to define trivial writer methods.

@location = location
end
end
end
8 changes: 4 additions & 4 deletions test/integration/application_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
begin
resource_group = resource.resource_groups.create(
name: resource_group_name,
location: LOCATION
location: Config.location
)

network.virtual_networks.create(
name: virtual_network_name,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name,
dns_servers: %w(10.1.0.0 10.2.0.0),
address_prefixes: %w(10.1.0.0/16 10.2.0.0/16)
Expand All @@ -68,7 +68,7 @@
network.public_ips.create(
name: public_ip_name,
resource_group: resource_group_name,
location: LOCATION,
location: Config.location,
public_ip_allocation_method: Fog::ARM::Network::Models::IPAllocationMethod::Dynamic
)

Expand All @@ -87,7 +87,7 @@

app_gateway = application_gateway.gateways.create(
name: app_gateway_name,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name,
tags: tags,
sku_name: 'Standard_Medium',
Expand Down
10 changes: 5 additions & 5 deletions test/integration/availability_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
puts "Create resource group (#{resource_group_name}):"
resource_group = rs.resource_groups.create(
name: resource_group_name,
location: LOCATION
location: Config.location
)
puts "Created resource group! [#{resource_group.name}]"

Expand Down Expand Up @@ -76,7 +76,7 @@
puts "Create unmanaged default availability set (#{unmanaged_as_name_default}):"
avail_set = compute.availability_sets.create(
name: unmanaged_as_name_default,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name,
tags: tags
)
Expand All @@ -92,7 +92,7 @@
puts "Create unmanaged custom availability set (#{unmanaged_as_name_custom}):"
avail_set = compute.availability_sets.create(
name: unmanaged_as_name_custom,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name,
tags: tags,
platform_fault_domain_count: 3,
Expand All @@ -110,7 +110,7 @@
puts "Create managed default availability set (#{managed_as_name_default}):"
avail_set = compute.availability_sets.create(
name: managed_as_name_default,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name,
tags: tags,
use_managed_disk: true
Expand All @@ -127,7 +127,7 @@
puts "Create managed custom availability set (#{managed_as_name_custom}):"
avail_set = compute.availability_sets.create(
name: managed_as_name_custom,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name,
tags: tags,
platform_fault_domain_count: 2,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
begin
resource_group = rs.resource_groups.create(
name: resource_group_name,
location: LOCATION
location: Config.location
)

storage_account = storage.storage_accounts.create(
name: storage_account_name,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name
)

Expand Down
4 changes: 2 additions & 2 deletions test/integration/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
begin
resource_group = rs.resource_groups.create(
name: resource_group_name,
location: LOCATION
location: Config.location
)

storage_account_name = "sa#{current_time}"

storage_account = storage.storage_accounts.create(
name: storage_account_name,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name
)

Expand Down
4 changes: 2 additions & 2 deletions test/integration/data_disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
begin
resource_group = rs.resource_groups.create(
name: resource_group_name,
location: LOCATION
location: Config.location
)

storage_account = storage.storage_accounts.create(
name: storage_account_name,
location: LOCATION,
location: Config.location,
resource_group: resource_group_name
)

Expand Down
2 changes: 1 addition & 1 deletion test/integration/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
begin
resource_group = resources.resource_groups.create(
name: 'TestRG-ZN',
location: LOCATION
location: Config.location
)

########################################################################################################################
Expand Down
4 changes: 2 additions & 2 deletions test/integration/express_route_circuit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
begin
resource_group = resources.resource_groups.create(
name: 'TestRG-ER',
location: LOCATION
location: Config.location
)
Fog::Logger.debug 'Resource Group created!'

Expand All @@ -46,7 +46,7 @@

express_route_circuit = network.express_route_circuits.create(
name: 'testERCircuit',
location: LOCATION,
location: Config.location,
tags: {
key1: 'value1',
key2: 'value2'
Expand Down
8 changes: 4 additions & 4 deletions test/integration/external_load_balancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
begin
resource_group = rs.resource_groups.create(
name: 'TestRG-LB',
location: LOCATION
location: Config.location
)

network.virtual_networks.create(
name: 'testVnet',
location: LOCATION,
location: Config.location,
resource_group: 'TestRG-LB',
dns_servers: %w(10.1.0.0 10.2.0.0),
address_prefixes: %w(10.1.0.0/16 10.2.0.0/16)
Expand All @@ -50,7 +50,7 @@
pip = network.public_ips.create(
name: 'mypubip',
resource_group: 'TestRG-LB',
location: LOCATION,
location: Config.location,
public_ip_allocation_method: Fog::ARM::Network::Models::IPAllocationMethod::Dynamic
)

Expand All @@ -68,7 +68,7 @@
load_balancer = network.load_balancers.create(
name: 'lb',
resource_group: 'TestRG-LB',
location: LOCATION,
location: Config.location,
frontend_ip_configurations:
[
{
Expand Down
6 changes: 3 additions & 3 deletions test/integration/internal_load_balancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
begin
resource_group = rs.resource_groups.create(
name: 'NRP-RG-Fog',
location: LOCATION
location: Config.location
)

network.virtual_networks.create(
name: 'NRPVNet',
location: LOCATION,
location: Config.location,
resource_group: 'NRP-RG-Fog',
dns_servers: %w(10.1.0.0 10.2.0.0),
address_prefixes: %w(10.1.0.0/16 10.2.0.0/16)
Expand All @@ -54,7 +54,7 @@
load_balancer = network.load_balancers.create(
name: 'lb',
resource_group: 'NRP-RG-Fog',
location: LOCATION,
location: Config.location,
frontend_ip_configurations:
[
{
Expand Down
4 changes: 2 additions & 2 deletions test/integration/local_network_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
begin
resource_group = resource.resource_groups.create(
name: 'TestRG-LNG',
location: LOCATION
location: Config.location
)

########################################################################################################################
Expand All @@ -45,7 +45,7 @@

local_network_gateway = network.local_network_gateways.create(
name: 'testlocalnetworkgateway',
location: LOCATION,
location: Config.location,
tags: {
key1: 'value1',
key2: 'value2'
Expand Down
4 changes: 2 additions & 2 deletions test/integration/managed_disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
begin
rs.resource_groups.create(
name: resource_group_name,
location: LOCATION
location: Config.location
)

########################################################################################################################
Expand All @@ -57,7 +57,7 @@

disk = compute.managed_disks.create(
name: disk_name,
location: LOCATION,
location: Config.location,
resource_group_name: resource_group_name,
tags: tags,
account_type: 'Premium_LRS',
Expand Down
12 changes: 6 additions & 6 deletions test/integration/network_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
begin
resource_group = rs.resource_groups.create(
name: 'TestRG-NI',
location: LOCATION
location: Config.location
)

network.virtual_networks.create(
name: 'testVnet',
location: LOCATION,
location: Config.location,
resource_group: 'TestRG-NI',
network_address_list: '10.1.0.0/16,10.2.0.0/16'
)
Expand All @@ -56,21 +56,21 @@
network.public_ips.create(
name: 'mypubip',
resource_group: 'TestRG-NI',
location: LOCATION,
location: Config.location,
public_ip_allocation_method: 'Dynamic'
)

network.public_ips.create(
name: 'mypubip1',
resource_group: 'TestRG-NI',
location: LOCATION,
location: Config.location,
public_ip_allocation_method: 'Dynamic'
)

nsg = network.network_security_groups.create(
name: 'test_nsg',
resource_group: 'TestRG-NI',
location: LOCATION,
location: Config.location,
security_rules:
[
{
Expand Down Expand Up @@ -101,7 +101,7 @@
network_interface = network.network_interfaces.create(
name: 'NetInt',
resource_group: 'TestRG-NI',
location: LOCATION,
location: Config.location,
network_security_group_id: nsg.id,
subnet_id: "/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-NI/providers/Microsoft.Network/virtualNetworks/testVnet/subnets/mysubnet",
public_ip_address_id: "/subscriptions/#{azure_credentials['subscription_id']}/resourceGroups/TestRG-NI/providers/Microsoft.Network/publicIPAddresses/mypubip",
Expand Down
4 changes: 2 additions & 2 deletions test/integration/network_security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
begin
resource_group = rs.resource_groups.create(
name: 'TestRG-NSG',
location: LOCATION
location: Config.location
)

########################################################################################################################
Expand All @@ -46,7 +46,7 @@
network_security_group = network.network_security_groups.create(
name: 'testGroup',
resource_group: 'TestRG-NSG',
location: LOCATION,
location: Config.location,
security_rules: [{
name: 'testRule',
protocol: Fog::ARM::Network::Models::SecurityRuleProtocol::Tcp,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/network_security_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
begin
resource_group = rs.resource_groups.create(
name: 'TestRG-NSR',
location: LOCATION
location: Config.location
)

########################################################################################################################
Expand All @@ -39,7 +39,7 @@
network.network_security_groups.create(
name: 'testGroup',
resource_group: 'TestRG-NSR',
location: LOCATION
location: Config.location
)

########################################################################################################################
Expand Down
4 changes: 2 additions & 2 deletions test/integration/public_ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
begin
resource_group = rs.resource_groups.create(
name: 'TestRG-PB',
location: LOCATION
location: Config.location
)

########################################################################################################################
Expand All @@ -46,7 +46,7 @@
public_ip = network.public_ips.create(
name: 'mypubip',
resource_group: 'TestRG-PB',
location: LOCATION,
location: Config.location,
public_ip_allocation_method: Fog::ARM::Network::Models::IPAllocationMethod::Dynamic,
tags: { key: 'value' }
)
Expand Down
Loading