Class: Shared::Log

Inherits:
Resource show all
Defined in:
lib/vas/shared/logs.rb

Overview

abstract A log file in a node instance

Instance Attribute Summary collapse

Attributes inherited from Resource

#location, #security

Instance Method Summary collapse

Constructor Details

#initialize(location, client, instance_type, instance_class) ⇒ Log

Returns a new instance of Log.



39
40
41
42
43
44
45
# File 'lib/vas/shared/logs.rb', line 39

def initialize(location, client, instance_type, instance_class)
  super(location, client)

  @name = details['name']
  @content_location = Util::LinkUtils.get_link_href(details, 'content')
  @instance = instance_class.new(Util::LinkUtils.get_link_href(details, instance_type), client)
end

Instance Attribute Details

#instanceNodeInstance (readonly)

Returns the node instance that the log belongs to.

Returns:

  • (NodeInstance)

    the node instance that the log belongs to



36
37
38
# File 'lib/vas/shared/logs.rb', line 36

def instance
  @instance
end

#nameString (readonly)

Returns the name of the log.

Returns:

  • (String)

    the name of the log



33
34
35
# File 'lib/vas/shared/logs.rb', line 33

def name
  @name
end

Instance Method Details

#content(options = {}) {|chunk| ... } ⇒ void

This method returns an undefined value.

Retrieve the content of the log

Parameters:

  • options (Hash) (defaults to: {})

    the options that control the content that is returned

Options Hash (options):

  • :start_line (Integer)

    the start point, in lines, of the content to pass to the block. Omitting the parameter will result in content from the start of the file being passed. If the provided value is greater than the number of lines in the file, no content will be passed.

  • :end_line (Integer)

    the end point, in lines, of the content to pass to the block. Omitting the parameter will result in content up to the end of the file being passed. If the provided value is greater than the number of lines in the file, content up to and including the last line in the file will be passed.

Yields:

  • (chunk)

    a chunk of the log’s content



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vas/shared/logs.rb', line 64

def content(options = {}, &block)
  query=""
  if (!options[:start_line].nil?)
    query << "start-line=#{options[:start_line]}"
  end
  if (!options[:end_line].nil?)
    if (query.length > 0)
      query << '&'
    end
    query << "end-line=#{options[:end_line]}"
  end

  if (query.length > 0)
    client.get_stream("#{@content_location}?#{query}", &block)
  else
    client.get_stream(@content_location, &block)
  end
end

#last_modifiedInteger

Returns the last modified stamp of the log.

Returns:

  • (Integer)

    the last modified stamp of the log



89
90
91
# File 'lib/vas/shared/logs.rb', line 89

def last_modified
  client.get(location)['last-modified']
end

#sizeInteger

Returns the size of the log.

Returns:

  • (Integer)

    the size of the log



84
85
86
# File 'lib/vas/shared/logs.rb', line 84

def size
  client.get(location)['size']
end

#to_sString

Returns a string representation of the log.

Returns:

  • (String)

    a string representation of the log



94
95
96
# File 'lib/vas/shared/logs.rb', line 94

def to_s
  "#<#{self.class} name='#@name'>"
end