module Jamf::MacOSManagedUpdates::ClassMethods

Class Methods

Public Class Methods

extended(extender) click to toggle source

when this module is included, also extend our Class Methods

   # File lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb
67 def self.extended(extender)
68   Jamf.load_msg "--> #{extender} is extending #{self}"
69 end

Public Instance Methods

available_os_updates(cnx: Jamf.cnx) click to toggle source

get the list of available OS versions

@return [Array<String>]

   # File lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb
75 def available_os_updates(cnx: Jamf.cnx)
76   data = cnx.jp_get(MANAGED_SW_UPDATES_AVAILABLE_VERSIONS_RSRC)
77   Jamf::OAPISchemas::AvailableUpdates.new(data).availableUpdates
78 end
send_managed_os_update(updateAction:, deviceIds: nil, groupId: nil, maxDeferrals: nil, version: nil, skipVersionVerification: false, applyMajorUpdate: false, forceRestart: false, cnx: Jamf.cnx) click to toggle source

Send the os update command to target Computers or a ComputerGroup

@param updateAction [Symbol, Symbol] Required. One of the keys or values from UPDATE_ACTIONS

@param deviceIds [String, Integer, Array<String, Integer>] Identifiers for the

computer targets. Required if no groupId is given.

@param groupId [String, Integer] Identifier for the computer group target.

Requied if no deviceIds are given.

@param maxDeferrals [Integer] Allow users to defer the update the provided number

of times before macOS forces the update. If a value is provided, the Software
Update will use the InstallLater install action. MaxDeferral is ignored if using the
:download updateAction.

@param version [String] The OS version to install. If no value is provided, the

version will default to latest version based on device eligibility.

@param skipVersionVerification [Boolean] Should the specified version be installed

even it it isn't applicable to this machine? If no value is provided, will default to false.
If true, the specified version will be forced to complete the :install updateAction.

@param applyMajorUpdate [Boolean] Available only when updating to the latest version

based on device eligibility. Defaults to false. If false the calculated latest version
will only include minor version updates. If a value is provided, the calculated latest
version will include minor and major version updates.

@param forceRestart [Boolean] Will default to false. Can only be true if updateAction

is :install and the target devices are on macOs 11 or higher.
If true, the DownloadAndInstall action is performed, a restart will be forced.
MaxDeferral will be ignored if true.

@param cnx [Jamf::Connection] The API connection to use. Defaults to Jamf.cnx

@return [Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse]

    # File lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb
116 def send_managed_os_update(updateAction:, deviceIds: nil, groupId: nil, maxDeferrals: nil, version: nil, skipVersionVerification: false,
117                            applyMajorUpdate: false, forceRestart: false, cnx: Jamf.cnx)
118   action_to_send = UPDATE_ACTIONS.value?(updateAction) ? updateAction : UPDATE_ACTIONS[updateAction]
119 
120   raise ArgumentError, "Unknown updateAction, must be one of: #{UPDATE_ACTIONS.keys.join ', '}" unless action_to_send
121 
122   if self == Jamf::Computer
123     raise ArgumentError, 'Must provide one or more deviceIds' unless deviceIds
124   elsif self == Jamf::ComputerGroup
125     raise ArgumentError, 'Must provide a groupId' unless groupId
126   else
127     raise Jamf::UnsupportedError, 'This method is only available for Jamf::Computer and Jamf::ComputerGroup'
128   end
129 
130   if version
131     available_versions = available_os_updates
132     raise ArgumentError, "Invalid version, must be one of: #{available_versions.join ', '}" unless available_versions.include? version
133   end
134 
135   if deviceIds
136     deviceIds = [deviceIds] unless deviceIds.is_a?(Array)
137     deviceIds.map! { |id| valid_id id, cnx: cnx }
138   end
139   groupId = valid_id(groupId, cnx: cnx) if groupId
140 
141   data = {}
142   # ids in the JPAPI are string containing integers
143   data[:deviceIds] = deviceIds.map(&:to_s) if deviceIds
144   data[:groupId] = groupId.to_s if groupId
145 
146   data[:maxDeferrals] = maxDeferrals if maxDeferrals
147   data[:version] = version if version
148   data[:skipVersionVerification] = skipVersionVerification if skipVersionVerification
149   data[:applyMajorUpdate] = applyMajorUpdate if applyMajorUpdate
150   data[:updateAction] = action_to_send
151   data[:forceRestart] = forceRestart if forceRestart
152 
153   payload = Jamf::OAPISchemas::MacOsManagedSoftwareUpdate.new(data).to_json
154 
155   result = cnx.jp_post MANAGED_SW_UPDATES_SEND_UPDATES_RSRC, payload
156   Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse.new result
157 end