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
Methods inherited from CloudstackCli::Base
Methods included from CloudstackCli::OptionResolver
#resolve_account, #resolve_cluster, #resolve_compute_offering, #resolve_disk_offering, #resolve_domain, #resolve_host, #resolve_ip_network_list, #resolve_iso, #resolve_iso_for_vm_deployment, #resolve_networks, #resolve_project, #resolve_snapshot, #resolve_template, #resolve_virtual_machine, #resolve_zone, #vm_options_to_params
Methods included from CloudstackCli::Helper
#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #get_server_default_nic, #pf_rule_to_object, #print_job_status, #print_options, #run_background_jobs, #update_job_status, #update_jobs, #watch_jobs
Methods inherited from Thor
banner, basename2, old_subcommand, subcommand
Instance Method Details
#delete(name) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cloudstack-cli/commands/network.rb', line 81 def delete(name) resolve_project unless network = client.list_networks().find {|n| n['name'] == name} say "Error: Network with name '#{name}' not found.", :red exit 1 end if yes? "Delete network \"#{network['name']}\"?" client.delete_network(id: network['id']) end end |
#list ⇒ Object
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 |
# File 'lib/cloudstack-cli/commands/network.rb', line 13 def list resolve_zone if [:zone] resolve_project ("listNetworks") if [:filter] networks = client.list_networks() networks = filter_objects(networks) if [:filter] if networks.size < 1 puts "No networks found." else case [:format].to_sym when :yaml puts({networks: networks}.to_yaml) when :json puts JSON.pretty_generate(networks: networks) else table = [%w(Name Displaytext Account/Project Zone Domain State Type Offering)] 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"], network["networkofferingname"] ] 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 end |
#restart(name) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cloudstack-cli/commands/network.rb', line 68 def restart(name) resolve_project unless network = client.list_networks().find {|n| n['name'] == name} say "Network with name '#{name}' not found." exit 1 end if yes? "Restart network \"#{network['name']}\" (cleanup=#{[:cleanup]})?" client.restart_network(id: network['id'], cleanup: [:cleanup]) end end |
#show(name) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cloudstack-cli/commands/network.rb', line 53 def show(name) resolve_project unless network = client.list_networks().find {|n| n['name'] == name} say "Error: No network with name '#{name}' found.", :red exit end table = network.map do |key, value| [ set_color("#{key}:", :yellow), "#{value}" ] end print_table table end |