Class: LoadBalancer

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

Constant Summary

Constants included from CloudstackCli::Helper

CloudstackCli::Helper::ASYNC_STATES

Instance Attribute Summary

Attributes inherited from CloudstackCli::Base

#config

Instance Method Summary collapse

Methods inherited from CloudstackCli::Base

exit_on_failure?

Methods included from CloudstackCli::Helper

#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #print_job_status, #print_options, #update_job_status, #watch_jobs

Instance Method Details

#add(name) ⇒ Object



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

def add(name)
  say "Add #{names.join(', ')} to rule #{id}...", :yellow
  rule = client.assign_to_load_balancer_rule(
    name,
    options[:servers],
  )
  if rule['success']
    say "OK!", :green
  else
    say "Failed!", :red
  end
end

#create(name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cloudstack-cli/commands/load_balancer.rb', line 26

def create(name)
  project = find_project
  options[:private_port] = options[:public_port] if options[:private_port] == nil
  say "Create rule #{name}...", :yellow
  rule = client.create_load_balancer_rule(
    name,
    options[:ip],
    options[:private_port],
    options[:public_port],
  )
  say "OK!", :green
end

#listObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cloudstack-cli/commands/load_balancer.rb', line 5

def list
  project = find_project if options[:project]
  rules = client.list_load_balancer_rules(
    { project_name: project ? project['name'] : nil }
  )
  if rules.size < 1
    puts "No load balancer rules found."
  else
    table = [["Name", "Public-IP", "Public-Port"]]
    rules.each do |rule|
      table << [rule['name'], rule['publicip'], rule['publicport']]
    end
    print_table table
  end
end