Пример #1
0
def do_image_show(gc, args):
    """Describe a specific image."""
    image = gc.images.get(args.id)
    ignore = ['self', 'access', 'file', 'schema']
    image = dict(
        [item for item in six.iteritems(image) if item[0] not in ignore])
    utils.print_dict(image, max_column_width=int(args.max_column_width))
Пример #2
0
def do_image_show(gc, args):
    """Describe a specific image."""
    image = gc.images.get(args.id)
    ignore = ['self', 'access', 'file', 'schema']
    image = dict([item for item in six.iteritems(image) if item[0] not in
                  ignore])
    utils.print_dict(image, max_column_width=int(args.max_column_width))
Пример #3
0
def do_md_resource_type_associate(gc, args):
    """Associate resource type with a metadata definitions namespace."""
    schema = gc.schemas.get("metadefs/resource_type")
    _args = [(x[0].replace("-", "_"), x[1]) for x in vars(args).items()]
    fields = dict(filter(lambda x: x[1] is not None and (schema.is_core_property(x[0])), _args))
    resource_type = gc.metadefs_resource_type.associate(args.namespace, **fields)
    utils.print_dict(resource_type)
Пример #4
0
def _image_show(image):
    # Flatten image properties dict for display
    info = copy.deepcopy(image._info)
    for (k, v) in info.pop('properties').iteritems():
        info['Property \'%s\'' % k] = v

    utils.print_dict(info)
Пример #5
0
def _image_show(image):
    # Flatten image properties dict for display
    info = copy.deepcopy(image._info)
    for (k, v) in info.pop('properties').iteritems():
        info['Property \'%s\'' % k] = v

    utils.print_dict(info)
Пример #6
0
def do_import_info(gc, args):
    """Print import methods available from Glance."""
    try:
        import_info = gc.images.get_import_info()
    except exc.HTTPNotFound:
        utils.exit('Target Glance does not support Image Import workflow')
    else:
        utils.print_dict(import_info)
Пример #7
0
    def test_prettytable(self):
        class Struct:
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        columns = ['ID', 'Name']
        val = ['Name1', 'another', 'veeeery long']
        images = [
            Struct(**{
                'id': i**16,
                'name': val[i]
            }) for i in range(len(val))
        ]

        saved_stdout = sys.stdout
        try:
            sys.stdout = output_list = six.StringIO()
            utils.print_list(images, columns)

            sys.stdout = output_dict = six.StringIO()
            utils.print_dict(
                {
                    'K':
                    'k',
                    'Key':
                    'veeeeeeeeeeeeeeeeeeeeeeee'
                    'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
                    'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
                    'eeeeeeeeeeeery long value'
                },
                max_column_width=60)

        finally:
            sys.stdout = saved_stdout

        self.assertEqual(
            '''\
+-------+--------------+
| ID    | Name         |
+-------+--------------+
|       | Name1        |
| 1     | another      |
| 65536 | veeeery long |
+-------+--------------+
''', output_list.getvalue())

        self.assertEqual(
            '''\
+----------+--------------------------------------------------------------+
| Property | Value                                                        |
+----------+--------------------------------------------------------------+
| K        | k                                                            |
| Key      | veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
|          | eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
|          | ery long value                                               |
+----------+--------------------------------------------------------------+
''', output_dict.getvalue())
Пример #8
0
def _image_show(image, human_readable=False):
    # Flatten image properties dict for display
    info = copy.deepcopy(image._info)
    if human_readable:
        info['size'] = utils.make_size_human_readable(info['size'])
    for (k, v) in info.pop('properties').iteritems():
        info['Property \'%s\'' % k] = v

    utils.print_dict(info)
Пример #9
0
def _image_show(image, human_readable=False, max_column_width=80):
    # Flatten image properties dict for display
    info = copy.deepcopy(image._info)
    if human_readable:
        info["size"] = utils.make_size_human_readable(info["size"])
    for (k, v) in six.iteritems(info.pop("properties")):
        info["Property '%s'" % k] = v

    utils.print_dict(info, max_column_width=max_column_width)
