lib/cloudstack-cli/commands/network.rb in cloudstack-cli-0.3.10 vs lib/cloudstack-cli/commands/network.rb in cloudstack-cli-0.3.11
- old
+ new
@@ -1,8 +1,46 @@
class Network < CloudstackCli::Base
- desc "default", "get the default network"
+ desc "network list", "list networks"
+ option :project
+ option :account
+ option :showid, type: :boolean
+ option :isdefault, type: :boolean
+ def list
+ project = find_project if options[:project]
+ networks = []
+ if project
+ networks = client.list_networks(project_id: project['id'])
+ elsif options[:account]
+ networks = client.list_networks(account: options[:account])
+ else
+ networks = client.list_networks(isdefault: options[:isdefault])
+ networks += client.list_networks(project_id: -1, isdefault: options[:isdefault])
+ end
+
+ if networks.size < 1
+ puts "No networks found."
+ else
+ table = [["Name", "Displaytext", "Account", "Project", "Domain", "State", "Type"]]
+ table[0] << "ID" if options[:showid]
+ networks.each do |network|
+ table << [
+ network["name"],
+ network["displaytext"],
+ network["account"],
+ network["project"],
+ network["domain"],
+ network["state"],
+ network["type"]
+ ]
+ table[-1] << network["id"] if options[:showid]
+ end
+ print_table table
+ end
+ end
+
+ desc "network default", "get the default network"
option :zone
def default
network = client.get_default_network(options[:zone])
unless network
puts "No default network found."
@@ -18,11 +56,11 @@
table[-1] << network["id"] if options[:showid]
print_table table
end
end
- desc "show NAME", "show detailed infos about a network"
+ desc "network show NAME", "show detailed infos about a network"
option :project
def show(name)
if options[:project]
if options[:project].downcase == "all"
options[:project_id] = -1
@@ -39,49 +77,11 @@
say "#{value}"
end
end
end
- desc "list", "list networks"
- option :project
- option :account
- option :showid, type: :boolean
- option :isdefault, type: :boolean
- def list
- project = find_project if options[:project]
- networks = []
- if project
- networks = client.list_networks(project_id: project['id'])
- elsif options[:account]
- networks = client.list_networks(account: options[:account])
- else
- networks = client.list_networks(isdefault: options[:isdefault])
- networks += client.list_networks(project_id: -1, isdefault: options[:isdefault])
- end
-
- if networks.size < 1
- puts "No networks found."
- else
- table = [["Name", "Displaytext", "Account", "Project", "Domain", "State", "Type"]]
- table[0] << "ID" if options[:showid]
- networks.each do |network|
- table << [
- network["name"],
- network["displaytext"],
- network["account"],
- network["project"],
- network["domain"],
- network["state"],
- network["type"]
- ]
- table[-1] << network["id"] if options[:showid]
- end
- print_table table
- end
- end
-
- desc "restart NAME", "restart network"
+ desc "network restart NAME", "restart network"
option :cleanup, type: :boolean, default: true
def restart(name)
network = client.get_network(name)
network = client.get_network(name, -1) unless network
unless network
@@ -91,10 +91,10 @@
if yes? "Restart network \"#{network['name']}\" (cleanup=#{options[:cleanup]})?"
p client.restart_network(network['id'], options[:cleanup])
end
end
- desc "delete NAME", "delete network"
+ desc "network delete NAME", "delete network"
def delete(name)
network = client.get_network(name)
network = client.get_network(name, -1) unless network
unless network
say "Network \"#{name}\" not found."
\ No newline at end of file