Class: RubyPhpipam::Subnet
- Inherits:
-
Object
- Object
- RubyPhpipam::Subnet
- Defined in:
- lib/ruby_phpipam/subnet.rb
Instance Attribute Summary collapse
-
#allowResquests ⇒ Object
readonly
Subnet attributes.
-
#description ⇒ Object
readonly
Subnet attributes.
-
#discoverSubnet ⇒ Object
readonly
Subnet attributes.
-
#DNSrecords ⇒ Object
readonly
Subnet attributes.
-
#DNSrecursive ⇒ Object
readonly
Subnet attributes.
-
#editDate ⇒ Object
readonly
Subnet attributes.
-
#freehosts ⇒ Object
readonly
Subnet usage attributes.
-
#freehosts_percent ⇒ Object
readonly
Subnet usage attributes.
-
#id ⇒ Object
readonly
Subnet attributes.
-
#isFolder ⇒ Object
readonly
Subnet attributes.
-
#isFull ⇒ Object
readonly
Subnet attributes.
-
#linked_subnet ⇒ Object
readonly
Subnet attributes.
-
#location ⇒ Object
readonly
Subnet attributes.
-
#mask ⇒ Object
readonly
Subnet attributes.
-
#masterSubnetId ⇒ Object
readonly
Subnet attributes.
-
#maxhosts ⇒ Object
readonly
Subnet usage attributes.
-
#namerServerId ⇒ Object
readonly
Subnet attributes.
-
#permissions ⇒ Object
readonly
Subnet attributes.
-
#pingSubnet ⇒ Object
readonly
Subnet attributes.
-
#scanAgent ⇒ Object
readonly
Subnet attributes.
-
#sectionId ⇒ Object
readonly
Subnet attributes.
-
#showName ⇒ Object
readonly
Subnet attributes.
-
#state ⇒ Object
readonly
Subnet attributes.
-
#subnet ⇒ Object
readonly
Subnet attributes.
-
#threshold ⇒ Object
readonly
Subnet attributes.
-
#used ⇒ Object
readonly
Subnet usage attributes.
-
#vlanId ⇒ Object
readonly
Subnet attributes.
-
#vrfId ⇒ Object
readonly
Subnet attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #addresses ⇒ Object
- #all_subnets(slave_mask) ⇒ Object
-
#first_free_ip ⇒ Object
RubyPhpipam::Address.new(data) end.
- #first_subnet(slave_mask) ⇒ Object
-
#initialize(json) ⇒ Subnet
constructor
A new instance of Subnet.
- #slaves ⇒ Object
- #slaves_recursive ⇒ Object
- #usage! ⇒ Object
Constructor Details
#initialize(json) ⇒ Subnet
Returns a new instance of Subnet.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_phpipam/subnet.rb', line 13 def initialize(json) @id = RubyPhpipam::Helper.to_type(json[:id], :int) @subnet = json[:subnet] @mask = RubyPhpipam::Helper.to_type(json[:mask], :int) @description = json[:description] @sectionId = RubyPhpipam::Helper.to_type(json[:sectionId], :int) @linked_subnet = RubyPhpipam::Helper.to_type(json[:linked_subnet], :int) @vlanId = RubyPhpipam::Helper.to_type(json[:vlanId], :int) @vrfId = RubyPhpipam::Helper.to_type(json[:vrfId], :int) @masterSubnetId = RubyPhpipam::Helper.to_type(json[:masterSubnetId], :int) @namerServerId = RubyPhpipam::Helper.to_type(json[:namerServerId], :int) @showName = RubyPhpipam::Helper.to_type(json[:showName], :binary) = RubyPhpipam::Helper.to_type(json[:permissions], :json) @DNSrecursive = RubyPhpipam::Helper.to_type(json[:DNSrecursive], :binary) @DNSrecords = RubyPhpipam::Helper.to_type(json[:DNSrecords], :binary) @allowResquests = RubyPhpipam::Helper.to_type(json[:allowResquests], :binary) @scanAgent = RubyPhpipam::Helper.to_type(json[:scanAgent], :binary) @pingSubnet = RubyPhpipam::Helper.to_type(json[:pingSubnet], :binary) @discoverSubnet = RubyPhpipam::Helper.to_type(json[:discoverSubnet], :binary) @isFolder = RubyPhpipam::Helper.to_type(json[:isFolder], :binary) @isFull = RubyPhpipam::Helper.to_type(json[:isFull], :binary) @state = RubyPhpipam::Helper.to_type(json[:state], :int) @threshold = RubyPhpipam::Helper.to_type(json[:threshold], :int) @location = RubyPhpipam::Helper.to_type(json[:location], :int) @editDate = RubyPhpipam::Helper.to_type(json[:editDate], :date) end |
Instance Attribute Details
#allowResquests ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def allowResquests @allowResquests end |
#description ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def description @description end |
#discoverSubnet ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def discoverSubnet @discoverSubnet end |
#DNSrecords ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def DNSrecords @DNSrecords end |
#DNSrecursive ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def DNSrecursive @DNSrecursive end |
#editDate ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def editDate @editDate end |
#freehosts ⇒ Object (readonly)
Subnet usage attributes
11 12 13 |
# File 'lib/ruby_phpipam/subnet.rb', line 11 def freehosts @freehosts end |
#freehosts_percent ⇒ Object (readonly)
Subnet usage attributes
11 12 13 |
# File 'lib/ruby_phpipam/subnet.rb', line 11 def freehosts_percent @freehosts_percent end |
#id ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def id @id end |
#isFolder ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def isFolder @isFolder end |
#isFull ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def isFull @isFull end |
#linked_subnet ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def linked_subnet @linked_subnet end |
#location ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def location @location end |
#mask ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def mask @mask end |
#masterSubnetId ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def masterSubnetId @masterSubnetId end |
#maxhosts ⇒ Object (readonly)
Subnet usage attributes
11 12 13 |
# File 'lib/ruby_phpipam/subnet.rb', line 11 def maxhosts @maxhosts end |
#namerServerId ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def namerServerId @namerServerId end |
#permissions ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def end |
#pingSubnet ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def pingSubnet @pingSubnet end |
#scanAgent ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def scanAgent @scanAgent end |
#sectionId ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def sectionId @sectionId end |
#showName ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def showName @showName end |
#state ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def state @state end |
#subnet ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def subnet @subnet end |
#threshold ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def threshold @threshold end |
#used ⇒ Object (readonly)
Subnet usage attributes
11 12 13 |
# File 'lib/ruby_phpipam/subnet.rb', line 11 def used @used end |
#vlanId ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def vlanId @vlanId end |
#vrfId ⇒ Object (readonly)
Subnet attributes
4 5 6 |
# File 'lib/ruby_phpipam/subnet.rb', line 4 def vrfId @vrfId end |
Class Method Details
.get(id) ⇒ Object
40 41 42 |
# File 'lib/ruby_phpipam/subnet.rb', line 40 def self.get(id) Subnet.new(RubyPhpipam::Query.get("/subnets/#{id}/")) end |
.search(cidr) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_phpipam/subnet.rb', line 44 def self.search(cidr) unless RubyPhpipam::Helper.validate_cidr(cidr) raise WrongFormatSearch, "CIDR doesn't match CIDR format x.x.x.x/y" end base, mask = cidr.split("/") data = RubyPhpipam::Query.get("/subnets/cidr/#{base}/#{mask}/") if data.nil? return nil else # Currently Rubyphpipam gives the resonse to this query as an array # just containing the element. return Subnet.new(data[0]) end end |
Instance Method Details
#addresses ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/ruby_phpipam/subnet.rb', line 73 def addresses data = RubyPhpipam::Query.get_array("/subnets/#{id}/addresses/") data.map do |addr| RubyPhpipam::Address.new(addr) end end |
#all_subnets(slave_mask) ⇒ Object
116 117 118 |
# File 'lib/ruby_phpipam/subnet.rb', line 116 def all_subnets(slave_mask) RubyPhpipam::Query.get_array("/subnets/#{id}/all_subnets/#{slave_mask}/") end |
#first_free_ip ⇒ Object
RubyPhpipam::Address.new(data) end
89 90 91 92 93 |
# File 'lib/ruby_phpipam/subnet.rb', line 89 def first_free_ip # Should this raise an exception if no address available or return nil? # Currently it returns nil RubyPhpipam::Query.get("/subnets/#{id}/first_free/") end |
#first_subnet(slave_mask) ⇒ Object
111 112 113 114 |
# File 'lib/ruby_phpipam/subnet.rb', line 111 def first_subnet(slave_mask) # nil when no available subnet exists RubyPhpipam::Query.get("/subnets/#{id}/first_subnet/#{slave_mask}/") end |
#slaves ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/ruby_phpipam/subnet.rb', line 95 def slaves data = RubyPhpipam::Query.get_array("/subnets/#{id}/slaves/") data.map do |subnet| RubyPhpipam::Subnet.new(subnet) end end |
#slaves_recursive ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/ruby_phpipam/subnet.rb', line 103 def slaves_recursive data = RubyPhpipam::Query.get_array("/subnets/#{id}/slaves_recursive/") data.map do |subnet| RubyPhpipam::Subnet.new(subnet) end end |
#usage! ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby_phpipam/subnet.rb', line 62 def usage! data = RubyPhpipam::Query.get("/subnets/#{id}/usage/") @used = RubyPhpipam::Helper.to_type(data[:used], :int) @maxhosts = RubyPhpipam::Helper.to_type(data[:maxhosts], :int) @freehosts = RubyPhpipam::Helper.to_type(data[:freehosts], :int) @freehosts_percent = data[:freehosts_percent] return self end |