Class: LxcForge::Command
- Inherits:
-
Object
- Object
- LxcForge::Command
- Defined in:
- lib/lxc_forge/command.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #configure ⇒ Object
- #container ⇒ Object
- #download ⇒ Object
-
#initialize(config, options) ⇒ Command
constructor
A new instance of Command.
- #list ⇒ Object
- #prompt(msg) ⇒ Object
- #prompt_yes_no(msg) ⇒ Object
- #run ⇒ Object
- #upload ⇒ Object
Constructor Details
#initialize(config, options) ⇒ Command
Returns a new instance of Command.
5 6 7 8 |
# File 'lib/lxc_forge/command.rb', line 5 def initialize(config, ) @config = config = end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/lxc_forge/command.rb', line 3 def config @config end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/lxc_forge/command.rb', line 3 def end |
Instance Method Details
#configure ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/lxc_forge/command.rb', line 58 def configure config = Config.new() config.access_key_id = prompt("Access Key ID: ") config.secret_access_key = prompt("Secret Access Key: ") config.region = prompt("Region: ") config.bucket = prompt("Bucket: ") config.save puts "Configuration Saved" end |
#container ⇒ Object
17 18 19 |
# File 'lib/lxc_forge/command.rb', line 17 def container @container ||= LxcForge::Container.new([:name], config) end |
#download ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lxc_forge/command.rb', line 44 def download raise "Remote file doesn't exist" unless container.remote_exists? if container.exists? prompt_yes_no "Container already exists. Replace it (y/n) " unless [:force] container.destroy end print "Downloading..." container.download print "Installing..." container.uncompress end |
#list ⇒ Object
68 69 70 |
# File 'lib/lxc_forge/command.rb', line 68 def list container.list end |
#prompt(msg) ⇒ Object
21 22 23 24 |
# File 'lib/lxc_forge/command.rb', line 21 def prompt(msg) print msg STDIN.gets.chomp() end |
#prompt_yes_no(msg) ⇒ Object
26 27 28 |
# File 'lib/lxc_forge/command.rb', line 26 def prompt_yes_no(msg) raise "Aborted" unless prompt(msg) == "y" end |
#run ⇒ Object
10 11 12 13 14 15 |
# File 'lib/lxc_forge/command.rb', line 10 def run start = Time.now send([:command]) finish = Time.now puts "Completed in #{finish - start} seconds" if [:verbose] end |
#upload ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lxc_forge/command.rb', line 30 def upload raise "Container doesn't exist" unless container.exists? if container.remote_exists? prompt_yes_no "Remote file already exists. Replace it (y/n) " unless [:force] container.destroy_remote end print "Compressing..." container.compress print "Uploading..." container.upload end |