Class: Jupiter::Template
- Inherits:
-
Object
- Object
- Jupiter::Template
- Defined in:
- lib/jupiter/template.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#sshpass ⇒ Object
readonly
Returns the value of attribute sshpass.
-
#sshport ⇒ Object
readonly
Returns the value of attribute sshport.
-
#sshuser ⇒ Object
readonly
Returns the value of attribute sshuser.
-
#vmhost ⇒ Object
readonly
Returns the value of attribute vmhost.
Instance Method Summary collapse
- #close_ssh ⇒ Object
-
#initialize(vmhost) ⇒ Template
constructor
A new instance of Template.
- #ssh ⇒ Object
- #templates_list ⇒ Object
- #transfer_template(file, new_name) ⇒ Object
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
4 5 6 |
# File 'lib/jupiter/template.rb', line 4 def host @host end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
4 5 6 |
# File 'lib/jupiter/template.rb', line 4 def location @location end |
#sshpass ⇒ Object (readonly)
Returns the value of attribute sshpass.
4 5 6 |
# File 'lib/jupiter/template.rb', line 4 def sshpass @sshpass end |
#sshport ⇒ Object (readonly)
Returns the value of attribute sshport.
4 5 6 |
# File 'lib/jupiter/template.rb', line 4 def sshport @sshport end |
#sshuser ⇒ Object (readonly)
Returns the value of attribute sshuser.
4 5 6 |
# File 'lib/jupiter/template.rb', line 4 def sshuser @sshuser end |
#vmhost ⇒ Object (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_ssh ⇒ Object
32 33 34 35 36 |
# File 'lib/jupiter/template.rb', line 32 def close_ssh ssh.close @ssh = nil true end |
#ssh ⇒ Object
28 29 30 |
# File 'lib/jupiter/template.rb', line 28 def ssh @ssh ||= Net::SSH.start(@host, @sshuser, password: @sshpass, port: @sshport) end |
#templates_list ⇒ Object
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 |