Class: RubyPhpipam::Subnet

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_phpipam/subnet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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)
  @permissions = 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

#allowResquestsObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def allowResquests
  @allowResquests
end

#descriptionObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def description
  @description
end

#discoverSubnetObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def discoverSubnet
  @discoverSubnet
end

#DNSrecordsObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def DNSrecords
  @DNSrecords
end

#DNSrecursiveObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def DNSrecursive
  @DNSrecursive
end

#editDateObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def editDate
  @editDate
end

#freehostsObject (readonly)

Subnet usage attributes



11
12
13
# File 'lib/ruby_phpipam/subnet.rb', line 11

def freehosts
  @freehosts
end

#freehosts_percentObject (readonly)

Subnet usage attributes



11
12
13
# File 'lib/ruby_phpipam/subnet.rb', line 11

def freehosts_percent
  @freehosts_percent
end

#idObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def id
  @id
end

#isFolderObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def isFolder
  @isFolder
end

#isFullObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def isFull
  @isFull
end

#linked_subnetObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def linked_subnet
  @linked_subnet
end

#locationObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def location
  @location
end

#maskObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def mask
  @mask
end

#masterSubnetIdObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def masterSubnetId
  @masterSubnetId
end

#maxhostsObject (readonly)

Subnet usage attributes



11
12
13
# File 'lib/ruby_phpipam/subnet.rb', line 11

def maxhosts
  @maxhosts
end

#namerServerIdObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def namerServerId
  @namerServerId
end

#permissionsObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def permissions
  @permissions
end

#pingSubnetObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def pingSubnet
  @pingSubnet
end

#scanAgentObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def scanAgent
  @scanAgent
end

#sectionIdObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def sectionId
  @sectionId
end

#showNameObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def showName
  @showName
end

#stateObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def state
  @state
end

#subnetObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def subnet
  @subnet
end

#thresholdObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def threshold
  @threshold
end

#usedObject (readonly)

Subnet usage attributes



11
12
13
# File 'lib/ruby_phpipam/subnet.rb', line 11

def used
  @used
end

#vlanIdObject (readonly)

Subnet attributes



4
5
6
# File 'lib/ruby_phpipam/subnet.rb', line 4

def vlanId
  @vlanId
end

#vrfIdObject (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

#addressesObject



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_ipObject

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

#slavesObject



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_recursiveObject



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