Skip to content

Commit

Permalink
fix(workflows): create tenant in nautobot if it doesn't exist
Browse files Browse the repository at this point in the history
When updating a tenant that doesn't exist in Nautobot, just create it
instead to get it in sync.
  • Loading branch information
cardoe committed Nov 13, 2024
1 parent 583969e commit e8196b0
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ def handle_project_create(conn: Connection, nautobot: Nautobot, project_id: uuid
def handle_project_update(conn: Connection, nautobot: Nautobot, project_id: uuid.UUID):
logger.info(f"got request to update tenant {project_id!s}")
project = conn.identity.get_project(project_id.hex) # type: ignore
ten = nautobot.session.tenancy.tenants.get(project_id)
ten.description = project.description # type: ignore
ten.save() # type: ignore
logger.info(f"tenant '{project_id!s}' last updated {ten.last_updated}") # type: ignore
ten_api = nautobot.session.tenancy.tenants
ten = ten_api.get(project_id)
if ten is None:
ten = ten_api.create(
id=str(project_id), name=project.name, description=project.description
)
logger.info(f"tenant '{project_id!s}' created {ten.created}") # type: ignore
else:
ten.description = project.description # type: ignore
ten.save() # type: ignore
logger.info(f"tenant '{project_id!s}' last updated {ten.last_updated}") # type: ignore


def handle_project_delete(conn: Connection, nautobot: Nautobot, project_id: uuid.UUID):
Expand Down

0 comments on commit e8196b0

Please sign in to comment.