#NEWLINE# def _parse_volumes( volumes ) : #NEWLINE# #INDENT# '\n    Parse a given volumes state specification for later use in\n    modules.docker.create_container(). This produces a dict that can be directly\n    consumed by the Docker API /containers/create.\n\n    Note: this only really exists for backwards-compatibility, and because\n    modules.dockerio.start() currently takes a binds argument.\n\n    volumes\n        A structure containing information about the volumes to be included in the\n        container that will be created, either:\n            - a bare dictionary\n            - a list of dictionaries and lists\n\n        .. code-block:: yaml\n\n            # bare dict style\n            - volumes:\n                /usr/local/etc/ssl/certs/example.crt:\n                  bind: /etc/ssl/certs/com.example.internal.crt\n                  ro: True\n                /var/run:\n                  bind: /var/run/host/\n                  ro: False\n\n            # list of dicts style:\n            - volumes:\n              - /usr/local/etc/ssl/certs/example.crt:\n                  bind: /etc/ssl/certs/com.example.internal.crt\n                  ro: True\n              - /var/run: /var/run/host/ # read-write bound volume\n              - /var/lib/mysql # un-bound, container-only volume\n\n        note: bind mounts specified like "/etc/timezone:/tmp/host_tz" will fall\n        through this parser.\n\n    Returns a dict of volume specifications:\n\n        .. code-block:: yaml\n\n            {\n              \'bindvols\': {\n                \'/usr/local/etc/ssl/certs/example.crt\': {\n                  \'bind\': \'/etc/ssl/certs/com.example.internal.crt\',\n                  \'ro\': True\n                  },\n                \'/var/run/\': {\n                  \'bind\': \'/var/run/host\',\n                  \'ro\': False\n                },\n              },\n              \'contvols\': [ \'/var/lib/mysql/\' ]\n            }\n\n    ' #NEWLINE# log . trace ( ( 'Parsing given volumes dict: ' + str ( volumes ) ) ) #NEWLINE# bindvolumes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# contvolumes = [ ] #NEWLINE# if isinstance ( volumes , dict ) : #NEWLINE# #INDENT# bindvolumes = volumes #NEWLINE# #UNINDENT# if isinstance ( volumes , list ) : #NEWLINE# #INDENT# for vol in volumes : #NEWLINE# #INDENT# if isinstance ( vol , dict ) : #NEWLINE# #INDENT# for ( volsource , voldef ) in vol . items ( ) : #NEWLINE# #INDENT# if isinstance ( voldef , dict ) : #NEWLINE# #INDENT# target = voldef [ 'bind' ] #NEWLINE# read_only = voldef . get ( 'ro' , False ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# target = str ( voldef ) #NEWLINE# read_only = False #NEWLINE# #UNINDENT# source = volsource #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ':' in vol ) : #NEWLINE# #INDENT# volspec = vol . split ( ':' ) #NEWLINE# source = volspec [ 0 ] #NEWLINE# target = volspec [ 1 ] #NEWLINE# read_only = False #NEWLINE# try : #NEWLINE# #INDENT# if ( len ( volspec ) > 2 ) : #NEWLINE# #INDENT# read_only = ( volspec [ 2 ] == 'ro' ) #NEWLINE# #UNINDENT# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# contvolumes . append ( str ( vol ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# bindvolumes [ source ] = { #NEWLINE# #INDENT# 'bind' : target , #NEWLINE# 'ro' : read_only , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# result = { #NEWLINE# #INDENT# 'bindvols' : bindvolumes , #NEWLINE# 'contvols' : contvolumes , #NEWLINE# #UNINDENT# } #NEWLINE# log . trace ( ( 'Finished parsing volumes, with result: ' + str ( result ) ) ) #NEWLINE# return result