jss-api 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/lib/jss-api.rb +1 -191
  2. metadata +16 -146
  3. data/.yardopts +0 -7
  4. data/CHANGES.md +0 -88
  5. data/LICENSE.txt +0 -174
  6. data/README.md +0 -396
  7. data/THANKS.md +0 -6
  8. data/bin/cgrouper +0 -485
  9. data/bin/subnet-update +0 -400
  10. data/lib/jss-api/api_connection.rb +0 -400
  11. data/lib/jss-api/api_object.rb +0 -616
  12. data/lib/jss-api/api_object/advanced_search.rb +0 -389
  13. data/lib/jss-api/api_object/advanced_search/advanced_computer_search.rb +0 -95
  14. data/lib/jss-api/api_object/advanced_search/advanced_mobile_device_search.rb +0 -96
  15. data/lib/jss-api/api_object/advanced_search/advanced_user_search.rb +0 -95
  16. data/lib/jss-api/api_object/building.rb +0 -92
  17. data/lib/jss-api/api_object/category.rb +0 -147
  18. data/lib/jss-api/api_object/computer.rb +0 -852
  19. data/lib/jss-api/api_object/creatable.rb +0 -98
  20. data/lib/jss-api/api_object/criteriable.rb +0 -189
  21. data/lib/jss-api/api_object/criteriable/criteria.rb +0 -231
  22. data/lib/jss-api/api_object/criteriable/criterion.rb +0 -228
  23. data/lib/jss-api/api_object/department.rb +0 -93
  24. data/lib/jss-api/api_object/distribution_point.rb +0 -560
  25. data/lib/jss-api/api_object/extendable.rb +0 -221
  26. data/lib/jss-api/api_object/extension_attribute.rb +0 -457
  27. data/lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb +0 -362
  28. data/lib/jss-api/api_object/extension_attribute/mobile_device_extension_attribute.rb +0 -189
  29. data/lib/jss-api/api_object/extension_attribute/user_extension_attribute.rb +0 -117
  30. data/lib/jss-api/api_object/group.rb +0 -380
  31. data/lib/jss-api/api_object/group/computer_group.rb +0 -124
  32. data/lib/jss-api/api_object/group/mobile_device_group.rb +0 -139
  33. data/lib/jss-api/api_object/group/user_group.rb +0 -139
  34. data/lib/jss-api/api_object/ldap_server.rb +0 -535
  35. data/lib/jss-api/api_object/locatable.rb +0 -286
  36. data/lib/jss-api/api_object/matchable.rb +0 -97
  37. data/lib/jss-api/api_object/mobile_device.rb +0 -556
  38. data/lib/jss-api/api_object/netboot_server.rb +0 -148
  39. data/lib/jss-api/api_object/network_segment.rb +0 -414
  40. data/lib/jss-api/api_object/osx_configuration_profile.rb +0 -261
  41. data/lib/jss-api/api_object/package.rb +0 -812
  42. data/lib/jss-api/api_object/peripheral.rb +0 -335
  43. data/lib/jss-api/api_object/peripheral_type.rb +0 -295
  44. data/lib/jss-api/api_object/policy.rb +0 -898
  45. data/lib/jss-api/api_object/purchasable.rb +0 -316
  46. data/lib/jss-api/api_object/removable_macaddr.rb +0 -98
  47. data/lib/jss-api/api_object/scopable.rb +0 -136
  48. data/lib/jss-api/api_object/scopable/scope.rb +0 -621
  49. data/lib/jss-api/api_object/script.rb +0 -631
  50. data/lib/jss-api/api_object/self_servable.rb +0 -355
  51. data/lib/jss-api/api_object/site.rb +0 -93
  52. data/lib/jss-api/api_object/software_update_server.rb +0 -109
  53. data/lib/jss-api/api_object/updatable.rb +0 -117
  54. data/lib/jss-api/api_object/uploadable.rb +0 -138
  55. data/lib/jss-api/api_object/user.rb +0 -272
  56. data/lib/jss-api/client.rb +0 -504
  57. data/lib/jss-api/compatibility.rb +0 -66
  58. data/lib/jss-api/composer.rb +0 -171
  59. data/lib/jss-api/configuration.rb +0 -306
  60. data/lib/jss-api/db_connection.rb +0 -298
  61. data/lib/jss-api/exceptions.rb +0 -95
  62. data/lib/jss-api/ruby_extensions.rb +0 -35
  63. data/lib/jss-api/ruby_extensions/filetest.rb +0 -43
  64. data/lib/jss-api/ruby_extensions/hash.rb +0 -79
  65. data/lib/jss-api/ruby_extensions/ipaddr.rb +0 -91
  66. data/lib/jss-api/ruby_extensions/pathname.rb +0 -77
  67. data/lib/jss-api/ruby_extensions/string.rb +0 -59
  68. data/lib/jss-api/ruby_extensions/time.rb +0 -63
  69. data/lib/jss-api/server.rb +0 -108
  70. data/lib/jss-api/utility.rb +0 -416
  71. data/lib/jss-api/version.rb +0 -31
@@ -1,148 +0,0 @@
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
@@ -1,414 +0,0 @@
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