labpack/platforms/docker.py
def _synopsis(self, container_settings, container_status=''):

        ''' a helper method for summarizing container settings '''
    
    # compose default response
        settings = {
            'container_status': container_settings['State']['Status'],
            'container_exit': container_settings['State']['ExitCode'],
            'container_ip': container_settings['NetworkSettings']['IPAddress'],
            'image_name': container_settings['Config']['Image'],
            'container_alias': container_settings['Name'].replace('/',''),
            'container_variables': {},
            'mapped_ports': {},
            'mounted_volumes': {},
            'container_networks': []
        }
    
    # parse fields nested in container settings
        import re
        num_pattern = re.compile('\d+')
        if container_settings['NetworkSettings']['Ports']:
            for key, value in container_settings['NetworkSettings']['Ports'].items():
                if value:
                    port = num_pattern.findall(value[0]['HostPort'])[0]
                    settings['mapped_ports'][port] = num_pattern.findall(key)[0]
        elif container_settings['HostConfig']['PortBindings']:
            for key, value in container_settings['HostConfig']['PortBindings'].items():
                port = num_pattern.findall(value[0]['HostPort'])[0]
                settings['mapped_ports'][port] = num_pattern.findall(key)[0]
        if container_settings['Config']['Env']:
            for variable in container_settings['Config']['Env']:
                k, v = variable.split('=')
                settings['container_variables'][k] = v
        for volume in container_settings['Mounts']:
            system_path = volume['Source']
            container_path = volume['Destination']
            settings['mounted_volumes'][system_path] = container_path
        if container_settings['NetworkSettings']:
            if container_settings['NetworkSettings']['Networks']:
                for key in container_settings['NetworkSettings']['Networks'].keys():
                    settings['container_networks'].append(key)

    # determine stopped status
        if settings['container_status'] == 'exited':
            if not container_status:
                try:
                    from subprocess import check_output, STDOUT
                    sys_command = 'docker logs --tail 1 %s' % settings['container_alias']
                    check_output(sys_command, shell=True, stderr=STDOUT).decode('utf-8')
                    settings['container_status'] = 'stopped'
                except:
                    pass
            else:
                settings['container_status'] = container_status

        return settings
 a helper method for summarizing container settings 
a helper method for summarizing container settings
a helper method for summarizing container settings
def _synopsis(self, container_settings, container_status=''):
        settings = {
            'container_status': container_settings['State']['Status'],
            'container_exit': container_settings['State']['ExitCode'],
            'container_ip': container_settings['NetworkSettings']['IPAddress'],
            'image_name': container_settings['Config']['Image'],
            'container_alias': container_settings['Name'].replace('/',''),
            'container_variables': {},
            'mapped_ports': {},
            'mounted_volumes': {},
            'container_networks': []
        }
        import re
        num_pattern = re.compile('\d+')
        if container_settings['NetworkSettings']['Ports']:
            for key, value in container_settings['NetworkSettings']['Ports'].items():
                if value:
                    port = num_pattern.findall(value[0]['HostPort'])[0]
                    settings['mapped_ports'][port] = num_pattern.findall(key)[0]
        elif container_settings['HostConfig']['PortBindings']:
            for key, value in container_settings['HostConfig']['PortBindings'].items():
                port = num_pattern.findall(value[0]['HostPort'])[0]
                settings['mapped_ports'][port] = num_pattern.findall(key)[0]
        if container_settings['Config']['Env']:
            for variable in container_settings['Config']['Env']:
                k, v = variable.split('=')
                settings['container_variables'][k] = v
        for volume in container_settings['Mounts']:
            system_path = volume['Source']
            container_path = volume['Destination']
            settings['mounted_volumes'][system_path] = container_path
        if container_settings['NetworkSettings']:
            if container_settings['NetworkSettings']['Networks']:
                for key in container_settings['NetworkSettings']['Networks'].keys():
                    settings['container_networks'].append(key)
        if settings['container_status'] == 'exited':
            if not container_status:
                try:
                    from subprocess import check_output, STDOUT
                    sys_command = 'docker logs --tail 1 %s' % settings['container_alias']
                    check_output(sys_command, shell=True, stderr=STDOUT).decode('utf-8')
                    settings['container_status'] = 'stopped'
                except:
                    pass
            else:
                settings['container_status'] = container_status
        return settings
def _synopsis ( self , container_settings , container_status = '' ) : settings = { 'container_status' : container_settings [ 'State' ] [ 'Status' ] , 'container_exit' : container_settings [ 'State' ] [ 'ExitCode' ] , 'container_ip' : container_settings [ 'NetworkSettings' ] [ 'IPAddress' ] , 'image_name' : container_settings [ 'Config' ] [ 'Image' ] , 'container_alias' : container_settings [ 'Name' ] . replace ( '/' , '' ) , 'container_variables' : { } , 'mapped_ports' : { } , 'mounted_volumes' : { } , 'container_networks' : [ ] } import re num_pattern = re . compile ( '\d+' ) if container_settings [ 'NetworkSettings' ] [ 'Ports' ] : for key , value in container_settings [ 'NetworkSettings' ] [ 'Ports' ] . items ( ) : if value : port = num_pattern . findall ( value [ 0 ] [ 'HostPort' ] ) [ 0 ] settings [ 'mapped_ports' ] [ port ] = num_pattern . findall ( key ) [ 0 ] elif container_settings [ 'HostConfig' ] [ 'PortBindings' ] : for key , value in container_settings [ 'HostConfig' ] [ 'PortBindings' ] . items ( ) : port = num_pattern . findall ( value [ 0 ] [ 'HostPort' ] ) [ 0 ] settings [ 'mapped_ports' ] [ port ] = num_pattern . findall ( key ) [ 0 ] if container_settings [ 'Config' ] [ 'Env' ] : for variable in container_settings [ 'Config' ] [ 'Env' ] : k , v = variable . split ( '=' ) settings [ 'container_variables' ] [ k ] = v for volume in container_settings [ 'Mounts' ] : system_path = volume [ 'Source' ] container_path = volume [ 'Destination' ] settings [ 'mounted_volumes' ] [ system_path ] = container_path if container_settings [ 'NetworkSettings' ] : if container_settings [ 'NetworkSettings' ] [ 'Networks' ] : for key in container_settings [ 'NetworkSettings' ] [ 'Networks' ] . keys ( ) : settings [ 'container_networks' ] . append ( key ) if settings [ 'container_status' ] == 'exited' : if not container_status : try : from subprocess import check_output , STDOUT sys_command = 'docker logs --tail 1 %s' % settings [ 'container_alias' ] check_output ( sys_command , shell = True , stderr = STDOUT ) . decode ( 'utf-8' ) settings [ 'container_status' ] = 'stopped' except : pass else : settings [ 'container_status' ] = container_status return settings
a helper method for summarizing container settings
a helper method for summarizing container settings
''' a helper method for summarizing container settings ''' # compose default response
 # parse fields nested in container settings
 # determine stopped status

self
container_settings
container_status