Class: Xolo::Admin::Version

Inherits:
Core::BaseClasses::Version
  • Object
show all
Defined in:
lib/xolo/admin/version.rb

Overview

A version/patch as used by xadm. This adds cli and walkthru UI, as well as an interface to the Xolo Server for Title objects.

Constant Summary collapse

SERVER_ROUTE =

This is the server path for dealing with titles POST to add a new one GET to get a list of versions for a title GET .../ to get the data for a single version PUT .../ to update a version with new data DELETE .../ to delete a version from the title

"/titles/#{Xolo::Admin::Title::TARGET_TITLE_PLACEHOLDER}/versions"
UPLOAD_PKG_ROUTE =

Server route for uploading packages

'pkg'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cnxObject

the server connection used to fetch this version



131
132
133
# File 'lib/xolo/admin/version.rb', line 131

def cnx
  @cnx
end

Class Method Details

.all_version_objects(title, cnx) ⇒ Array<Xolo::Admin::Version>

Returns The currently known versions of a title on the server.

Returns:



68
69
70
71
# File 'lib/xolo/admin/version.rb', line 68

def self.all_version_objects(title, cnx)
  resp = cnx.get server_route(title)
  resp.body.map { |vd| Xolo::Admin::Version.new vd }
end

.all_versions(title, cnx) ⇒ Array<String>

Returns The currently known versions of a title on the server.

Returns:

  • (Array<String>)

    The currently known versions of a title on the server



61
62
63
64
# File 'lib/xolo/admin/version.rb', line 61

def self.all_versions(title, cnx)
  resp = cnx.get server_route(title)
  resp.body
end

.cli_optsHash{Symbol: Hash}

Returns The ATTRIBUTES that are available as CLI & walkthru options.

Returns:

  • (Hash{Symbol: Hash})

    The ATTRIBUTES that are available as CLI & walkthru options



41
42
43
# File 'lib/xolo/admin/version.rb', line 41

def self.cli_opts
  @cli_opts ||= ATTRIBUTES.select { |_k, v| v[:cli] }
end

.delete(title, version, cnx) ⇒ Hash

Delete a version of a title from the server

Parameters:

  • title (String)

    the title

  • version (String)

    the version to delete

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response body, parsed JSON



121
122
123
124
# File 'lib/xolo/admin/version.rb', line 121

def self.delete(title, version, cnx)
  resp = cnx.delete server_route(title, version)
  resp.body
end

.deploy(title, version, cnx, groups: [], computers: []) ⇒ Hash

Deploy a version to desired computers and groups via MDM

Parameters:

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

  • groups (Array<String, Integer>) (defaults to: [])

    The groups to deploy to

  • computers (Array<String, Integer>) (defaults to: [])

    The computers to deploy to

Returns:

  • (Hash)

    The response from the server

Raises:

  • (ArgumentError)


106
107
108
109
110
111
112
113
# File 'lib/xolo/admin/version.rb', line 106

def self.deploy(title, version, cnx, groups: [], computers: [])
  raise ArgumentError, 'Must provide at least one group or computer' if groups.pix_empty? && computers.pix_empty?

  route = "#{server_route(title, version)}/deploy"
  content = { groups: groups, computers: computers }
  resp = cnx.post(route) { |req| req.body = content }
  resp.body
end

.exist?(title, version, cnx) ⇒ Boolean

Does a version of a title exist on the server?

Parameters:

  • title (String)

    the title

  • version (String)

    the version

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

Returns:

  • (Boolean)


79
80
81
# File 'lib/xolo/admin/version.rb', line 79

def self.exist?(title, version, cnx)
  all_versions(title, cnx).include? version
end

.fetch(title, version, cnx) ⇒ Xolo::Admin::Title

Fetch a version of a title from the server

Parameters:

  • title (String)

    the title

  • version (String)

    the version to fetch

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

Returns:



89
90
91
92
93
94
95
96
# File 'lib/xolo/admin/version.rb', line 89

def self.fetch(title, version, cnx)
  resp = cnx.get server_route(title, version)
  vers_obj = new resp.body
  vers_obj.cnx = cnx
  vers_obj
rescue Faraday::ResourceNotFound
  raise Xolo::NoSuchItemError, "No such version '#{version}'"
end

.server_route(title, version = nil) ⇒ Xolo::Admin::Title

get the server route to a specific version (or the version list) for a title

