Lazily load the IPAClient objects

This change ensures that the JoinController does not instantiate
an IPAClient object each time it is invoked -- every tieme a
compute.update notifcation comes in. Rather it does so only after
confirming the notification was meant to create a node that will
be enrolled within IPA.

Change-Id: I6511d1a4f174e277735e8a68cb711c78193243a9
This commit is contained in:
Harry Rybacki 2019-10-15 15:56:58 -04:00
parent a71617627a
commit b6134a9a1e
1 changed files with 10 additions and 3 deletions

View File

@ -77,9 +77,16 @@ class Controller(object):
class JoinController(Controller):
def __init__(self, ipaclient=IPAClient()):
def __init__(self, ipaclient=None):
super(JoinController, self).__init__(None)
self.ipaclient = ipaclient
self._ipaclient = ipaclient
@property
def ipaclient(self):
if self._ipaclient is None:
self._ipaclient = IPAClient()
return self._ipaclient
def _get_allowed_hostclass(self, project_name):
"""Get the allowed list of hostclass from configuration."""
@ -192,8 +199,8 @@ class JoinController(Controller):
ipaotp = uuid.uuid4().hex
instance_id = body.get('instance-id', '')
data['hostname'] = util.get_fqdn(hostname_short, project_name)
_, realm = self.ipaclient.get_host_and_realm()
data['hostname'] = util.get_fqdn(hostname_short, project_name)
data['krb_realm'] = realm
try: