Class: Windoo::PatchManager

Inherits:
BaseClasses::ArrayManager show all
Defined in:
lib/windoo/objects/patch_manager.rb

Overview

An ArrayManager for dealing with the Patches of a SoftwareTitle

An instance of this is returned by SoftwareTitle#patches

Constant Summary collapse

MEMBER_CLASS =

Constants

Windoo::Patch

Constants inherited from BaseClasses::ArrayManager

BaseClasses::ArrayManager::PP_OMITTED_INST_VARS

Instance Attribute Summary

Attributes inherited from BaseClasses::ArrayManager

#container

Instance Method Summary collapse

Methods inherited from BaseClasses::ArrayManager

#[], #each, #empty?, #find, #find_by_attr, #first, #index, #initialize, #last, #pretty_print_instance_variables, #size, #to_a

Constructor Details

This class inherits a constructor from Windoo::BaseClasses::ArrayManager

Instance Method Details

#add_patch(version:, minimumOperatingSystem:, releaseDate: nil, reboot: nil, standalone: nil, absoluteOrderId: 0) ⇒ Integer

Add a Patch to this SoftwareTitle. NOTE: patches cannot be enabled when added, you must call ‘enable’ on them after creating any necessary sub-objects.

Patches must be ordered from newest to oldest, and are indexed zero-based, like Ruby Arrays.

By default, patches are added at the front, index 0,meaning the are the newest.

To make the new patch appear later in the order, provide a zero-based integer as ‘absoluteOrderId’ (0, the first in the order, is the default). So to add this new patch as older than the first and second, use

absoluteOrderId: 2

All others will be adjusted automatically.

Parameters:

  • version (String)

    The version of the title that is installed by this patch. Required.

  • minimumOperatingSystem (String)

    The lowest OS version that this patch will run on. Required.

  • releaseDate (Time, String) (defaults to: nil)

    The date and time this patch became available. Will be stored as a UTC timestampe in ISO8601 format.

  • reboot (Boolean) (defaults to: nil)

    Does this patch require a reboot after installation?

  • standalone (Boolean) (defaults to: nil)

    Can this patch be installed as the initial install of this SoftwareTitle? If not, a previous version must already be installed before this one can be.

  • absoluteOrderId (Integer) (defaults to: 0)

    The zero-based position of this patch among all the others for this title. Ordered from newest to oldest. By default, this patch will be added at ‘0’ the newest, first in the Array.

Returns:

  • (Integer)

    The id of the new Patch



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/windoo/objects/patch_manager.rb', line 107

def add_patch(version:, minimumOperatingSystem:, releaseDate: nil, reboot: nil, standalone: nil, absoluteOrderId: 0)
  new_patch = Windoo::Patch.create(
    cnx: container.cnx,
    container: container,
    version: version,
    minimumOperatingSystem: minimumOperatingSystem,
    releaseDate: releaseDate,
    reboot: reboot,
    standalone: standalone,
    absoluteOrderId: absoluteOrderId
  )

  # call the method from our superclass to add it to the array
  add_member new_patch, index: absoluteOrderId
  update_local_absoluteOrderIds
  new_patch.patchId
end

#all_enabledArray<Windoo::Patch] An array of the currently enabled patches

Returns Array<Windoo::Patch] An array of the currently enabled patches.

Returns:

  • (Array<Windoo::Patch] An array of the currently enabled patches)

    Array<Windoo::Patch] An array of the currently enabled patches



28
29
30
# File 'lib/windoo/objects/patch_manager.rb', line 28

def all_enabled
  @managed_array.select(&:enabled?)
end

#all_versionsHash {Integer => String}

Returns The Versions for this title.

Returns:

  • (Hash {Integer => String})

    The Versions for this title



49
50
51
# File 'lib/windoo/objects/patch_manager.rb', line 49

def all_versions
  @managed_array.map(&:version)
end

#delete_all_patchesvoid

This method returns an undefined value.

Delete all the patches



