示例#1
0
def do_image_show(gc, args):
    """Describe a specific image."""
    image_id = utils.find_resource(gc.images, args.image).id
    image = gc.images.get(image_id)
    _image_show(image,
                args.human_readable,
                max_column_width=int(args.max_column_width))
示例#2
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    utils.save_image(body, args.file)
示例#3
0
def do_image_update(gc, args):
    """Update a specific image."""
    # Filter out None values
    fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))

    image_arg = fields.pop("image")
    image = utils.find_resource(gc.images, image_arg)

    if "is_protected" in fields:
        fields["protected"] = fields.pop("is_protected")

    raw_properties = fields.pop("property")
    fields["properties"] = {}
    for datum in raw_properties:
        key, value = datum.split("=", 1)
        fields["properties"][key] = value

    # Filter out values we can't use
    UPDATE_PARAMS = glanceclient.v1.images.UPDATE_PARAMS
    fields = dict(filter(lambda x: x[0] in UPDATE_PARAMS, fields.items()))

    if image.status == "queued":
        _set_data_field(fields, args)

        if args.progress:
            filesize = utils.get_file_size(fields["data"])
            fields["data"] = progressbar.VerboseFileWrapper(fields["data"], filesize)

    image = gc.images.update(image, purge_props=args.purge_props, **fields)
    _image_show(image, args.human_readable)
示例#4
0
def do_image_update(gc, args):
    """Update a specific image."""
    # Filter out None values
    fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))

    image_arg = fields.pop('image')
    image = utils.find_resource(gc.images, image_arg)

    if 'is_protected' in fields:
        fields['protected'] = fields.pop('is_protected')

    raw_properties = fields.pop('property')
    fields['properties'] = {}
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields['properties'][key] = value

    # Filter out values we can't use
    UPDATE_PARAMS = glanceclient.v1.images.UPDATE_PARAMS
    fields = dict(filter(lambda x: x[0] in UPDATE_PARAMS, fields.items()))

    _set_data_field(fields, args)

    image = gc.images.update(image, purge_props=args.purge_props, **fields)
    _image_show(image, args.human_readable)
示例#5
0
def do_image_update(gc, args):
    """Update a specific image."""
    # Filter out None values
    fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))

    image_arg = fields.pop('image')
    image = utils.find_resource(gc.images, image_arg)

    if 'is_protected' in fields:
        fields['protected'] = fields.pop('is_protected')

    raw_properties = fields.pop('property')
    fields['properties'] = {}
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields['properties'][key] = value

    # Filter out values we can't use
    UPDATE_PARAMS = glanceclient.v1.images.UPDATE_PARAMS
    fields = dict(filter(lambda x: x[0] in UPDATE_PARAMS, fields.items()))

    if image.status == 'queued':
        _set_data_field(fields, args)

        if args.progress:
            filesize = utils.get_file_size(fields['data'])
            fields['data'] = progressbar.VerboseFileWrapper(
                fields['data'], filesize)

    image = gc.images.update(image, purge_props=args.purge_props, **fields)
    _image_show(image, args.human_readable)
示例#6
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    utils.save_image(body, args.file)
示例#7
0
def do_member_delete(gc, args):
    """Remove a shared image from a tenant."""
    image_id = utils.find_resource(gc.images, args.image).id
    if not args.dry_run:
        gc.image_members.delete(image_id, args.tenant_id)
    else:
        print "Dry run. We would have done the following:"
        print('Remove "%s" from the member list of image '
              '"%s"' % (args.tenant_id, args.image))
示例#8
0
def do_member_delete(gc, args):
    """Remove a shared image from a tenant."""
    image_id = utils.find_resource(gc.images, args.image).id
    if not args.dry_run:
        gc.image_members.delete(image_id, args.tenant_id)
    else:
        print "Dry run. We would have done the following:"
        print ('Remove "%s" from the member list of image '
               '"%s"' % (args.tenant_id, args.image))
示例#9
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    if not (sys.stdout.isatty() and args.file is None):
        utils.save_image(body, args.file)
    else:
        print('No redirection or local file specified for downloaded image '
              'data. Please specify a local file with --file to save '
              'downloaded image or redirect output to another source.')
示例#10
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    if not (sys.stdout.isatty() and args.file is None):
        utils.save_image(body, args.file)
    else:
        print('No redirection or local file specified for downloaded image '
              'data. Please specify a local file with --file to save '
              'downloaded image or redirect output to another source.')
示例#11
0
def do_image_delete(gc, args):
    """Delete specified image(s)."""
    for args_image in args.images:
        image = utils.find_resource(gc.images, args_image)
        try:
            if args.verbose:
                print("Requesting image delete for %s ..." % strutils.safe_encode(args_image), end=" ")

            gc.images.delete(image)

            if args.verbose:
                print("[Done]")

        except exc.HTTPException as e:
            if args.verbose:
                print("[Fail]")
            print("%s: Unable to delete image %s" % (e, args_image))
