Class: Puter::CLI::Vm

Inherits:
Thor
  • Object
show all
Defined in:
lib/puter/cli/vm.rb

Instance Method Summary collapse

Instance Method Details

#apply(instance_name, context) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puter/cli/vm.rb', line 21

def apply(instance_name, context)
  CLI.run_cli do
    instance_path = "#{options[:instances]}/#{instance_name}"
    puterfile_path = File.expand_path 'Puterfile', context
    puterfile = Puter::Puterfile.from_path puterfile_path

    vm.host(instance_path) do |host|
      Puter.ui.info "Applying '#{puterfile_path}' to '#{instance_path}' at #{host}"
      backend = Puter::Backend::Ssh.new(host, Puter::CLI::SSH_OPTS)
      ret = puterfile.apply(context, backend, Puter.ui)
    end
    Puter.ui.info "Successfully applied '#{puterfile_path}' to '#{instance_name}'"
  end
end

#build(image_name, context) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/puter/cli/vm.rb', line 40

def build(image_name, context)
  CLI.run_cli do
    build_path = "#{options[:build]}/#{image_name}"
    images_path = "#{options[:images]}/#{image_name}"

    puterfile_path = File.expand_path 'Puterfile', context
    puterfile = Puter::Puterfile.from_path puterfile_path

    Puter.ui.info "Building '#{images_path}' FROM '#{options[:images]}/#{puterfile.from}'"
    Puter.ui.info "Waiting for SSH"
    vm.build(build_path, images_path, "#{options[:images]}/#{puterfile.from}", options) do |host|
      Puter.ui.info "Applying '#{puterfile_path}' to '#{build_path}' at #{host}"
      backend = Puter::Backend::Ssh.new(host, Puter::CLI::SSH_OPTS)
      ret = puterfile.apply(context, backend, Puter.ui)
      Puter.ui.info "Stopping '#{build_path}' and moving to '#{images_path}'"
    end
    Puter.ui.info "Successfully built '#{image_name}'"
  end
end

#create(image_name, instance_name) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/puter/cli/vm.rb', line 74

def create(image_name, instance_name)
  CLI.run_cli do
    image_path = "#{options[:images]}/#{image_name}"
    instance_path = "#{options[:instances]}/#{instance_name}"

    vm.create image_path, instance_path, options
    Puter.ui.info "Created instance '#{instance_path}' from '#{image_path}'"
  end
end

#imagesObject



13
14
15
16
17
# File 'lib/puter/cli/vm.rb', line 13

def images()
  CLI.run_cli do
    vm.images(options[:images]).each { |i| Puter.ui.info i }
  end
end

#init(path = '/Puter') ⇒ Object



153
154
155
156
157
158
# File 'lib/puter/cli/vm.rb', line 153

def init(path = '/Puter')
  CLI.run_cli do
    vm.init(path)
    Puter.ui.info "Create Puter folders under #{path}"
  end
end

#kill(instance_name) ⇒ Object



120
121
122
123
124
125
126
127
128
# File 'lib/puter/cli/vm.rb', line 120

def kill(instance_name)
  CLI.run_cli do
    instance_path = "#{options[:instances]}/#{instance_name}"

    Puter.ui.info "Killing instance '#{instance_path}'"
    vm.kill instance_path
    Puter.ui.info "Killed '#{instance_path}'."
  end
end

#psObject



87
88
89
90
91
# File 'lib/puter/cli/vm.rb', line 87

def ps()
  CLI.run_cli do
    vm.ps(options[:instances], options[:all]).each { |i| Puter.ui.info i }
  end
end

#rm(instance_name) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/puter/cli/vm.rb', line 132

def rm(instance_name)
  CLI.run_cli do
    instance_path = "#{options[:instances]}/#{instance_name}"
    vm.rm instance_path
    Puter.ui.info "Removed instance '#{instance_path}'"
  end
end

#rmi(image_name) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/puter/cli/vm.rb', line 62

def rmi(image_name)
  image_path = "#{options[:images]}/#{image_name}"
  CLI.run_cli do
    vm.rmi image_path
    Puter.ui.info "Removed image '#{image_path}'"
  end
end

#start(instance_name) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/puter/cli/vm.rb', line 95

def start(instance_name)
  CLI.run_cli do
    instance_path = "#{options[:instances]}/#{instance_name}"

    Puter.ui.info "Starting instance '#{instance_path}', waiting for SSH..."
    vm.start instance_path do |host|
      Puter.ui.info "Started '#{instance_path}' at #{host}."
    end
  end
end

#stop(instance_name) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/puter/cli/vm.rb', line 108

def stop(instance_name)
  CLI.run_cli do
    instance_path = "#{options[:instances]}/#{instance_name}"

    Puter.ui.info "Stopping instance '#{instance_path}', waiting for shutdown..."
    vm.stop instance_path
    Puter.ui.info "Stopped '#{instance_path}'."
  end
end