Class: Router

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

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, #get_async_job_status, #print_options, #watch_jobs

Instance Method Details

#destroy(*names) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/cloudstack-cli/commands/router.rb', line 120

def destroy(*names)
  names.each do |name|
    router = get_router(name)
    exit unless options[:force] || yes?("Destroy router #{router['name']}?", :magenta)
    say "OK", :green if client.destroy_router(router['id'])
    puts
  end
end

#listObject



13
14
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
# File 'lib/cloudstack-cli/commands/router.rb', line 13

def list
  projectid = find_project['id'] if options[:project]
routers = client.list_routers(
  {
    account: options[:account], 
    projectid: projectid,
    status: options[:status],
    zone: options[:zone]
  }
)

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

if options[:redundant_state]
  routers = filter_by(routers, 'redundantstate', options[:redundant_state].downcase)
end

routers.reverse! if options[:reverse]
if routers.size < 1
  say "No routers found."
else
  table = [[
    'Name', 'Zone', 'Account', 'Project', 'Redundant-State', 'IP', 'Linklocal IP', 'Status', 'ID'
  ]]
  table[0].delete('ID') unless options[:showid]
    routers.each do |router|
      table << [
        router["name"],
        router["zonename"],
        router["account"],
        router["project"],
        router["redundantstate"],
        router["nic"].first ? router["nic"].first['ipaddress'] : "",
        router["linklocalip"],
        router["state"],
        router["id"]
      ]
      table[-1].delete_at(-1) unless table[0].index "ID"
    end
    print_table table
    puts
    say "Number of routers: #{routers.size}"
 end

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

#start(*names) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/cloudstack-cli/commands/router.rb', line 107

def start(*names)
  jobs = []
  names.each do |name|
    router = get_router(name)
    exit unless options[:force] || yes?("Start router #{router['name']}?", :magenta)
    jobs << {id: client.start_router(router['id'], async: false)['jobid'], name: "Start router #{name}"}
  end
  puts
  watch_jobs(jobs)
end

#stop(*names) ⇒ Object



94
95
96
97
98
99
100
101
102
103
# File 'lib/cloudstack-cli/commands/router.rb', line 94

def stop(*names)
  jobs = []
  names.each do |name|
    router = get_router(name)
    exit unless options[:force] || yes?("Stop router #{router['name']}?", :magenta)
    jobs << {id: client.stop_router(router['id'], async: false)['jobid'], name: "Stop router #{name}"}
  end
  puts
  watch_jobs(jobs)
end