Sha256: 68b33b93931b073a016f0a67b0a52a785c2025c8e15b326f685b41c54d928be7

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require 'netbox_client_ruby/entity'
require 'netbox_client_ruby/api/ipam/role'
require 'netbox_client_ruby/api/dcim/site'
require 'netbox_client_ruby/api/ipam/vrf'
require 'netbox_client_ruby/api/ipam/vlan'
require 'netbox_client_ruby/api/ipam/vlan_group'
require 'netbox_client_ruby/api/tenancy/tenant'

module NetboxClientRuby
  class Prefix
    include NetboxClientRuby::Entity

    id id: :id
    deletable true
    path 'ipam/prefixes/:id.json'
    creation_path 'ipam/prefixes/'
    object_fields(
      site: proc { |raw_data| NetboxClientRuby::Site.new raw_data['id'] },
      vrf: proc { |raw_data| NetboxClientRuby::Vrf.new raw_data['id'] },
      tenant: proc { |raw_data| NetboxClientRuby::Tenant.new raw_data['id'] },
      vlan: proc { |raw_data| NetboxClientRuby::Vlan.new raw_data['id'] },
      status: proc { |raw_data| NetboxClientRuby::PrefixStatus.new raw_data['value'] },
      role: proc { |raw_data| NetboxClientRuby::Role.new raw_data['id'] }
    )
    readonly_fields :display_name
  end

  class PrefixStatus
    attr_reader :value, :label

    def initialize(status_value)
      @value = status_value
      @label = case status_value
               when 0 then
                 'Container'.freeze
               when 1 then
                 'Active'.freeze
               when 2 then
                 'Reserved'.freeze
               when 3 then
                 'Deprecated'.freeze
               else
                 'UNDEFINED'.freeze
               end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
netbox-client-ruby-0.0.2 lib/netbox_client_ruby/api/ipam/prefix.rb
netbox-client-ruby-0.0.1 lib/netbox_client_ruby/api/ipam/prefix.rb