def build_volume_from(volume_from_spec):
 if isinstance(volume_from_spec.source, Service):
  containers = volume_from_spec.source.containers(stopped=True)
  if (not containers):
   return u'{}:{}'.format(volume_from_spec.source.create_container().id, volume_from_spec.mode)
  container = containers[0]
  return u'{}:{}'.format(container.id, volume_from_spec.mode)
 elif isinstance(volume_from_spec.source, Container):
  return u'{}:{}'.format(volume_from_spec.source.id, volume_from_spec.mode)

def build_volume_from ( volume_from_spec ) : if isinstance ( volume_from_spec . source , Service ) : containers = volume_from_spec . source . containers ( stopped = True ) if ( not containers ) : return u'{}:{}' . format ( volume_from_spec . source . create_container ( ) . id , volume_from_spec . mode ) container = containers [ 0 ] return u'{}:{}' . format ( container . id , volume_from_spec . mode ) elif isinstance ( volume_from_spec . source , Container ) : return u'{}:{}' . format ( volume_from_spec . source . id , volume_from_spec . mode )
volume_from can be either a service or a container .