mirror of
https://github.com/ansible/awx.git
synced 2026-03-27 05:45:02 -02:30
Adding an instance manager.
This commit is contained in:
27
awx/main/managers.py
Normal file
27
awx/main/managers.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (c) 2014 Ansible, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceManager(models.Manager):
|
||||||
|
"""A custom manager class for the Instance model.
|
||||||
|
|
||||||
|
Provides "table-level" methods including getting the currently active
|
||||||
|
instance or role.
|
||||||
|
"""
|
||||||
|
@cached_property
|
||||||
|
def me(self):
|
||||||
|
"""Return the currently active instance."""
|
||||||
|
return self.get(uuid=settings.SYSTEM_UUID)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def my_role(self):
|
||||||
|
"""Return the role of the currently active instance, as a string
|
||||||
|
('primary' or 'secondary').
|
||||||
|
"""
|
||||||
|
if self.me.primary:
|
||||||
|
return 'primary'
|
||||||
|
return 'secondary'
|
||||||
@@ -2,13 +2,16 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from awx.main.managers import InstanceManager
|
||||||
|
|
||||||
|
|
||||||
class Instance(models.Model):
|
class Instance(models.Model):
|
||||||
"""A model representing an Ansible Tower instance, primary or secondary,
|
"""A model representing an Ansible Tower instance, primary or secondary,
|
||||||
running against this database.
|
running against this database.
|
||||||
"""
|
"""
|
||||||
uuid = models.CharField(max_length=40)
|
objects = InstanceManager()
|
||||||
|
|
||||||
|
uuid = models.CharField(max_length=40, unique=True)
|
||||||
primary = models.BooleanField(default=False)
|
primary = models.BooleanField(default=False)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user