rebuild a container with a different image
rebuild a container with a different image. by this way, you can upgrade the container. For example, rebuild a ubuntu:14.04 container to ubuntu:16.04 for upgrade. Change-Id: Id08f7dca5de019da33695561f69976aaed6a022c Implements:blueprint replace-image
This commit is contained in:
@@ -1134,6 +1134,18 @@ class RebuildContainer(command.Command):
|
|||||||
metavar='<container>',
|
metavar='<container>',
|
||||||
nargs='+',
|
nargs='+',
|
||||||
help='ID or name of the (container)s to rebuild.')
|
help='ID or name of the (container)s to rebuild.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--image',
|
||||||
|
metavar='<image>',
|
||||||
|
help='The image for specified container to update.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--image-driver',
|
||||||
|
metavar='<image_driver>',
|
||||||
|
help='The image driver to use to update container image. '
|
||||||
|
'It can have following values: '
|
||||||
|
'"docker": update the image from Docker Hub. '
|
||||||
|
'"glance": update the image from Glance. '
|
||||||
|
'The default value is source container\'s image driver ')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@@ -1141,6 +1153,10 @@ class RebuildContainer(command.Command):
|
|||||||
for container in parsed_args.containers:
|
for container in parsed_args.containers:
|
||||||
opts = {}
|
opts = {}
|
||||||
opts['id'] = container
|
opts['id'] = container
|
||||||
|
if parsed_args.image:
|
||||||
|
opts['image'] = parsed_args.image
|
||||||
|
if parsed_args.image_driver:
|
||||||
|
opts['image_driver'] = parsed_args.image_driver
|
||||||
try:
|
try:
|
||||||
client.containers.rebuild(**opts)
|
client.containers.rebuild(**opts)
|
||||||
print(_('Request to rebuild container %s has '
|
print(_('Request to rebuild container %s has '
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ fake_responses = {
|
|||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
'/v1/containers/%s/rebuild'
|
'/v1/containers/%s/rebuild?image=cirros'
|
||||||
% (CONTAINER1['id']):
|
% (CONTAINER1['id']):
|
||||||
{
|
{
|
||||||
'POST': (
|
'POST': (
|
||||||
@@ -711,10 +711,12 @@ class ContainerManagerTest(testtools.TestCase):
|
|||||||
self.assertTrue(containers)
|
self.assertTrue(containers)
|
||||||
|
|
||||||
def test_containers_rebuild(self):
|
def test_containers_rebuild(self):
|
||||||
self.mgr.rebuild(CONTAINER1['id'])
|
opts = {'image': 'cirros'}
|
||||||
|
self.mgr.rebuild(CONTAINER1['id'], **opts)
|
||||||
expect = [
|
expect = [
|
||||||
('POST',
|
('POST',
|
||||||
'/v1/containers/%s/rebuild' % (CONTAINER1['id']),
|
'/v1/containers/%s/rebuild?image=cirros'
|
||||||
|
% (CONTAINER1['id']),
|
||||||
{'Content-Length': '0'}, None)
|
{'Content-Length': '0'}, None)
|
||||||
]
|
]
|
||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
|
|||||||
@@ -130,8 +130,9 @@ class ContainerManager(base.Manager):
|
|||||||
return self._action(id, '/stop',
|
return self._action(id, '/stop',
|
||||||
qparams={'timeout': timeout})
|
qparams={'timeout': timeout})
|
||||||
|
|
||||||
def rebuild(self, id):
|
def rebuild(self, id, **kwargs):
|
||||||
return self._action(id, '/rebuild')
|
return self._action(id, '/rebuild',
|
||||||
|
qparams=kwargs)
|
||||||
|
|
||||||
def restart(self, id, timeout):
|
def restart(self, id, timeout):
|
||||||
return self._action(id, '/reboot',
|
return self._action(id, '/reboot',
|
||||||
|
|||||||
@@ -262,11 +262,27 @@ def do_show(cs, args):
|
|||||||
metavar='<container>',
|
metavar='<container>',
|
||||||
nargs='+',
|
nargs='+',
|
||||||
help='ID of the (container)s to rebuild.')
|
help='ID of the (container)s to rebuild.')
|
||||||
|
@utils.arg('--image',
|
||||||
|
metavar='<image>',
|
||||||
|
help='The image for specified container to update.')
|
||||||
|
@utils.arg('--image-driver',
|
||||||
|
metavar='<image_driver>',
|
||||||
|
help='The image driver to use to pull container image. '
|
||||||
|
'It can have following values: '
|
||||||
|
'"docker": pull the image from Docker Hub. '
|
||||||
|
'"glance": pull the image from Glance. '
|
||||||
|
'The default value is source container\'s image driver ')
|
||||||
def do_rebuild(cs, args):
|
def do_rebuild(cs, args):
|
||||||
"""Rebuild specified containers."""
|
"""Rebuild specified containers."""
|
||||||
for container in args.containers:
|
for container in args.containers:
|
||||||
|
opts = {}
|
||||||
|
opts['id'] = container
|
||||||
|
if args.image:
|
||||||
|
opts['image'] = args.image
|
||||||
|
if args.image_driver:
|
||||||
|
opts['image_driver'] = args.image_driver
|
||||||
try:
|
try:
|
||||||
cs.containers.rebuild(container)
|
cs.containers.rebuild(**opts)
|
||||||
print("Request to rebuild container %s has been accepted." %
|
print("Request to rebuild container %s has been accepted." %
|
||||||
container)
|
container)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user