Class: Jupiter::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/jupiter/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vmhost) ⇒ Template

Returns a new instance of Template.



6
7
8
9
10
11
12
13
# File 'lib/jupiter/template.rb', line 6

def initialize(vmhost)
  @vmhost     = vmhost
  @location   = Jupiter.templates.fetch(:location)
  @sshuser    = Jupiter.templates.fetch(:sshuser)
  @sshpass    = Jupiter.templates.fetch(:sshpass)
  @sshport    = Jupiter.templates.fetch(:sshport)
  @host       = Jupiter.templates.fetch(:host)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/jupiter/template.rb', line 4

def host
  @host
end

#locationObject (readonly)

Returns the value of attribute location.



4
5
6
# File 'lib/jupiter/template.rb', line 4

def location
  @location
end

#sshpassObject (readonly)

Returns the value of attribute sshpass.



4
5
6
# File 'lib/jupiter/template.rb', line 4

def sshpass
  @sshpass
end

#sshportObject (readonly)

Returns the value of attribute sshport.



4
5
6
# File 'lib/jupiter/template.rb', line 4

def sshport
  @sshport
end

#sshuserObject (readonly)

Returns the value of attribute sshuser.



4
5
6
# File 'lib/jupiter/template.rb', line 4

def sshuser
  @sshuser
end

#vmhostObject (readonly)

Returns the value of attribute vmhost.



4
5
6
# File 'lib/jupiter/template.rb', line 4

def vmhost
  @vmhost
end

Instance Method Details

#close_sshObject



32
33
34
35
36
# File 'lib/jupiter/template.rb', line 32

def close_ssh
  ssh.close
  @ssh = nil
  true
end

#sshObject



28
29
30
# File 'lib/jupiter/template.rb', line 28

def ssh
  @ssh ||= Net::SSH.start(@host, @sshuser, password: @sshpass, port: @sshport)
end

#templates_listObject



15
16
17
18
19
20
# File 'lib/jupiter/template.rb', line 15

def templates_list
  template_list = ssh.exec!("ls #{@location}").to_s
  close_ssh
  array_of_templates= template_list.split("\n")
  array_of_templates.select! { |x| x.include? '.tar.gz'}
end

#transfer_template(file, new_name) ⇒ Object



22
23
24
25
26
# File 'lib/jupiter/template.rb', line 22

def transfer_template(file, new_name)
  ssh.exec!("scp -P #{@vmhost.sshport} #{location}/#{file}.tar.gz #{@vmhost.sshuser}@#{@vmhost.host}:#{@vmhost.vmpath}/")
  close_ssh
  @vmhost.setup_template(file, new_name)
end