Sha256: ab6751b35b7d53340cb268f6d157a1702d25f391cfa9b010d2a94700ef199568

Contents?: true

Size: 1.97 KB

Versions: 6

Compression:

Stored size: 1.97 KB

Contents

class Network < CloudstackCli::Base

  desc "create NAME", "create network"
  def create(name)
    # TODO
  end

  desc "default", "get the default network"
  option :zone
  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

  desc "list", "list networks"
  option :project
  option :account
  option :showid, type: :boolean
  option :isdefault, type: :boolean
  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

  desc "delete NAME", "delete network"
  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

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cloudstack-cli-0.3.1 lib/cloudstack-cli/commands/network.rb
cloudstack-cli-0.2.2 lib/cloudstack-cli/commands/network.rb
cloudstack-cli-0.2.1 lib/cloudstack-cli/commands/network.rb
cloudstack-cli-0.2.0 lib/cloudstack-cli/commands/network.rb
cloudstack-cli-0.1.7 lib/cloudstack-cli/commands/network.rb
cloudstack-cli-0.1.6 lib/cloudstack-cli/commands/network.rb