Пример #10
0
def do_location_add(gc, args):
    """Add a location (and related metadata) to an image."""
    try:
        metadata = json.loads(args.metadata)
    except ValueError:
        utils.exit('Metadata is not a valid JSON object.')
    else:
        image = gc.images.add_location(args.id, args.url, metadata)
        utils.print_dict(image)
Пример #11
0
def do_location_update(gc, args):
    """Update metadata of an image's location."""
    try:
        metadata = json.loads(args.metadata)
    except ValueError:
        utils.exit('Metadata is not a valid JSON object.')
    else:
        image = gc.images.update_location(args.id, args.url, metadata)
        utils.print_dict(image)
Пример #12
0
def do_location_add(gc, args):
    """Add a location (and related metadata) to an image."""
    try:
        metadata = json.loads(args.metadata)
    except ValueError:
        utils.exit("Metadata is not a valid JSON object.")
    else:
        image = gc.images.add_location(args.id, args.url, metadata)
        utils.print_dict(image)
Пример #13
0
def do_location_update(gc, args):
    """Update metadata of an image's location."""
    try:
        metadata = json.loads(args.metadata)
    except ValueError:
        utils.exit("Metadata is not a valid JSON object.")
    else:
        image = gc.images.update_location(args.id, args.url, metadata)
        utils.print_dict(image)
Пример #14
0
def _image_show(image, human_readable=False, max_column_width=80):
    # Flatten image properties dict for display
    info = copy.deepcopy(image._info)
    if human_readable:
        info['size'] = utils.make_size_human_readable(info['size'])
    for (k, v) in six.iteritems(info.pop('properties')):
        info['Property \'%s\'' % k] = v

    utils.print_dict(info, max_column_width=max_column_width)
Пример #15
0
def do_md_object_property_show(gc, args):
    """Describe a specific metadata definitions property inside an object."""
    obj = gc.metadefs_object.get(args.namespace, args.object)
    try:
        prop = obj["properties"][args.property]
        prop["name"] = args.property
    except KeyError:
        utils.exit("Property %s not found in object %s." % (args.property, args.object))
    utils.print_dict(prop, int(args.max_column_width))
Пример #16
0
    def test_prettytable(self):
        class Struct(object):
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        columns = ["ID", "Name"]
        val = ["Name1", "another", "veeeery long"]
        images = [Struct(**{"id": i ** 16, "name": val[i]}) for i in range(len(val))]

        saved_stdout = sys.stdout
        try:
            sys.stdout = output_list = six.StringIO()
            utils.print_list(images, columns)

            sys.stdout = output_dict = six.StringIO()
            utils.print_dict(
                {
                    "K": "k",
                    "Key": "veeeeeeeeeeeeeeeeeeeeeeee"
                    "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
                    "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
                    "eeeeeeeeeeeery long value",
                },
                max_column_width=60,
            )

        finally:
            sys.stdout = saved_stdout

        self.assertEqual(
            """\
+-------+--------------+
| ID    | Name         |
+-------+--------------+
|       | Name1        |
| 1     | another      |
| 65536 | veeeery long |
+-------+--------------+
""",
            output_list.getvalue(),
        )

        self.assertEqual(
            """\
+----------+--------------------------------------------------------------+
| Property | Value                                                        |
+----------+--------------------------------------------------------------+
| K        | k                                                            |
| Key      | veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
|          | eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
|          | ery long value                                               |
+----------+--------------------------------------------------------------+
""",
            output_dict.getvalue(),
        )
Пример #17
0
def do_md_resource_type_associate(gc, args):
    """Associate resource type with a metadata definitions namespace."""
    schema = gc.schemas.get('metadefs/resource_type')
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(
        filter(lambda x: x[1] is not None and (schema.is_core_property(x[0])),
               _args))
    resource_type = gc.metadefs_resource_type.associate(
        args.namespace, **fields)
    utils.print_dict(resource_type)
