def get_hostname(config=None):
 hostname = None
 if (config is None):
  from config import get_config
  config = get_config(parse_args=True)
 config_hostname = config.get('hostname')
 if (config_hostname and is_valid_hostname(config_hostname)):
  return config_hostname
 gce_hostname = GCE.get_hostname(config)
 if (gce_hostname is not None):
  if is_valid_hostname(gce_hostname):
   return gce_hostname
 if Platform.is_containerized():
  docker_util = DockerUtil()
  docker_hostname = docker_util.get_hostname(use_default_gw=False)
  if ((docker_hostname is not None) and is_valid_hostname(docker_hostname)):
   hostname = docker_hostname
  elif Platform.is_k8s():
   kube_util = KubeUtil()
   (_, kube_hostname) = kube_util.get_node_info()
   if ((kube_hostname is not None) and is_valid_hostname(kube_hostname)):
    hostname = kube_hostname
 if (hostname is None):
  if (Platform.is_unix() or Platform.is_solaris()):
   unix_hostname = _get_hostname_unix()
   if (unix_hostname and is_valid_hostname(unix_hostname)):
    hostname = unix_hostname
 if (Platform.is_ecs_instance() or ((hostname is not None) and EC2.is_default(hostname))):
  instanceid = EC2.get_instance_id(config)
  if instanceid:
   hostname = instanceid
 if (hostname is None):
  try:
   socket_hostname = socket.gethostname()
  except socket.error:
   socket_hostname = None
  if (socket_hostname and is_valid_hostname(socket_hostname)):
   hostname = socket_hostname
 if (hostname is None):
  log.critical('Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file')
  raise Exception('Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file')
 return hostname

def get_hostname ( config = None ) : hostname = None if ( config is None ) : from config import get_config config = get_config ( parse_args = True ) config_hostname = config . get ( 'hostname' ) if ( config_hostname and is_valid_hostname ( config_hostname ) ) : return config_hostname gce_hostname = GCE . get_hostname ( config ) if ( gce_hostname is not None ) : if is_valid_hostname ( gce_hostname ) : return gce_hostname if Platform . is_containerized ( ) : docker_util = DockerUtil ( ) docker_hostname = docker_util . get_hostname ( use_default_gw = False ) if ( ( docker_hostname is not None ) and is_valid_hostname ( docker_hostname ) ) : hostname = docker_hostname elif Platform . is_k8s ( ) : kube_util = KubeUtil ( ) ( _ , kube_hostname ) = kube_util . get_node_info ( ) if ( ( kube_hostname is not None ) and is_valid_hostname ( kube_hostname ) ) : hostname = kube_hostname if ( hostname is None ) : if ( Platform . is_unix ( ) or Platform . is_solaris ( ) ) : unix_hostname = _get_hostname_unix ( ) if ( unix_hostname and is_valid_hostname ( unix_hostname ) ) : hostname = unix_hostname if ( Platform . is_ecs_instance ( ) or ( ( hostname is not None ) and EC2 . is_default ( hostname ) ) ) : instanceid = EC2 . get_instance_id ( config ) if instanceid : hostname = instanceid if ( hostname is None ) : try : socket_hostname = socket . gethostname ( ) except socket . error : socket_hostname = None if ( socket_hostname and is_valid_hostname ( socket_hostname ) ) : hostname = socket_hostname if ( hostname is None ) : log . critical ( 'Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file' ) raise Exception ( 'Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file' ) return hostname
returns a hostname to use to contact the module .