Class: Router

Inherits:
Thor
  • Object
show all
Includes:
CommandLineReporter, Thor::Actions
Defined in:
lib/cloudstack-cli/commands/router.rb

Instance Method Summary collapse

Instance Method Details

#destroy(id) ⇒ Object



118
119
120
121
# File 'lib/cloudstack-cli/commands/router.rb', line 118

def destroy(id)
  cs_cli = CloudstackCli::Helper.new(options[:config])
  puts "OK" if cs_cli.destroy_router(name)
end

#listObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cloudstack-cli/commands/router.rb', line 15

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

routers = cs_cli.list_routers(
  {
    account: options[:account], 
    projectid: projectid,
    status: options[:status],
    zone: options[:zone]
  }, 
  options[:redundant_state]
)


if options[:listall]
  projects = cs_cli.projects
  projects.each do |project|
    routers = routers + cs_cli.list_routers(
      {
        account: options[:account],
        projectid: project['id'],
        status: options[:status],
        zone: options[:zone]
      },
      options[:redundant_state]
    )
  end
end

routers.reverse! if options[:reverse]
if options[:text]
  puts routers.map {|r| r['name']}.join(" ")
else
  puts "Total number of routers: #{routers.size}"
  table(border: true) do
    row do
      column 'ID', width: 40
       column 'Name'
       column 'Zone'
       column 'Account', width: 14 unless options[:project]
       column 'Project', width: 14 if options[:listall] || options[:project]
       column 'Redundant State'
       column 'Linklocal IP', width: 15
       column 'Status'
     end
     routers.each do |router|
       row do
        column router["id"]
         column router["name"]
         column router["zonename"]
         column router["account"] unless options[:project]
         column router["project"] if options[:listall] || options[:project]
         column router["redundantstate"]
         column router["linklocalip"]
         column router["state"]
       end
     end
   end
 end

 if options[:command]
  case options[:command].downcase
  when "start"
    exit unless yes?("Start the routers above? [y/N]:", :magenta)
    routers.each do |router|
      print "Start router #{router['name']}"
      cs_cli.start_router router['id']
      puts
    end
  when "stop"
    exit unless yes?("Stop the routers above? [y/N]:", :magenta)
    routers.each do |router|
      print "Stop router #{router['name']}"
      cs_cli.stop_router router['id']
      puts
    end
  else
    say "Command #{options[:command]} not supported", :red
    exit
  end
 end
end

#start(id) ⇒ Object



111
112
113
114
115
# File 'lib/cloudstack-cli/commands/router.rb', line 111

def start(id)
  exit unless yes?("Start the router with ID #{id}?", :magenta)
  cs_cli = CloudstackCli::Helper.new(options[:config])
  cs_cli.start_router id
end

#stop(id) ⇒ Object



104
105
106
107
108
# File 'lib/cloudstack-cli/commands/router.rb', line 104

def stop(id)
  exit unless yes?("Stop the router with ID #{id}?", :magenta)
  cs_cli = CloudstackCli::Helper.new(options[:config])
  cs_cli.stop_router id
end