Class: Server

Inherits:
CloudstackCli::Base show all
Defined in:
lib/cloudstack-cli/commands/server.rb

Instance Attribute Summary

Attributes inherited from CloudstackCli::Base

#config

Instance Method Summary collapse

Instance Method Details

#bootstrapObject



74
75
76
# File 'lib/cloudstack-cli/commands/server.rb', line 74

def bootstrap
  CloudstackCli::Helper.new(options[:config]).bootstrap_server_interactive()
end

#create(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cloudstack-cli/commands/server.rb', line 42

def create(name)
  CloudstackCli::Helper.new(options[:config]).bootstrap_server(
    name,
    options[:zone],
    options[:template],
    options[:offering],
    options[:networks],
    options[:port_forwarding],
    options[:project]
  )
end

#destroy(name) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cloudstack-cli/commands/server.rb', line 56

def destroy(name)
  server = client.get_server(name)
  unless server
    error "Server not found."
    exit
  end
  ask = "Are you sure you want to destroy the following server?\n"
  ask += "#{server['name']} (#{server['state']})?"

  unless options[:force] == true || yes?(ask)
    exit  
  end

  client.destroy_server(server["id"])
  puts
end

#listObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cloudstack-cli/commands/server.rb', line 6

def list
  if options[:project]
    if options[:project].downcase == "all"
      options[:project_id] = -1
    else
      project = find_project
      options[:project_id] = project['id']
    end
  end
  servers = client.list_servers(options)
  if servers.size < 1
    puts "No servers found"
  else
    table = [["Name", "State", "Offering", "Zone", options[:project] ? "Project" : "Account", "IP's"]]
    servers.each do |server|
      table << [
        server['name'],
        server['state'],
        server['serviceofferingname'],
        server['zonename'],
        options[:project] ? server['project'] : server['account'],
        server['nic'].map { |nic| nic['ipaddress']}.join(' ')
      ]
    end
    print_table table
  end
end

#restart(name) ⇒ Object



91
92
93
94
# File 'lib/cloudstack-cli/commands/server.rb', line 91

def restart(name)
  client.reboot_server(name)
  puts
end

#start(name) ⇒ Object



85
86
87
88
# File 'lib/cloudstack-cli/commands/server.rb', line 85

def start(name)
  client.start_server(name)
  puts
end

#stop(name) ⇒ Object



79
80
81
82
# File 'lib/cloudstack-cli/commands/server.rb', line 79

def stop(name)
  client.stop_server(name)
  puts
end