-
Notifications
You must be signed in to change notification settings - Fork 89
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
expose the resource group for load balancer, and wrap config for availability set #541
Changes from 1 commit
01c1657
30af791
808addd
ad5a4f9
115e49f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,33 +5,23 @@ class VMCloudProps | |
include Helpers | ||
attr_reader :resource_group_name, :instance_type | ||
attr_reader :storage_account_type, :storage_account_kind, :storage_account_max_disk_number, :storage_account_name | ||
attr_reader :availability_zone, :availability_set | ||
attr_reader :availability_zone | ||
attr_reader :availability_set | ||
attr_reader :tags | ||
attr_reader :caching | ||
attr_reader :root_disk, :ephemeral_disk | ||
attr_reader :ip_forwarding, :accelerated_networking, :assign_dynamic_public_ip, :load_balancer, :application_gateway | ||
attr_reader :ip_forwarding, :accelerated_networking, :assign_dynamic_public_ip, :application_gateway | ||
attr_reader :load_balancer | ||
attr_reader :application_security_groups, :security_group | ||
attr_reader :platform_update_domain_count, :platform_fault_domain_count | ||
|
||
attr_writer :availability_zone, :availability_set | ||
attr_writer :availability_zone | ||
attr_writer :availability_set | ||
attr_writer :assign_dynamic_public_ip | ||
# In AzureStack, availability sets can only be configured with 1 update domain. | ||
# In Azure, the max update domain count of a managed/unmanaged availability set is 5. | ||
def default_update_domain_count(global_azure_config) | ||
global_azure_config.environment == ENVIRONMENT_AZURESTACK ? 1 : 5 | ||
end | ||
|
||
# In AzureStack, availability sets can only be configured with 1 fault domain and 1 update domain. | ||
# In Azure, the max fault domain count of an unmanaged availability set is 3; | ||
# the max fault domain count of a managed availability set is 2 in some regions. | ||
# When all regions support 3 fault domains, the default value should be changed to 3. | ||
def default_fault_domain_count(global_azure_config) | ||
if global_azure_config.environment == ENVIRONMENT_AZURESTACK | ||
1 | ||
else | ||
global_azure_config.use_managed_disks ? 2 : 3 | ||
end | ||
end | ||
AVAILABILITY_SET_KEY = 'availability_set' | ||
LOAD_BALANCER_KEY = 'load_balancer' | ||
RESOURCE_GROUP_NAME_KEY = 'resource_group_name' | ||
NAME_KEY = 'name' | ||
|
||
def initialize(vm_properties, global_azure_config) | ||
@vm_properties = vm_properties.dup | ||
|
@@ -40,7 +30,7 @@ def initialize(vm_properties, global_azure_config) | |
@resource_group_name = vm_properties.fetch('resource_group_name', global_azure_config.resource_group_name) | ||
@storage_account_type = vm_properties['storage_account_type'] | ||
@availability_zone = vm_properties['availability_zone'] | ||
@availability_set = vm_properties['availability_set'] | ||
@availability_set = _parse_availability_set_config(vm_properties, global_azure_config) | ||
@storage_account_name = vm_properties['storage_account_name'] | ||
@storage_account_max_disk_number = vm_properties.fetch('storage_account_max_disk_number', 30) | ||
@storage_account_kind = vm_properties.fetch('storage_account_kind', STORAGE_ACCOUNT_KIND_GENERAL_PURPOSE_V1) | ||
|
@@ -50,7 +40,9 @@ def initialize(vm_properties, global_azure_config) | |
@ip_forwarding = vm_properties['ip_forwarding'] | ||
@accelerated_networking = vm_properties['accelerated_networking'] | ||
@assign_dynamic_public_ip = vm_properties['assign_dynamic_public_ip'] | ||
@load_balancer = vm_properties['load_balancer'] | ||
|
||
@load_balancer = _parse_load_balancer_config(vm_properties, global_azure_config) | ||
|
||
@application_gateway = vm_properties['application_gateway'] | ||
|
||
@application_security_groups = vm_properties['application_security_groups'] | ||
|
@@ -64,9 +56,65 @@ def initialize(vm_properties, global_azure_config) | |
ephemeral_disk_hash['size'], | ||
ephemeral_disk_hash['type'] | ||
) | ||
end | ||
|
||
private | ||
|
||
# In AzureStack, availability sets can only be configured with 1 update domain. | ||
# In Azure, the max update domain count of a managed/unmanaged availability set is 5. | ||
def _default_update_domain_count(global_azure_config) | ||
global_azure_config.environment == ENVIRONMENT_AZURESTACK ? 1 : 5 | ||
end | ||
|
||
# In AzureStack, availability sets can only be configured with 1 fault domain and 1 update domain. | ||
# In Azure, the max fault domain count of an unmanaged availability set is 3; | ||
# the max fault domain count of a managed availability set is 2 in some regions. | ||
# When all regions support 3 fault domains, the default value should be changed to 3. | ||
def _default_fault_domain_count(global_azure_config) | ||
if global_azure_config.environment == ENVIRONMENT_AZURESTACK | ||
1 | ||
else | ||
global_azure_config.use_managed_disks ? 2 : 3 | ||
end | ||
end | ||
|
||
def _parse_load_balancer_config(vm_properties, global_azure_config) | ||
if vm_properties[LOAD_BALANCER_KEY].is_a?(Hash) | ||
resource_group_name = if vm_properties[LOAD_BALANCER_KEY][RESOURCE_GROUP_NAME_KEY].nil? | ||
global_azure_config.resource_group_name | ||
else | ||
vm_properties[LOAD_BALANCER_KEY][RESOURCE_GROUP_NAME_KEY] | ||
end | ||
Bosh::AzureCloud::LoadBalancerConfig.new( | ||
resource_group_name, | ||
vm_properties[LOAD_BALANCER_KEY][NAME_KEY] | ||
) | ||
else | ||
Bosh::AzureCloud::LoadBalancerConfig.new( | ||
global_azure_config.resource_group_name, | ||
vm_properties[LOAD_BALANCER_KEY] | ||
) | ||
end | ||
end | ||
|
||
@platform_update_domain_count = vm_properties['platform_update_domain_count'] || default_update_domain_count(global_azure_config) | ||
@platform_fault_domain_count = vm_properties['platform_fault_domain_count'] || default_fault_domain_count(global_azure_config) | ||
def _parse_availability_set_config(vm_properties, global_azure_config) | ||
if vm_properties[AVAILABILITY_SET_KEY].is_a?(Hash) | ||
platform_update_domain_count = vm_properties[AVAILABILITY_SET_KEY]['platform_update_domain_count'] || _default_update_domain_count(global_azure_config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about defining two varialbes?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are the same. and if define two variable will increate two line of code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to avoid call them twice. Anyway, both ways are fine for me. |
||
platform_fault_domain_count = vm_properties[AVAILABILITY_SET_KEY]['platform_fault_domain_count'] || _default_fault_domain_count(global_azure_config) | ||
Bosh::AzureCloud::AvailabilitySetConfig.new( | ||
vm_properties[AVAILABILITY_SET_KEY][NAME_KEY], | ||
platform_update_domain_count, | ||
platform_fault_domain_count | ||
) | ||
else | ||
platform_update_domain_count = vm_properties['platform_update_domain_count'] || _default_update_domain_count(global_azure_config) | ||
platform_fault_domain_count = vm_properties['platform_fault_domain_count'] || _default_fault_domain_count(global_azure_config) | ||
Bosh::AzureCloud::AvailabilitySetConfig.new( | ||
vm_properties[AVAILABILITY_SET_KEY], | ||
platform_update_domain_count, | ||
platform_fault_domain_count | ||
) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,7 @@ def rest_api_url(resource_provider, resource_type, resource_group_name: nil, nam | |
url | ||
end | ||
|
||
def parse_name_from_id(id) | ||
def _parse_name_from_id(id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the purpose of renaming it but not making it private? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make it private now. |
||
ret = id.match('/subscriptions/([^/]*)/resourceGroups/([^/]*)/providers/([^/]*)/([^/]*)/([^/]*)(.*)') | ||
raise AzureError, "\"#{id}\" is not a valid URL." if ret.nil? | ||
|
||
|
@@ -1263,9 +1263,10 @@ def delete_public_ip(resource_group_name, name) | |
# | ||
# @See https://docs.microsoft.com/en-us/rest/api/loadbalancer/get-information-about-a-load-balancer | ||
# | ||
def get_load_balancer_by_name(name) | ||
url = rest_api_url(REST_API_PROVIDER_NETWORK, REST_API_LOAD_BALANCERS, name: name) | ||
get_load_balancer(url) | ||
|
||
def get_load_balancer_by_name(resource_group_name, name) | ||
url = rest_api_url(REST_API_PROVIDER_NETWORK, REST_API_LOAD_BALANCERS, resource_group_name: resource_group_name, name: name) | ||
_get_load_balancer(url) | ||
end | ||
|
||
# Get a load balancer's information | ||
|
@@ -1275,7 +1276,7 @@ def get_load_balancer_by_name(name) | |
# | ||
# @See https://docs.microsoft.com/en-us/rest/api/loadbalancer/get-information-about-a-load-balancer | ||
# | ||
def get_load_balancer(url) | ||
def _get_load_balancer(url) | ||
load_balancer = nil | ||
result = get_resource_by_id(url) | ||
unless result.nil? | ||
|
@@ -1959,15 +1960,15 @@ def parse_network_interface(result, recursive: true) | |
end | ||
unless ip_configuration_properties['loadBalancerBackendAddressPools'].nil? | ||
if recursive | ||
names = parse_name_from_id(ip_configuration_properties['loadBalancerBackendAddressPools'][0]['id']) | ||
interface[:load_balancer] = get_load_balancer_by_name(names[:resource_name]) | ||
names = _parse_name_from_id(ip_configuration_properties['loadBalancerBackendAddressPools'][0]['id']) | ||
interface[:load_balancer] = get_load_balancer_by_name(names[:resource_group_name], names[:resource_name]) | ||
else | ||
interface[:load_balancer] = { id: ip_configuration_properties['loadBalancerBackendAddressPools'][0]['id'] } | ||
end | ||
end | ||
unless ip_configuration_properties['applicationGatewayBackendAddressPools'].nil? | ||
if recursive | ||
names = parse_name_from_id(ip_configuration_properties['applicationGatewayBackendAddressPools'][0]['id']) | ||
names = _parse_name_from_id(ip_configuration_properties['applicationGatewayBackendAddressPools'][0]['id']) | ||
interface[:application_gateway] = get_application_gateway_by_name(names[:resource_name]) | ||
else | ||
interface[:application_gateway] = { id: ip_configuration_properties['applicationGatewayBackendAddressPools'][0]['id'] } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Bosh::AzureCloud::AvailabilitySetConfig do | ||
describe '#to_s' do | ||
context 'when called' do | ||
let(:name) { 'fake_av_set' } | ||
let(:fault_domain) { 5 } | ||
let(:update_domain) { 1 } | ||
let(:availability_set_config) { Bosh::AzureCloud::AvailabilitySetConfig.new(name, update_domain, fault_domain) } | ||
let(:av_set_string) { "name: #{name}, platform_update_domain_count: #{update_domain} platform_fault_domain_count: #{fault_domain}" } | ||
|
||
it 'should return the correct string' do | ||
expect(availability_set_config.to_s).to eq(av_set_string) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Bosh::AzureCloud::LoadBalancerConfig do | ||
describe '#to_s' do | ||
context 'when called' do | ||
let(:name) { 'fake_name' } | ||
let(:resource_group_name) { 'fake_rg' } | ||
let(:lb_string) { "name: #{name}, resource_group_name: #{resource_group_name}" } | ||
let(:load_balancer_config) { Bosh::AzureCloud::LoadBalancerConfig.new(resource_group_name, name) } | ||
|
||
it 'should return the correct string' do | ||
expect(load_balancer_config.to_s).to eq(lb_string) | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it simple?
resource_group_name = vm_properties[LOAD_BALANCER_KEY][RESOURCE_GROUP_NAME_KEY] || global_azure_config.resource_group_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good suggestion.