Conch API

Logo

Datacenter build and management service

View the Project on GitHub joyent/conch-api

Conch::DB::ResultSet::Device

SOURCE

https://github.com/joyent/conch-api/blob/master/lib/Conch/DB/ResultSet/Device.pm

DESCRIPTION

Interface to queries involving devices.

METHODS

with_user_role

Constrains the resultset to those where the provided user_id has (at least) the specified role in at least one build associated with the specified device(s) (also taking into consideration the rack location of the device(s) if its phase is early enough).

This is a nested query which searches all builds in the database, so only use this query when its impact is outweighed by the impact of filtering a large resultset of devices in the database. (That is, usually you should start with a single device and then apply $device_rs->user_has_role($user_id, $role) to it.)

user_has_role

Checks that the provided user_id has (at least) the specified role in at least one build associated with the specified device(s), also taking into consideration the rack location of the device(s) if its phase is early enough.

Returns a boolean.

devices_without_location

Restrict results to those that do not have a registered location.

devices_reported_by_user_relay

Restrict results to those that have sent a device report proxied by a relay registered using the provided user’s credentials.

Note: this is not accurate if the relay is now registered to a different user than that which sent the report.

latest_device_report

Returns a resultset that finds the most recent device report matching the device(s). This is not a window function, so only one report is returned for all matching devices, not one report per device! (We probably never need to do the latter. *)

* but if we did, you’d want something like:

$self->search(undef, {
    '+columns' => {
        $col => $self->correlate('device_reports')
            ->columns($col)
            ->order_by({ -desc => 'device_reports.created' })
            ->rows(1)
            ->as_query
    },
});

device_settings_as_hash

Returns a hash of all (active) device settings for the specified device(s). (Will return merged results when passed a resultset referencing multiple devices, which is probably not what you want, so don’t do that.)

with_device_location

Modifies the resultset to add columns rack_id, rack_name (the full rack name including room data) and rack_unit_start.

with_sku

Modifies the resultset to add the sku column.

with_build_name

Modifies the resultset to add the build_name column.

location_data

Returns a resultset that provides location data (response.json#/$defs/DeviceLocation), optionally returned under a hash using the provided key name.

LICENSING

Copyright Joyent, Inc.

This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://www.mozilla.org/en-US/MPL/2.0/.