215
216
217
218
219
220
# File 'lib/windoo/objects/patch_manager.rb', line 215

def delete_all_patches
  delete_all_members
  # titles without a patch are not valid
  # so must be disabled
  @container.disable
end

#delete_patch(patchId) ⇒ Integer

Delete a Patch from this SoftwareTitle

When deleting a Patch via this method, it is deleted from the server immediately, there is no need to #save the SoftwareTitle

Parameters:

  • patchId (Integer)

    the id of the Patch to be updated.

Returns:

  • (Integer)

    The id of the deleted Patch



199
200
201
202
203
204
205
206
207
208
209
# File 'lib/windoo/objects/patch_manager.rb', line 199

def delete_patch(patchId)
  patch = delete_member(patchId)

  # titles without a patch are not valid
  # so must be disabled
  patch.softwareTitle.disable if empty?

  update_local_absoluteOrderIds

  patchId
end

#move_patch(patchId, absoluteOrderId:) ⇒ Integer

Change the position of an existing patch in the array This just calls update_patch, with absoluteOrderId as the only attribute.

Parameters:

  • patchId (Integer)

    The patchId of the patch to update.

  • absoluteOrderId (Integer)

    The zero-based position to which you want to move the patch. So if you want to make it the third patch in the list, use 2.

Returns:

  • (Integer)

    the new absoluteOrderId



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/windoo/objects/patch_manager.rb', line 176

def move_patch(patchId, absoluteOrderId:)
  # Can't move it beyond the end of the array....
  max_idx = @managed_array.size - 1
  absoluteOrderId = max_idx if absoluteOrderId > max_idx

  # ... or before the beginning
  absoluteOrderId = 0 if absoluteOrderId.negative?

  update_patch patchId, absoluteOrderId: absoluteOrderId
  absoluteOrderId
end

#patch(ident) ⇒ Windoo::Patch

get a patch by id or version

Parameters:

  • ident (Integer, String)

    the patchId or version to return

Returns:



59
60
61
62
63
64
65
66
67
68
# File 'lib/windoo/objects/patch_manager.rb', line 59

def patch(ident)
  case ident
  when Integer
    find_by_attr(:patchId, ident)
  when String
    find_by_attr(:version, ident)
  else
    raise ArgumentError, 'ident must be an Integer patchId, or a String Version'
  end
end

#patchIds_to_versionsHash {Integer => String}

Returns The Patch IDs => Version installed by the patch.

Returns:

  • (Hash {Integer => String})

    The Patch IDs => Version installed by the patch.



35
36
37
# File 'lib/windoo/objects/patch_manager.rb', line 35

def patchIds_to_versions
  @managed_array.map { |p| [p.patchId, p.version] }.to_h
end

#update_patch(patchId, **attribs) ⇒ Integer

Update a Patch in this SoftwareTitle. Do not use this to update absoluteOrderId, instead use #move_patch

Parameters:

  • patchId (Integer)

    the id of the Patch to be updated.

  • attribs (Hash)

    The attribute(s) to update. See #add_patch

Returns:

  • (Integer)

    The id of the updated Patch



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/windoo/objects/patch_manager.rb', line 148

def update_patch(patchId, **attribs)
  # TODO: use this to undo if we changed
  # the absoluteOrderId but something about the
  # API transaction failed
  @managed_array.index { |p| p.patchId == patchId }

  patch = update_member(patchId, **attribs)

  if attribs[:absoluteOrderId]
    move_member patch, index: patch.absoluteOrderId
    update_local_absoluteOrderIds
  end

  patch.patchId
end

#versions_to_patchIdsHash {Integer => String}

Returns The Versions => Patch ID installed by the patch.

Returns:

  • (Hash {Integer => String})

    The Versions => Patch ID installed by the patch.



42
43
44
# File 'lib/windoo/objects/patch_manager.rb', line 42

def versions_to_patchIds
  @managed_array.map { |p| [p.version, p.patchId] }.to_h
end