Class: VFabric::AgentImage

Inherits:
Shared::Resource show all
Defined in:
lib/vas/vfabric/agent_image.rb

Overview

Provides access to the installation image for the vFabric Administration Agent

Instance Attribute Summary

Attributes inherited from Shared::Resource

#location, #security

Instance Method Summary collapse

Constructor Details

#initialize(location, client) ⇒ AgentImage

Returns a new instance of AgentImage.



23
24
25
26
# File 'lib/vas/vfabric/agent_image.rb', line 23

def initialize(location, client)
  super(location, client)
  @content_location = Util::LinkUtils.get_link_href(details, "content")
end

Instance Method Details

#content {|chunk| ... } ⇒ void

This method returns an undefined value.

Retrieves the content of the agent installation image (a zip file) from the server

Yields:

  • (chunk)

    a chunk of the agent image’s content



33
34
35
# File 'lib/vas/vfabric/agent_image.rb', line 33

def content(&block)
  client.get_stream(@content_location, &block)
end

#extract_to(location = '.') ⇒ void

This method returns an undefined value.

Downloads and extracts the agent installation image

Parameters:

  • location (String) (defaults to: '.')

    the location to extract the agent to



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vas/vfabric/agent_image.rb', line 42

def extract_to(location = '.')
  Tempfile.open('agent-image.zip') { |temp_file|
    content { |chunk| temp_file << chunk }
    temp_file.rewind
    Zip::ZipFile.foreach(temp_file.path) { |entry|
      FileUtils.mkdir_p(File.dirname(entry.name))
      entry.extract
    }
    temp_file.rewind
    Zip::ZipFile.foreach(temp_file.path) { |entry|
      File.chmod(entry.unix_perms, entry.name)
    }
    temp_file.delete
  }

  File.join(location, 'vfabric-administration-agent')
end