2
2
# Copyright (c) Microsoft Corporation. All rights reserved.
3
3
# ---------------------------------------------------------
4
4
5
- from typing import Any , Dict , Optional
5
+ from typing import Any , Dict , Optional , List
6
6
7
7
from azure .ai .ml ._restclient .v2022_12_01_preview .models import (
8
8
ManagedNetworkSettings as RestManagedNetwork ,
19
19
20
20
@experimental
21
21
class OutboundRule :
22
+ """Base class for Outbound Rules, should not be instantiated directly.
23
+
24
+ :param rule_name: Name of the outbound rule.
25
+ :type rule_name: str
26
+ :param type: Type of the outbound rule. Supported types are "FQDN", "PrivateEndpoint", "ServiceTag"
27
+ :type type: str
28
+ """
29
+
22
30
def __init__ (
23
- self , type : str = None , category : str = OutboundRuleCategory .USER_DEFINED # pylint: disable=redefined-builtin
31
+ self ,
32
+ * ,
33
+ rule_name : str = None ,
34
+ ** kwargs ,
24
35
) -> None :
25
- self .type = type
26
- self .category = category
36
+ self .rule_name = rule_name
37
+ self .type = kwargs .pop ("type" , None )
38
+ self .category = kwargs .pop ("category" , OutboundRuleCategory .USER_DEFINED )
27
39
28
40
@classmethod
29
- def _from_rest_object (cls , rest_obj : Any ) -> "OutboundRule" :
41
+ def _from_rest_object (cls , rest_obj : Any , rule_name : str ) -> "OutboundRule" :
30
42
if isinstance (rest_obj , RestFqdnOutboundRule ):
31
- rule = FqdnDestination (destination = rest_obj .destination )
43
+ rule = FqdnDestination (destination = rest_obj .destination , rule_name = rule_name )
32
44
rule .category = rest_obj .category
33
45
return rule
34
46
if isinstance (rest_obj , RestPrivateEndpointOutboundRule ):
35
47
rule = PrivateEndpointDestination (
36
48
service_resource_id = rest_obj .destination .service_resource_id ,
37
49
subresource_target = rest_obj .destination .subresource_target ,
38
50
spark_enabled = rest_obj .destination .spark_enabled ,
51
+ rule_name = rule_name ,
39
52
)
40
53
rule .category = rest_obj .category
41
54
return rule
@@ -44,37 +57,44 @@ def _from_rest_object(cls, rest_obj: Any) -> "OutboundRule":
44
57
service_tag = rest_obj .destination .service_tag ,
45
58
protocol = rest_obj .destination .protocol ,
46
59
port_ranges = rest_obj .destination .port_ranges ,
60
+ rule_name = rule_name ,
47
61
)
48
62
rule .category = rest_obj .category
49
63
return rule
50
64
51
65
52
66
@experimental
53
67
class FqdnDestination (OutboundRule ):
54
- def __init__ (self , destination : str , category : str = OutboundRuleCategory . USER_DEFINED ) -> None :
68
+ def __init__ (self , * , rule_name : str , destination : str , ** kwargs ) -> None :
55
69
self .destination = destination
56
- OutboundRule .__init__ (self , type = OutboundRuleType .FQDN , category = category )
70
+ category = kwargs .pop ("category" , OutboundRuleCategory .USER_DEFINED )
71
+ OutboundRule .__init__ (self , type = OutboundRuleType .FQDN , category = category , rule_name = rule_name )
57
72
58
73
def _to_rest_object (self ) -> RestFqdnOutboundRule :
59
74
return RestFqdnOutboundRule (type = self .type , category = self .category , destination = self .destination )
60
75
61
76
def _to_dict (self ) -> Dict :
62
- return {"type" : OutboundRuleType .FQDN , "category" : self .category , "destination" : self .destination }
77
+ return {
78
+ self .rule_name : {"type" : OutboundRuleType .FQDN , "category" : self .category , "destination" : self .destination }
79
+ }
63
80
64
81
65
82
@experimental
66
83
class PrivateEndpointDestination (OutboundRule ):
67
84
def __init__ (
68
85
self ,
86
+ * ,
87
+ rule_name : str ,
69
88
service_resource_id : str ,
70
89
subresource_target : str ,
71
90
spark_enabled : bool = False ,
72
- category : str = OutboundRuleCategory . USER_DEFINED ,
91
+ ** kwargs ,
73
92
) -> None :
74
93
self .service_resource_id = service_resource_id
75
94
self .subresource_target = subresource_target
76
95
self .spark_enabled = spark_enabled
77
- OutboundRule .__init__ (self , OutboundRuleType .PRIVATE_ENDPOINT , category = category )
96
+ category = kwargs .pop ("category" , OutboundRuleCategory .USER_DEFINED )
97
+ OutboundRule .__init__ (self , type = OutboundRuleType .PRIVATE_ENDPOINT , category = category , rule_name = rule_name )
78
98
79
99
def _to_rest_object (self ) -> RestPrivateEndpointOutboundRule :
80
100
return RestPrivateEndpointOutboundRule (
@@ -89,25 +109,34 @@ def _to_rest_object(self) -> RestPrivateEndpointOutboundRule:
89
109
90
110
def _to_dict (self ) -> Dict :
91
111
return {
92
- "type" : OutboundRuleType .PRIVATE_ENDPOINT ,
93
- "category" : self .category ,
94
- "destination" : {
95
- "service_resource_id" : self .service_resource_id ,
96
- "subresource_target" : self .subresource_target ,
97
- "spark_enabled" : self .spark_enabled ,
98
- },
112
+ self .rule_name : {
113
+ "type" : OutboundRuleType .PRIVATE_ENDPOINT ,
114
+ "category" : self .category ,
115
+ "destination" : {
116
+ "service_resource_id" : self .service_resource_id ,
117
+ "subresource_target" : self .subresource_target ,
118
+ "spark_enabled" : self .spark_enabled ,
119
+ },
120
+ }
99
121
}
100
122
101
123
102
124
@experimental
103
125
class ServiceTagDestination (OutboundRule ):
104
126
def __init__ (
105
- self , service_tag : str , protocol : str , port_ranges : str , category : str = OutboundRuleCategory .USER_DEFINED
127
+ self ,
128
+ * ,
129
+ rule_name : str ,
130
+ service_tag : str ,
131
+ protocol : str ,
132
+ port_ranges : str ,
133
+ ** kwargs ,
106
134
) -> None :
107
135
self .service_tag = service_tag
108
136
self .protocol = protocol
109
137
self .port_ranges = port_ranges
110
- OutboundRule .__init__ (self , OutboundRuleType .SERVICE_TAG , category = category )
138
+ category = kwargs .pop ("category" , OutboundRuleCategory .USER_DEFINED )
139
+ OutboundRule .__init__ (self , type = OutboundRuleType .SERVICE_TAG , category = category , rule_name = rule_name )
111
140
112
141
def _to_rest_object (self ) -> RestServiceTagOutboundRule :
113
142
return RestServiceTagOutboundRule (
@@ -120,13 +149,15 @@ def _to_rest_object(self) -> RestServiceTagOutboundRule:
120
149
121
150
def _to_dict (self ) -> Dict :
122
151
return {
123
- "type" : OutboundRuleType .SERVICE_TAG ,
124
- "category" : self .category ,
125
- "destination" : {
126
- "service_tag" : self .service_tag ,
127
- "protocol" : self .protocol ,
128
- "port_ranges" : self .port_ranges ,
129
- },
152
+ self .rule_name : {
153
+ "type" : OutboundRuleType .SERVICE_TAG ,
154
+ "category" : self .category ,
155
+ "destination" : {
156
+ "service_tag" : self .service_tag ,
157
+ "protocol" : self .protocol ,
158
+ "port_ranges" : self .port_ranges ,
159
+ },
160
+ }
130
161
}
131
162
132
163
@@ -135,7 +166,7 @@ class ManagedNetwork:
135
166
def __init__ (
136
167
self ,
137
168
isolation_mode : str = IsolationMode .DISABLED ,
138
- outbound_rules : Optional [Dict [ str , OutboundRule ]] = None ,
169
+ outbound_rules : Optional [List [ OutboundRule ]] = None ,
139
170
network_id : Optional [str ] = None ,
140
171
) -> None :
141
172
self .isolation_mode = isolation_mode
@@ -145,8 +176,8 @@ def __init__(
145
176
def _to_rest_object (self ) -> RestManagedNetwork :
146
177
rest_outbound_rules = (
147
178
{
148
- rule_name : self . outbound_rules [ rule_name ] ._to_rest_object () # pylint: disable=protected-access
149
- for rule_name in self .outbound_rules
179
+ outbound_rule . rule_name : outbound_rule ._to_rest_object () # pylint: disable=protected-access
180
+ for outbound_rule in self .outbound_rules
150
181
}
151
182
if self .outbound_rules
152
183
else None
@@ -156,12 +187,12 @@ def _to_rest_object(self) -> RestManagedNetwork:
156
187
@classmethod
157
188
def _from_rest_object (cls , obj : RestManagedNetwork ) -> "ManagedNetwork" :
158
189
from_rest_outbound_rules = (
159
- {
160
- rule_name : OutboundRule ._from_rest_object ( # pylint: disable=protected-access
161
- obj .outbound_rules [rule_name ]
190
+ [
191
+ OutboundRule ._from_rest_object ( # pylint: disable=protected-access
192
+ obj .outbound_rules [rule_name ], rule_name = rule_name
162
193
)
163
194
for rule_name in obj .outbound_rules
164
- }
195
+ ]
165
196
if obj .outbound_rules
166
197
else {}
167
198
)
0 commit comments