'Convert container in Container instances'

def _to_container(self, data):

    try:
        name = data.get('Name').strip('/')
    except:
        try:
            name = data.get('Names')[0].strip('/')
        except:
            name = data.get('Id')
    state = data.get('State')
    if isinstance(state, dict):
        status = data.get('Status', (state.get('Status') if (state is not None) else None))
    else:
        status = data.get('Status')
    if ('Exited' in status):
        state = ContainerState.STOPPED
    elif status.startswith('Up    '):
        state = ContainerState.RUNNING
    elif ('running' in status):
        state = ContainerState.RUNNING
    else:
        state = ContainerState.STOPPED
    image = data.get('Image')
    ports = data.get('Ports', [])
    created = data.get('Created')
    if isinstance(created, float):
        created = ts_to_str(created)
    extra = {'id': data.get('Id'), 'status': data.get('Status'), 'created': created, 'image': image, 'ports': ports, 'command': data.get('Command'), 'sizerw': data.get('SizeRw'), 'sizerootfs': data.get('SizeRootFs')}
    ips = []
    if (ports is not None):
        for port in ports:
            if (port.get('IP') is not None):
                ips.append(port.get('IP'))
    return Container(id=data['Id'], name=name, image=ContainerImage(id=data.get('ImageID', None), path=image, name=image, version=None, driver=self.connection.driver), ip_addresses=ips, state=state, driver=self.connection.driver, extra=extra)
