Class: Network

Inherits:
CloudstackCli::Base show all
Defined in:
lib/cloudstack-cli/commands/network.rb

Instance Attribute Summary

Attributes inherited from CloudstackCli::Base

#config

Instance Method Summary collapse

Methods inherited from CloudstackCli::Base

exit_on_failure?

Instance Method Details

#create(name) ⇒ Object



4
5
6
# File 'lib/cloudstack-cli/commands/network.rb', line 4

def create(name)
  # TODO
end

#defaultObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cloudstack-cli/commands/network.rb', line 10

def default
  network = client.get_default_network(options[:zone])
  unless network
    puts "No default network found."
  else
    table = [["Name", "Displaytext", "Domain", "Zone"]]
    table[0] << "ID" if options[:showid]
      table << [
        network["name"],
        network["displaytext"],
        network["domain"],
        network["zonename"]
      ]
      table[-1] << network["id"] if options[:showid]
    print_table table
  end
end

#delete(name) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/cloudstack-cli/commands/network.rb', line 66

def delete(name)
  network = client.get_network(name, -1)
  unless network
    say "Network #{name} not found."
    exit 1
  end
  if yes? "Destroy network #{network['name']} - #{network['name']}?"
    p client.delete_network(network['id'])
  end
end

#listObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cloudstack-cli/commands/network.rb', line 33

def list
  project = find_project if options[:project]
  networks = []
  if project
    networks = client.list_networks(project['id'])
  elsif options[:account]
    networks = client.list_networks(account: options[:account])
  else
    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