Class: ServersController

Inherits:
MVCLI::Controller
  • Object
show all
Defined in:
app/controllers/servers_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/servers_controller.rb', line 14

def create
  template = Servers::CreateForm
  argv = MVCLI::Argv.new command.argv
  form = template.new argv.options
  form.validate!
  #Add personalization
  options = {
    name: form.name,
    flavor_id: form.flavor_id,
    image_id: form.image_id,
    private_key_path: form.ssh_private, #"~/.ssh/id_rsa"
    public_key_path: form.ssh_public #"~/.ssh/id_rsa.pub"
  }
  command.output.puts "--> bootstrapping server #{options[:name]}"
  #Progress bar
  server = compute.servers.bootstrap options
  command.output.puts "    done."
  return server
end

#destroyObject



48
49
50
51
52
# File 'app/controllers/servers_controller.rb', line 48

def destroy
  server.tap do |s|
    s.destroy
  end
end

#indexObject



5
6
7
# File 'app/controllers/servers_controller.rb', line 5

def index
  compute.servers.all
end

#showObject



9
10
11
12
# File 'app/controllers/servers_controller.rb', line 9

def show
  #What if you have two or more servers with the same name?
  server
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/servers_controller.rb', line 34

def update
  template = Servers::UpdateForm
  argv = MVCLI::Argv.new command.argv
  form = template.new argv.options
  form.validate!

  unupdated_server = server
  unupdated_server.name = form.name unless form.name == nil
  unupdated_server.ipv4_address = form.ipv4 unless form.ipv4 == nil
  unupdated_server.ipv6_address = form.ipv6 unless form.ipv6 == nil

  unupdated_server.update
end