diff --git a/novajoin/join.py b/novajoin/join.py index 57fded2..0c69689 100644 --- a/novajoin/join.py +++ b/novajoin/join.py @@ -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: