Exemplo n.º 1
0
def list_vapps(ctx, name):
    try:
        client = ctx.obj['client']
        result = []
        if name is None:
            resource_type = 'adminVApp' if is_sysadmin(ctx) else 'vApp'
            qfilter = None
            attributes = None
        else:
            resource_type = 'adminVm' if is_sysadmin(ctx) else 'vm'
            qfilter = 'containerName==%s' % name
            attributes = [
                'name', 'containerName', 'ipAddress', 'status', 'memoryMB',
                'numberOfCpus'
            ]
        q = client.get_typed_query(
            resource_type,
            query_result_format=QueryResultFormat.ID_RECORDS,
            qfilter=qfilter)
        records = list(q.execute())
        if len(records) == 0:
            result = 'not found'
        else:
            for r in records:
                result.append(
                    to_dict(
                        r, resource_type=resource_type, attributes=attributes))
        stdout(result, ctx, show_id=False)
    except Exception as e:
        stderr(e, ctx)
Exemplo n.º 2
0
def list_vapps(ctx, name, filter):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        result = []
        records = []
        if name is None:
            if is_sysadmin(ctx):
                resource_type = ResourceType.ADMIN_VAPP.value
            else:
                resource_type = ResourceType.VAPP.value
            name = None
            attributes = None
        else:
            if name is not None:
                if is_sysadmin(ctx):
                    resource_type = ResourceType.ADMIN_VM.value
                else:
                    resource_type = ResourceType.VM.value
            if filter is None:
                filter = 'containerName==' + name
                attributes = [
                'name', 'containerName', 'ipAddress', 'status', 'memoryMB',
                'numberOfCpus'
                ]
            else:
                filter = 'name==' + name + ';' + filter
                resource_type = ResourceType.ADMIN_VAPP.value
                attributes = [
                'isDeployed', 'isEnabled', 'memoryAllocationMB', 'name', 'numberOfCpus', 'numberOfVMs', 'ownerName',
                'status', 'storageKB', 'vdcName'
                ]

        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        records = vdc.list_vapp_details(resource_type, filter)

        if len(records) == 0:
            if name is None:
                result = 'No vApps were found.'
            else:
                result = 'No vms were found.'

        else:
            for r in records:
                result.append(
                    to_dict(
                        r, resource_type=resource_type, attributes=attributes))

            stdout(result, ctx, show_id=False)
    except Exception as e:
        stderr(e, ctx)
Exemplo n.º 3
0
def list_catalogs_or_items(ctx, catalog_name):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        if catalog_name is None:
            in_use_org_href = ctx.obj['profiles'].get('org_href')
            org = Org(client, in_use_org_href)
            result = org.list_catalogs()
        else:
            result = []
            if is_sysadmin(ctx):
                resource_type = ResourceType.ADMIN_CATALOG_ITEM.value
            else:
                resource_type = ResourceType.CATALOG_ITEM.value
            q = client.get_typed_query(
                resource_type,
                query_result_format=QueryResultFormat.ID_RECORDS,
                equality_filter=('catalogName', catalog_name))
            records = list(q.execute())
            if len(records) == 0:
                result = 'not found'
            else:
                for r in records:
                    result.append(to_dict(r, resource_type=resource_type))
        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
Exemplo n.º 4
0
def list_catalogs_or_items(ctx, catalog_name):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        if catalog_name is None:
            in_use_org_href = ctx.obj['profiles'].get('org_href')
            org = Org(client, in_use_org_href)
            result = org.list_catalogs()
        else:
            result = []
            resource_type = \
                'adminCatalogItem' if is_sysadmin(ctx) else 'catalogItem'
            q = client.get_typed_query(
                resource_type,
                query_result_format=QueryResultFormat.ID_RECORDS,
                qfilter='catalogName==%s' % catalog_name)
            records = list(q.execute())
            if len(records) == 0:
                result = 'not found'
            else:
                for r in records:
                    result.append(to_dict(r, resource_type=resource_type))
        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
Exemplo n.º 5
0
def list_catalogs_or_items(ctx, catalog_name):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        if catalog_name is None:
            in_use_org_href = ctx.obj['profiles'].get('org_href')
            org = Org(client, in_use_org_href)
            result = org.list_catalogs()
        else:
            result = []
            if is_sysadmin(ctx):
                resource_type = ResourceType.ADMIN_CATALOG_ITEM.value
            else:
                resource_type = ResourceType.CATALOG_ITEM.value
            q = client.get_typed_query(
                resource_type,
                query_result_format=QueryResultFormat.ID_RECORDS,
                equality_filter=('catalogName', catalog_name))
            records = list(q.execute())
            if len(records) == 0:
                result = 'not found'
            else:
                for r in records:
                    result.append(to_dict(r, resource_type=resource_type))
        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
Exemplo n.º 6
0
def list_vapps(ctx, name):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        result = []
        if name is None:
            if is_sysadmin(ctx):
                resource_type = ResourceType.ADMIN_VAPP.value
            else:
                resource_type = ResourceType.VAPP.value
            name_filter = None
            attributes = None
        else:
            if is_sysadmin(ctx):
                resource_type = ResourceType.ADMIN_VM.value
            else:
                resource_type = ResourceType.VM.value
            name_filter = ('containerName', name)
            attributes = [
                'name', 'containerName', 'ipAddress', 'status', 'memoryMB',
                'numberOfCpus'
            ]
        q = client.get_typed_query(
            resource_type,
            query_result_format=QueryResultFormat.ID_RECORDS,
            equality_filter=name_filter)
        records = list(q.execute())
        if len(records) == 0:
            if name is None:
                result = 'No vApps were found.'
            else:
                result = 'No vms were found.'
        else:
            for r in records:
                result.append(
                    to_dict(r,
                            resource_type=resource_type,
                            attributes=attributes))
        stdout(result, ctx, show_id=False)
    except Exception as e:
        stderr(e, ctx)