@@ -94,32 +94,34 @@ def _find_outside_network(conn: Connection, project_id: str):
94
94
)
95
95
96
96
97
- def _tenant_attrs (conn : Connection , project_id : uuid .UUID ) -> tuple [str , str ]:
97
+ def _tenant_attrs (conn : Connection , project_id : uuid .UUID ) -> tuple [str , str , bool ]:
98
98
project = conn .identity .get_project (project_id .hex ) # type: ignore
99
99
domain_id = project .domain_id
100
+ is_default_domain = domain_id == "default"
100
101
101
- if domain_id == "default" :
102
+ if is_default_domain :
102
103
domain_name = "default"
103
104
else :
104
105
domain = conn .identity .get_project (domain_id ) # type: ignore
105
106
domain_name = domain .name
106
107
107
108
tenant_name = f"{ domain_name } :{ project .name } "
108
- return tenant_name , str (project .description )
109
+ return tenant_name , str (project .description ), is_default_domain
109
110
110
111
111
112
def handle_project_create (
112
113
conn : Connection , nautobot : Nautobot , project_id : uuid .UUID
113
114
) -> int :
114
115
logger .info ("got request to create tenant %s" , project_id .hex )
115
- tenant_name , tenant_description = _tenant_attrs (conn , project_id )
116
+ tenant_name , tenant_description , is_default_domain = _tenant_attrs (conn , project_id )
116
117
117
118
nautobot_tenant_api = nautobot .session .tenancy .tenants
118
119
try :
119
120
tenant = nautobot_tenant_api .create (
120
121
id = str (project_id ), name = tenant_name , description = tenant_description
121
122
)
122
- _create_outside_network (conn , project_id )
123
+ if is_default_domain :
124
+ _create_outside_network (conn , project_id )
123
125
except Exception :
124
126
logger .exception (
125
127
"Unable to create project %s / %s" , str (project_id ), tenant_name
@@ -134,7 +136,7 @@ def handle_project_update(
134
136
conn : Connection , nautobot : Nautobot , project_id : uuid .UUID
135
137
) -> int :
136
138
logger .info ("got request to update tenant %s" , project_id .hex )
137
- tenant_name , tenant_description = _tenant_attrs (conn , project_id )
139
+ tenant_name , tenant_description , is_default_domain = _tenant_attrs (conn , project_id )
138
140
139
141
tenant_api = nautobot .session .tenancy .tenants
140
142
existing_tenant = tenant_api .get (project_id )
@@ -155,7 +157,8 @@ def handle_project_update(
155
157
existing_tenant .last_updated , # type: ignore
156
158
)
157
159
158
- _create_outside_network (conn , project_id )
160
+ if is_default_domain :
161
+ _create_outside_network (conn , project_id )
159
162
except Exception :
160
163
logger .exception (
161
164
"Unable to update project %s / %s" , str (project_id ), tenant_name
0 commit comments