Example #1
0
    def get(self, context, request_args, pagination_params):
        """Get all devices, with optional filtering."""
        details = request_args.get("details")
        device_objs, link_params = dbapi.devices_get_all(
            context, request_args, pagination_params,
        )
        links = base.links_from(link_params)

        devices = {"hosts": [], "network-devices": []}
        for device_obj in device_objs:
            if details:
                device = utils.get_resource_with_vars(request_args,
                                                      device_obj)
            else:
                device = jsonutils.to_primitive(device_obj)

            utils.add_up_link(context, device)

            if isinstance(device_obj, models.Host):
                devices["hosts"].append(device)
            elif isinstance(device_obj, models.NetworkDevice):
                devices["network-devices"].append(device)
            else:
                LOG.error(
                    "The device is of unknown type: '%s'", device_obj
                )
                raise exceptions.UnknownException

        response_body = jsonutils.to_primitive(
            {'devices': devices, 'links': links}
        )

        return response_body, 200, None
Example #2
0
    def get(self, context, request_args, pagination_params):
        """Get all projects. Requires super admin privileges."""
        project_name = request_args["name"]
        details = request_args.get("details")

        if project_name:
            projects_obj, link_params = dbapi.projects_get_by_name(
                context,
                project_name,
                request_args,
                pagination_params,
            )
        else:
            projects_obj, link_params = dbapi.projects_get_all(
                context,
                request_args,
                pagination_params,
            )
            if details:
                projects_obj = [
                    utils.get_resource_with_vars(request_args, p)
                    for p in projects_obj
                ]

        links = base.links_from(link_params)
        response_body = {'projects': projects_obj, 'links': links}
        return jsonutils.to_primitive(response_body), 200, None
Example #3
0
    def get(self, context, request_args, pagination_params):
        """Get cloud(s) for the project. Get cloud details if
        for a particular cloud.
        """
        cloud_id = request_args.get("id")
        cloud_name = request_args.get("name")
        details = request_args.get("details")

        if not (cloud_id or cloud_name):
            # Get all clouds for this project
            clouds_obj, link_params = dbapi.clouds_get_all(
                context,
                request_args,
                pagination_params,
            )
            if details:
                clouds_obj = [
                    utils.get_resource_with_vars(request_args, c)
                    for c in clouds_obj
                ]
        else:
            if cloud_name:
                cloud_obj = dbapi.clouds_get_by_name(context, cloud_name)
                cloud_obj.data = cloud_obj.variables

            if cloud_id:
                cloud_obj = dbapi.clouds_get_by_id(context, cloud_id)
                cloud_obj.data = cloud_obj.variables

            clouds_obj = [cloud_obj]
            link_params = {}
        links = base.links_from(link_params)
        response_body = {'clouds': clouds_obj, 'links': links}
        return jsonutils.to_primitive(response_body), 200, None
Example #4
0
    def get(self, context, request_args, pagination_params):
        """Get region(s) for the project. Get region details if
        for a particular region.
        """
        region_id = request_args.get("id")
        region_name = request_args.get("name")
        details = request_args.get("details")

        if not (region_id or region_name):
            # Get all regions for this tenant
            regions_obj, link_params = dbapi.regions_get_all(
                context,
                request_args,
                pagination_params,
            )
            if details:
                regions_obj = [
                    utils.get_resource_with_vars(request_args, r)
                    for r in regions_obj
                ]
        else:
            if region_name:
                region_obj = dbapi.regions_get_by_name(context, region_name)
                region_obj.data = region_obj.variables

            if region_id:
                region_obj = dbapi.regions_get_by_id(context, region_id)
                region_obj.data = region_obj.variables

            regions_obj = [region_obj]
            link_params = {}
        links = base.links_from(link_params)
        response_body = {'regions': regions_obj, 'links': links}
        return jsonutils.to_primitive(response_body), 200, None
Example #5
0
    def get(self, context, id, request_args):
        """Get host by given id"""
        host_obj = dbapi.hosts_get_by_id(context, id)
        host = utils.get_resource_with_vars(request_args, host_obj)

        utils.add_up_link(context, host)

        return host, 200, None
Example #6
0
    def get(self, context, request_args, pagination_params):
        """Get all networks, with optional filtering."""
        details = request_args.get("details")
        networks_obj, link_params = dbapi.networks_get_all(
            context,
            request_args,
            pagination_params,
        )
        if details:
            networks_obj = [
                utils.get_resource_with_vars(request_args, n)
                for n in networks_obj
            ]

        links = base.links_from(link_params)
        response_body = {'networks': networks_obj, 'links': links}
        return jsonutils.to_primitive(response_body), 200, None
Example #7
0
    def get(self, context, request_args, pagination_params):
        """Get all hosts for region, with optional filtering."""
        details = request_args.get("details")
        hosts_obj, link_params = dbapi.hosts_get_all(
            context, request_args, pagination_params,
        )
        if details:
            hosts_obj = [utils.get_resource_with_vars(request_args, h)
                         for h in hosts_obj]

        links = base.links_from(link_params)
        response_body = jsonutils.to_primitive(
            {'hosts': hosts_obj, 'links': links}
        )

        for host in response_body["hosts"]:
            utils.add_up_link(context, host)

        return response_body, 200, None
Example #8
0
    def get(self, context, request_args, pagination_params):
        """Get all network devices."""
        details = request_args.get("details")
        devices_obj, link_params = dbapi.network_devices_get_all(
            context,
            request_args,
            pagination_params,
        )
        if details:
            devices_obj = [
                utils.get_resource_with_vars(request_args, d)
                for d in devices_obj
            ]

        links = base.links_from(link_params)
        response_body = jsonutils.to_primitive({
            'network_devices': devices_obj,
            'links': links
        })

        for device in response_body["network_devices"]:
            utils.add_up_link(context, device)

        return response_body, 200, None
Example #9
0
 def get(self, context, id, request_args):
     cell_obj = dbapi.cells_get_by_id(context, id)
     cell = utils.get_resource_with_vars(request_args, cell_obj)
     return cell, 200, None
Example #10
0
 def get(self, context, id, request_args):
     region_obj = dbapi.regions_get_by_id(context, id)
     region = utils.get_resource_with_vars(request_args, region_obj)
     return region, 200, None