Method: Jamf::Prestage::ClassMethods#assigned?

Defined in:
lib/jamf/api/jamf_pro/mixins/prestage.rb

#assigned?(sn, prestage: nil, cnx: Jamf.cnx) ⇒ Boolean

Is the given serialNumber assigned to any prestage, or to the given prestage if a prestage is specified?

This uses .serials_by_prestage_id, the class-level scope path which gets a hash of all assigned SNS => the id of the prestage they are assigned to. The instance#assigned? method uses a different path which returnds more data in an OAPI object.

NOTE: If a serial number isn’t assigned to any prestage, it may really be unassigned or it may not exist in your ADE. To see if a SN exists in one of your Device Enrollment instances, use Jamf::DeviceEnrollment.include?

Parameters:

  • sn (String)

    the serial number to look for

  • prestage (Integer, String) (defaults to: nil)

    If provided, the id or name of an existing prestage in which to look for the sn. if omitted, all prestages are searched.

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API connection to use

Returns:

  • (Boolean)

    Is the sn assigned, at all or to the given prestage?

Raises:



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 164

def assigned?(sn, prestage: nil, cnx: Jamf.cnx)
  assigned_id = assigned_prestage_id(sn, cnx: cnx)

  # it isn't assigned at all
  return false unless assigned_id

  # we are looking to see if its assigned at all, which it is
  return true unless prestage

  # we are looking to see if its in a specific prestage
  psid = valid_id prestage, cnx: cnx
  raise Jamf::NoSuchItemError, "No #{self} matching '#{prestage}'" unless psid

  psid == assigned_id
end