Class: Shared::Log

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

Overview

abstract A log file in a node instance

Instance Attribute Summary collapse

Attributes included from Deletable

#collection

Attributes inherited from Resource

#location, #security

Instance Method Summary collapse

Methods included from Deletable

#delete

Constructor Details

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

Returns a new instance of Log.



44
45
46
47
48
49
50
51
# File 'lib/vas/shared/logs.rb', line 44

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

  @content_location = Util::LinkUtils.get_link_href(details, 'content')
  @instance_location = Util::LinkUtils.get_link_href(details, instance_type)

  @instance_class = instance_class
end

Instance Attribute Details

#last_modifiedInteger (readonly)

Returns the last modified stamp of the log.

Returns:

  • (Integer)

    the last modified stamp of the log



41
42
43
# File 'lib/vas/shared/logs.rb', line 41

def last_modified
  @last_modified
end

#nameString (readonly)

Returns the name of the log.

Returns:

  • (String)

    the name of the log



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

def name
  @name
end

#sizeInteger (readonly)

Returns the size of the log.

Returns:

  • (Integer)

    the size of the log



38
39
40
# File 'lib/vas/shared/logs.rb', line 38

def size
  @size
end

Instance Method Details

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

This method returns an undefined value.

Retrieves the content of the log from the server

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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vas/shared/logs.rb', line 82

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

#instanceNodeInstance

Returns the node instance that the log belongs to.

Returns:

  • (NodeInstance)

    the node instance that the log belongs to



102
103
104
# File 'lib/vas/shared/logs.rb', line 102

def instance
  @instance ||= @instance_class.new(@instance_location, client)
end

#reloadvoid

This method returns an undefined value.

Reloads the log’s details from the server



56
57
58
59
60
61
62
# File 'lib/vas/shared/logs.rb', line 56

def reload
  super
  @name = details['name']
  @size = details['size']
  @last_modified = details['last-modified']
  @instance = nil
end

#to_sString

Returns a string representation of the log.

Returns:

  • (String)

    a string representation of the log



107
108
109
# File 'lib/vas/shared/logs.rb', line 107

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