Skip to content

Commit

Permalink
[Network-Manager] Fix #7143: `az network manager connect-config creat…
Browse files Browse the repository at this point in the history
…e/update`: Fix to allow cross tenant resource id for `--hub` (#7149)

* allow cross tenant resource id for `az network manager connect-config` `--hubs`

* allow cross tenant resource id for `az network manager connect-config update` `--hubs`

* style

* lint

* lint

* lint

* lint
  • Loading branch information
calvinhzy committed Jan 5, 2024
1 parent f1f98fc commit 83a89db
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 61 deletions.
4 changes: 4 additions & 0 deletions src/network-manager/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Release History
===============
1.0.1
+++++
* `az network manager connect-config`: Fix cross-tenant resource id for `--hubs`

1.0.0
+++++
* Fix example and help info (Fix #6788)
Expand Down
7 changes: 3 additions & 4 deletions src/network-manager/azext_network_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

# pylint disable=unused-import
from azure.cli.core import AzCommandsLoader
import azext_network_manager._help
import azext_network_manager._help # pylint: disable=unused-import


class NetworkManagementClientCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_command_type = CliCommandType(operations_tmpl='azext_network_manager.custom#{}')
super(NetworkManagementClientCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=custom_command_type)
super().__init__(cli_ctx=cli_ctx, custom_command_type=custom_command_type)

def load_command_table(self, args):
from azext_network_manager.commands import load_command_table
Expand Down
32 changes: 20 additions & 12 deletions src/network-manager/azext_network_manager/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def load_arguments(self, _):
c.argument('description', type=str, help='A description of the network manager.')
c.argument('network_manager_scopes', action=AddNetworkManagerScopes, nargs='+', help='Scope of Network '
'Manager.')
c.argument('network_manager_scope_accesses', options_list=['--scope-accesses'], nargs='+', help='Scope Access. Available value: SecurityAdmin, '
'Connectivity.')
c.argument('network_manager_scope_accesses', options_list=['--scope-accesses'], nargs='+',
help='Scope Access. Available value: SecurityAdmin, Connectivity.')

with self.argument_context('network manager update') as c:
c.argument('network_manager_name', options_list=['--name', '-n', '--network-manager-name'], type=str,
Expand All @@ -54,8 +54,8 @@ def load_arguments(self, _):
c.argument('description', type=str, help='A description of the network manager.')
c.argument('network_manager_scopes', action=AddNetworkManagerScopes, nargs='+', help='Scope of Network '
'Manager.')
c.argument('network_manager_scope_accesses', options_list=['--scope-accesses'], nargs='+', help='Scope Access. Available value: SecurityAdmin, '
'Connectivity.')
c.argument('network_manager_scope_accesses', options_list=['--scope-accesses'], nargs='+',
help='Scope Access. Available value: SecurityAdmin, Connectivity.')
c.ignore('parameters')

with self.argument_context('network manager connect-config create') as c:
Expand Down Expand Up @@ -117,33 +117,41 @@ def load_arguments(self, _):
c.argument('rule_collection_name', type=str, help='The name of the admin rule collection.')

with self.argument_context('network manager security-admin-config rule-collection rule create') as c:
c.argument('access', type=str, help='Indicates the access allowed for this particular rule.', arg_type=get_enum_type(['Allow', 'Deny', 'AlwaysAllow']))
c.argument('access', type=str, help='Indicates the access allowed for this particular rule.',
arg_type=get_enum_type(['Allow', 'Deny', 'AlwaysAllow']))
c.argument('flag', type=str, help='Default rule flag.')
c.argument('kind', type=str, help='Required. Whether the rule is custom or default.Constant filled by server.', arg_type=get_enum_type(['Custom', 'Default']))
c.argument('kind', type=str, help='Required. Whether the rule is custom or default.Constant filled by server.',
arg_type=get_enum_type(['Custom', 'Default']))
c.argument('priority', type=int, help='The priority of the rule.')
c.argument('sources', action=AddSource, nargs='+', help='The CIDR or source IP ranges. Address prefix type is an enum with values IPPrefix or ServiceTag')
c.argument('sources', action=AddSource, nargs='+', help='The CIDR or source IP ranges. Address prefix type is'
' an enum with values IPPrefix or ServiceTag')
c.argument('destinations', action=AddDestination, nargs='+', help='The destination address prefixes. CIDR or '
'destination IP ranges. Address prefix type is an enum with values IPPrefix or ServiceTag')
c.argument('description', type=str, help='A description for this rule. Restricted to 140 chars.')
c.argument('protocol', arg_type=get_enum_type(['Tcp', 'Udp', 'Icmp', 'Esp', 'Any', 'Ah']), help='Network '
'protocol this rule applies to.')
c.argument('source_port_ranges', nargs='+', help='The source port ranges.')
c.argument('destination_port_ranges', options_list=['--dest-port-ranges'], nargs='+', help='The destination port ranges.')
c.argument('destination_port_ranges', options_list=['--dest-port-ranges'], nargs='+',
help='The destination port ranges.')
c.argument('direction', arg_type=get_enum_type(['Inbound', 'Outbound']), help='Indicates if the traffic '
'matched against the rule in inbound or outbound.')

with self.argument_context('network manager security-admin-config rule-collection rule update') as c:
c.argument('access', type=str, help='Indicates the access allowed for this particular rule.', arg_type=get_enum_type(['Allow', 'Deny', 'AlwaysAllow']))
c.argument('access', type=str, help='Indicates the access allowed for this particular rule.',
arg_type=get_enum_type(['Allow', 'Deny', 'AlwaysAllow']))
c.argument('flag', type=str, help='Default rule flag.')
c.argument('kind', type=str, help='Required. Whether the rule is custom or default.Constant filled by server.', arg_type=get_enum_type(['Custom', 'Default']))
c.argument('kind', type=str, help='Required. Whether the rule is custom or default.Constant filled by server.',
arg_type=get_enum_type(['Custom', 'Default']))
c.argument('priority', type=int, help='The priority of the rule.')
c.argument('sources', action=AddSource, nargs='+', help='The CIDR or source IP ranges. Address prefix type is an enum with values IPPrefix or ServiceTag')
c.argument('sources', action=AddSource, nargs='+', help='The CIDR or source IP ranges. Address prefix type is '
'an enum with values IPPrefix or ServiceTag')
c.argument('destinations', action=AddDestination, nargs='+', help='The destination address prefixes. CIDR or '
'destination IP ranges. Address prefix type is an enum with values IPPrefix or ServiceTag')
c.argument('description', type=str, help='A description for this rule. Restricted to 140 chars.')
c.argument('protocol', arg_type=get_enum_type(['Tcp', 'Udp', 'Icmp', 'Esp', 'Any', 'Ah']), help='Network '
'protocol this rule applies to.')
c.argument('source_port_ranges', nargs='+', help='The source port ranges.')
c.argument('destination_port_ranges', options_list=['--dest-port-ranges'], nargs='+', help='The destination port ranges.')
c.argument('destination_port_ranges', options_list=['--dest-port-ranges'], nargs='+',
help='The destination port ranges.')
c.argument('direction', arg_type=get_enum_type(['Inbound', 'Outbound']), help='Indicates if the traffic '
'matched against the rule in inbound or outbound.')
58 changes: 29 additions & 29 deletions src/network-manager/azext_network_manager/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.network_manager_scopes = action

def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
except ValueError as exc:
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
d = {}
for k in properties:
kl = k.lower()
Expand All @@ -36,24 +36,24 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
elif kl == 'subscriptions':
d['subscriptions'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter network_manager_scopes. All possible keys '
'are: management-groups, subscriptions'.format(k))
raise CLIError(f'Unsupported Key {k} is provided for parameter network_manager_scopes. '
f'All possible keys are: management-groups, subscriptions')
return d


class AddConnectivityconfigurationsAppliesToGroups(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddConnectivityconfigurationsAppliesToGroups, self).__call__(parser, namespace, action, option_string)
super().__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
except ValueError as exc:
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
d = {}
for k in properties:
kl = k.lower()
Expand All @@ -67,24 +67,24 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
elif kl == 'group-connectivity':
d['group_connectivity'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter applies_to_groups. All possible keys are: '
'network-group-id, use-hub-gateway, is-global, group-connectivity'.format(k))
raise CLIError(f'Unsupported Key {k} is provided for parameter applies_to_groups. All possible keys '
f'are: network-group-id, use-hub-gateway, is-global, group-connectivity')
return d


class AddGroupMembers(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddGroupMembers, self).__call__(parser, namespace, action, option_string)
super().__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
except ValueError as exc:
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
d = {}
for k in properties:
kl = k.lower()
Expand All @@ -94,24 +94,24 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
elif kl == 'resource-type':
d['resource_type'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter group_members. All possible keys are: '
'resource-id, resource-type'.format(k))
raise CLIError(f'Unsupported Key {k} is provided for parameter group_members. All possible keys are: '
'resource-id, resource-type')
return d


class AddSource(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddSource, self).__call__(parser, namespace, action, option_string)
super().__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
except ValueError as exc:
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
d = {}
for k in properties:
kl = k.lower()
Expand All @@ -121,24 +121,24 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
elif kl == 'address-prefix-type':
d['address_prefix_type'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter source. All possible keys are: '
'address-prefix, address-prefix-type'.format(k))
raise CLIError(f'Unsupported Key {k} is provided for parameter source. All possible keys are: '
'address-prefix, address-prefix-type')
return d


class AddDestination(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddDestination, self).__call__(parser, namespace, action, option_string)
super().__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
except ValueError as exc:
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
d = {}
for k in properties:
kl = k.lower()
Expand All @@ -148,6 +148,6 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
elif kl == 'address-prefix-type':
d['address_prefix_type'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter destination. All possible keys are: '
'address-prefix, address-prefix-type'.format(k))
raise CLIError(f'Unsupported Key {k} is provided for parameter destination. All possible keys are: '
'address-prefix, address-prefix-type')
return d
8 changes: 6 additions & 2 deletions src/network-manager/azext_network_manager/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=too-many-statements
# pylint: disable=too-many-locals option_length_too_long
# pylint: disable=too-many-locals


def load_command_table(self, _):
Expand All @@ -18,6 +18,9 @@ def load_command_table(self, _):
g.custom_command('update', 'network_manager_update')

with self.command_group('network manager connect-config') as g:
from .custom import ConnectConfigCreate, ConnectConfigUpdate
self.command_table["network manager connect-config create"] = ConnectConfigCreate(loader=self)
self.command_table["network manager connect-config update"] = ConnectConfigUpdate(loader=self)
g.custom_command('create', 'network_manager_connect_config_create')
g.custom_command('update', 'network_manager_connect_config_update')

Expand All @@ -43,4 +46,5 @@ def load_command_table(self, _):

with self.command_group("network manager connection management-group"):
from .custom import ConnectionManagementGroupCreate
self.command_table["network manager connection management-group create"] = ConnectionManagementGroupCreate(loader=self)
self.command_table["network manager connection management-group create"] = \
ConnectionManagementGroupCreate(loader=self)
Loading

0 comments on commit 83a89db

Please sign in to comment.