Parameters:

  • title (String)

    the title

  • version (String) (defaults to: nil)

    the version to fetch

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

Returns:



51
52
53
54
55
56
57
# File 'lib/xolo/admin/version.rb', line 51

def self.server_route(title, version = nil)
  route = SERVER_ROUTE.sub(Xolo::Admin::Title::TARGET_TITLE_PLACEHOLDER, title)
  route << "/#{URI::Parser.new.escape(version)}" if version
  ### the CGI escape one doesn't seem to work with, e.g. "7.1.5 (84650)"
  # route << "/#{CGI.escape(version)}" if version
  route
end

Instance Method Details

#add(cnx = self.cnx) ⇒ Hash

Add this version to the server

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response from the server



165
166
167
168
# File 'lib/xolo/admin/version.rb', line 165

def add(cnx = self.cnx)
  resp = cnx.post self.class.server_route(title), to_h
  resp.body
end

#delete(cnx = self.cnx) ⇒ Hash

Delete this title from the server

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response from the server



192
193
194
195
# File 'lib/xolo/admin/version.rb', line 192

def delete(cnx = self.cnx)
  self.class.delete title, version, cnx
  # already returns resp.body
end

#gui_urls(cnx = self.cnx) ⇒ Hash{String => String}

Fetch a hash of URLs for the GUI pages for this title

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash{String => String})

    page_name => url



201
202
203
204
# File 'lib/xolo/admin/version.rb', line 201

def gui_urls(cnx = self.cnx)
  resp = cnx.get "#{self.class.server_route(title, version)}/urls"
  resp.body
end

#managed?Boolean

Returns whether this version is from a managed title or not.

Returns:

  • (Boolean)

    whether this version is from a managed title or not



252
253
254
# File 'lib/xolo/admin/version.rb', line 252

def managed?
  title_object.managed?
end

#patch_report_data(cnx = self.cnx) ⇒ Array<Hash>

Get the Patch Report data for this version It's the JPAPI report data with each hash having a frozen: key added

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Array<Hash>)

    Data for each computer with this version of this title installed



232
233
234
235
# File 'lib/xolo/admin/version.rb', line 232

def patch_report_data(cnx = self.cnx)
  resp = cnx.get "#{self.class.server_route(title, version)}/patch_report"
  resp.body
end

#repair(cnx = self.cnx) ⇒ Hash

Repair this version

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response body from the server



183
184
185
186
# File 'lib/xolo/admin/version.rb', line 183

def repair(cnx = self.cnx)
  resp = cnx.post "#{self.class.server_route(title, version)}/repair"
  resp.body
end

#subscribed?Boolean

Returns whether this version is from a subscribed title or not.

Returns:

  • (Boolean)

    whether this version is from a subscribed title or not



246
247
248
# File 'lib/xolo/admin/version.rb', line 246

def subscribed?
  title_object.subscribed?
end

#title_object(cnx = self.cnx, refresh: false) ⇒ Xolo::Admin::Title

Returns the title for this version.

Returns:



239
240
241
242
# File 'lib/xolo/admin/version.rb', line 239

def title_object(cnx = self.cnx, refresh: false)
  @title_object = nil if refresh
  @title_object ||= Xolo::Admin::Title.fetch(title, cnx)
end

#update(cnx = self.cnx) ⇒ Hash

Update this version to the server

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response from the server



174
175
176
177
# File 'lib/xolo/admin/version.rb', line 174

def update(cnx = self.cnx)
  resp = cnx.put self.class.server_route(title, version), to_h
  resp.body
end

#upload_pkg(upload_cnx) ⇒ Faraday::Response

Upload a .pkg for this version At this point, the pkg_to_upload attribute will contain the local file path.

Parameters:

Returns:

  • (Faraday::Response)

    The server response



214
215
216
217
218
219
220
221
222
223
224
# File 'lib/xolo/admin/version.rb', line 214

def upload_pkg(upload_cnx)
  return unless pkg_to_upload.is_a? Pathname

  # route = "#{UPLOAD_PKG_ROUTE}/#{title}/#{version}"
  route = "#{self.class.server_route(title, version)}/#{UPLOAD_PKG_ROUTE}"

  upfile = Faraday::Multipart::FilePart.new(pkg_to_upload.expand_path.to_s, 'application/octet-stream')

  content = { file: upfile }
  upload_cnx.post(route) { |req| req.body = content }
end