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_compute_offering, #resolve_disk_offering, #resolve_domain, #resolve_iso, #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, #get_server_fqdn, #get_server_public_ip, #get_ssh_port_forwarding_rule, #print_job_status, #print_options, #run_background_jobs, #update_job_status, #update_jobs, #watch_jobs

Instance Method Details

#delete(name) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/cloudstack-cli/commands/network.rb', line 71

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



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

def list
  resolve_zone if options[:zone]
  resolve_project
  networks = client.list_networks(options)

  if networks.size < 1
    puts "No networks found."
  else
    networks = filter_by(networks, 'type', options[:type]) if options[:type]
    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

#restart(name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/cloudstack-cli/commands/network.rb', line 58

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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cloudstack-cli/commands/network.rb', line 43

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