Class: LxcForge::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/lxc_forge/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @config = config
  @options = options
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/lxc_forge/command.rb', line 3

def config
  @config
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/lxc_forge/command.rb', line 3

def options
  @options
end

Instance Method Details

#configureObject



58
59
60
61
62
63
64
65
66
# File 'lib/lxc_forge/command.rb', line 58

def configure
  config = Config.new(options)
  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

#containerObject



17
18
19
# File 'lib/lxc_forge/command.rb', line 17

def container
  @container ||= LxcForge::Container.new(options[:name], config)
end

#downloadObject



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 options[:force]
    container.destroy
  end

  print "Downloading..."
  container.download
  print "Installing..."
  container.uncompress
end

#listObject



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

#runObject



10
11
12
13
14
15
# File 'lib/lxc_forge/command.rb', line 10

def run
  start = Time.now
  send(options[:command])
  finish = Time.now
  puts "Completed in #{finish - start} seconds" if options[:verbose]
end

#uploadObject



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 options[:force]
    container.destroy_remote
  end

  print "Compressing..."
  container.compress
  print "Uploading..."
  container.upload
end