Class: Lb

Inherits:
Thor
  • Object
show all
Defined in:
lib/cloudstack-cli/commands/load_balancer.rb

Instance Method Summary collapse

Instance Method Details

#add(name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cloudstack-cli/commands/load_balancer.rb', line 46

def add(name)
  cs_cli = CloudstackCli::Helper.new(options[:config])
  if options[:project]
    project = cs_cli.projects.select { |p| p['name'] == options[:project] }.first
    exit_now! "Project '#{options[:project]}' not found" unless project
  end
  
  rule = cs_cli.assign_to_load_balancer_rule(
    name,
    options[:servers],
  )
end

#create(name) ⇒ Object



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

def create(name)
  cs_cli = CloudstackCli::Helper.new(options[:config])
  if options[:project]
    project = cs_cli.projects.select { |p| p['name'] == options[:project] }.first
    exit_now! "Project '#{options[:project]}' not found" unless project
  end

  options[:private_port] = options[:public_port] if options[:private_port] == nil
  
  rule = cs_cli.create_load_balancer_rule(
    name,
    options[:ip],
    options[:private_port],
    options[:public_port],
  )
end

#listObject



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

def list
  cs_cli = CloudstackCli::Helper.new(options[:config])
  if options[:project]
    project = cs_cli.projects.select { |p| p['name'] == options[:project] }.first
    exit_now! "Project '#{options[:project]}' not found" unless project
  end
  
  rules = cs_cli.list_load_balancer_rules(project ? project['id'] : nil)
  if rules.size < 1
    puts "No load balancer rules found"
  else
    rules.each do |rule|
      puts "#{rule['name']} - #{rule['publicip']}:#{rule['publicport']}"
    end
  end
end