'If username and password are provided, authenticate with the registry.
Otherwise, check the config file for existing authentication data.'

@conductor_only
def login(self, username, password, email, url, config_path):

    if (username and password):
        try:
            self.client.login(username=username, password=password, email=email, registry=url, reauth=True)
        except docker_errors.APIError as exc:
            raise exceptions.AnsibleContainerConductorException(u'Error    logging    into    registry:    {}'.format(exc))
        except Exception:
            raise
        self._update_config_file(username, password, email, url, config_path)
    (username, password) = self._get_registry_auth(url, config_path)
    if (not username):
        raise exceptions.AnsibleContainerConductorException(u'Please    provide    login    credentials    for    registry    {}.'.format(url))
    return (username, password)