Пример #18
0
def do_md_object_property_show(gc, args):
    """Describe a specific metadata definitions property inside an object."""
    obj = gc.metadefs_object.get(args.namespace, args.object)
    try:
        prop = obj['properties'][args.property]
        prop['name'] = args.property
    except KeyError:
        utils.exit('Property %s not found in object %s.' %
                   (args.property, args.object))
    utils.print_dict(prop, int(args.max_column_width))
Пример #19
0
def _object_show(obj, max_column_width=None):
    obj = dict(obj)  # Warlock objects are compatible with dicts
    # Flatten dicts for display
    if 'properties' in obj:
        objects = [k for k in obj['properties']]
        obj['properties'] = objects

    if max_column_width:
        utils.print_dict(obj, max_column_width)
    else:
        utils.print_dict(obj)
Пример #20
0
def do_md_property_create(gc, args):
    """Create a new metadata definitions property inside a namespace."""
    try:
        schema = json.loads(args.schema)
    except ValueError:
        utils.exit("Schema is not a valid JSON object.")
    else:
        fields = {"name": args.name, "title": args.title}
        fields.update(schema)
        new_property = gc.metadefs_property.create(args.namespace, **fields)
        utils.print_dict(new_property)
Пример #21
0
def _object_show(obj, max_column_width=None):
    obj = dict(obj)  # Warlock objects are compatible with dicts
    # Flatten dicts for display
    if "properties" in obj:
        objects = [k for k in obj["properties"]]
        obj["properties"] = objects

    if max_column_width:
        utils.print_dict(obj, max_column_width)
    else:
        utils.print_dict(obj)
Пример #22
0
def do_md_property_create(gc, args):
    """Create a new metadata definitions property inside a namespace."""
    try:
        schema = json.loads(args.schema)
    except ValueError:
        utils.exit('Schema is not a valid JSON object.')
    else:
        fields = {'name': args.name, 'title': args.title}
        fields.update(schema)
        new_property = gc.metadefs_property.create(args.namespace, **fields)
        utils.print_dict(new_property)
Пример #23
0
def do_location_update(gc, args):
    """Update metadata of an image's location."""
    try:
        metadata = json.loads(args.metadata)

        if metadata == {}:
            print("WARNING -- The location's metadata will be updated to "
                  "an empty JSON object.")
    except ValueError:
        utils.exit('Metadata is not a valid JSON object.')
    else:
        image = gc.images.update_location(args.id, args.url, metadata)
        utils.print_dict(image)
Пример #24
0
def do_location_update(gc, args):
    """Update metadata of an image's location."""
    try:
        metadata = json.loads(args.metadata)

        if metadata == {}:
            print("WARNING -- The location's metadata will be updated to "
                  "an empty JSON object.")
    except ValueError:
        utils.exit('Metadata is not a valid JSON object.')
    else:
        image = gc.images.update_location(args.id, args.url, metadata)
        utils.print_dict(image)
Пример #25
0
def do_task_create(gc, args):
    """Create a new task."""
    if not (args.type and args.input):
        utils.exit("Unable to create task. Specify task type and input.")
    else:
        try:
            input = json.loads(args.input)
        except ValueError:
            utils.exit('Failed to parse the "input" parameter. Must be a ' "valid JSON object.")

        task_values = {"type": args.type, "input": input}
        task = gc.tasks.create(**task_values)
        ignore = ["self", "schema"]
        task = dict([item for item in task.iteritems() if item[0] not in ignore])
        utils.print_dict(task)
Пример #26
0
    def test_prettytable(self):
        class Struct(object):
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        columns = ['ID', 'Name']
        val = ['Name1', 'another', 'veeeery long']
        images = [Struct(**{'id': i ** 16, 'name': val[i]})
                  for i in range(len(val))]

        saved_stdout = sys.stdout
        try:
            sys.stdout = output_list = six.StringIO()
            utils.print_list(images, columns)

            sys.stdout = output_dict = six.StringIO()
            utils.print_dict({'K': 'k', 'Key': 'veeeeeeeeeeeeeeeeeeeeeeee'
                              'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
                              'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
                              'eeeeeeeeeeeery long value'},
                             max_column_width=60)

        finally:
            sys.stdout = saved_stdout

        self.assertEqual('''\
+-------+--------------+
| ID    | Name         |
+-------+--------------+
|       | Name1        |
| 1     | another      |
| 65536 | veeeery long |
+-------+--------------+
''',
                         output_list.getvalue())

        self.assertEqual('''\
+----------+--------------------------------------------------------------+
| Property | Value                                                        |
+----------+--------------------------------------------------------------+
| K        | k                                                            |
| Key      | veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
|          | eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
|          | ery long value                                               |
+----------+--------------------------------------------------------------+
''',
                         output_dict.getvalue())
