예제 #1
0
def import_image(client, arguments):
    """ cloudify.docker.ImportImage type create lifecycle operation.
        Derives some definition from parent type cloudify.docker.Image.
        Identical to the docker import command.

    :node_property src: Path to tarfile or URL.
    :node_property params: (Optional) Use any other parameter allowed
        by the docker API to Docker PY.
    :param daemon_client: optional configuration for client creation
    """

    ctx.logger.info('Import image arguments {}'.format(arguments))

    try:
        output = client.import_image(**arguments)
    except APIError as e:
        raise NonRecoverableError(
            'Failed to start container: {0}.'.format(str(e)))

    ctx.logger.info('output: {}'.format(output))
    image_id = json.loads(output).get('status')

    image_id = utils.get_image_id(
        arguments.get('tag'), arguments.get('repository'), client)

    ctx.instance.runtime_properties['image_id'] = image_id
    ctx.logger.info('Imported image, image_id {0}'.format(image_id))
    return image_id
예제 #2
0
def import_image(client, arguments):
    """ cloudify.docker.ImportImage type create lifecycle operation.
        Derives some definition from parent type cloudify.docker.Image.
        Identical to the docker import command.

    :node_property src: Path to tarfile or URL.
    :node_property params: (Optional) Use any other parameter allowed
        by the docker API to Docker PY.
    :param daemon_client: optional configuration for client creation
    """

    ctx.logger.info('Import image arguments {}'.format(arguments))

    try:
        output = client.import_image(**arguments)
    except APIError as e:
        raise NonRecoverableError(
            'Failed to start container: {0}.'.format(str(e)))

    ctx.logger.info('output: {}'.format(output))

    # json.loads crashes when trying to import a URL image because
    # output have more than one JSON object solution, skip every
    # JSON until the result JSON arrives (last one)
    lines = output.split('\n', (output.count('\n')+1))
    output = lines[len(lines)-1]

    image_id = json.loads(output).get('status')

    image_id = utils.get_image_id(
        arguments.get('tag'), arguments.get('repository'), client)

    ctx.instance.runtime_properties['image_id'] = image_id
    ctx.logger.info('Imported image, image_id {0}'.format(image_id))
    return image_id
예제 #3
0
def pull(client, arguments):
    """ cloudify.docker.Image type create lifecycle operation.
        Identical to the docker pull command.

    :node_property params: (Optional) Use any other parameter allowed
        by the docker API to Docker PY.
    :param daemon_client: optional configuration for client creation
    """

    arguments.update({'stream': True})
    ctx.logger.info('Pull arguments: {0}'.format(arguments))

    image_id = None

    try:
        for stream in client.pull(**arguments):
            stream_dict = json.loads(stream)
            if 'id' in stream_dict:
                image_id = stream_dict.get('id')
            if 'Complete' in stream_dict.get('status', ''):
                ctx.logger.info('docker_plugin.tasks.pull: {0}.'.format(
                    stream_dict))
    except APIError as e:
        raise NonRecoverableError(
            'Unabled to pull image: {0}. Error: {1}.'
            .format(arguments, str(e)))

    image_id = utils.get_image_id(
        arguments.get('tag'), arguments.get('repository'), client)

    ctx.instance.runtime_properties['image_id'] = image_id
    ctx.logger.info('Pulled image, image_id: {0}'.format(image_id))
    return image_id
예제 #4
0
def import_image(client, arguments):
    """ cloudify.docker.ImportImage type create lifecycle operation.
        Derives some definition from parent type cloudify.docker.Image.
        Identical to the docker import command.

    :node_property src: Path to tarfile or URL.
    :node_property params: (Optional) Use any other parameter allowed
        by the docker API to Docker PY.
    :param daemon_client: optional configuration for client creation
    """

    ctx.logger.info('Import image arguments {}'.format(arguments))

    try:
        output = client.import_image(**arguments)
    except APIError as e:
        raise NonRecoverableError('Failed to start container: {0}.'.format(
            str(e)))

    ctx.logger.info('output: {}'.format(output))

    # json.loads crashes when trying to import a URL image because
    # output have more than one JSON object solution, skip every
    # JSON until the result JSON arrives (last one)
    lines = output.split('\n', (output.count('\n') + 1))
    output = lines[len(lines) - 1]

    image_id = json.loads(output).get('status')

    image_id = utils.get_image_id(arguments.get('tag'),
                                  arguments.get('repository'), client)

    ctx.instance.runtime_properties['image_id'] = image_id
    ctx.logger.info('Imported image, image_id {0}'.format(image_id))
    return image_id