ruby-jss 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ruby-jss might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.yardopts +7 -0
- data/CHANGES.md +112 -0
- data/LICENSE.txt +174 -0
- data/README.md +426 -0
- data/THANKS.md +6 -0
- data/bin/cgrouper +485 -0
- data/bin/subnet-update +400 -0
- data/lib/jss-api.rb +2 -0
- data/lib/jss.rb +190 -0
- data/lib/jss/api_connection.rb +410 -0
- data/lib/jss/api_object.rb +616 -0
- data/lib/jss/api_object/advanced_search.rb +389 -0
- data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +95 -0
- data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +96 -0
- data/lib/jss/api_object/advanced_search/advanced_user_search.rb +95 -0
- data/lib/jss/api_object/building.rb +92 -0
- data/lib/jss/api_object/category.rb +147 -0
- data/lib/jss/api_object/computer.rb +852 -0
- data/lib/jss/api_object/creatable.rb +98 -0
- data/lib/jss/api_object/criteriable.rb +189 -0
- data/lib/jss/api_object/criteriable/criteria.rb +231 -0
- data/lib/jss/api_object/criteriable/criterion.rb +228 -0
- data/lib/jss/api_object/department.rb +93 -0
- data/lib/jss/api_object/distribution_point.rb +560 -0
- data/lib/jss/api_object/extendable.rb +221 -0
- data/lib/jss/api_object/extension_attribute.rb +466 -0
- data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +362 -0
- data/lib/jss/api_object/extension_attribute/mobile_device_extension_attribute.rb +189 -0
- data/lib/jss/api_object/extension_attribute/user_extension_attribute.rb +117 -0
- data/lib/jss/api_object/group.rb +380 -0
- data/lib/jss/api_object/group/computer_group.rb +124 -0
- data/lib/jss/api_object/group/mobile_device_group.rb +139 -0
- data/lib/jss/api_object/group/user_group.rb +139 -0
- data/lib/jss/api_object/ldap_server.rb +535 -0
- data/lib/jss/api_object/locatable.rb +286 -0
- data/lib/jss/api_object/matchable.rb +97 -0
- data/lib/jss/api_object/mobile_device.rb +556 -0
- data/lib/jss/api_object/netboot_server.rb +148 -0
- data/lib/jss/api_object/network_segment.rb +414 -0
- data/lib/jss/api_object/osx_configuration_profile.rb +262 -0
- data/lib/jss/api_object/package.rb +839 -0
- data/lib/jss/api_object/peripheral.rb +335 -0
- data/lib/jss/api_object/peripheral_type.rb +295 -0
- data/lib/jss/api_object/policy.rb +898 -0
- data/lib/jss/api_object/purchasable.rb +316 -0
- data/lib/jss/api_object/removable_macaddr.rb +98 -0
- data/lib/jss/api_object/scopable.rb +136 -0
- data/lib/jss/api_object/scopable/scope.rb +621 -0
- data/lib/jss/api_object/script.rb +631 -0
- data/lib/jss/api_object/self_servable.rb +356 -0
- data/lib/jss/api_object/site.rb +93 -0
- data/lib/jss/api_object/software_update_server.rb +109 -0
- data/lib/jss/api_object/updatable.rb +117 -0
- data/lib/jss/api_object/uploadable.rb +138 -0
- data/lib/jss/api_object/user.rb +272 -0
- data/lib/jss/client.rb +504 -0
- data/lib/jss/compatibility.rb +66 -0
- data/lib/jss/composer.rb +185 -0
- data/lib/jss/configuration.rb +306 -0
- data/lib/jss/db_connection.rb +298 -0
- data/lib/jss/exceptions.rb +95 -0
- data/lib/jss/ruby_extensions.rb +35 -0
- data/lib/jss/ruby_extensions/filetest.rb +43 -0
- data/lib/jss/ruby_extensions/hash.rb +79 -0
- data/lib/jss/ruby_extensions/ipaddr.rb +91 -0
- data/lib/jss/ruby_extensions/pathname.rb +77 -0
- data/lib/jss/ruby_extensions/string.rb +59 -0
- data/lib/jss/ruby_extensions/time.rb +63 -0
- data/lib/jss/server.rb +108 -0
- data/lib/jss/utility.rb +478 -0
- data/lib/jss/version.rb +31 -0
- metadata +187 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
### Copyright 2016 Pixar
|
2
|
+
###
|
3
|
+
### Licensed under the Apache License, Version 2.0 (the "Apache License")
|
4
|
+
### with the following modification; you may not use this file except in
|
5
|
+
### compliance with the Apache License and the following modification to it:
|
6
|
+
### Section 6. Trademarks. is deleted and replaced with:
|
7
|
+
###
|
8
|
+
### 6. Trademarks. This License does not grant permission to use the trade
|
9
|
+
### names, trademarks, service marks, or product names of the Licensor
|
10
|
+
### and its affiliates, except as required to comply with Section 4(c) of
|
11
|
+
### the License and to reproduce the content of the NOTICE file.
|
12
|
+
###
|
13
|
+
### You may obtain a copy of the Apache License at
|
14
|
+
###
|
15
|
+
### http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
###
|
17
|
+
### Unless required by applicable law or agreed to in writing, software
|
18
|
+
### distributed under the Apache License with the above modification is
|
19
|
+
### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
20
|
+
### KIND, either express or implied. See the Apache License for the specific
|
21
|
+
### language governing permissions and limitations under the Apache License.
|
22
|
+
###
|
23
|
+
###
|
24
|
+
|
25
|
+
###
|
26
|
+
module JSS
|
27
|
+
|
28
|
+
#####################################
|
29
|
+
### Module Variables
|
30
|
+
#####################################
|
31
|
+
|
32
|
+
#####################################
|
33
|
+
### Module Methods
|
34
|
+
#####################################
|
35
|
+
|
36
|
+
#####################################
|
37
|
+
### Classes
|
38
|
+
#####################################
|
39
|
+
|
40
|
+
###
|
41
|
+
### A NetBoot Server in the JSS
|
42
|
+
###
|
43
|
+
###
|
44
|
+
### Only minimally implemented, mostly for access to the APIObject list methods
|
45
|
+
###
|
46
|
+
### @see JSS::APIObject
|
47
|
+
###
|
48
|
+
class NetBootServer < JSS::APIObject
|
49
|
+
|
50
|
+
#####################################
|
51
|
+
### Mix-Ins
|
52
|
+
#####################################
|
53
|
+
|
54
|
+
#####################################
|
55
|
+
### Class Methods
|
56
|
+
#####################################
|
57
|
+
|
58
|
+
#####################################
|
59
|
+
### Class Constants
|
60
|
+
#####################################
|
61
|
+
|
62
|
+
### The base for REST resources of this class
|
63
|
+
RSRC_BASE = "netbootservers"
|
64
|
+
|
65
|
+
### the hash key used for the JSON list output of all objects in the JSS
|
66
|
+
RSRC_LIST_KEY = :netboot_servers
|
67
|
+
|
68
|
+
### The hash key used for the JSON object output.
|
69
|
+
### It's also used in various error messages
|
70
|
+
RSRC_OBJECT_KEY = :netboot_server
|
71
|
+
|
72
|
+
### these keys, as well as :id and :name, are present in valid API JSON data for this class
|
73
|
+
VALID_DATA_KEYS = [:protocol, :boot_args]
|
74
|
+
|
75
|
+
#####################################
|
76
|
+
### Attributes
|
77
|
+
#####################################
|
78
|
+
|
79
|
+
### @return [String] the nvram/bless args
|
80
|
+
attr_reader :boot_args
|
81
|
+
|
82
|
+
### @return [String] the nvram/bless args
|
83
|
+
attr_reader :boot_device
|
84
|
+
|
85
|
+
### @return [String] the nvram/bless args
|
86
|
+
attr_reader :boot_file
|
87
|
+
|
88
|
+
### @return [Boolean]
|
89
|
+
attr_reader :configure_manually
|
90
|
+
|
91
|
+
### @return [boolean] is this one default?
|
92
|
+
attr_reader :default_image
|
93
|
+
|
94
|
+
### @return [String] the actual dmg name , eg "NetBoot.dmg"
|
95
|
+
attr_reader :image
|
96
|
+
|
97
|
+
### @return [String] the server's IP address
|
98
|
+
attr_reader :ip_address
|
99
|
+
|
100
|
+
### @return [String] "nfs" or "http"
|
101
|
+
attr_reader :protocol
|
102
|
+
|
103
|
+
### @return [String] the nbi folder "MetroNB-test-10.9.3-1063.nbi"
|
104
|
+
attr_reader :set
|
105
|
+
|
106
|
+
### @return [String] the tftp/protocol sharepoint name, usually "NetBootSP0"
|
107
|
+
attr_reader :share_point
|
108
|
+
|
109
|
+
### @return [Boolean]
|
110
|
+
attr_reader :specific_image
|
111
|
+
|
112
|
+
### @return [String] e.g."Intel/x86"
|
113
|
+
attr_reader :target_platform
|
114
|
+
|
115
|
+
|
116
|
+
#####################################
|
117
|
+
### Constructor
|
118
|
+
#####################################
|
119
|
+
|
120
|
+
###
|
121
|
+
### See JSS::APIObject#initialize
|
122
|
+
###
|
123
|
+
|
124
|
+
def initialize (args = {})
|
125
|
+
super
|
126
|
+
@boot_args = @init_data[:boot_args]
|
127
|
+
@boot_device = @init_data[:boot_device]
|
128
|
+
@boot_file = @init_data[:boot_file]
|
129
|
+
@configure_manually = @init_data[:configure_manually]
|
130
|
+
@default_image = @init_data[:default_image]
|
131
|
+
@image = @init_data[:image]
|
132
|
+
@ip_address = @init_data[:ip_address]
|
133
|
+
@protocol = @init_data[:protocol]
|
134
|
+
@set = @init_data[:set]
|
135
|
+
@share_point = @init_data[:share_point]
|
136
|
+
@specific_image = @init_data[:specific_image]
|
137
|
+
@target_platform = @init_data[:target_platform]
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
#####################################
|
142
|
+
### Public Instance Methods
|
143
|
+
#####################################
|
144
|
+
|
145
|
+
|
146
|
+
end # class NetbootServer
|
147
|
+
|
148
|
+
end # module
|
@@ -0,0 +1,414 @@
|
|
1
|
+
### Copyright 2016 Pixar
|
2
|
+
###
|
3
|
+
### Licensed under the Apache License, Version 2.0 (the "Apache License")
|
4
|
+
### with the following modification; you may not use this file except in
|
5
|
+
### compliance with the Apache License and the following modification to it:
|
6
|
+
### Section 6. Trademarks. is deleted and replaced with:
|
7
|
+
###
|
8
|
+
### 6. Trademarks. This License does not grant permission to use the trade
|
9
|
+
### names, trademarks, service marks, or product names of the Licensor
|
10
|
+
### and its affiliates, except as required to comply with Section 4(c) of
|
11
|
+
### the License and to reproduce the content of the NOTICE file.
|
12
|
+
###
|
13
|
+
### You may obtain a copy of the Apache License at
|
14
|
+
###
|
15
|
+
### http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
###
|
17
|
+
### Unless required by applicable law or agreed to in writing, software
|
18
|
+
### distributed under the Apache License with the above modification is
|
19
|
+
### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
20
|
+
### KIND, either express or implied. See the Apache License for the specific
|
21
|
+
### language governing permissions and limitations under the Apache License.
|
22
|
+
###
|
23
|
+
###
|
24
|
+
|
25
|
+
###
|
26
|
+
module JSS
|
27
|
+
|
28
|
+
#####################################
|
29
|
+
### Module Variables
|
30
|
+
#####################################
|
31
|
+
|
32
|
+
#####################################
|
33
|
+
### Module Methods
|
34
|
+
#####################################
|
35
|
+
|
36
|
+
#####################################
|
37
|
+
### Classes
|
38
|
+
#####################################
|
39
|
+
|
40
|
+
###
|
41
|
+
### A Network Segment in the JSS
|
42
|
+
###
|
43
|
+
### @see JSS::APIObject
|
44
|
+
###
|
45
|
+
class NetworkSegment < JSS::APIObject
|
46
|
+
|
47
|
+
#####################################
|
48
|
+
### Mix Ins
|
49
|
+
#####################################
|
50
|
+
include JSS::Creatable
|
51
|
+
include JSS::Updatable
|
52
|
+
include Comparable
|
53
|
+
|
54
|
+
#####################################
|
55
|
+
### Class Constants
|
56
|
+
#####################################
|
57
|
+
|
58
|
+
### the REST resource base
|
59
|
+
RSRC_BASE = "networksegments"
|
60
|
+
|
61
|
+
### the hash key used for the JSON list output of all objects in the JSS
|
62
|
+
RSRC_LIST_KEY = :network_segments
|
63
|
+
|
64
|
+
### The hash key used for the JSON object output.
|
65
|
+
### It's also used in various error messages
|
66
|
+
RSRC_OBJECT_KEY = :network_segment
|
67
|
+
|
68
|
+
### these keys, as well as :id and :name, are present in valid API JSON data for this class
|
69
|
+
VALID_DATA_KEYS = [:distribution_point, :starting_address, :override_departments ]
|
70
|
+
|
71
|
+
#####################################
|
72
|
+
### Class Variables
|
73
|
+
#####################################
|
74
|
+
|
75
|
+
@@network_ranges = nil
|
76
|
+
|
77
|
+
#####################################
|
78
|
+
### Class Methods
|
79
|
+
#####################################
|
80
|
+
|
81
|
+
###
|
82
|
+
### All NetworkSegments in the jss as IPAddr objects representing the
|
83
|
+
### subnet as a masked IPv4 address.
|
84
|
+
###
|
85
|
+
### Using the #include? and #to_range methods on those
|
86
|
+
### objects is very useful.
|
87
|
+
###
|
88
|
+
### @return [Hash{Integer => IPAddr}] the network segments as masked IPv4 addresses
|
89
|
+
###
|
90
|
+
def self.network_ranges(refresh = false)
|
91
|
+
@@network_ranges = nil if refresh
|
92
|
+
return @@network_ranges if @@network_ranges
|
93
|
+
@@network_ranges = {}
|
94
|
+
self.all.each{|ns| @@network_ranges[ns[:id]] = IPAddr.jss_masked_v4addr(ns[:starting_address], ns[:ending_address])}
|
95
|
+
@@network_ranges
|
96
|
+
end # def network_segments
|
97
|
+
|
98
|
+
###
|
99
|
+
### An alias for {NetworkSegment.network_ranges}
|
100
|
+
###
|
101
|
+
def self.subnets(refresh = false); self.network_ranges refresh; end
|
102
|
+
|
103
|
+
###
|
104
|
+
### Find the ids of the network segments that contain a given IP address.
|
105
|
+
###
|
106
|
+
### Even tho IPAddr.include? will take a String or an IPAddr
|
107
|
+
### I convert the ip to an IPAddr so that an exception will be raised if
|
108
|
+
### the ip isn't a valid ip.
|
109
|
+
###
|
110
|
+
### @param ip[String, IPAddr] the IP address to locate
|
111
|
+
###
|
112
|
+
### @return [Array<Integer>] the ids of the NetworkSegments containing the given ip
|
113
|
+
###
|
114
|
+
def self.network_segment_for_ip(ip)
|
115
|
+
ok_ip = IPAddr.new(ip)
|
116
|
+
matches = []
|
117
|
+
self.network_ranges.each{ |id, subnet| matches << id if subnet.include?(ok_ip) }
|
118
|
+
matches
|
119
|
+
end
|
120
|
+
|
121
|
+
###
|
122
|
+
### Find the current network segment ids for the machine running this code
|
123
|
+
###
|
124
|
+
### @return [Array<Integer>] the NetworkSegment ids for this machine right now.
|
125
|
+
###
|
126
|
+
def self.my_network_segment
|
127
|
+
network_segment_for_ip JSS::Client.my_ip_address
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
#####################################
|
133
|
+
### Attributes
|
134
|
+
#####################################
|
135
|
+
|
136
|
+
|
137
|
+
### @return [IPAddr] starting IP adresss
|
138
|
+
attr_reader :starting_address
|
139
|
+
|
140
|
+
### @return [IPAddr] ending IP adresss
|
141
|
+
attr_reader :ending_address
|
142
|
+
|
143
|
+
### @return [Integer] the CIDR
|
144
|
+
attr_reader :cidr
|
145
|
+
|
146
|
+
### @return [String] building for this segment. Must be one of the buildings in the JSS
|
147
|
+
attr_reader :building
|
148
|
+
|
149
|
+
### @return [String] department for this segment. Must be one of the depts in the JSS
|
150
|
+
attr_reader :department
|
151
|
+
|
152
|
+
### @return [String] the name of the distribution point to be used from this network segment
|
153
|
+
attr_reader :distribution_point
|
154
|
+
|
155
|
+
### @return [String] the mount url for the distribution point
|
156
|
+
attr_reader :url
|
157
|
+
|
158
|
+
### @return [String] the netboot server for this segment
|
159
|
+
attr_reader :netboot_server
|
160
|
+
|
161
|
+
### @return [String] the swupdate server for this segment.
|
162
|
+
attr_reader :swu_server
|
163
|
+
|
164
|
+
### @return [Boolean] should machines checking in from this segment update their dept
|
165
|
+
attr_reader :override_departments
|
166
|
+
|
167
|
+
### @return [Boolean] should machines checking in from this segment update their building
|
168
|
+
attr_reader :override_buildings
|
169
|
+
|
170
|
+
### @return [String] the unique identifier for this subnet, regardless of the JSS id
|
171
|
+
attr_reader :uid
|
172
|
+
|
173
|
+
### @return [IPAddr] the IPAddr object representing this network segment, created from the uid
|
174
|
+
attr_reader :subnet
|
175
|
+
|
176
|
+
###
|
177
|
+
### @see APIObject#initialize
|
178
|
+
###
|
179
|
+
def initialize(args = {} )
|
180
|
+
|
181
|
+
super args
|
182
|
+
|
183
|
+
if args[:id] == :new
|
184
|
+
raise MissingDataError, "Missing :starting_address." unless args[:starting_address]
|
185
|
+
raise MissingDataError, "Missing :ending_address or :cidr." unless args[:ending_address] or args[:cidr]
|
186
|
+
@init_data[:starting_address] = args[:starting_address]
|
187
|
+
@init_data[:ending_address] = args[:ending_address]
|
188
|
+
@init_data[:cidr] = args[:cidr].to_i
|
189
|
+
end
|
190
|
+
|
191
|
+
@building = @init_data[:building]
|
192
|
+
@department = @init_data[:department]
|
193
|
+
@distribution_point = @init_data[:distribution_point]
|
194
|
+
@netboot_server = @init_data[:netboot_server]
|
195
|
+
@override_buildings = @init_data[:override_buildings]
|
196
|
+
@override_departments = @init_data[:override_departments]
|
197
|
+
@starting_address = IPAddr.new @init_data[:starting_address]
|
198
|
+
@swu_server = @init_data[:swu_server]
|
199
|
+
@url = @init_data[:url]
|
200
|
+
|
201
|
+
### by now, we must have either an ending address or a cidr
|
202
|
+
### along with a starting address, so figure out the other one.
|
203
|
+
if @init_data[:ending_address]
|
204
|
+
@ending_address = IPAddr.new @init_data[:ending_address]
|
205
|
+
@cidr = IPAddr.jss_cidr_from_ends(@starting_address,@ending_address)
|
206
|
+
else
|
207
|
+
@cidr = @init_data[:cidr].to_i if @init_data[:cidr]
|
208
|
+
@ending_address = IPAddr.jss_ending_address(@starting_address, @cidr)
|
209
|
+
end # if args[:cidr]
|
210
|
+
|
211
|
+
### we now have all our data, make our unique identifier, the startingaddr/cidr
|
212
|
+
@uid = "#{@starting_address}/#{@cidr}"
|
213
|
+
|
214
|
+
### the IPAddr object for this whole net segment
|
215
|
+
@subnet = IPAddr.new @uid
|
216
|
+
|
217
|
+
end #init
|
218
|
+
|
219
|
+
###
|
220
|
+
### Thanks to Comparable, we can tell if we're equal or not.
|
221
|
+
###
|
222
|
+
### See Comparable#<=>
|
223
|
+
###
|
224
|
+
### @return [-1,0,1] ar we less than, equal or greater than the other?
|
225
|
+
###
|
226
|
+
def <=> (other)
|
227
|
+
self.subnet <=> other.subnet
|
228
|
+
end
|
229
|
+
|
230
|
+
###
|
231
|
+
### Set the building
|
232
|
+
###
|
233
|
+
### @param newval[String, Integer] the new building by name or id, must be in the JSS
|
234
|
+
###
|
235
|
+
### @return [void]
|
236
|
+
###
|
237
|
+
def building= (newval)
|
238
|
+
new = JSS::Building.all.select{|b| b[:id] == newval or b[:name] == newval }[0]
|
239
|
+
raise JSS::MissingDataError, "No building matching '#{newval}'" unless new
|
240
|
+
@building = new[:name]
|
241
|
+
@need_to_update = true
|
242
|
+
end
|
243
|
+
|
244
|
+
###
|
245
|
+
### set the override buildings option
|
246
|
+
###
|
247
|
+
### @param newval[Boolean] the new override buildings option
|
248
|
+
###
|
249
|
+
### @return [void]
|
250
|
+
###
|
251
|
+
def override_buildings= (newval)
|
252
|
+
raise JSS::InvalidDataError, "New value must be boolean true or false" unless JSS::TRUE_FALSE.include? newval
|
253
|
+
@override_buildings = newval
|
254
|
+
@need_to_update = true
|
255
|
+
end
|
256
|
+
|
257
|
+
###
|
258
|
+
### set the department
|
259
|
+
###
|
260
|
+
### @param newval[String, Integer] the new dept by name or id, must be in the JSS
|
261
|
+
###
|
262
|
+
### @return [void]
|
263
|
+
###
|
264
|
+
def department= (newval)
|
265
|
+
new = JSS::Department.all.select{|b| b[:id] == newval or b[:name] == newval }[0]
|
266
|
+
raise JSS::MissingDataError, "No department matching '#{newval}' in the JSS" unless new
|
267
|
+
@department = new[:name]
|
268
|
+
@need_to_update = true
|
269
|
+
end
|
270
|
+
|
271
|
+
###
|
272
|
+
### set the override depts option
|
273
|
+
###
|
274
|
+
### @param newval[Boolean] the new setting
|
275
|
+
###
|
276
|
+
### @return [void]
|
277
|
+
###
|
278
|
+
###
|
279
|
+
def override_departments= (newval)
|
280
|
+
raise JSS::InvalidDataError, "New value must be boolean true or false" unless JSS::TRUE_FALSE.include? newval
|
281
|
+
@override_departments = newval
|
282
|
+
@need_to_update = true
|
283
|
+
end
|
284
|
+
|
285
|
+
###
|
286
|
+
### set the distribution_point
|
287
|
+
###
|
288
|
+
### @param newval[String, Integer] the new dist. point by name or id, must be in the JSS
|
289
|
+
###
|
290
|
+
### @return [void]
|
291
|
+
###
|
292
|
+
def distribution_point= (newval)
|
293
|
+
new = JSS::DistributionPoint.all.select{|b| b[:id] == newval or b[:name] == newval }[0]
|
294
|
+
raise JSS::MissingDataError, "No distribution_point matching '#{newval}' in the JSS" unless new
|
295
|
+
@distribution_point = new[:name]
|
296
|
+
@need_to_update = true
|
297
|
+
end
|
298
|
+
|
299
|
+
###
|
300
|
+
### set the netboot_server
|
301
|
+
###
|
302
|
+
### @param newval[String, Integer] the new netboot server by name or id, must be in the JSS
|
303
|
+
###
|
304
|
+
### @return [void]
|
305
|
+
###
|
306
|
+
def netboot_server= (newval)
|
307
|
+
new = JSS::NetbootServer.all.select{|b| b[:id] == newval or b[:name] == newval }[0]
|
308
|
+
raise JSS::MissingDataError, "No netboot_server matching '#{newval}' in the JSS" unless new
|
309
|
+
@netboot_server = new[:name]
|
310
|
+
@need_to_update = true
|
311
|
+
end
|
312
|
+
|
313
|
+
###
|
314
|
+
### set the sw update server
|
315
|
+
###
|
316
|
+
### @param newval[String, Integer] the new server by name or id, must be in the JSS
|
317
|
+
###
|
318
|
+
### @return [void]
|
319
|
+
###
|
320
|
+
def swu_server= (newval)
|
321
|
+
new = JSS::SoftwareUpdateServer.all.select{|b| b[:id] == newval or b[:name] == newval }[0]
|
322
|
+
raise JSS::MissingDataError, "No swu_server matching '#{newval}' in the JSS" unless new
|
323
|
+
@swu_server = new[:name]
|
324
|
+
@need_to_update = true
|
325
|
+
end
|
326
|
+
|
327
|
+
###
|
328
|
+
### set the starting address
|
329
|
+
###
|
330
|
+
### @param newval[String, IPAddr] the new starting address
|
331
|
+
###
|
332
|
+
### @return [void]
|
333
|
+
###
|
334
|
+
def starting_address= (newval)
|
335
|
+
@starting_address = IPAddr.new newval # this will raise an error if the IP addr isn't valid
|
336
|
+
raise JSS::InvalidDataError, "New starting address #{@starting_address} is higher than ending address #{@ending_address}" if @starting_address > @ending_address
|
337
|
+
@cidr = IPAddr.jss_cidr_from_ends(@starting_address ,@ending_address)
|
338
|
+
@uid = "#{@starting_address}/#{@cidr}"
|
339
|
+
@subnet = IPAddr.new @uid
|
340
|
+
@need_to_update = true
|
341
|
+
end
|
342
|
+
|
343
|
+
###
|
344
|
+
### set the ending address
|
345
|
+
###
|
346
|
+
### @param newval[String, IPAddr] the new ending address
|
347
|
+
###
|
348
|
+
### @return [void]
|
349
|
+
###
|
350
|
+
def ending_address= (newval)
|
351
|
+
@ending_address = IPAddr.new newval # this will raise an error if the IP addr isn't valid
|
352
|
+
raise JSS::InvalidDataError, "New ending address #{@ending_address} is lower than starting address #{@starting_address}" if @ending_address < @starting_address
|
353
|
+
@cidr = IPAddr.jss_cidr_from_ends(@starting_address,@ending_address)
|
354
|
+
@uid = "#{@starting_address}/#{@cidr}"
|
355
|
+
@subnet = IPAddr.new @uid
|
356
|
+
@need_to_update = true
|
357
|
+
end
|
358
|
+
|
359
|
+
###
|
360
|
+
### set the cidr
|
361
|
+
###
|
362
|
+
### @param newval[String, IPAddr] the new cidr
|
363
|
+
###
|
364
|
+
### @return [void]
|
365
|
+
###
|
366
|
+
def cidr= (newval)
|
367
|
+
@cidr = newval
|
368
|
+
@ending_address = IPAddr.jss_ending_address(@starting_address, @cidr)
|
369
|
+
@uid = "#{@starting_address}/#{@cidr}"
|
370
|
+
@subnet = IPAddr.new @uid
|
371
|
+
@need_to_update = true
|
372
|
+
end
|
373
|
+
|
374
|
+
###
|
375
|
+
### is a given address in this network segment?
|
376
|
+
###
|
377
|
+
### @param some_addr[IPAddr,String] the IP address to check
|
378
|
+
###
|
379
|
+
### @return [Boolean]
|
380
|
+
###
|
381
|
+
def include? (some_addr)
|
382
|
+
@subnet.include? IPAddr.new(some_addr)
|
383
|
+
end
|
384
|
+
|
385
|
+
|
386
|
+
### aliases
|
387
|
+
alias identifier uid
|
388
|
+
alias range subnet
|
389
|
+
|
390
|
+
######################
|
391
|
+
### private methods
|
392
|
+
private
|
393
|
+
|
394
|
+
###
|
395
|
+
### the xml formated data for adding or updating this in the JSS
|
396
|
+
###
|
397
|
+
def rest_xml
|
398
|
+
doc = REXML::Document.new APIConnection::XML_HEADER
|
399
|
+
ns = doc.add_element "network_segment"
|
400
|
+
ns.add_element('building').text = @building
|
401
|
+
ns.add_element('department').text = @department
|
402
|
+
ns.add_element('distribution_point').text = @distribution_point
|
403
|
+
ns.add_element('ending_address').text = @ending_address
|
404
|
+
ns.add_element('name').text = @name
|
405
|
+
ns.add_element('netboot_server').text = @netboot_server
|
406
|
+
ns.add_element('override_buildings').text = @override_buildings
|
407
|
+
ns.add_element('override_departments').text = @override_departments
|
408
|
+
ns.add_element('starting_address').text = @starting_address
|
409
|
+
ns.add_element('swu_server').text = @swu_server
|
410
|
+
return doc.to_s
|
411
|
+
end #rest_xml
|
412
|
+
|
413
|
+
end # class NetworkSegment
|
414
|
+
end # module
|