Class: CivoCLI::Network

Inherits:
Thor
  • Object
show all
Defined in:
lib/network.rb

Instance Method Summary collapse

Instance Method Details

#create(label) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/network.rb', line 20

def create(label)
  CivoCLI::Config.set_api_auth
  network = Civo::Network.create(label: label)
  puts "Create a private network called #{label.colorize(:green)} with ID #{network.id.colorize(:green)}"
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end

#listObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/network.rb', line 4

def list
  CivoCLI::Config.set_api_auth
  rows = []
  Civo::Network.all.items.each do |network|
    if network.default
      rows << [network.id, network.label, network.cidr, "<====="]
    else
      rows << [network.id, network.label, network.cidr, ""]
    end
  end
  puts Terminal::Table.new headings: ['ID', 'Label', 'CIDR', 'Default?'], rows: rows
end

#remove(id) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/network.rb', line 31

def remove(id)
  CivoCLI::Config.set_api_auth
  network = Civo::Network.all.items.detect {|key| key.id == id}
  Civo::Network.remove(id: id)
  puts "Removed the network #{network.label.colorize(:green)} with ID #{network.id.colorize(:green)}"
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end