Skip to content

Commit 83a89db

Browse files
authored
[Network-Manager] Fix #7143: az network manager connect-config create/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
1 parent f1f98fc commit 83a89db

File tree

8 files changed

+100
-61
lines changed

8 files changed

+100
-61
lines changed

src/network-manager/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
Release History
44
===============
5+
1.0.1
6+
+++++
7+
* `az network manager connect-config`: Fix cross-tenant resource id for `--hubs`
8+
59
1.0.0
610
+++++
711
* Fix example and help info (Fix #6788)

src/network-manager/azext_network_manager/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
# Changes may cause incorrect behavior and will be lost if the code is
88
# regenerated.
99
# --------------------------------------------------------------------------
10-
10+
# pylint disable=unused-import
1111
from azure.cli.core import AzCommandsLoader
12-
import azext_network_manager._help
12+
import azext_network_manager._help # pylint: disable=unused-import
1313

1414

1515
class NetworkManagementClientCommandsLoader(AzCommandsLoader):
1616

1717
def __init__(self, cli_ctx=None):
1818
from azure.cli.core.commands import CliCommandType
1919
custom_command_type = CliCommandType(operations_tmpl='azext_network_manager.custom#{}')
20-
super(NetworkManagementClientCommandsLoader, self).__init__(cli_ctx=cli_ctx,
21-
custom_command_type=custom_command_type)
20+
super().__init__(cli_ctx=cli_ctx, custom_command_type=custom_command_type)
2221

2322
def load_command_table(self, args):
2423
from azext_network_manager.commands import load_command_table

src/network-manager/azext_network_manager/_params.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def load_arguments(self, _):
4242
c.argument('description', type=str, help='A description of the network manager.')
4343
c.argument('network_manager_scopes', action=AddNetworkManagerScopes, nargs='+', help='Scope of Network '
4444
'Manager.')
45-
c.argument('network_manager_scope_accesses', options_list=['--scope-accesses'], nargs='+', help='Scope Access. Available value: SecurityAdmin, '
46-
'Connectivity.')
45+
c.argument('network_manager_scope_accesses', options_list=['--scope-accesses'], nargs='+',
46+
help='Scope Access. Available value: SecurityAdmin, Connectivity.')
4747

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

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

119119
with self.argument_context('network manager security-admin-config rule-collection rule create') as c:
120-
c.argument('access', type=str, help='Indicates the access allowed for this particular rule.', arg_type=get_enum_type(['Allow', 'Deny', 'AlwaysAllow']))
120+
c.argument('access', type=str, help='Indicates the access allowed for this particular rule.',
121+
arg_type=get_enum_type(['Allow', 'Deny', 'AlwaysAllow']))
121122
c.argument('flag', type=str, help='Default rule flag.')
122-
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']))
123+
c.argument('kind', type=str, help='Required. Whether the rule is custom or default.Constant filled by server.',
124+
arg_type=get_enum_type(['Custom', 'Default']))
123125
c.argument('priority', type=int, help='The priority of the rule.')
124-
c.argument('sources', action=AddSource, nargs='+', help='The CIDR or source IP ranges. Address prefix type is an enum with values IPPrefix or ServiceTag')
126+
c.argument('sources', action=AddSource, nargs='+', help='The CIDR or source IP ranges. Address prefix type is'
127+
' an enum with values IPPrefix or ServiceTag')
125128
c.argument('destinations', action=AddDestination, nargs='+', help='The destination address prefixes. CIDR or '
126129
'destination IP ranges. Address prefix type is an enum with values IPPrefix or ServiceTag')
127130
c.argument('description', type=str, help='A description for this rule. Restricted to 140 chars.')
128131
c.argument('protocol', arg_type=get_enum_type(['Tcp', 'Udp', 'Icmp', 'Esp', 'Any', 'Ah']), help='Network '
129132
'protocol this rule applies to.')
130133
c.argument('source_port_ranges', nargs='+', help='The source port ranges.')
131-
c.argument('destination_port_ranges', options_list=['--dest-port-ranges'], nargs='+', help='The destination port ranges.')
134+
c.argument('destination_port_ranges', options_list=['--dest-port-ranges'], nargs='+',
135+
help='The destination port ranges.')
132136
c.argument('direction', arg_type=get_enum_type(['Inbound', 'Outbound']), help='Indicates if the traffic '
133137
'matched against the rule in inbound or outbound.')
134138

135139
with self.argument_context('network manager security-admin-config rule-collection rule update') as c:
136-
c.argument('access', type=str, help='Indicates the access allowed for this particular rule.', arg_type=get_enum_type(['Allow', 'Deny', 'AlwaysAllow']))
140+
c.argument('access', type=str, help='Indicates the access allowed for this particular rule.',
141+
arg_type=get_enum_type(['Allow', 'Deny', 'AlwaysAllow']))
137142
c.argument('flag', type=str, help='Default rule flag.')
138-
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']))
143+
c.argument('kind', type=str, help='Required. Whether the rule is custom or default.Constant filled by server.',
144+
arg_type=get_enum_type(['Custom', 'Default']))
139145
c.argument('priority', type=int, help='The priority of the rule.')
140-
c.argument('sources', action=AddSource, nargs='+', help='The CIDR or source IP ranges. Address prefix type is an enum with values IPPrefix or ServiceTag')
146+
c.argument('sources', action=AddSource, nargs='+', help='The CIDR or source IP ranges. Address prefix type is '
147+
'an enum with values IPPrefix or ServiceTag')
141148
c.argument('destinations', action=AddDestination, nargs='+', help='The destination address prefixes. CIDR or '
142149
'destination IP ranges. Address prefix type is an enum with values IPPrefix or ServiceTag')
143150
c.argument('description', type=str, help='A description for this rule. Restricted to 140 chars.')
144151
c.argument('protocol', arg_type=get_enum_type(['Tcp', 'Udp', 'Icmp', 'Esp', 'Any', 'Ah']), help='Network '
145152
'protocol this rule applies to.')
146153
c.argument('source_port_ranges', nargs='+', help='The source port ranges.')
147-
c.argument('destination_port_ranges', options_list=['--dest-port-ranges'], nargs='+', help='The destination port ranges.')
154+
c.argument('destination_port_ranges', options_list=['--dest-port-ranges'], nargs='+',
155+
help='The destination port ranges.')
148156
c.argument('direction', arg_type=get_enum_type(['Inbound', 'Outbound']), help='Indicates if the traffic '
149157
'matched against the rule in inbound or outbound.')

src/network-manager/azext_network_manager/action.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def __call__(self, parser, namespace, values, option_string=None):
1919
action = self.get_action(values, option_string)
2020
namespace.network_manager_scopes = action
2121

22-
def get_action(self, values, option_string): # pylint: disable=no-self-use
22+
def get_action(self, values, option_string):
2323
try:
2424
properties = defaultdict(list)
2525
for (k, v) in (x.split('=', 1) for x in values):
2626
properties[k].append(v)
2727
properties = dict(properties)
28-
except ValueError:
29-
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
28+
except ValueError as exc:
29+
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
3030
d = {}
3131
for k in properties:
3232
kl = k.lower()
@@ -36,24 +36,24 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
3636
elif kl == 'subscriptions':
3737
d['subscriptions'] = v
3838
else:
39-
raise CLIError('Unsupported Key {} is provided for parameter network_manager_scopes. All possible keys '
40-
'are: management-groups, subscriptions'.format(k))
39+
raise CLIError(f'Unsupported Key {k} is provided for parameter network_manager_scopes. '
40+
f'All possible keys are: management-groups, subscriptions')
4141
return d
4242

4343

4444
class AddConnectivityconfigurationsAppliesToGroups(argparse._AppendAction):
4545
def __call__(self, parser, namespace, values, option_string=None):
4646
action = self.get_action(values, option_string)
47-
super(AddConnectivityconfigurationsAppliesToGroups, self).__call__(parser, namespace, action, option_string)
47+
super().__call__(parser, namespace, action, option_string)
4848

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

7474

7575
class AddGroupMembers(argparse._AppendAction):
7676
def __call__(self, parser, namespace, values, option_string=None):
7777
action = self.get_action(values, option_string)
78-
super(AddGroupMembers, self).__call__(parser, namespace, action, option_string)
78+
super().__call__(parser, namespace, action, option_string)
7979

80-
def get_action(self, values, option_string): # pylint: disable=no-self-use
80+
def get_action(self, values, option_string):
8181
try:
8282
properties = defaultdict(list)
8383
for (k, v) in (x.split('=', 1) for x in values):
8484
properties[k].append(v)
8585
properties = dict(properties)
86-
except ValueError:
87-
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
86+
except ValueError as exc:
87+
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
8888
d = {}
8989
for k in properties:
9090
kl = k.lower()
@@ -94,24 +94,24 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
9494
elif kl == 'resource-type':
9595
d['resource_type'] = v[0]
9696
else:
97-
raise CLIError('Unsupported Key {} is provided for parameter group_members. All possible keys are: '
98-
'resource-id, resource-type'.format(k))
97+
raise CLIError(f'Unsupported Key {k} is provided for parameter group_members. All possible keys are: '
98+
'resource-id, resource-type')
9999
return d
100100

101101

102102
class AddSource(argparse._AppendAction):
103103
def __call__(self, parser, namespace, values, option_string=None):
104104
action = self.get_action(values, option_string)
105-
super(AddSource, self).__call__(parser, namespace, action, option_string)
105+
super().__call__(parser, namespace, action, option_string)
106106

107-
def get_action(self, values, option_string): # pylint: disable=no-self-use
107+
def get_action(self, values, option_string):
108108
try:
109109
properties = defaultdict(list)
110110
for (k, v) in (x.split('=', 1) for x in values):
111111
properties[k].append(v)
112112
properties = dict(properties)
113-
except ValueError:
114-
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
113+
except ValueError as exc:
114+
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
115115
d = {}
116116
for k in properties:
117117
kl = k.lower()
@@ -121,24 +121,24 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
121121
elif kl == 'address-prefix-type':
122122
d['address_prefix_type'] = v[0]
123123
else:
124-
raise CLIError('Unsupported Key {} is provided for parameter source. All possible keys are: '
125-
'address-prefix, address-prefix-type'.format(k))
124+
raise CLIError(f'Unsupported Key {k} is provided for parameter source. All possible keys are: '
125+
'address-prefix, address-prefix-type')
126126
return d
127127

128128

129129
class AddDestination(argparse._AppendAction):
130130
def __call__(self, parser, namespace, values, option_string=None):
131131
action = self.get_action(values, option_string)
132-
super(AddDestination, self).__call__(parser, namespace, action, option_string)
132+
super().__call__(parser, namespace, action, option_string)
133133

134-
def get_action(self, values, option_string): # pylint: disable=no-self-use
134+
def get_action(self, values, option_string):
135135
try:
136136
properties = defaultdict(list)
137137
for (k, v) in (x.split('=', 1) for x in values):
138138
properties[k].append(v)
139139
properties = dict(properties)
140-
except ValueError:
141-
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
140+
except ValueError as exc:
141+
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from exc
142142
d = {}
143143
for k in properties:
144144
kl = k.lower()
@@ -148,6 +148,6 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
148148
elif kl == 'address-prefix-type':
149149
d['address_prefix_type'] = v[0]
150150
else:
151-
raise CLIError('Unsupported Key {} is provided for parameter destination. All possible keys are: '
152-
'address-prefix, address-prefix-type'.format(k))
151+
raise CLIError(f'Unsupported Key {k} is provided for parameter destination. All possible keys are: '
152+
'address-prefix, address-prefix-type')
153153
return d

src/network-manager/azext_network_manager/commands.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# regenerated.
99
# --------------------------------------------------------------------------
1010
# pylint: disable=too-many-statements
11-
# pylint: disable=too-many-locals option_length_too_long
11+
# pylint: disable=too-many-locals
1212

1313

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

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

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

4447
with self.command_group("network manager connection management-group"):
4548
from .custom import ConnectionManagementGroupCreate
46-
self.command_table["network manager connection management-group create"] = ConnectionManagementGroupCreate(loader=self)
49+
self.command_table["network manager connection management-group create"] = \
50+
ConnectionManagementGroupCreate(loader=self)

0 commit comments

Comments
 (0)