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
-
.included(includer) ⇒ Object
when this module is included, also extend our Class Methods.
Instance Method Summary collapse
-
#assign(*sns_to_assign) ⇒ Object
(also: #add)
Assign.
-
#assigned?(sn) ⇒ Boolean
(also: #include?)
Is this SN assigned to this prestage?.
-
#assigned_sns(refresh: false) ⇒ Array<String>
The serialnumbers assigned to this prestage.
- #save ⇒ Object
-
#scope(refresh: false) ⇒ PrestageScope
The scope data for this prestage.
-
#scope_path ⇒ Object
The scope endpoint for this instance.
- #unassign(*sns_to_unassign) ⇒ Object (also: #remove)
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
320 321 322 323 324 325 326 327 328 329 |
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 320 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?
This method uses the instance’s scope object, from a different API path than the class-level .assigned? method.
314 315 316 |
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 314 def assigned?(sn) assigned_sns.include? sn end |
#assigned_sns(refresh: false) ⇒ Array<String>
Returns the serialnumbers assigned to this prestage.
298 299 300 301 302 303 |
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 298 def assigned_sns(refresh: false) return @assigned_sns if @assigned_sns @assigned_sns = nil if refresh @assigned_sns = scope.assignments.map(&:serialNumber) end |
#save ⇒ Object
342 343 344 345 346 347 |
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 342 def save super # the scope needs to be refreshed, since its versionLock will need to be # updated @scope = nil end |
#scope(refresh: false) ⇒ PrestageScope
The scope data for this prestage
TODO: retain this caching?
283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 283 def scope(refresh: false) @scope = nil if refresh return @scope if @scope @scope = INSTANCE_SCOPE_OBJECT.new @cnx.get(scope_path) # TODO: is this the best way to deal with fetching a scope that # is more updated than the rest of the object? 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_path ⇒ Object
The scope endpoint for this instance
350 351 352 |
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 350 def scope_path @scope_path ||= "#{get_path}/#{SCOPE_PATH}" end |
#unassign(*sns_to_unassign) ⇒ Object Also known as: remove
332 333 334 335 336 337 338 339 |
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 332 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 |