Class: JSS::NetworkSegment
- Defined in:
- lib/jss-api/api_object/network_segment.rb,
lib/jss-api.rb
Overview
A Network Segment in the JSS
Constant Summary collapse
- RSRC_BASE =
the REST resource base
"networksegments"
- RSRC_LIST_KEY =
the hash key used for the JSON list output of all objects in the JSS
:network_segments
- RSRC_OBJECT_KEY =
The hash key used for the JSON object output. It’s also used in various error messages
:network_segment
- VALID_DATA_KEYS =
these keys, as well as :id and :name, are present in valid API JSON data for this class
[:distribution_point, :starting_address, :override_departments ]
- @@network_ranges =
Class Variables
nil
Instance Attribute Summary collapse
-
#building ⇒ String
Building for this segment.
-
#cidr ⇒ Integer
The CIDR.
-
#department ⇒ String
Department for this segment.
-
#distribution_point ⇒ String
The name of the distribution point to be used from this network segment.
-
#ending_address ⇒ IPAddr
Ending IP adresss.
-
#need_to_update ⇒ Boolean
included
from Updatable
readonly
Do we have unsaved changes?.
-
#netboot_server ⇒ String
The netboot server for this segment.
-
#override_buildings ⇒ Boolean
Should machines checking in from this segment update their building.
-
#override_departments ⇒ Boolean
Should machines checking in from this segment update their dept.
-
#starting_address ⇒ IPAddr
Starting IP adresss.
-
#subnet ⇒ IPAddr
(also: #range)
readonly
The IPAddr object representing this network segment, created from the uid.
-
#swu_server ⇒ String
The swupdate server for this segment.
-
#uid ⇒ String
(also: #identifier)
readonly
The unique identifier for this subnet, regardless of the JSS id.
-
#url ⇒ String
readonly
The mount url for the distribution point.
Class Method Summary collapse
-
.my_network_segment ⇒ Array<Integer>
Find the current network segment ids for the machine running this code.
-
.network_ranges(refresh = false) ⇒ Hash{Integer => IPAddr}
All NetworkSegments in the jss as IPAddr objects representing the subnet as a masked IPv4 address.
-
.network_segment_for_ip(ip) ⇒ Array<Integer>
Find the ids of the network segments that contain a given IP address.
-
.subnets(refresh = false) ⇒ Object
An alias for NetworkSegment.network_ranges.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Thanks to Comparable, we can tell if we’re equal or not.
-
#create ⇒ Integer
included
from Creatable
Create a new object in the JSS.
-
#include?(some_addr) ⇒ Boolean
is a given address in this network segment?.
-
#initialize(args = {}) ⇒ NetworkSegment
constructor
A new instance of NetworkSegment.
-
#name=(newname) ⇒ void
included
from Updatable
Change the name of this item Remember to #update to push changes to the server.
-
#update ⇒ Boolean
included
from Updatable
Save changes to the JSS.
Constructor Details
#initialize(args = {}) ⇒ NetworkSegment
Returns a new instance of NetworkSegment.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/jss-api/api_object/network_segment.rb', line 179 def initialize(args = {} ) super args if args[:id] == :new raise MissingDataError, "Missing :starting_address." unless args[:starting_address] raise MissingDataError, "Missing :ending_address or :cidr." unless args[:ending_address] or args[:cidr] @init_data[:starting_address] = args[:starting_address] @init_data[:ending_address] = args[:ending_address] @init_data[:cidr] = args[:cidr].to_i end @building = @init_data[:building] @department = @init_data[:department] @distribution_point = @init_data[:distribution_point] @netboot_server = @init_data[:netboot_server] @override_buildings = @init_data[:override_buildings] @override_departments = @init_data[:override_departments] @starting_address = IPAddr.new @init_data[:starting_address] @swu_server = @init_data[:swu_server] @url = @init_data[:url] ### by now, we must have either an ending address or a cidr ### along with a starting address, so figure out the other one. if @init_data[:ending_address] @ending_address = IPAddr.new @init_data[:ending_address] @cidr = IPAddr.jss_cidr_from_ends(@starting_address,@ending_address) else @cidr = @init_data[:cidr].to_i if @init_data[:cidr] @ending_address = IPAddr.jss_ending_address(@starting_address, @cidr) end # if args[:cidr] ### we now have all our data, make our unique identifier, the startingaddr/cidr @uid = "#{@starting_address}/#{@cidr}" ### the IPAddr object for this whole net segment @subnet = IPAddr.new @uid end |
Instance Attribute Details
#building ⇒ String
Returns building for this segment. Must be one of the buildings in the JSS.
147 148 149 |
# File 'lib/jss-api/api_object/network_segment.rb', line 147 def building @building end |
#cidr ⇒ Integer
Returns the CIDR.
144 145 146 |
# File 'lib/jss-api/api_object/network_segment.rb', line 144 def cidr @cidr end |
#department ⇒ String
Returns department for this segment. Must be one of the depts in the JSS.
150 151 152 |
# File 'lib/jss-api/api_object/network_segment.rb', line 150 def department @department end |
#distribution_point ⇒ String
Returns the name of the distribution point to be used from this network segment.
153 154 155 |
# File 'lib/jss-api/api_object/network_segment.rb', line 153 def distribution_point @distribution_point end |
#ending_address ⇒ IPAddr
Returns ending IP adresss.
141 142 143 |
# File 'lib/jss-api/api_object/network_segment.rb', line 141 def ending_address @ending_address end |
#need_to_update ⇒ Boolean (readonly) Originally defined in module Updatable
Returns do we have unsaved changes?.
#netboot_server ⇒ String
Returns the netboot server for this segment.
159 160 161 |
# File 'lib/jss-api/api_object/network_segment.rb', line 159 def netboot_server @netboot_server end |
#override_buildings ⇒ Boolean
Returns should machines checking in from this segment update their building.
168 169 170 |
# File 'lib/jss-api/api_object/network_segment.rb', line 168 def override_buildings @override_buildings end |
#override_departments ⇒ Boolean
Returns should machines checking in from this segment update their dept.
165 166 167 |
# File 'lib/jss-api/api_object/network_segment.rb', line 165 def override_departments @override_departments end |
#starting_address ⇒ IPAddr
Returns starting IP adresss.
138 139 140 |
# File 'lib/jss-api/api_object/network_segment.rb', line 138 def starting_address @starting_address end |
#subnet ⇒ IPAddr (readonly) Also known as: range
Returns the IPAddr object representing this network segment, created from the uid.
174 175 176 |
# File 'lib/jss-api/api_object/network_segment.rb', line 174 def subnet @subnet end |
#swu_server ⇒ String
Returns the swupdate server for this segment.
162 163 164 |
# File 'lib/jss-api/api_object/network_segment.rb', line 162 def swu_server @swu_server end |
#uid ⇒ String (readonly) Also known as: identifier
Returns the unique identifier for this subnet, regardless of the JSS id.
171 172 173 |
# File 'lib/jss-api/api_object/network_segment.rb', line 171 def uid @uid end |
#url ⇒ String (readonly)
Returns the mount url for the distribution point.
156 157 158 |
# File 'lib/jss-api/api_object/network_segment.rb', line 156 def url @url end |
Class Method Details
.my_network_segment ⇒ Array<Integer>
Find the current network segment ids for the machine running this code
126 127 128 |
# File 'lib/jss-api/api_object/network_segment.rb', line 126 def self.my_network_segment network_segment_for_ip JSS::Client.my_ip_address end |
.network_ranges(refresh = false) ⇒ Hash{Integer => IPAddr}
All NetworkSegments in the jss as IPAddr objects representing the subnet as a masked IPv4 address.
Using the #include? and #to_range methods on those objects is very useful.
90 91 92 93 94 95 96 |
# File 'lib/jss-api/api_object/network_segment.rb', line 90 def self.network_ranges(refresh = false) @@network_ranges = nil if refresh return @@network_ranges if @@network_ranges @@network_ranges = {} self.all.each{|ns| @@network_ranges[ns[:id]] = IPAddr.jss_masked_v4addr(ns[:starting_address], ns[:ending_address])} @@network_ranges end |
.network_segment_for_ip(ip) ⇒ Array<Integer>
Find the ids of the network segments that contain a given IP address.
Even tho IPAddr.include? will take a String or an IPAddr I convert the ip to an IPAddr so that an exception will be raised if the ip isn’t a valid ip.
114 115 116 117 118 119 |
# File 'lib/jss-api/api_object/network_segment.rb', line 114 def self.network_segment_for_ip(ip) ok_ip = IPAddr.new(ip) matches = [] self.network_ranges.each{ |id, subnet| matches << id if subnet.include?(ok_ip) } matches end |
.subnets(refresh = false) ⇒ Object
An alias for network_ranges
101 |
# File 'lib/jss-api/api_object/network_segment.rb', line 101 def self.subnets(refresh = false); self.network_ranges refresh; end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Thanks to Comparable, we can tell if we’re equal or not.
See Comparable#<=>
226 227 228 |
# File 'lib/jss-api/api_object/network_segment.rb', line 226 def <=> (other) self.subnet <=> other.subnet end |
#create ⇒ Integer Originally defined in module Creatable
Create a new object in the JSS.
#include?(some_addr) ⇒ Boolean
is a given address in this network segment?
381 382 383 |
# File 'lib/jss-api/api_object/network_segment.rb', line 381 def include? (some_addr) @subnet.include? IPAddr.new(some_addr) end |
#name=(newname) ⇒ void Originally defined in module Updatable
This method returns an undefined value.
Change the name of this item Remember to #update to push changes to the server.
#update ⇒ Boolean Originally defined in module Updatable
Save changes to the JSS