Add preliminary save container support
Save all objects from a container implements bp: swift-client Change-Id: I7f2437236574e212033e63d768929d813289ed05
This commit is contained in:
parent
e47787e12f
commit
505c784bad
@ -152,6 +152,30 @@ class ListContainer(lister.Lister):
|
||||
) for s in data))
|
||||
|
||||
|
||||
class SaveContainer(command.Command):
|
||||
"""Save the contents of a container locally"""
|
||||
|
||||
log = logging.getLogger(__name__ + ".SaveContainer")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SaveContainer, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'container',
|
||||
metavar='<container>',
|
||||
help='Container name to save',
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
|
||||
lib_container.save_container(
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
parsed_args.container
|
||||
)
|
||||
|
||||
|
||||
class ShowContainer(show.ShowOne):
|
||||
"""Show container information"""
|
||||
|
||||
|
@ -21,6 +21,8 @@ try:
|
||||
except ImportError:
|
||||
from urlparse import urlparse # noqa
|
||||
|
||||
from openstackclient.object.v1.lib import object as object_lib
|
||||
|
||||
|
||||
def create_container(
|
||||
session,
|
||||
@ -120,6 +122,23 @@ def list_containers(
|
||||
return session.get(url, params=params).json()
|
||||
|
||||
|
||||
def save_container(
|
||||
session,
|
||||
url,
|
||||
container
|
||||
):
|
||||
"""Save all the content from a container
|
||||
|
||||
:param session: an authenticated keystoneclient.session.Session object
|
||||
:param url: endpoint
|
||||
:param container: name of container to save
|
||||
"""
|
||||
|
||||
objects = object_lib.list_objects(session, url, container)
|
||||
for object in objects:
|
||||
object_lib.save_object(session, url, container, object['name'])
|
||||
|
||||
|
||||
def show_container(
|
||||
session,
|
||||
url,
|
||||
|
@ -273,6 +273,7 @@ openstack.object_store.v1 =
|
||||
container_create = openstackclient.object.v1.container:CreateContainer
|
||||
container_delete = openstackclient.object.v1.container:DeleteContainer
|
||||
container_list = openstackclient.object.v1.container:ListContainer
|
||||
container_save = openstackclient.object.v1.container:SaveContainer
|
||||
container_show = openstackclient.object.v1.container:ShowContainer
|
||||
object_create = openstackclient.object.v1.object:CreateObject
|
||||
object_delete = openstackclient.object.v1.object:DeleteObject
|
||||
|
Loading…
Reference in New Issue
Block a user