示例#12
0
def do_image_delete(gc, args):
    """Delete specified image(s)."""
    for args_image in args.images:
        image = utils.find_resource(gc.images, args_image)
        try:
            if args.verbose:
                print 'Requesting image delete for %s ...' % args_image,

            gc.images.delete(image)

            if args.verbose:
                print '[Done]'

        except exc.HTTPException, e:
            if args.verbose:
                print '[Fail]'
            print '%s: Unable to delete image %s' % (e, args_image)
示例#13
0
def do_image_delete(gc, args):
    """Delete specified image(s)."""
    for args_image in args.images:
        image = utils.find_resource(gc.images, args_image)
        try:
            if args.verbose:
                print 'Requesting image delete for %s ...' % \
                      strutils.safe_encode(args_image),

            gc.images.delete(image)

            if args.verbose:
                print '[Done]'

        except exc.HTTPException as e:
            if args.verbose:
                print '[Fail]'
            print '%s: Unable to delete image %s' % (e, args_image)
示例#14
0
def do_image_delete(gc, args):
    """Delete specified image(s)."""
    for args_image in args.images:
        image = utils.find_resource(gc.images, args_image)
        if image and image.status == "deleted":
            msg = "No image with an ID of '%s' exists." % image.id
            raise exc.CommandError(msg)
        try:
            if args.verbose:
                print('Requesting image delete for %s ...' %
                      encodeutils.safe_decode(args_image), end=' ')

            gc.images.delete(image)

            if args.verbose:
                print('[Done]')

        except exc.HTTPException as e:
            if args.verbose:
                print('[Fail]')
            print('%s: Unable to delete image %s' % (e, args_image))
示例#15
0
def do_image_delete(gc, args):
    """Delete specified image(s)."""
    for args_image in args.images:
        image = utils.find_resource(gc.images, args_image)
        if image and image.status == "deleted":
            msg = "No image with an ID of '%s' exists." % image.id
            raise exc.CommandError(msg)
        try:
            if args.verbose:
                print('Requesting image delete for %s ...' %
                      encodeutils.safe_decode(args_image), end=' ')

            gc.images.delete(image)

            if args.verbose:
                print('[Done]')

        except exc.HTTPException as e:
            if args.verbose:
                print('[Fail]')
            print('%s: Unable to delete image %s' % (e, args_image))
示例#16
0
def do_image_update(gc, args):
    """Update a specific image."""
    # Filter out None values
    fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))

    image_arg = fields.pop('image')
    image = utils.find_resource(gc.images, image_arg)

    if 'is_protected' in fields:
        fields['protected'] = fields.pop('is_protected')

    raw_properties = fields.pop('property')
    fields['properties'] = {}
    for datum in raw_properties:
        key, value = datum.split('=', 1)
        fields['properties'][key] = value

    # Filter out values we can't use
    UPDATE_PARAMS = glanceclient.v1.images.UPDATE_PARAMS
    fields = dict(filter(lambda x: x[0] in UPDATE_PARAMS, fields.items()))

    if image.status == 'queued':
        _set_data_field(fields, args)

        if args.progress:
            filesize = utils.get_file_size(fields['data'])
            fields['data'] = progressbar.VerboseFileWrapper(
                fields['data'], filesize
            )

    elif _is_image_data_provided(args):
        # NOTE(kragniz): Exit with an error if the status is not queued
        # and image data was provided
        utils.exit('Unable to upload image data to an image which '
                   'is %s.' % image.status)

    image = gc.images.update(image, purge_props=args.purge_props, **fields)
    _image_show(image, args.human_readable)
示例#17
0
def do_member_create(gc, args):
    """Share a specific image with a tenant."""
    image = utils.find_resource(gc.images, args.image)
    gc.image_members.create(image, args.tenant_id, args.can_share)
示例#18
0
def do_member_delete(gc, args):
    """Remove a shared image from a tenant."""
    image_id = utils.find_resource(gc.images, args.image).id
    gc.image_members.delete(image_id, args.tenant_id)
示例#19
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    utils.save_image(body, args.file)
示例#20
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    utils.save_image(body, args.file)
示例#21
0
def do_member_create(gc, args):
    """Share a specific image with a tenant."""
    image = utils.find_resource(gc.images, args.image)
    gc.image_members.create(image, args.tenant_id, args.can_share)
示例#22
0
def do_image_show(gc, args):
    """Describe a specific image."""
    image_id = utils.find_resource(gc.images, args.image).id
    image = gc.images.get(image_id)
    _image_show(image, args.human_readable, max_column_width=int(args.max_column_width))
示例#23
0
def do_member_delete(gc, args):
    """Remove a shared image from a tenant."""
    image_id = utils.find_resource(gc.images, args.image).id
    gc.image_members.delete(image_id, args.tenant_id)