Sha256: 07b9216cc7b668f17393b3c401a4d1ee74d245e3505c4698093fd72fdddd1a90

Contents?: true

Size: 1.64 KB

Versions: 13

Compression:

Stored size: 1.64 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, type: :boolean, default: true
  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

13 entries across 13 versions & 1 rubygems

Version Path
cloudstack-cli-1.6.10 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.9 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.8 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.7 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.6 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.5 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.4 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.3 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.2 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.1 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.6.0 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.13 lib/cloudstack-cli/commands/ip_address.rb
cloudstack-cli-1.5.12 lib/cloudstack-cli/commands/ip_address.rb