Module: Jamf::Prestage

Included in:
ComputerPrestage, MobileDevicePrestage
Defined in:
lib/jamf/api/jamf_pro/mixins/prestage.rb

Overview

The Shared Code for ComputerPrestage and MobileDevicePrestage

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SCOPE_PATH =

The scope of a prestage is all the SN's that have been assigned to it

'scope'.freeze
ALL_SCOPES_OBJECT =

The class-level scopes method returns one of these objects

Jamf::OAPISchemas::PrestageScopeV2
INSTANCE_SCOPE_OBJECT =

the instance level scope method or the class level serials_for_prestage method returns one of these.

Jamf::OAPISchemas::PrestageScopeResponseV2
ALT_IDENTIFIERS =

Identifiers not marked in the superclass's OAPI_PROPERTIES constant which usually only marks ':id'. These values are unique in the collection

%i[profileUuid].freeze
NON_UNIQUE_IDENTIFIERS =

Values which are useful as identifiers, but are not necessarily unique in the collection - e.g. more than one computer can have the same name WARNING When more than one item in the collection has the same value for one of these fields, which one is used, returned, selected, is undefined You Have Been Warned!

%i[displayName].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object

when this module is included, also extend our Class Methods



32
33
34
35
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 32

def self.included(includer)
  Jamf.load_msg "--> #{includer} is including Jamf::Prestage"
  includer.extend(ClassMethods)
end

Instance Method Details

#assign(*sns_to_assign) ⇒ Object Also known as: add

Assign



305
306
307
308
309
310
311
312
313
314
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 305

def assign(*sns_to_assign)
  @scope = self.class.assign(sns_to_assign, to_prestage: @id, cnx: @cnx)
  @versionLock = @scope.versionLock

  # sns_to_assign.map!(&:to_s)
  # new_scope_sns = assigned_sns
  # new_scope_sns += sns_to_assign
  # new_scope_sns.uniq!
  # update_scope(new_scope_sns)
end

#assigned?(sn) ⇒ Boolean Also known as: include?

Is this SN assigned to this prestage?

Parameters:

  • sn (String)

    the sn to look for

Returns:

  • (Boolean)


299
300
301
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 299

def assigned?(sn)
  assigned_sns.include? sn
end

#assigned_snsArray<String>

Returns the serialnumbers assigned to this prestage.

Returns:

  • (Array<String>)

    the serialnumbers assigned to this prestage



289
290
291
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 289

def assigned_sns
  scope.assignments.map(&:serialNumber)
end

#saveObject



327
328
329
330
331
332
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 327

def save
  super
  # the scope needs to be refreshed, since its versionLock will need to be
  # updated
  @scope = nil
end

#scopePrestageScope

The scope data for this prestage

Parameters:

  • refresh (Boolean)

    reload fromthe API?

Returns:

  • (PrestageScope)


276
277
278
279
280
281
282
283
284
285
286
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 276

def scope(refresh: false)
  @scope = nil if refresh
  return @scope if @scope

  @scope = INSTANCE_SCOPE_OBJECT.new @cnx.get(scope_path)
  unless @scope.versionLock == @versionLock
    raise Jamf::VersionLockError, "The #{self.class} '#{name}' has been modified since it was fetched. Please refetch and try again"
  end

  @scope
end

#scope_pathObject

The scope endpoint for this instance



335
336
337
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 335

def scope_path
  @scope_path ||= "#{get_path}/#{SCOPE_PATH}"
end

#unassign(*sns_to_unassign) ⇒ Object Also known as: remove



317
318
319
320
321
322
323
324
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 317

def unassign(*sns_to_unassign)
  @scope = self.class.unassign(sns_to_unassign, from_prestage: @id, cnx: @cnx)
  @versionLock = @scope.versionLock
  # sns_to_unassign.map!(&:to_s)
  # new_scope_sns = assigned_sns
  # new_scope_sns -= sns_to_unassign
  # update_scope(new_scope_sns)
end