class OvirtSDK4::TemplateService

Public Class Methods

new(connection, path) click to toggle source

Creates a new implementation of the service.

@param connection [Connection] The connection to be used by this service.

@param path [String] The relative path of this service, for example `vms/123/disks`.

@api private

# File lib/ovirtsdk4/services.rb, line 21554
def initialize(connection, path)
  @connection = connection
  @path = path
end

Public Instance Methods

cdroms_service() click to toggle source

Locates the `cdroms` service.

@return [TemplateCdromsService] A reference to `cdroms` service.

# File lib/ovirtsdk4/services.rb, line 21668
def cdroms_service
  return TemplateCdromsService.new(@connection, "#{@path}/cdroms")
end
disk_attachments_service() click to toggle source

Reference to the service that manages a specific disk attachment of the template.

@return [TemplateDiskAttachmentsService] A reference to `disk_attachments` service.

# File lib/ovirtsdk4/services.rb, line 21677
def disk_attachments_service
  return TemplateDiskAttachmentsService.new(@connection, "#{@path}/diskattachments")
end
export(opts = {}) click to toggle source

Executes the `export` method.

# File lib/ovirtsdk4/services.rb, line 21562
def export(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = Request.new({
  :method => :POST,
  :path => "#{@path}/export",
  :body => body,
  })
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_fault(response)
  end
end
get(opts = {}) click to toggle source

Returns the representation of the object managed by this service.

@param opts [Hash] Additional options.

@option opts [Boolean] :filter Indicates if the results should be filtered according to the permissions of the user.

@return [Template]

# File lib/ovirtsdk4/services.rb, line 21591
def get(opts = {})
  query = {}
  value = opts[:filter]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['filter'] = value
  end
  request = Request.new(:method => :GET, :path => @path, :query => query)
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return TemplateReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
graphics_consoles_service() click to toggle source

Locates the `graphics_consoles` service.

@return [GraphicsConsolesService] A reference to `graphics_consoles` service.

# File lib/ovirtsdk4/services.rb, line 21685
def graphics_consoles_service
  return GraphicsConsolesService.new(@connection, "#{@path}/graphicsconsoles")
end
nics_service() click to toggle source

Locates the `nics` service.

@return [TemplateNicsService] A reference to `nics` service.

# File lib/ovirtsdk4/services.rb, line 21693
def nics_service
  return TemplateNicsService.new(@connection, "#{@path}/nics")
end
permissions_service() click to toggle source

Locates the `permissions` service.

@return [AssignedPermissionsService] A reference to `permissions` service.

# File lib/ovirtsdk4/services.rb, line 21701
def permissions_service
  return AssignedPermissionsService.new(@connection, "#{@path}/permissions")
end
remove(opts = {}) click to toggle source

Deletes the object managed by this service.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the remove should be performed asynchronously.

# File lib/ovirtsdk4/services.rb, line 21620
def remove(opts = {})
  query = {}
  value = opts[:async]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['async'] = value
  end
  request = Request.new(:method => :DELETE, :path => @path, :query => query)
  response = @connection.send(request)
  unless response.code == 200
    check_fault(response)
  end
end
service(path) click to toggle source

Locates the service corresponding to the given path.

@param path [String] The path of the service.

@return [Service] A reference to the service.

# File lib/ovirtsdk4/services.rb, line 21728
def service(path)
  if path.nil? || path == ''
    return self
  end
  if path == 'cdroms'
    return cdroms_service
  end
  if path.start_with?('cdroms/')
    return cdroms_service.service(path[7..-1])
  end
  if path == 'diskattachments'
    return disk_attachments_service
  end
  if path.start_with?('diskattachments/')
    return disk_attachments_service.service(path[16..-1])
  end
  if path == 'graphicsconsoles'
    return graphics_consoles_service
  end
  if path.start_with?('graphicsconsoles/')
    return graphics_consoles_service.service(path[17..-1])
  end
  if path == 'nics'
    return nics_service
  end
  if path.start_with?('nics/')
    return nics_service.service(path[5..-1])
  end
  if path == 'permissions'
    return permissions_service
  end
  if path.start_with?('permissions/')
    return permissions_service.service(path[12..-1])
  end
  if path == 'tags'
    return tags_service
  end
  if path.start_with?('tags/')
    return tags_service.service(path[5..-1])
  end
  if path == 'watchdogs'
    return watchdogs_service
  end
  if path.start_with?('watchdogs/')
    return watchdogs_service.service(path[10..-1])
  end
  raise Error.new("The path \"#{path}\" doesn't correspond to any service")
end
tags_service() click to toggle source

Locates the `tags` service.

@return [AssignedTagsService] A reference to `tags` service.

# File lib/ovirtsdk4/services.rb, line 21709
def tags_service
  return AssignedTagsService.new(@connection, "#{@path}/tags")
end
to_s() click to toggle source

Returns an string representation of this service.

@return [String]

# File lib/ovirtsdk4/services.rb, line 21782
def to_s
  return "#<#{TemplateService}:#{@path}>"
end
update(template) click to toggle source

Updates the object managed by this service.

# File lib/ovirtsdk4/services.rb, line 21637
def update(template)
  if template.is_a?(Hash)
    template = OvirtSDK4::Template.new(template)
  end
  request = Request.new(:method => :PUT, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    TemplateWriter.write_one(template, writer)
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return TemplateReader.read_one(reader)
    ensure
      reader.close
    end
    return result
  else
    check_fault(response)
  end
end
watchdogs_service() click to toggle source

Locates the `watchdogs` service.

@return [TemplateWatchdogsService] A reference to `watchdogs` service.

# File lib/ovirtsdk4/services.rb, line 21717
def watchdogs_service
  return TemplateWatchdogsService.new(@connection, "#{@path}/watchdogs")
end