コード例 #1
0
ファイル: devices.py プロジェクト: mark4h/craton
    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
コード例 #2
0
ファイル: networks.py プロジェクト: mark4h/craton
    def put(self, context, id, request_data):
        """Update existing device values."""
        net_obj = dbapi.network_devices_update(context, id, request_data)

        device = jsonutils.to_primitive(net_obj)
        utils.add_up_link(context, device)

        return device, 200, None
コード例 #3
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
コード例 #4
0
    def put(self, context, id, request_data):
        """Update existing host data, or create if it does not exist."""
        host_obj = dbapi.hosts_update(context, id, request_data)

        host = jsonutils.to_primitive(host_obj)

        utils.add_up_link(context, host)

        return host, 200, None
コード例 #5
0
ファイル: networks.py プロジェクト: mark4h/craton
    def get(self, context, id, request_args):
        """Get network device by given id"""
        obj = dbapi.network_devices_get_by_id(context, id)
        obj = utils.format_variables(request_args, obj)
        device = jsonutils.to_primitive(obj)
        device['variables'] = jsonutils.to_primitive(obj.vars)

        utils.add_up_link(context, device)

        return device, 200, None
コード例 #6
0
ファイル: networks.py プロジェクト: mark4h/craton
    def post(self, context, request_data):
        """Create a new network device."""
        json = util.copy_project_id_into_json(context, request_data)
        obj = dbapi.network_devices_create(context, json)
        device = jsonutils.to_primitive(obj)
        if 'variables' in json:
            device["variables"] = jsonutils.to_primitive(obj.variables)
        else:
            device["variables"] = {}

        utils.add_up_link(context, device)

        location = v1.api.url_for(NetworkDeviceById, id=obj.id, _external=True)
        headers = {'Location': location}

        return device, 201, headers
コード例 #7
0
ファイル: hosts.py プロジェクト: thomasem/craton
    def post(self, context, request_data):
        """Create a new host."""
        json = util.copy_project_id_into_json(context, request_data)
        host_obj = dbapi.hosts_create(context, json)
        host = jsonutils.to_primitive(host_obj)
        if 'variables' in json:
            host["variables"] = jsonutils.to_primitive(host_obj.variables)
        else:
            host["variables"] = {}

        utils.add_up_link(context, host)

        location = v1.api.url_for(HostById, id=host_obj.id, _external=True)
        headers = {'Location': location}

        return host, 201, headers
コード例 #8
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
コード例 #9
0
ファイル: networks.py プロジェクト: mark4h/craton
    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