'get an instance of the api based on the supplied configuration'

def get_consul_api(self):

    host = 'localhost'
    port = 8500
    token = None
    scheme = 'http'
    if hasattr(self, 'url'):
        try:
            from urlparse import urlparse
        except ImportError:
            from urllib.parse import urlparse
        o = urlparse(self.url)
        if o.hostname:
            host = o.hostname
        if o.port:
            port = o.port
        if o.scheme:
            scheme = o.scheme
    if hasattr(self, 'token'):
        token = self.token
        if (not token):
            token = 'anonymous'
    return consul.Consul(host=host, port=port, token=token, scheme=scheme)
