Sha256: 3918781e12f3db33be71ed5bd4695396d4ef299005c0d3c1a47b5cf4e5363c6c

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

class IpAddress < CloudstackCli::Base

  desc "release ID [ID2 ID3]", "release public IP address by ID"
  def release(*ids)
    ids.each do |id|
      say(" OK, released address with ID #{id}", :green) if client.disassociate_ip_address(id: id)
    end
  end

  desc "assign NETWORK", "assign a public IP address"
  option :project
  def assign(network)
    resolve_project
    options[:name] = network
    unless network = client.list_networks(options).first
      error "Network #{network} not found."
      exit 1
    end

    if address = client.associate_ip_address(networkid: network["id"])
      say " OK. Assigned IP address:", :green
      table = [%w(ID Address Account Zone)]
      table << [address["id"], address["ipaddress"], address["account"], address["zonename"]]
      print_table table
    end
  end

  desc "list", "list public IP address"
  option :project
  option :account
  option :listall
  option :format, default: "table",
    enum: %w(table json yaml)
  def list
    resolve_account
    resolve_project
    addresses = client.list_public_ip_addresses(options)
    if addresses.size < 1
      say "No ip addresses found."
    else
      case options[:format].to_sym
      when :yaml
        puts({ip_addresses: addresses}.to_yaml)
      when :json
        puts JSON.pretty_generate(ip_addresses: addresses)
      else
        table = [%w(ID Address Account Zone)]
        addresses.each do |address|
          table << [address["id"], address["ipaddress"], address["account"], address["zonename"]]
        end
        print_table table
        say "Total number of addresses: #{addresses.size}"
      end
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cloudstack-cli-1.5.10 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.9 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.8 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.7 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.6 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.5 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.4 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.3 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.2 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.1 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.0 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.4.2 lib/cloudstack-cli/commands/ip_address.rb