-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Network] Load Balancer Outbound Rules #7114
Changes from all commits
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 |
---|---|---|
|
@@ -250,6 +250,19 @@ def validate_ip_tags(cmd, namespace): | |
namespace.ip_tags = ip_tags | ||
|
||
|
||
def validate_frontend_ip_configs(cmd, namespace): | ||
from msrestazure.tools import is_valid_resource_id | ||
if namespace.frontend_ip_configurations: | ||
config_ids = [] | ||
for item in namespace.frontend_ip_configurations: | ||
if not is_valid_resource_id(item): | ||
config_ids.append(_generate_lb_subproperty_id( | ||
cmd.cli_ctx, namespace, 'frontendIpConfigurations', item)) | ||
else: | ||
config_ids.append(item) | ||
namespace.frontend_ip_configurations = config_ids | ||
|
||
|
||
def validate_metadata(namespace): | ||
if namespace.metadata: | ||
namespace.metadata = dict(x.split('=', 1) for x in namespace.metadata) | ||
|
@@ -606,11 +619,21 @@ def process_lb_create_namespace(cmd, namespace): | |
|
||
|
||
def process_lb_frontend_ip_namespace(cmd, namespace): | ||
from msrestazure.tools import is_valid_resource_id, resource_id | ||
if namespace.subnet and namespace.public_ip_address: | ||
raise ValueError( | ||
'incorrect usage: --subnet NAME --vnet-name NAME | ' | ||
'--subnet ID | --public-ip NAME_OR_ID') | ||
|
||
if namespace.public_ip_prefix: | ||
if not is_valid_resource_id(namespace.public_ip_prefix): | ||
namespace.public_ip_prefix = resource_id( | ||
subscription=get_subscription_id(cmd.cli_ctx), | ||
resource_group=namespace.resource_group_name, | ||
namespace='Microsoft.Network', | ||
type='publicIpPrefixes', | ||
name=namespace.public_ip_prefix) | ||
|
||
if namespace.subnet: | ||
get_subnet_validator()(cmd, namespace) | ||
else: | ||
|
@@ -1095,3 +1118,14 @@ def process_nw_troubleshooting_show_namespace(cmd, namespace): | |
raise resource_usage | ||
|
||
get_network_watcher_from_resource(cmd, namespace) | ||
|
||
|
||
def process_lb_outbound_rule_namespace(cmd, namespace): | ||
from msrestazure.tools import is_valid_resource_id | ||
|
||
validate_frontend_ip_configs(cmd, namespace) | ||
|
||
if namespace.backend_address_pool: | ||
if not is_valid_resource_id(namespace.backend_address_pool): | ||
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. You can combine the two conditions |
||
namespace.backend_address_pool = _generate_lb_subproperty_id( | ||
cmd.cli_ctx, namespace, 'backendAddressPools', namespace.backend_address_pool) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,8 @@ | |
process_nw_troubleshooting_start_namespace, process_nw_troubleshooting_show_namespace, | ||
process_public_ip_create_namespace, process_tm_endpoint_create_namespace, | ||
process_vnet_create_namespace, process_vnet_gateway_create_namespace, process_vnet_gateway_update_namespace, | ||
process_vpn_connection_create_namespace, process_route_table_create_namespace) | ||
process_vpn_connection_create_namespace, process_route_table_create_namespace, | ||
process_lb_outbound_rule_namespace) | ||
|
||
|
||
# pylint: disable=too-many-locals, too-many-statements | ||
|
@@ -425,7 +426,7 @@ def _make_singular(value): | |
'inbound_nat_pools': 'inbound-nat-pool', | ||
'backend_address_pools': 'address-pool', | ||
'load_balancing_rules': 'rule', | ||
'probes': 'probe' | ||
'probes': 'probe', | ||
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. don't need the |
||
} | ||
for subresource, alias in property_map.items(): | ||
with self.command_group('network lb {}'.format(alias), network_util) as g: | ||
|
@@ -462,6 +463,15 @@ def _make_singular(value): | |
g.generic_update_command('update', child_collection_prop_name='probes', | ||
custom_func_name='set_lb_probe') | ||
|
||
with self.command_group('network lb outbound-rule', network_lb_sdk, min_api='2018-07-01') as g: | ||
g.custom_command('create', 'create_lb_outbound_rule', validator=process_lb_outbound_rule_namespace) | ||
g.generic_update_command('update', child_collection_prop_name='outbound_rules', | ||
custom_func_name='set_lb_outbound_rule', validator=process_lb_outbound_rule_namespace) | ||
|
||
with self.command_group('network lb outbound-rule', network_util, min_api='2018-07-01') as g: | ||
g.command('list', list_network_resource_property('load_balancers', 'outbound_rules')) | ||
g.show_command('show', get_network_resource_property_entry('load_balancers', 'outbound_rules')) | ||
g.command('delete', delete_network_resource_property_entry('load_balancers', 'outbound_rules')) | ||
# endregion | ||
|
||
# region LocalGateways | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1759,17 +1759,18 @@ def set_lb_inbound_nat_pool( | |
|
||
def create_lb_frontend_ip_configuration( | ||
cmd, resource_group_name, load_balancer_name, item_name, public_ip_address=None, | ||
subnet=None, virtual_network_name=None, private_ip_address=None, | ||
public_ip_prefix=None, subnet=None, virtual_network_name=None, private_ip_address=None, | ||
private_ip_address_allocation='dynamic', zone=None): | ||
FrontendIPConfiguration, PublicIPAddress, Subnet = cmd.get_models( | ||
'FrontendIPConfiguration', 'PublicIPAddress', 'Subnet') | ||
FrontendIPConfiguration, SubResource, Subnet = cmd.get_models( | ||
'FrontendIPConfiguration', 'SubResource', 'Subnet') | ||
ncf = network_client_factory(cmd.cli_ctx) | ||
lb = ncf.load_balancers.get(resource_group_name, load_balancer_name) | ||
new_config = FrontendIPConfiguration( | ||
name=item_name, | ||
private_ip_address=private_ip_address, | ||
private_ip_allocation_method=private_ip_address_allocation, | ||
public_ip_address=PublicIPAddress(id=public_ip_address) if public_ip_address else None, | ||
public_ip_address=SubResource(id=public_ip_address) if public_ip_address else None, | ||
public_ip_prefix=SubResource(id=public_ip_prefix) if public_ip_prefix else None, | ||
subnet=Subnet(id=subnet) if subnet else None) | ||
|
||
if zone and cmd.supported_api_version(min_api='2017-06-01'): | ||
|
@@ -1815,6 +1816,39 @@ def create_lb_backend_address_pool(cmd, resource_group_name, load_balancer_name, | |
return _get_property(poller.result().backend_address_pools, item_name) | ||
|
||
|
||
def create_lb_outbound_rule(cmd, resource_group_name, load_balancer_name, item_name, | ||
backend_address_pool, frontend_ip_configurations, outbound_ports=None, | ||
protocol=None, enable_tcp_reset=None, idle_timeout=None): | ||
OutboundRule, SubResource = cmd.get_models('OutboundRule', 'SubResource') | ||
client = network_client_factory(cmd.cli_ctx).load_balancers | ||
lb = client.get(resource_group_name, load_balancer_name) | ||
rule = OutboundRule( | ||
protocol=protocol, enable_tcp_reset=enable_tcp_reset, idle_timeout_in_minutes=idle_timeout, | ||
backend_address_pool=SubResource(id=backend_address_pool), | ||
frontend_ip_configurations=[SubResource(id=x) for x in frontend_ip_configurations] \ | ||
if frontend_ip_configurations else None, | ||
allocated_outbound_ports=outbound_ports, name=item_name) | ||
_upsert(lb, 'outbound_rules', rule, 'name') | ||
poller = client.create_or_update(resource_group_name, load_balancer_name, lb) | ||
return _get_property(poller.result().outbound_rules, item_name) | ||
|
||
|
||
def set_lb_outbound_rule(instance, cmd, parent, item_name, protocol=None, outbound_ports=None, | ||
idle_timeout=None, frontend_ip_configurations=None, enable_tcp_reset=None, | ||
backend_address_pool=None): | ||
SubResource = cmd.get_models('SubResource') | ||
_set_param(instance, 'protocol', protocol) | ||
_set_param(instance, 'allocated_outbound_ports', outbound_ports) | ||
_set_param(instance, 'idle_timeout_in_minutes', idle_timeout) | ||
_set_param(instance, 'enable_tcp_reset', enable_tcp_reset) | ||
_set_param(instance, 'backend_address_pool', SubResource(id=backend_address_pool) \ | ||
if backend_address_pool else None) | ||
_set_param(instance, 'frontend_ip_configurations', \ | ||
[SubResource(x) for x in frontend_ip_configurations] if frontend_ip_configurations else None) | ||
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. shorter if this is |
||
|
||
return parent | ||
|
||
|
||
def create_lb_probe(cmd, resource_group_name, load_balancer_name, item_name, protocol, port, | ||
path=None, interval=None, threshold=None): | ||
Probe = cmd.get_models('Probe') | ||
|
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.
You can combine these two conditions.