Пример #27
0
def do_task_create(gc, args):
    """Create a new task."""
    if not (args.type and args.input):
        utils.exit('Unable to create task. Specify task type and input.')
    else:
        try:
            input = json.loads(args.input)
        except ValueError:
            utils.exit('Failed to parse the "input" parameter. Must be a '
                       'valid JSON object.')

        task_values = {'type': args.type, 'input': input}
        task = gc.tasks.create(**task_values)
        ignore = ['self', 'schema']
        task = dict([item for item in task.items() if item[0] not in ignore])
        utils.print_dict(task)
Пример #28
0
def do_md_property_update(gc, args):
    """Update metadata definitions property inside a namespace."""
    fields = {}
    if args.name:
        fields["name"] = args.name
    if args.title:
        fields["title"] = args.title
    if args.schema:
        try:
            schema = json.loads(args.schema)
        except ValueError:
            utils.exit("Schema is not a valid JSON object.")
        else:
            fields.update(schema)

    new_property = gc.metadefs_property.update(args.namespace, args.property, **fields)
    utils.print_dict(new_property)
Пример #29
0
def do_md_property_update(gc, args):
    """Update metadata definitions property inside a namespace."""
    fields = {}
    if args.name:
        fields['name'] = args.name
    if args.title:
        fields['title'] = args.title
    if args.schema:
        try:
            schema = json.loads(args.schema)
        except ValueError:
            utils.exit('Schema is not a valid JSON object.')
        else:
            fields.update(schema)

    new_property = gc.metadefs_property.update(args.namespace, args.property,
                                               **fields)
    utils.print_dict(new_property)
Пример #30
0
def do_image_create(gc, args):
    """Create a new image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(
        filter(
            lambda x: x[1] is not None and
            (x[0] == 'property' or schema.is_core_property(x[0])), _args))

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

    image = gc.images.create(**fields)
    ignore = ['self', 'access', 'file', 'schema']
    image = dict([item for item in image.iteritems() if item[0] not in ignore])
    utils.print_dict(image)
Пример #31
0
def _namespace_show(namespace, max_column_width=None):
    namespace = dict(namespace)  # Warlock objects are compatible with dicts
    # Flatten dicts for display
    if 'properties' in namespace:
        props = [k for k in namespace['properties']]
        namespace['properties'] = props
    if 'resource_type_associations' in namespace:
        assocs = [assoc['name']
                  for assoc in namespace['resource_type_associations']]
        namespace['resource_type_associations'] = assocs
    if 'objects' in namespace:
        objects = [obj['name'] for obj in namespace['objects']]
        namespace['objects'] = objects

    if max_column_width:
        utils.print_dict(namespace, max_column_width)
    else:
        utils.print_dict(namespace)
Пример #32
0
def _namespace_show(namespace, max_column_width=None):
    namespace = dict(namespace)  # Warlock objects are compatible with dicts
    # Flatten dicts for display
    if 'properties' in namespace:
        props = [k for k in namespace['properties']]
        namespace['properties'] = props
    if 'resource_type_associations' in namespace:
        assocs = [assoc['name']
                  for assoc in namespace['resource_type_associations']]
        namespace['resource_type_associations'] = assocs
    if 'objects' in namespace:
        objects = [obj['name'] for obj in namespace['objects']]
        namespace['objects'] = objects

    if max_column_width:
        utils.print_dict(namespace, max_column_width)
    else:
        utils.print_dict(namespace)
Пример #33
0
def do_image_create(gc, args):
    """Create a new image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(filter(lambda x: x[1] is not None and
                         (x[0] == 'property' or
                          schema.is_core_property(x[0])),
                         _args))

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

    image = gc.images.create(**fields)
    ignore = ['self', 'access', 'file', 'schema']
    image = dict([item for item in six.iteritems(image)
                  if item[0] not in ignore])
    utils.print_dict(image)
