Class: Network
- Inherits:
-
CloudstackCli::Base
- Object
- Thor
- CloudstackCli::Base
- Network
- Defined in:
- lib/cloudstack-cli/commands/network.rb
Constant Summary
Constants included from CloudstackCli::Helper
CloudstackCli::Helper::ASYNC_STATES
Instance Attribute Summary
Attributes inherited from CloudstackCli::Base
Instance Method Summary collapse
- #default ⇒ Object
- #delete(name) ⇒ Object
- #list ⇒ Object
- #restart(name) ⇒ Object
- #show(name) ⇒ Object
Methods inherited from CloudstackCli::Base
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
#default ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cloudstack-cli/commands/network.rb', line 60 def default network = client.get_default_network([:zone]) unless network puts "No default network found." else table = [["Name", "Displaytext", "Domain", "Zone"]] table[0] << "ID" if [:showid] table << [ network["name"], network["displaytext"], network["domain"], network["zonename"] ] table[-1] << network["id"] if [:showid] print_table table end end |
#delete(name) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cloudstack-cli/commands/network.rb', line 114 def delete(name) network = client.get_network(name) network = client.get_network(name, -1) unless network unless network say "Network \"#{name}\" not found." exit 1 end if yes? "Destroy network \"#{network['name']}\"?" p client.delete_network(network['id']) end end |
#list ⇒ Object
10 11 12 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 |
# File 'lib/cloudstack-cli/commands/network.rb', line 10 def list project = find_project if [:project] if [:zone] unless zone = client.get_zone([:zone]) say "Zone '#{options[:zone]}' not found.", :red exit 1 end zone_id = zone['id'] end networks = [] if project networks = client.list_networks(project_id: project['id'], zone_id: zone_id) elsif [:account] networks = client.list_networks(account: [:account], zone_id: zone_id) else networks = client.list_networks(zone_id: zone_id) networks += client.list_networks(project_id: -1, zone_id: zone_id) end if [:type] networks = filter_by(networks, 'type', [:type]) end if networks.size < 1 puts "No networks found." else table = [["Name", "Displaytext", "Account/Project", "Zone", "Domain", "State", "Type"]] table[0] << "ID" if [:showid] table[0] << "VLAN" if [:showvlan] networks.each do |network| table << [ network["name"], network["displaytext"], network["account"] || network["project"], network["zonename"], network["domain"], network["state"], network["type"] ] table[-1] << network["id"] if [:showid] table[-1] << network["vlan"] if [:showvlan] end print_table table say "Total number of networks: #{networks.count}" end end |
#restart(name) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cloudstack-cli/commands/network.rb', line 101 def restart(name) network = client.get_network(name) network = client.get_network(name, -1) unless network unless network say "Network #{name} not found." exit 1 end if yes? "Restart network \"#{network['name']}\" (cleanup=#{options[:cleanup]})?" p client.restart_network(network['id'], [:cleanup]) end end |
#show(name) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cloudstack-cli/commands/network.rb', line 80 def show(name) if [:project] if [:project].downcase == "all" [:project_id] = -1 else project = find_project [:project_id] = project['id'] end end unless server = client.get_network(name, [:project_id]) puts "No network found." else server.each do |key, value| say "#{key}: ", :yellow say "#{value}" end end end |