def metadata_from_service(metadata_service_endpoint=METADATA_SERVICE_ENDPOINT, connect_timeout=5.0):
 endpoint_url = 'http://{}:{}/{}'.format(metadata_service_endpoint[0], metadata_service_endpoint[1], '/'.join(METADATA_RELATIVE_PATH))
 try:
  response = requests.get(endpoint_url, timeout=connect_timeout)
 except requests.exceptions.ConnectTimeout as e:
  Message.new(message_type=u'flocker:node:agents:blockdevice:openstack:compute_instance_id:metadataservice_connect_timeout', error_message=unicode(e)).write()
  return None
 except requests.exceptions.ConnectionError as e:
  Message.new(message_type=u'flocker:node:agents:blockdevice:openstack:compute_instance_id:metadataservice_connection_error', error_message=unicode(e)).write()
  return None
 if response.ok:
  try:
   return response.json()
  except ValueError as e:
   Message.new(message_type=u'flocker:node:agents:blockdevice:openstack:compute_instance_id:metadata_file_not_json', error_message=unicode(e)).write()

def metadata_from_service ( metadata_service_endpoint = METADATA_SERVICE_ENDPOINT , connect_timeout = 5.0 ) : endpoint_url = 'http://{}:{}/{}' . format ( metadata_service_endpoint [ 0 ] , metadata_service_endpoint [ 1 ] , '/' . join ( METADATA_RELATIVE_PATH ) ) try : response = requests . get ( endpoint_url , timeout = connect_timeout ) except requests . exceptions . ConnectTimeout as e : Message . new ( message_type = u'flocker:node:agents:blockdevice:openstack:compute_instance_id:metadataservice_connect_timeout' , error_message = unicode ( e ) ) . write ( ) return None except requests . exceptions . ConnectionError as e : Message . new ( message_type = u'flocker:node:agents:blockdevice:openstack:compute_instance_id:metadataservice_connection_error' , error_message = unicode ( e ) ) . write ( ) return None if response . ok : try : return response . json ( ) except ValueError as e : Message . new ( message_type = u'flocker:node:agents:blockdevice:openstack:compute_instance_id:metadata_file_not_json' , error_message = unicode ( e ) ) . write ( )
attempt to retrieve metadata from the openstack metadata service .