Class: Router

Inherits:
CloudstackCli::Base show all
Defined in:
lib/cloudstack-cli/commands/router.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

#destroy(*names) ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/cloudstack-cli/commands/router.rb', line 122

def destroy(*names)
  routers = names.map {|name| get_router(name)}
  print_routers(routers)
  exit unless options[:force] || yes?("\nDestroy router(s) above?", :magenta)
	jobs = routers.map do |router|
		{id: client.destroy_router(router['id'], async: false)['jobid'], name: "Destroy router #{router['name']}"}
	end
  puts
  watch_jobs(jobs)
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
# File 'lib/cloudstack-cli/commands/router.rb', line 13

def list
  if options[:project]
 	  if ['-1', 'all'].include? options[:project]
      projectid = '-1'
    else
      projectid = find_project['id']
    end
  end
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]
  
  print_routers(routers, options)		

 if options[:command]
 	case options[:command].downcase
 	when "start"
 		exit unless yes?("\nStart the router(s) above? [y/N]:", :magenta)
 		jobs = routers.map do |router|
 			{id: client.start_router(router['id'], async: false)['jobid'], name: "Start router #{router['name']}"}
 		end
 	when "stop"
 		exit unless yes?("\nStop the router(s) above? [y/N]:", :magenta)
 		jobs = routers.map do |router|
 			{id: client.stop_router(router['id'], async: false)['jobid'], name: "Stop router #{router['name']}"}
 		end
 	else
 		say "\nCommand #{options[:command]} not supported.", :red
 		exit 1
 	end
    puts
    watch_jobs(jobs)
 end
end

#restart(*names) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cloudstack-cli/commands/router.rb', line 101

def restart(*names)
  routers = names.map {|name| get_router(name)}
  print_routers(routers)
  exit unless options[:force] || yes?("\nRestart router(s) above?", :magenta)
  jobs = routers.map do |router|
    {id: client.stop_router(router['id'], async: false)['jobid'], name: "Stop router #{router['name']}"}
  end
  puts
  watch_jobs(jobs)

  jobs = routers.map do |router|
    {id: client.start_router(router['id'], async: false)['jobid'], name: "Start router #{router['name']}"}
  end
  puts
  watch_jobs(jobs)

  say "Finished.", :green
end

#start(*names) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/cloudstack-cli/commands/router.rb', line 88

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

#stop(*names) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/cloudstack-cli/commands/router.rb', line 75

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