Ejemplo n.º 1
0
def info(ctx, resource_type, resource_id):
    """Display details of a resource in vCloud Director.

\b
    Description
        The info command displays details of a resource with the provided type
        and id. Resource type is not case sensitive. When invoked without a
        resource type, list the available types. Admin resources are only
        allowed when the user is the system administrator.
\b
    Examples
        vcd info task ffb96443-d7f3-4200-825d-0f297388ebc0
            Get details of task by id.
\b
        vcd info vapp c48a4e1a-7bd9-4177-9c67-4c330016b99f
            Get details of vApp by id.
\b
        vcd catalog info my-catalog my-item
            Get details of an item listed in the previous command.
\b
        vcd info catalogitem f653b137-0d14-4ea9-8f14-dcd2b7914110
            Get details of the catalog item based on the 'id' listed in the
            previous command.
\b
        vcd info vapptemplate 53b83b27-1f2b-488e-9020-a27aee8cb640
            Get details of the vApp tepmlate based on the 'template-id' listed
            in the previous command.
\b
    See Also
        Several 'vcd' commands provide the id of a resource, including the
        'vcd search' command.
    """

    try:
        if resource_type is None or resource_id is None:
            click.secho(ctx.get_help())
            click.echo('\nAvailable resource types:')
            click.echo(tabulate(tabulate_names(RESOURCE_TYPES, 4)))
            return
        restore_session(ctx)
        client = ctx.obj['client']
        q = client.get_typed_query(
            to_camel_case(resource_type, RESOURCE_TYPES),
            query_result_format=QueryResultFormat.REFERENCES,
            qfilter='id==%s' % resource_id)
        records = list(q.execute())
        if len(records) == 0:
            raise Exception('not found')
        elif len(records) > 1:
            raise Exception('multiple found')
        resource = client.get_resource(records[0].get('href'))
        stdout_xml(resource, ctx.find_root().params['is_colorized'])
    except Exception as e:
        import traceback
        traceback.print_exc()
        stderr(e, ctx)
Ejemplo n.º 2
0
def info(ctx, resource_type, resource_id):
    """Display details of a resource in vCloud Director.

\b
    Description
        The info command displays details of a resource with the provided type
        and id. Resource type is not case sensitive. When invoked without a
        resource type, list the available types. Admin resources are only
        allowed when the user is the system administrator.
\b
    Examples
        vcd info task ffb96443-d7f3-4200-825d-0f297388ebc0
            Get details of task by id.
\b
        vcd info vapp c48a4e1a-7bd9-4177-9c67-4c330016b99f
            Get details of vApp by id.
\b
        vcd catalog info my-catalog my-item
            Get details of an item listed in the previous command.
\b
        vcd info catalogitem f653b137-0d14-4ea9-8f14-dcd2b7914110
            Get details of the catalog item based on the 'id' listed in the
            previous command.
\b
        vcd info vapptemplate 53b83b27-1f2b-488e-9020-a27aee8cb640
            Get details of the vApp tepmlate based on the 'template-id' listed
            in the previous command.
\b
    See Also
        Several 'vcd' commands provide the id of a resource, including the
        'vcd search' command.
    """
    try:
        if resource_type is None or resource_id is None:
            click.secho(ctx.get_help())
            click.echo('\nAvailable resource types:')
            click.echo(tabulate(tabulate_names(RESOURCE_TYPES, 4)))
            return
        restore_session(ctx)
        client = ctx.obj['client']
        q = client.get_typed_query(
            to_camel_case(resource_type, RESOURCE_TYPES),
            query_result_format=QueryResultFormat.REFERENCES,
            equality_filter=('id', resource_id))
        records = list(q.execute())
        if len(records) == 0:
            raise Exception('not found')
        elif len(records) > 1:
            raise Exception('multiple found')
        resource = client.get_resource(records[0].get('href'))
        stdout_xml(resource, ctx.find_root().params['is_colorized'])
    except Exception as e:
        import traceback
        traceback.print_exc()
        stderr(e, ctx)