Module: Jamf::MacOSManagedUpdates::ClassMethods

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

Overview

Class Methods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object

when this module is included, also extend our Class Methods



67
68
69
# File 'lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb', line 67

def self.extended(extender)
  Jamf.load_msg "--> #{extender} is extending #{self}"
end

Instance Method Details

#available_os_updates(cnx: Jamf.cnx) ⇒ Array<String>

get the list of available OS versions

Returns:



75
76
77
78
# File 'lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb', line 75

def available_os_updates(cnx: Jamf.cnx)
  data = cnx.jp_get(MANAGED_SW_UPDATES_AVAILABLE_VERSIONS_RSRC)
  Jamf::OAPISchemas::AvailableUpdates.new(data).availableUpdates
end

#send_managed_os_update(updateAction:, deviceIds: nil, groupId: nil, maxDeferrals: nil, version: nil, skipVersionVerification: false, applyMajorUpdate: false, forceRestart: false, cnx: Jamf.cnx) ⇒ Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse

Send the os update command to target Computers or a ComputerGroup

Parameters:

  • updateAction (Symbol, Symbol)

    Required. One of the keys or values from UPDATE_ACTIONS

  • deviceIds (String, Integer, Array<String, Integer>) (defaults to: nil)

    Identifiers for the computer targets. Required if no groupId is given.

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

    Identifier for the computer group target. Requied if no deviceIds are given.

  • maxDeferrals (Integer) (defaults to: nil)

    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.

  • version (String) (defaults to: nil)

    The OS version to install. If no value is provided, the version will default to latest version based on device eligibility.

  • skipVersionVerification (Boolean) (defaults to: false)

    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.

  • applyMajorUpdate (Boolean) (defaults to: false)

    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.

  • forceRestart (Boolean) (defaults to: false)

    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.

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

    The API connection to use. Defaults to Jamf.cnx

Returns:

Raises:

  • (ArgumentError)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb', line 116

def send_managed_os_update(updateAction:, deviceIds: nil, groupId: nil, maxDeferrals: nil, version: nil, skipVersionVerification: false,
                           applyMajorUpdate: false, forceRestart: false, cnx: Jamf.cnx)
  action_to_send = UPDATE_ACTIONS.value?(updateAction) ? updateAction : UPDATE_ACTIONS[updateAction]

  raise ArgumentError, "Unknown updateAction, must be one of: #{UPDATE_ACTIONS.keys.join ', '}" unless action_to_send

  if self == Jamf::Computer
    raise ArgumentError, 'Must provide one or more deviceIds' unless deviceIds
  elsif self == Jamf::ComputerGroup
    raise ArgumentError, 'Must provide a groupId' unless groupId
  else
    raise Jamf::UnsupportedError, 'This method is only available for Jamf::Computer and Jamf::ComputerGroup'
  end

  if version
    available_versions = available_os_updates
    raise ArgumentError, "Invalid version, must be one of: #{available_versions.join ', '}" unless available_versions.include? version
  end

  if deviceIds
    deviceIds = [deviceIds] unless deviceIds.is_a?(Array)
    deviceIds.map! { |id| valid_id id, cnx: cnx }
  end
  groupId = valid_id(groupId, cnx: cnx) if groupId

  data = {}
  # ids in the JPAPI are string containing integers
  data[:deviceIds] = deviceIds.map(&:to_s) if deviceIds
  data[:groupId] = groupId.to_s if groupId

  data[:maxDeferrals] = maxDeferrals if maxDeferrals
  data[:version] = version if version
  data[:skipVersionVerification] = skipVersionVerification if skipVersionVerification
  data[:applyMajorUpdate] = applyMajorUpdate if applyMajorUpdate
  data[:updateAction] = action_to_send
  data[:forceRestart] = forceRestart if forceRestart

  payload = Jamf::OAPISchemas::MacOsManagedSoftwareUpdate.new(data).to_json

  result = cnx.jp_post MANAGED_SW_UPDATES_SEND_UPDATES_RSRC, payload
  Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse.new result
end