#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time           : 18-6-22 上午11:32
# @Author         : Tom.Lee
# @File           : docker_image_tag.py
# @Product        : PyCharm
# @Docs           : https://docs.docker.com/engine/api/v1.37/#operation/ImageTag
# @Source         : 

import requests

if __name__ == '__main__':
    """ result data:
    {
        Containers: -1,
        Created: 1529636422,
        Id: "sha256:c05d19af1ab1ae147bd279c85212916e28f59e08f6ff27bd1995ba395a712961",
        Labels: { },
        ParentId: "sha256:d1c6d0681dae9ee452e0424025237c12455b68f94d885729ee3507d3a8c1bbf7",
        RepoDigests: null,
        RepoTags: [
            "api_test_build_01:v2.0",
            "docker.service.ob.local/api_test_build_01:v0.1"
        ],
        SharedSize: -1,
        Size: 6704207,
        VirtualSize: 6704207
    }
    """

    url = 'http://192.168.46.251:2375/images/{name}/tag'.format(name='api_test_build_01:v2.0')
    request_params = {
        'repo': 'docker.service.ob.local/api_test_build_01',
        'tag': 'v0.2'
    }
    # command $ docker tag api_test_build_01:v2.0 docker.service.ob.local/api_test_build_01:v0.2
    data = requests.post(url=url, params=request_params)

    print 'tag status: {}'.format(data.status_code)  # 201
    print 'output: {}'.format(data.text)  # None
