Skip to content

Commit 8be60b8

Browse files
authored
Merge pull request #1033 from rackerlabs/outside-only-in-default-domain
fix: sync_keystone: No OUTSIDE network unless project in default domain
2 parents 5984cea + eddc553 commit 8be60b8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

python/understack-workflows/understack_workflows/main/sync_keystone.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,34 @@ def _find_outside_network(conn: Connection, project_id: str):
9494
)
9595

9696

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]:
9898
project = conn.identity.get_project(project_id.hex) # type: ignore
9999
domain_id = project.domain_id
100+
is_default_domain = domain_id == "default"
100101

101-
if domain_id == "default":
102+
if is_default_domain:
102103
domain_name = "default"
103104
else:
104105
domain = conn.identity.get_project(domain_id) # type: ignore
105106
domain_name = domain.name
106107

107108
tenant_name = f"{domain_name}:{project.name}"
108-
return tenant_name, str(project.description)
109+
return tenant_name, str(project.description), is_default_domain
109110

110111

111112
def handle_project_create(
112113
conn: Connection, nautobot: Nautobot, project_id: uuid.UUID
113114
) -> int:
114115
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)
116117

117118
nautobot_tenant_api = nautobot.session.tenancy.tenants
118119
try:
119120
tenant = nautobot_tenant_api.create(
120121
id=str(project_id), name=tenant_name, description=tenant_description
121122
)
122-
_create_outside_network(conn, project_id)
123+
if is_default_domain:
124+
_create_outside_network(conn, project_id)
123125
except Exception:
124126
logger.exception(
125127
"Unable to create project %s / %s", str(project_id), tenant_name
@@ -134,7 +136,7 @@ def handle_project_update(
134136
conn: Connection, nautobot: Nautobot, project_id: uuid.UUID
135137
) -> int:
136138
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)
138140

139141
tenant_api = nautobot.session.tenancy.tenants
140142
existing_tenant = tenant_api.get(project_id)
@@ -155,7 +157,8 @@ def handle_project_update(
155157
existing_tenant.last_updated, # type: ignore
156158
)
157159

158-
_create_outside_network(conn, project_id)
160+
if is_default_domain:
161+
_create_outside_network(conn, project_id)
159162
except Exception:
160163
logger.exception(
161164
"Unable to update project %s / %s", str(project_id), tenant_name

0 commit comments

Comments
 (0)