Implement container snapshot
This patch implements zun client container snapshot command. example CLI: zun commit --repository myrepo --tag mytag Change-Id: I51f94a84ab9ff8c4816fc6ba43ce46f206603827
This commit is contained in:
parent
d9d0f4d70c
commit
df6a60f5a0
@ -49,6 +49,7 @@ openstack.container.v1 =
|
||||
appcontainer_attach = zunclient.osc.v1.containers:AttachContainer
|
||||
appcontainer_cp = zunclient.osc.v1.containers:CopyContainer
|
||||
appcontainer_stats = zunclient.osc.v1.containers:StatsContainer
|
||||
appcontainer_commit = zunclient.osc.v1.containers:CommitContainer
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = doc/source
|
||||
|
@ -811,3 +811,40 @@ class StatsContainer(command.Command):
|
||||
container = parsed_args.container
|
||||
stats_info = client.containers.stats(container)
|
||||
cliutils.print_dict(stats_info)
|
||||
|
||||
|
||||
class CommitContainer(command.Command):
|
||||
"""Create a new image from a container's changes"""
|
||||
log = logging.getLogger(__name__ + ".CommitContainer")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CommitContainer, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the (container)s to commit.')
|
||||
parser.add_argument(
|
||||
'--repository',
|
||||
required=True,
|
||||
metavar='<repository>',
|
||||
help='Repository of the new image.')
|
||||
parser.add_argument(
|
||||
'--tag',
|
||||
metavar='<tag>',
|
||||
help='Tag of the new iamge')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = _get_client(self, parsed_args)
|
||||
container = parsed_args.container
|
||||
opts = {}
|
||||
opts['repository'] = parsed_args.repository
|
||||
opts['tag'] = parsed_args.tag
|
||||
opts = zun_utils.remove_null_parms(**opts)
|
||||
try:
|
||||
client.containers.commit(container, **opts)
|
||||
print(_('Request to commit container %s has been accepted')
|
||||
% container)
|
||||
except Exception as e:
|
||||
print("commit container %(container)s failed: %(e)s" %
|
||||
{'container': container, 'e': e})
|
||||
|
@ -59,6 +59,8 @@ tty_height = "56"
|
||||
tty_width = "121"
|
||||
path = "/tmp/test.txt"
|
||||
data = "/tmp/test.tar"
|
||||
repo = "repo-test"
|
||||
tag = "tag-test"
|
||||
|
||||
fake_responses = {
|
||||
'/v1/containers':
|
||||
@ -273,6 +275,15 @@ fake_responses = {
|
||||
None,
|
||||
),
|
||||
},
|
||||
'/v1/containers/%s/commit?%s'
|
||||
% (CONTAINER1['id'], parse.urlencode({'repository': repo,
|
||||
'tag': tag})):
|
||||
{
|
||||
'POST': (
|
||||
{},
|
||||
None,
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -569,3 +580,13 @@ class ContainerManagerTest(testtools.TestCase):
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertTrue(containers)
|
||||
|
||||
def test_containers_commit(self):
|
||||
containers = self.mgr.commit(CONTAINER1['id'], repo, tag)
|
||||
expect = [
|
||||
('POST', '/v1/containers/%s/commit?%s' % (CONTAINER1['id'],
|
||||
parse.urlencode({'repository': repo, 'tag': tag})),
|
||||
{'Content-Length': '0'}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertIsNone(containers)
|
||||
|
@ -192,3 +192,11 @@ class ContainerManager(base.Manager):
|
||||
|
||||
def stats(self, id):
|
||||
return self._action(id, '/stats', method='GET')[1]
|
||||
|
||||
def commit(self, id, repository, tag=None):
|
||||
if tag is not None:
|
||||
return self._action(id, '/commit', qparams={
|
||||
'repository': repository, 'tag': tag})[1]
|
||||
else:
|
||||
return self._action(id, '/commit', qparams={
|
||||
'repository': repository})[1]
|
||||
|
@ -566,3 +566,29 @@ def do_stats(cs, args):
|
||||
"""Display stats snapshot of the container."""
|
||||
stats_info = cs.containers.stats(args.container)
|
||||
utils.print_dict(stats_info)
|
||||
|
||||
|
||||
@utils.arg('container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to commit.')
|
||||
@utils.arg('--repository',
|
||||
metavar='<repository>',
|
||||
required=True,
|
||||
help='The repository of the image.')
|
||||
@utils.arg('--tag',
|
||||
metavar='<tag>',
|
||||
help='The tag of the image')
|
||||
def do_commit(cs, args):
|
||||
"""Create a new image from a container's changes."""
|
||||
opts = {}
|
||||
if args.repository is not None:
|
||||
opts['repository'] = args.repository
|
||||
if args.tag is not None:
|
||||
opts['tag'] = args.tag
|
||||
try:
|
||||
cs.containers.commit(args.container, **opts)
|
||||
print("Request to commit container %s has been accepted." %
|
||||
args.container)
|
||||
except Exception as e:
|
||||
print("Commit for container %(container)s failed: %(e)s" %
|
||||
{'container': args.container, 'e': e})
|
||||
|
Loading…
x
Reference in New Issue
Block a user