21
21
_EXIT_API_ERROR = 1
22
22
_EXIT_EVENT_UNKNOWN = 2
23
23
24
- OUTSIDE_NETWORK_NAME = "OUTSIDE"
25
-
26
24
27
25
class Event (StrEnum ):
28
26
ProjectCreate = "identity.project.created"
@@ -50,55 +48,7 @@ def argument_parser():
50
48
return parser
51
49
52
50
53
- def _create_outside_network (conn : Connection , project_id : uuid .UUID ):
54
- network = _find_outside_network (conn , project_id .hex )
55
- if network :
56
- logger .info (
57
- "%s Network %s already exists for this tenant" ,
58
- OUTSIDE_NETWORK_NAME ,
59
- network .id ,
60
- )
61
- else :
62
- payload = {
63
- "project_id" : project_id .hex ,
64
- "name" : OUTSIDE_NETWORK_NAME ,
65
- "router:external" : False ,
66
- }
67
- network = conn .network .create_network (** payload ) # type: ignore
68
- logger .info (
69
- "Created %s Network %s for tenant" , OUTSIDE_NETWORK_NAME , network .id
70
- )
71
- conn .network .create_rbac_policy ( # type: ignore
72
- object_type = "network" ,
73
- object_id = network .id ,
74
- action = "access_as_external" ,
75
- target_project_id = project_id .hex ,
76
- )
77
- conn .network .create_rbac_policy ( # type: ignore
78
- object_type = "network" ,
79
- object_id = network .id ,
80
- action = "access_as_shared" ,
81
- target_project_id = project_id .hex ,
82
- )
83
-
84
-
85
- def _delete_outside_network (conn : Connection , project_id : uuid .UUID ):
86
- network = _find_outside_network (conn , project_id .hex )
87
- if network :
88
- conn .delete_network (network .id )
89
- logger .info (
90
- "Deleted %s Network %s for this tenant" , OUTSIDE_NETWORK_NAME , network .id
91
- )
92
-
93
-
94
- def _find_outside_network (conn : Connection , project_id : str ):
95
- return conn .network .find_network ( # type: ignore
96
- project_id = project_id ,
97
- name_or_id = OUTSIDE_NETWORK_NAME ,
98
- )
99
-
100
-
101
- def _tenant_attrs (conn : Connection , project_id : uuid .UUID ) -> tuple [str , str , bool ]:
51
+ def _tenant_attrs (conn : Connection , project_id : uuid .UUID ) -> tuple [str , str ]:
102
52
project = conn .identity .get_project (project_id .hex ) # type: ignore
103
53
domain_id = project .domain_id
104
54
is_default_domain = domain_id == "default"
@@ -110,7 +60,7 @@ def _tenant_attrs(conn: Connection, project_id: uuid.UUID) -> tuple[str, str, bo
110
60
domain_name = domain .name
111
61
112
62
tenant_name = f"{ domain_name } :{ project .name } "
113
- return tenant_name , str (project .description ), is_default_domain
63
+ return tenant_name , str (project .description )
114
64
115
65
116
66
def _unmap_tenant_from_devices (
@@ -127,14 +77,12 @@ def handle_project_create(
127
77
conn : Connection , nautobot : pynautobot .api , project_id : uuid .UUID
128
78
) -> int :
129
79
logger .info ("got request to create tenant %s" , project_id .hex )
130
- tenant_name , tenant_description , is_default_domain = _tenant_attrs (conn , project_id )
80
+ tenant_name , tenant_description = _tenant_attrs (conn , project_id )
131
81
132
82
try :
133
83
tenant = nautobot .tenancy .tenants .create (
134
84
id = str (project_id ), name = tenant_name , description = tenant_description
135
85
)
136
- if is_default_domain :
137
- _create_outside_network (conn , project_id )
138
86
except Exception :
139
87
logger .exception (
140
88
"Unable to create project %s / %s" , str (project_id ), tenant_name
@@ -149,7 +97,7 @@ def handle_project_update(
149
97
conn : Connection , nautobot : pynautobot .api , project_id : uuid .UUID
150
98
) -> int :
151
99
logger .info ("got request to update tenant %s" , project_id .hex )
152
- tenant_name , tenant_description , is_default_domain = _tenant_attrs (conn , project_id )
100
+ tenant_name , tenant_description = _tenant_attrs (conn , project_id )
153
101
154
102
existing_tenant = nautobot .tenancy .tenants .get (id = project_id )
155
103
logger .info ("existing_tenant: %s" , existing_tenant )
@@ -170,8 +118,6 @@ def handle_project_update(
170
118
existing_tenant .last_updated , # type: ignore
171
119
)
172
120
173
- if is_default_domain :
174
- _create_outside_network (conn , project_id )
175
121
except Exception :
176
122
logger .exception (
177
123
"Unable to update project %s / %s" , str (project_id ), tenant_name
@@ -189,7 +135,6 @@ def handle_project_delete(
189
135
logger .warning ("tenant %s does not exist, nothing to delete" , project_id )
190
136
return _EXIT_SUCCESS
191
137
192
- _delete_outside_network (conn , project_id )
193
138
_unmap_tenant_from_devices (tenant_id = project_id , nautobot = nautobot )
194
139
195
140
tenant = cast (Record , tenant )
0 commit comments