Class: Network

Inherits:
CloudstackCli::Base show all
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

#config

Instance Method Summary collapse

Methods inherited from CloudstackCli::Base

exit_on_failure?, start

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(options).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

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

def list
  resolve_zone if options[:zone]
  resolve_project
  add_filters_to_options("listNetworks") if options[:filter]
  networks = client.list_networks(options)
  networks = filter_objects(networks) if options[:filter]
  if networks.size < 1
    puts "No networks found."
  else
    case options[: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 options[:showid]
      table[0] << "VLAN" if options[: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 options[:showid]
        table[-1] << network["vlan"] if options[: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(options).find {|n| n['name'] == name}
    say "Network with name '#{name}' not found."
    exit 1
  end
  if yes? "Restart network \"#{network['name']}\" (cleanup=#{options[:cleanup]})?"
    client.restart_network(id: network['id'], cleanup: options[: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(options).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