Пример #34
0
def _namespace_show(namespace, max_column_width=None):
    namespace = dict(namespace)  # Warlock objects are compatible with dicts
    # Flatten dicts for display
    if "properties" in namespace:
        props = [k for k in namespace["properties"]]
        namespace["properties"] = props
    if "resource_type_associations" in namespace:
        assocs = [assoc["name"] for assoc in namespace["resource_type_associations"]]
        namespace["resource_type_associations"] = assocs
    if "objects" in namespace:
        objects = [obj["name"] for obj in namespace["objects"]]
        namespace["objects"] = objects

    if "tags" in namespace:
        tags = [tag["name"] for tag in namespace["tags"]]
        namespace["tags"] = tags

    if max_column_width:
        utils.print_dict(namespace, max_column_width)
    else:
        utils.print_dict(namespace)
Пример #35
0
def do_image_update(gc, args):
    """Update an existing image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(filter(lambda x: x[1] is not None and
                         (x[0] in ['property', 'remove_property'] or
                          schema.is_core_property(x[0])),
                         _args))

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

    remove_properties = fields.pop('remove_property', None)

    image_id = fields.pop('id')
    image = gc.images.update(image_id, remove_properties, **fields)
    ignore = ['self', 'access', 'file', 'schema']
    image = dict([item for item in image.iteritems()
                  if item[0] not in ignore])
    utils.print_dict(image)
Пример #36
0
def do_image_update(gc, args):
    """Update an existing image."""
    schema = gc.schemas.get("image")
    _args = [(x[0].replace('-', '_'), x[1]) for x in vars(args).items()]
    fields = dict(
        filter(
            lambda x: x[1] is not None and
            (x[0] in ['property', 'remove_property'] or schema.
             is_core_property(x[0])), _args))

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

    remove_properties = fields.pop('remove_property', None)

    image_id = fields.pop('id')
    image = gc.images.update(image_id, remove_properties, **fields)
    ignore = ['self', 'access', 'file', 'schema']
    image = dict(
        [item for item in six.iteritems(image) if item[0] not in ignore])
    utils.print_dict(image)
Пример #37
0
def do_md_property_show(gc, args):
    """Describe a specific metadata definitions property inside a namespace."""
    prop = gc.metadefs_property.get(args.namespace, args.property)
    utils.print_dict(prop, int(args.max_column_width))
Пример #38
0
def _tag_show(tag, max_column_width=None):
    tag = dict(tag)  # Warlock objects are compatible with dicts
    if max_column_width:
        utils.print_dict(tag, max_column_width)
    else:
        utils.print_dict(tag)
Пример #39
0
def do_task_show(gc, args):
    """Describe a specific task."""
    task = gc.tasks.get(args.id)
    ignore = ["self", "schema"]
    task = dict([item for item in task.iteritems() if item[0] not in ignore])
    utils.print_dict(task)
Пример #40
0
def do_task_show(gc, args):
    """Describe a specific task."""
    task = gc.tasks.get(args.id)
    ignore = ['self', 'schema']
    task = dict([item for item in task.iteritems() if item[0] not in ignore])
    utils.print_dict(task)
Пример #41
0
def do_md_property_show(gc, args):
    """Describe a specific metadata definitions property inside a namespace."""
    prop = gc.metadefs_property.get(args.namespace, args.property)
    utils.print_dict(prop, int(args.max_column_width))
Пример #42
0
def _tag_show(tag, max_column_width=None):
    tag = dict(tag)  # Warlock objects are compatible with dicts
    if max_column_width:
        utils.print_dict(tag, max_column_width)
    else:
        utils.print_dict(tag)