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,96 @@
|
|
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
|
+
### An AdvancedComputerSearch in the JSS
|
42
|
+
###
|
43
|
+
### @see JSS::AdvancedSearch
|
44
|
+
###
|
45
|
+
### @see JSS::APIObject
|
46
|
+
###
|
47
|
+
class AdvancedMobileDeviceSearch < JSS::AdvancedSearch
|
48
|
+
|
49
|
+
#####################################
|
50
|
+
### Mix-Ins
|
51
|
+
#####################################
|
52
|
+
|
53
|
+
#####################################
|
54
|
+
### Class Constants
|
55
|
+
#####################################
|
56
|
+
|
57
|
+
### The base for REST resources of this class
|
58
|
+
RSRC_BASE = "advancedmobiledevicesearches"
|
59
|
+
|
60
|
+
### the hash key used for the JSON list output of all objects in the JSS
|
61
|
+
### NOTE - THIS IS A BUG, it should be advanced_mobile_device_searches
|
62
|
+
RSRC_LIST_KEY = :advanced_computer_searches
|
63
|
+
|
64
|
+
### The hash key used for the JSON object output.
|
65
|
+
### It's also used in various error messages
|
66
|
+
RSRC_OBJECT_KEY = :advanced_mobile_device_search
|
67
|
+
|
68
|
+
### these keys, as well as :id and :name, are present in valid API JSON data for this class
|
69
|
+
VALID_DATA_KEYS = [:sql_text, :display_fields, :mobile_devices]
|
70
|
+
|
71
|
+
### what kind of thing is returned by this search?
|
72
|
+
RESULT_CLASS = JSS::MobileDevice
|
73
|
+
|
74
|
+
### what data fields come back along with the display fields
|
75
|
+
### for each mobiledevices?
|
76
|
+
RESULT_ID_FIELDS = [:id, :name, :udid]
|
77
|
+
|
78
|
+
#####################################
|
79
|
+
### Attributes
|
80
|
+
#####################################
|
81
|
+
|
82
|
+
#####################################
|
83
|
+
### Constructor
|
84
|
+
#####################################
|
85
|
+
|
86
|
+
#####################################
|
87
|
+
### Public Instance Methods
|
88
|
+
#####################################
|
89
|
+
|
90
|
+
#####################################
|
91
|
+
### Private Instance Methods
|
92
|
+
#####################################
|
93
|
+
|
94
|
+
end # class
|
95
|
+
|
96
|
+
end # module
|
@@ -0,0 +1,95 @@
|
|
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
|
+
### An AdvancedUserSearch in the JSS
|
42
|
+
###
|
43
|
+
### @see JSS::AdvancedSearch
|
44
|
+
###
|
45
|
+
### @see JSS::APIObject
|
46
|
+
###
|
47
|
+
class AdvancedUserSearch < JSS::AdvancedSearch
|
48
|
+
|
49
|
+
#####################################
|
50
|
+
### Mix-Ins
|
51
|
+
#####################################
|
52
|
+
|
53
|
+
#####################################
|
54
|
+
### Class Constants
|
55
|
+
#####################################
|
56
|
+
|
57
|
+
### The base for REST resources of this class
|
58
|
+
RSRC_BASE = "advancedusersearches"
|
59
|
+
|
60
|
+
### the hash key used for the JSON list output of all objects in the JSS
|
61
|
+
RSRC_LIST_KEY = :advanced_user_searches
|
62
|
+
|
63
|
+
### The hash key used for the JSON object output.
|
64
|
+
### It's also used in various error messages
|
65
|
+
RSRC_OBJECT_KEY = :advanced_user_search
|
66
|
+
|
67
|
+
### these keys, as well as :id and :name, are present in valid API JSON data for this class
|
68
|
+
VALID_DATA_KEYS = [:criteria, :display_fields, :users]
|
69
|
+
|
70
|
+
### what kind of thing is returned by this search?
|
71
|
+
RESULT_CLASS = JSS::User
|
72
|
+
|
73
|
+
### what data fields come back along with the display fields
|
74
|
+
### for each user?
|
75
|
+
RESULT_ID_FIELDS = [:id, :name]
|
76
|
+
|
77
|
+
#####################################
|
78
|
+
### Attributes
|
79
|
+
#####################################
|
80
|
+
|
81
|
+
#####################################
|
82
|
+
### Constructor
|
83
|
+
#####################################
|
84
|
+
|
85
|
+
#####################################
|
86
|
+
### Public Instance Methods
|
87
|
+
#####################################
|
88
|
+
|
89
|
+
#####################################
|
90
|
+
### Private Instance Methods
|
91
|
+
#####################################
|
92
|
+
|
93
|
+
end # class
|
94
|
+
|
95
|
+
end # module
|
@@ -0,0 +1,92 @@
|
|
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
|
+
#####################################
|
38
|
+
### Classes
|
39
|
+
#####################################
|
40
|
+
|
41
|
+
###
|
42
|
+
### A Building in the JSS.
|
43
|
+
### These are simple, in that they only have an ID and a name.
|
44
|
+
###
|
45
|
+
### @see JSS::APIObject
|
46
|
+
###
|
47
|
+
class Building < JSS::APIObject
|
48
|
+
|
49
|
+
#####################################
|
50
|
+
### Mix-Ins
|
51
|
+
#####################################
|
52
|
+
include JSS::Creatable
|
53
|
+
include JSS::Updatable
|
54
|
+
|
55
|
+
#####################################
|
56
|
+
### Class Methods
|
57
|
+
#####################################
|
58
|
+
|
59
|
+
#####################################
|
60
|
+
### Class Constants
|
61
|
+
#####################################
|
62
|
+
|
63
|
+
### The base for REST resources of this class
|
64
|
+
RSRC_BASE = "buildings"
|
65
|
+
|
66
|
+
### the hash key used for the JSON list output of all objects in the JSS
|
67
|
+
RSRC_LIST_KEY = :buildings
|
68
|
+
|
69
|
+
### The hash key used for the JSON object output.
|
70
|
+
### It's also used in various error messages
|
71
|
+
RSRC_OBJECT_KEY = :building
|
72
|
+
|
73
|
+
### these keys, as well as :id and :name, are present in valid API JSON data for this class
|
74
|
+
VALID_DATA_KEYS = []
|
75
|
+
|
76
|
+
#####################################
|
77
|
+
### Attributes
|
78
|
+
#####################################
|
79
|
+
|
80
|
+
#####################################
|
81
|
+
### Constructor
|
82
|
+
#####################################
|
83
|
+
|
84
|
+
|
85
|
+
#####################################
|
86
|
+
### Public Instance Methods
|
87
|
+
#####################################
|
88
|
+
|
89
|
+
|
90
|
+
end # class building
|
91
|
+
|
92
|
+
end # module
|
@@ -0,0 +1,147 @@
|
|
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
|
+
#####################################
|
38
|
+
### Classes
|
39
|
+
#####################################
|
40
|
+
|
41
|
+
###
|
42
|
+
### A Category in the JSS.
|
43
|
+
###
|
44
|
+
###
|
45
|
+
### @see JSS::APIObject
|
46
|
+
###
|
47
|
+
class Category < JSS::APIObject
|
48
|
+
|
49
|
+
#####################################
|
50
|
+
### Mix-Ins
|
51
|
+
#####################################
|
52
|
+
include JSS::Creatable
|
53
|
+
include JSS::Updatable
|
54
|
+
|
55
|
+
#####################################
|
56
|
+
### Class Methods
|
57
|
+
#####################################
|
58
|
+
|
59
|
+
#####################################
|
60
|
+
### Class Constants
|
61
|
+
#####################################
|
62
|
+
|
63
|
+
### The base for REST resources of this class
|
64
|
+
RSRC_BASE = "categories"
|
65
|
+
|
66
|
+
### the hash key used for the JSON list output of all objects in the JSS
|
67
|
+
RSRC_LIST_KEY = :categories
|
68
|
+
|
69
|
+
### The hash key used for the JSON object output.
|
70
|
+
### It's also used in various error messages
|
71
|
+
RSRC_OBJECT_KEY = :category
|
72
|
+
|
73
|
+
### these keys, as well as :id and :name, are present in valid API JSON data for this class
|
74
|
+
VALID_DATA_KEYS = [:priority]
|
75
|
+
|
76
|
+
### The Default category
|
77
|
+
DEFAULT_CATEGORY = "Unknown"
|
78
|
+
|
79
|
+
### The range of possible priorities
|
80
|
+
POSSIBLE_PRIORITIES = 1..20
|
81
|
+
|
82
|
+
### The Default Priority
|
83
|
+
DEFAULT_PRIORITY = 5
|
84
|
+
|
85
|
+
#####################################
|
86
|
+
### Attributes
|
87
|
+
#####################################
|
88
|
+
|
89
|
+
### @return [Integer] the SelfService priority for this category
|
90
|
+
attr_reader :priority
|
91
|
+
|
92
|
+
#####################################
|
93
|
+
### Constructor
|
94
|
+
#####################################
|
95
|
+
|
96
|
+
###
|
97
|
+
### See JSS::APIObject#initialize
|
98
|
+
###
|
99
|
+
def initialize(args = {})
|
100
|
+
super
|
101
|
+
@priority = @init_data[:priority] || DEFAULT_PRIORITY
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
#####################################
|
107
|
+
### Public Instance Methods
|
108
|
+
#####################################
|
109
|
+
|
110
|
+
|
111
|
+
###
|
112
|
+
### Change the Priority
|
113
|
+
###
|
114
|
+
### @param new_val[Integer] the new priority, must be in the range POSSIBLE_PRIORITIES
|
115
|
+
###
|
116
|
+
### @return [void]
|
117
|
+
###
|
118
|
+
def priority= (new_val = @priority)
|
119
|
+
return nil if new_val == @priority
|
120
|
+
raise JSS::InvalidDataError, "priority must be an integer between #{POSSIBLE_PRIORITIES.first} and #{POSSIBLE_PRIORITIES.last} (inclusive)" unless POSSIBLE_PRIORITIES.include? new_val
|
121
|
+
@priority = new_val
|
122
|
+
@need_to_update = true
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
#####################################
|
127
|
+
### Private Instance Methods
|
128
|
+
#####################################
|
129
|
+
private
|
130
|
+
|
131
|
+
###
|
132
|
+
### Return a String with the XML Resource
|
133
|
+
### for submitting creation or changes to the JSS via
|
134
|
+
### the API via the Creatable or Updatable modules
|
135
|
+
###
|
136
|
+
### Most classes will redefine this method.
|
137
|
+
###
|
138
|
+
def rest_xml
|
139
|
+
doc = REXML::Document.new APIConnection::XML_HEADER
|
140
|
+
tmpl = doc.add_element self.class::RSRC_OBJECT_KEY.to_s
|
141
|
+
tmpl.add_element('name').text = @name
|
142
|
+
tmpl.add_element('priority').text = @priority
|
143
|
+
return doc.to_s
|
144
|
+
end
|
145
|
+
end # class category
|
146
|
+
|
147
|
+
end # module
|
@@ -0,0 +1,852 @@
|
|
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 Constants
|
30
|
+
#####################################
|
31
|
+
|
32
|
+
#####################################
|
33
|
+
### Module Variables
|
34
|
+
#####################################
|
35
|
+
|
36
|
+
#####################################
|
37
|
+
### Module Methods
|
38
|
+
#####################################
|
39
|
+
|
40
|
+
|
41
|
+
###
|
42
|
+
### This class represents a Computer in the JSS.
|
43
|
+
###
|
44
|
+
### ===Adding Computers to the JSS
|
45
|
+
###
|
46
|
+
### This class cannot be used to add new Computers to the JSS. Please use other
|
47
|
+
### Casper methods (like the Recon App or QuickAdd package)
|
48
|
+
###
|
49
|
+
### ---
|
50
|
+
### ===Editing values
|
51
|
+
###
|
52
|
+
### Any data that arrives in the JSS via an "inventory update"
|
53
|
+
### (a.k.a. 'recon') cannot be modified through this class, or the API.
|
54
|
+
###
|
55
|
+
### Data that can be modified are:
|
56
|
+
### * Management Account (see #set_management_to)
|
57
|
+
### * asset_tag
|
58
|
+
### * barcodes 1 and 2
|
59
|
+
### * ip_address
|
60
|
+
### * udid
|
61
|
+
### * mac_addresses
|
62
|
+
### * location data from the Locatable module
|
63
|
+
### * purchasing data from the Purchasable module
|
64
|
+
###
|
65
|
+
### After making any changes, you must call #update to send those
|
66
|
+
### changes to the server.
|
67
|
+
###
|
68
|
+
### ---
|
69
|
+
### ===MDM Commands
|
70
|
+
###
|
71
|
+
### ==== MDM Commands are Not Yet Supported!
|
72
|
+
### *Hopefully they will be soon*
|
73
|
+
###
|
74
|
+
### The following methods will be used to send an APNS command to the computer represented by an
|
75
|
+
### instance of JSS::Computer, equivalent to clicking one of the buttons on
|
76
|
+
### the Management Commands section of the Management tab of the Computer details page in the JSS UI.
|
77
|
+
###
|
78
|
+
### The methods supported will be:
|
79
|
+
### - #blank_push (aliases blank, noop, send_blank_push)
|
80
|
+
### - #device_lock (aliases lock, lock_device)
|
81
|
+
### - #erase_device (aliases wipe)
|
82
|
+
###
|
83
|
+
### To send an MDM command without making an instance, use the class method {.send_mdm_command}
|
84
|
+
###
|
85
|
+
### Each returns true if the command as sent.
|
86
|
+
###
|
87
|
+
### ---
|
88
|
+
### ===Other Methods
|
89
|
+
###
|
90
|
+
### - {#set_management_to} change the management acct and passwd for this computer, aliased to #make_managed
|
91
|
+
### - requires calling #update to push changes to the server
|
92
|
+
### - {#make_unmanaged} an shortcut method for {#set_management_to}(nil)
|
93
|
+
### - requires calling #update to push changes to the server
|
94
|
+
### - {#apps} a shortcut to {#software} [:applications]
|
95
|
+
### - {#licensed_sw} a shortcut to {#software} [:licensed_software]
|
96
|
+
### - {#computer_groups} a shortcut to {#groups_accounts} [:computer_group_memberships]
|
97
|
+
### - {#local_accounts} a shortcut to {#groups_accounts} [:local_accounts]
|
98
|
+
### - {#drives} a shortcut to {#hardware} [:storage]
|
99
|
+
### - {#printers} a shortcut to {#hardware} [:mapped_printers]
|
100
|
+
###
|
101
|
+
### @see APIObject
|
102
|
+
### @see Locatable
|
103
|
+
### @see Purchasable
|
104
|
+
### @see Matchable
|
105
|
+
### @see FileUpload
|
106
|
+
###
|
107
|
+
class Computer < JSS::APIObject
|
108
|
+
|
109
|
+
#####################################
|
110
|
+
### MixIns
|
111
|
+
#####################################
|
112
|
+
|
113
|
+
include JSS::Updatable
|
114
|
+
include JSS::Locatable
|
115
|
+
include JSS::Purchasable
|
116
|
+
include JSS::Uploadable
|
117
|
+
include JSS::Extendable
|
118
|
+
|
119
|
+
extend JSS::Matchable
|
120
|
+
|
121
|
+
#####################################
|
122
|
+
### Class Variables
|
123
|
+
#####################################
|
124
|
+
|
125
|
+
@@all_computers = nil
|
126
|
+
|
127
|
+
#####################################
|
128
|
+
### Class Methods
|
129
|
+
#####################################
|
130
|
+
|
131
|
+
### A larger set of info about the computers in the JSS.
|
132
|
+
###
|
133
|
+
### Casper 9.4 introduced the API Resource /computers/subset/basic
|
134
|
+
### that returns an array of hashes with more data than just /computers/
|
135
|
+
### (which was just :name and :id). Similar to /mobildevices/, this new
|
136
|
+
### list includes :udid, :serial_number, and :mac_address, as well as :model,
|
137
|
+
### :managed, :building, :department, :username, and :report_date
|
138
|
+
###
|
139
|
+
### Because this requires a different, unusual, resource path, we're completely re-defining
|
140
|
+
### {APIObject.all} for JSS::Computer. Hopefully some day the original /computers/
|
141
|
+
### resource will be updated to return this data.
|
142
|
+
###
|
143
|
+
### @param refresh[Boolean] should the data be re-queried from the API?
|
144
|
+
###
|
145
|
+
### @return [Array<Hash{:name=>String, :id=> Integer}>]
|
146
|
+
###
|
147
|
+
def self.all(refresh = false)
|
148
|
+
@@all_computers = nil if refresh
|
149
|
+
return @@all_computers if @@all_computers
|
150
|
+
@@all_computers = JSS::API.get_rsrc(self::LIST_RSRC)[self::RSRC_LIST_KEY]
|
151
|
+
end
|
152
|
+
|
153
|
+
### @return [Array<String>] all computer serial numbers in the jss
|
154
|
+
def self.all_serial_numbers(refresh = false)
|
155
|
+
self.all(refresh).map{|i| i[:serial_number]}
|
156
|
+
end
|
157
|
+
|
158
|
+
### @return [Array<String>] all computer mac_addresses in the jss
|
159
|
+
def self.all_mac_addresses(refresh = false)
|
160
|
+
self.all(refresh).map{|i| i[:mac_address]}
|
161
|
+
end
|
162
|
+
|
163
|
+
### @return [Array<String>] all computer udids in the jss
|
164
|
+
def self.all_udids(refresh = false)
|
165
|
+
self.all(refresh).map{|i| i[:udid]}
|
166
|
+
end
|
167
|
+
|
168
|
+
### @return [Array<Hash>] all managed computers in the jss
|
169
|
+
def self.all_managed(refresh = false)
|
170
|
+
self.all(refresh).select{|d| d[:managed] }
|
171
|
+
end
|
172
|
+
|
173
|
+
### @return [Array<Hash>] all unmanaged computers in the jss
|
174
|
+
def self.all_unmanaged(refresh = false)
|
175
|
+
self.all(refresh).select{|d| not d[:managed] }
|
176
|
+
end
|
177
|
+
|
178
|
+
### @return [Array<Hash>] all laptop computers in the jss
|
179
|
+
def self.all_laptops(refresh = false)
|
180
|
+
self.all(refresh).select{|d| d[:model] =~ /book/i }
|
181
|
+
end
|
182
|
+
|
183
|
+
### @return [Array<Hash>] all macbooks in the jss
|
184
|
+
def self.all_macbooks(refresh = false)
|
185
|
+
self.all(refresh).select{|d| d[:model] =~ /^macbook\d/i }
|
186
|
+
end
|
187
|
+
|
188
|
+
### @return [Array<Hash>] all macbookpros in the jss
|
189
|
+
def self.all_macbookpros(refresh = false)
|
190
|
+
self.all(refresh).select{|d| d[:model] =~ /^macbookpro\d/i }
|
191
|
+
end
|
192
|
+
|
193
|
+
### @return [Array<Hash>] all macbookairs in the jss
|
194
|
+
def self.all_macbookairs(refresh = false)
|
195
|
+
self.all(refresh).select{|d| d[:model] =~ /^macbookair\d/i }
|
196
|
+
end
|
197
|
+
|
198
|
+
### @return [Array<Hash>] all xserves in the jss
|
199
|
+
def self.all_xserves(refresh = false)
|
200
|
+
self.all(refresh).select{|d| d[:model] =~ /serve/i }
|
201
|
+
end
|
202
|
+
|
203
|
+
### @return [Array<Hash>] all desktop macs in the jss
|
204
|
+
def self.all_desktops(refresh = false)
|
205
|
+
self.all(refresh).select{|d| d[:model] !~ /serve|book/i }
|
206
|
+
end
|
207
|
+
|
208
|
+
### @return [Array<Hash>] all imacs in the jss
|
209
|
+
def self.all_imacs(refresh = false)
|
210
|
+
self.all(refresh).select{|d| d[:model] =~ /^imac/i }
|
211
|
+
end
|
212
|
+
|
213
|
+
### @return [Array<Hash>] all mac minis in the jss
|
214
|
+
def self.all_minis(refresh = false)
|
215
|
+
self.all(refresh).select{|d| d[:model] =~ /^macmini/i }
|
216
|
+
end
|
217
|
+
|
218
|
+
### @return [Array<Hash>] all macpros in the jss
|
219
|
+
def self.all_macpros(refresh = false)
|
220
|
+
self.all(refresh).select{|d| d[:model] =~ /^macpro/i }
|
221
|
+
end
|
222
|
+
|
223
|
+
###
|
224
|
+
### Send an MDM command to a managed computer by id or name
|
225
|
+
###
|
226
|
+
### @param computer[String,Integer] the name or id of the computer to recieve the command
|
227
|
+
### @param command[Symbol] the command to send, one of the keys of COMPUTER_MDM_COMMANDS
|
228
|
+
###
|
229
|
+
### @return [true] if the command was sent
|
230
|
+
###
|
231
|
+
|
232
|
+
# Not functional until I get more docs from JAMF
|
233
|
+
#
|
234
|
+
# def self.send_mdm_command(computer,command)
|
235
|
+
#
|
236
|
+
# raise JSS::NoSuchItemError, "Unknown command '#{command}'" unless COMPUTER_MDM_COMMANDS.keys.include? command
|
237
|
+
#
|
238
|
+
# command_xml ="#{JSS::APIConnection::XML_HEADER}<computer><command>#{COMPUTER_MDM_COMMANDS[command]}</command></computer>"
|
239
|
+
# the_id = nil
|
240
|
+
#
|
241
|
+
# if computer.to_s =~ /^\d+$/
|
242
|
+
# the_id = computer
|
243
|
+
# else
|
244
|
+
# the_id = self.map_all_ids_to(:name).invert[computer]
|
245
|
+
# end
|
246
|
+
#
|
247
|
+
# if the_id
|
248
|
+
# response = JSS::API.put_rsrc("#{RSRC_BASE}/id/#{the_id}", command_xml)
|
249
|
+
# response =~ %r{<notification_sent>(.+)</notification_sent>}
|
250
|
+
# return ($1 and $1 == "true")
|
251
|
+
# end
|
252
|
+
# raise JSS::UnmanagedError, "Cannot send command to unknown/unmanaged computer '#{computer}'"
|
253
|
+
# end
|
254
|
+
|
255
|
+
|
256
|
+
#####################################
|
257
|
+
### Class Constants
|
258
|
+
#####################################
|
259
|
+
|
260
|
+
|
261
|
+
### The base for REST resources of this class
|
262
|
+
RSRC_BASE = "computers"
|
263
|
+
|
264
|
+
### The (temporary?) list-resource
|
265
|
+
LIST_RSRC = "#{RSRC_BASE}/subset/basic"
|
266
|
+
|
267
|
+
### the hash key used for the JSON list output of all objects in the JSS
|
268
|
+
RSRC_LIST_KEY = :computers
|
269
|
+
|
270
|
+
### The hash key used for the JSON object output.
|
271
|
+
### It's also used in various error messages
|
272
|
+
RSRC_OBJECT_KEY = :computer
|
273
|
+
|
274
|
+
### these keys, as well as :id and :name, are present in valid API JSON data for this class
|
275
|
+
VALID_DATA_KEYS = [:sus, :distribution_point, :alt_mac_address ]
|
276
|
+
|
277
|
+
### This class lets us seach for computers
|
278
|
+
SEARCH_CLASS = JSS::AdvancedComputerSearch
|
279
|
+
|
280
|
+
### This is the class for relevant Extension Attributes
|
281
|
+
EXT_ATTRIB_CLASS = JSS::ComputerExtensionAttribute
|
282
|
+
|
283
|
+
### Boot partitions are noted with the string "(Boot Partition)" at the end
|
284
|
+
BOOT_FLAG = " (Boot Partition)"
|
285
|
+
|
286
|
+
### file uploads can send attachments to the JSS using :computers as the sub-resource.
|
287
|
+
UPLOAD_TYPES = { :attachment => :computers}
|
288
|
+
|
289
|
+
### A mapping of Symbols available to the send_mdm_command class method, to
|
290
|
+
### the String commands actuallly sent via the API.
|
291
|
+
COMPUTER_MDM_COMMANDS = {
|
292
|
+
:blank_push => "BlankPush",
|
293
|
+
:send_blank_push => "BlankPush",
|
294
|
+
:blank => "BlankPush",
|
295
|
+
:noop => "BlankPush",
|
296
|
+
:device_lock => "DeviceLock",
|
297
|
+
:lock => "DeviceLock",
|
298
|
+
:lock_device => "DeviceLock",
|
299
|
+
:erase_device => "EraseDevice",
|
300
|
+
:erase => "EraseDevice",
|
301
|
+
:wipe => "EraseDevice",
|
302
|
+
:unmanage_device => "UnmanageDevice",
|
303
|
+
:unmanage => "UnmanageDevice"
|
304
|
+
}
|
305
|
+
|
306
|
+
#####################################
|
307
|
+
### Attributes
|
308
|
+
#####################################
|
309
|
+
|
310
|
+
### The values returned in the General, Location, and Purchasing subsets are stored as direct attributes
|
311
|
+
### Location and Purchasing are defined in the Locatable and Purchasable mixin modules.
|
312
|
+
### Here's General, in alphabetical order
|
313
|
+
|
314
|
+
### @return [String] the secondary mac address
|
315
|
+
attr_reader :alt_mac_address
|
316
|
+
|
317
|
+
### @return [String] the asset tag
|
318
|
+
attr_reader :asset_tag
|
319
|
+
|
320
|
+
### @return [String] the barcodes
|
321
|
+
attr_reader :barcode_1, :barcode_2
|
322
|
+
|
323
|
+
|
324
|
+
### @return [String] The name of the distribution point for this computer
|
325
|
+
attr_reader :distribution_point
|
326
|
+
|
327
|
+
### @return [Time] when was it added to the JSS
|
328
|
+
attr_reader :initial_entry_date
|
329
|
+
|
330
|
+
### @return [IPAddr] the last known IP address
|
331
|
+
attr_reader :ip_address
|
332
|
+
|
333
|
+
### @return [String] the version of the jamf binary
|
334
|
+
attr_reader :jamf_version
|
335
|
+
|
336
|
+
### @return [Time] the last contact time
|
337
|
+
attr_reader :last_contact_time
|
338
|
+
|
339
|
+
### @return [String] the primary macaddress
|
340
|
+
attr_reader :mac_address
|
341
|
+
|
342
|
+
### @return [Boolean] is this machine "managed" by Casper?
|
343
|
+
attr_reader :managed
|
344
|
+
|
345
|
+
### @return [String] the name of the management account
|
346
|
+
attr_reader :management_username
|
347
|
+
|
348
|
+
### @return [Boolean] doesit support MDM?
|
349
|
+
attr_reader :mdm_capable
|
350
|
+
|
351
|
+
### @return [String] the name of the netboot server for this machine
|
352
|
+
attr_reader :netboot_server
|
353
|
+
|
354
|
+
### @return [String] what kind of computer?
|
355
|
+
attr_reader :platform
|
356
|
+
|
357
|
+
### @return [Time] the last recon time
|
358
|
+
attr_reader :report_date
|
359
|
+
|
360
|
+
### @return [String] the serial number
|
361
|
+
attr_reader :serial_number
|
362
|
+
|
363
|
+
|
364
|
+
### @return [Hash] the :name and :id of the site for this machine
|
365
|
+
attr_reader :site
|
366
|
+
|
367
|
+
### @return [String] the name of the Software Update Server assigned to this machine.
|
368
|
+
attr_reader :sus
|
369
|
+
|
370
|
+
### @return [String] the UDID of the computer
|
371
|
+
attr_reader :udid
|
372
|
+
|
373
|
+
|
374
|
+
############
|
375
|
+
### The remaining subsets each go into an attribute of their own.
|
376
|
+
###
|
377
|
+
|
378
|
+
### @return [Array<Hash>]
|
379
|
+
###
|
380
|
+
### A Hash for each ConfigurationProfile on the computer
|
381
|
+
###
|
382
|
+
### The Hash keys are:
|
383
|
+
### * :id => the ConfigurationProfile id in the JSS
|
384
|
+
### * :name => the username to whom this user-level profile has been applied (if it's a user-level profile)
|
385
|
+
### * :uuid => the ConfigurationProfile uuid
|
386
|
+
###
|
387
|
+
attr_reader :configuration_profiles
|
388
|
+
|
389
|
+
### @return [Hash]
|
390
|
+
###
|
391
|
+
### Info about the local accts and ComputerGroups to which this machine beloings
|
392
|
+
###
|
393
|
+
### The Hash keys are:
|
394
|
+
### * :computer_group_memberships => An Array of names of ComputerGroups to which this computer belongs
|
395
|
+
### * :local_accounts => An Array of Hashes for each local user acct on this computer. Each hash has these keys:
|
396
|
+
### * :name => String, the login name of the acct
|
397
|
+
### * :realname => the real name of the acct
|
398
|
+
### * :uid => String, the uid of the acct
|
399
|
+
### * :home => String, the path to the home folder
|
400
|
+
### * :home_size => String, the size of the homedir as a string like "53245MB"
|
401
|
+
### * :home_size_mb => Integer, the size of the homedir as an integer like 53245
|
402
|
+
### * :administrator => Boolean
|
403
|
+
### * :filevault_enabled => Boolean
|
404
|
+
###
|
405
|
+
attr_reader :groups_accounts
|
406
|
+
|
407
|
+
### @return [Hash]
|
408
|
+
###
|
409
|
+
### A Hash with info about the hardware of this cmoputer.
|
410
|
+
###
|
411
|
+
### These are the keys & sample data
|
412
|
+
### * :number_processors=>2,
|
413
|
+
### * :processor_speed_mhz=>2530,
|
414
|
+
### * :make=>"Apple",
|
415
|
+
### * :cache_size=>3072,
|
416
|
+
### * :processor_type=>"Intel Core i5",
|
417
|
+
### * :total_ram_mb=>8192,
|
418
|
+
### * :model=>"15-inch MacBook Pro (Mid 2010)",
|
419
|
+
### * :available_ram_slots=>0,
|
420
|
+
### * :processor_architecture=>"i386",
|
421
|
+
### * :bus_speed_mhz=>0,
|
422
|
+
### * :total_ram=>8192,
|
423
|
+
### * :os_name=>"Mac OS X",
|
424
|
+
### * :optical_drive=>"HL-DT-ST DVDRW GS23N",
|
425
|
+
### * :model_identifier=>"MacBookPro6,2",
|
426
|
+
### * :cache_size_kb=>3072,
|
427
|
+
### * :boot_rom=>"MBP61.0057.B0F",
|
428
|
+
### * :os_version=>"10.9.3",
|
429
|
+
### * :mapped_printers=> An Array of Hashes, one per printer, with these keys
|
430
|
+
### * :name => the name of the printer
|
431
|
+
### * :location => the location of the printer
|
432
|
+
### * :type => the printer model
|
433
|
+
### * :uri => the uri to reach the printer on the network
|
434
|
+
### * :nic_speed=>"10/100/1000",
|
435
|
+
### * :processor_speed=>2530,
|
436
|
+
### * :active_directory_status=>"Not Bound",
|
437
|
+
### * :bus_speed=>0,
|
438
|
+
### * :os_build=>"13D65",
|
439
|
+
### * :smc_version=>"1.58f17",
|
440
|
+
### * :service_pack=>"",
|
441
|
+
### * :battery_capacity=>87
|
442
|
+
### * :storage=> An Array of Hashes, one per Drive, with these keys
|
443
|
+
### * :smart_status=>"Verified",
|
444
|
+
### * :connection_type=>"NO",
|
445
|
+
### * :model=>"M4-CT256M4SSD2",
|
446
|
+
### * :revision=>"040H",
|
447
|
+
### * :serial_number=>"00000000130709JH7GhhC",
|
448
|
+
### * :size=>262205,
|
449
|
+
### * :disk=>"disk0",
|
450
|
+
### * :drive_capacity_mb=>262205}],
|
451
|
+
### * :partition=> A Hash with these keys
|
452
|
+
### * :filevault2_status=>"Encrypted",
|
453
|
+
### * :type=>"boot",
|
454
|
+
### * :filevault2_percent=>100,
|
455
|
+
### * :partition_capacity_mb=>38014,
|
456
|
+
### * :lvgUUID=>"C4883AF5-3E58-4F76-A56C-094D4CEC7E9F",
|
457
|
+
### * :percentage_full=>61,
|
458
|
+
### * :lvUUID=>"745A262E-AEA6-4608-8A3A-6CDC225B4DE6",
|
459
|
+
### * :filevault_status=>"Encrypted",
|
460
|
+
### * :size=>38014,
|
461
|
+
### * :pvUUID=>"C38051CF-5066-442F-A442-1035060ED462",
|
462
|
+
### * :name=>"KimDrive40 (Boot Partition)",
|
463
|
+
### * :filevault_percent=>100
|
464
|
+
###
|
465
|
+
attr_reader :hardware
|
466
|
+
|
467
|
+
### DEPRECATED
|
468
|
+
### attr_reader :iphones
|
469
|
+
|
470
|
+
### @return [Array<Hash>]
|
471
|
+
###
|
472
|
+
### A Hash per peripheral
|
473
|
+
###
|
474
|
+
### Each hash has these keys & sample data:
|
475
|
+
### * :id=>286,
|
476
|
+
### * :type=>"Display",
|
477
|
+
### * :field_0=>"HP",
|
478
|
+
### * :field_1=>"HP LP2480zx",
|
479
|
+
### * :field_2=>"DreamColor",
|
480
|
+
### * :field_3=>"3CM10800F4",
|
481
|
+
### * :field_4=>"",
|
482
|
+
### * :field_5=>""
|
483
|
+
### * :field_6=>"",
|
484
|
+
### * :bar_code_1=>"",
|
485
|
+
### * :bar_code_2=>"",
|
486
|
+
### * :purchasing=> A hash with these keys:
|
487
|
+
### * :warranty_expires_utc=>"",
|
488
|
+
### * :is_leased=>false,
|
489
|
+
### * :po_date=>"",
|
490
|
+
### * :lease_expires=>"",
|
491
|
+
### * :po_number=>"",
|
492
|
+
### * :po_date_epoch=>0,
|
493
|
+
### * :lease_expires_epoch=>0,
|
494
|
+
### * :vendor=>"",
|
495
|
+
### * :attachments=>[],
|
496
|
+
### * :po_date_utc=>"",
|
497
|
+
### * :lease_expires_utc=>"",
|
498
|
+
### * :applecare_id=>"",
|
499
|
+
### * :warranty_expires=>"",
|
500
|
+
### * :life_expectancy=>0,
|
501
|
+
### * :purchase_price=>"",
|
502
|
+
### * :warranty_expires_epoch=>0,
|
503
|
+
### * :is_purchased=>true,
|
504
|
+
### * :purchasing_contact=>"",
|
505
|
+
### * :purchasing_account=>""
|
506
|
+
###
|
507
|
+
attr_reader :peripherals
|
508
|
+
|
509
|
+
### @return [Hash]
|
510
|
+
###
|
511
|
+
### A Hash of software data
|
512
|
+
###
|
513
|
+
### The Hash has these keys:
|
514
|
+
### * :running_services => An Array of services running on the computer (if gathered) TODO - is each item a hash?
|
515
|
+
### * :installed_by_casper => An Array of Package names unstalled on this computer by Casper
|
516
|
+
### * :fonts => An Array of fonts on this computer (if gathered) TODO - is each item a hash?
|
517
|
+
### * :installed_by_installer_swu => An Array of pkg IDs for pkgs installed by SoftwareUpdate or the Apple Installer
|
518
|
+
### * :applications => An Array of Hashes, one per Application on the computer, with these keys:
|
519
|
+
### * :path => String, the path to the app
|
520
|
+
### * :name => String, the name of the app, including the .app suffix
|
521
|
+
### * :version => String, the version of the app at that path.
|
522
|
+
### * :cached_by_casper => An Array of Casper Package names cached on the machine, awaiting installation
|
523
|
+
### * :available_software_updates => An Array of available SoftwareUpdate (if gathered) TODO - is each item a hash?
|
524
|
+
### * :plugins => An Array of plugins installed on the machine (if gathered) TODO - is each item a hash?
|
525
|
+
### * :available_updates => A Hash - Deprecated?
|
526
|
+
### * :licensed_software => An Array, the names of Licenced Software (as defined in Casper) on this machine
|
527
|
+
### * :unix_executables => DEPRECATED
|
528
|
+
###
|
529
|
+
attr_reader :software
|
530
|
+
|
531
|
+
#####################################
|
532
|
+
### Instance Methods
|
533
|
+
#####################################
|
534
|
+
|
535
|
+
###
|
536
|
+
### @param (see APIObject#initialize)
|
537
|
+
###
|
538
|
+
### As well as :id and :name, computers can be queried using :udid, :serialnumber, and :mac_address
|
539
|
+
###
|
540
|
+
def initialize (args = {})
|
541
|
+
|
542
|
+
super args, [:udid, :serialnumber, :mac_address]
|
543
|
+
|
544
|
+
### now we have raw @init_data with something in it, so fill out the instance vars
|
545
|
+
@alt_mac_address = @init_data[:general][:alt_mac_address]
|
546
|
+
@asset_tag = @init_data[:general][:asset_tag]
|
547
|
+
@barcode_1 = @init_data[:general][:barcode_1]
|
548
|
+
@barcode_2 = @init_data[:general][:barcode_2]
|
549
|
+
@distribution_point = @init_data[:general][:distribution_point]
|
550
|
+
@initial_entry_date = JSS.epoch_to_time @init_data[:general][:initial_entry_date_epoch]
|
551
|
+
@ip_address = @init_data[:general][:ip_address]
|
552
|
+
@jamf_version = @init_data[:general][:jamf_version]
|
553
|
+
@last_contact_time = JSS.epoch_to_time @init_data[:general][:last_contact_time_epoch]
|
554
|
+
@mac_address = @init_data[:general][:mac_address]
|
555
|
+
@managed = @init_data[:general][:remote_management][:managed]
|
556
|
+
@management_username = @init_data[:general][:remote_management][:management_username]
|
557
|
+
@mdm_capable = @init_data[:general][:mdm_capable]
|
558
|
+
@netboot_server = @init_data[:general][:netboot_server]
|
559
|
+
@platform = @init_data[:general][:platform]
|
560
|
+
@report_date = JSS.epoch_to_time @init_data[:general][:report_date_epoch]
|
561
|
+
@serial_number = @init_data[:general][:serial_number]
|
562
|
+
@site = JSS::APIObject.get_name( @init_data[:general][:site])
|
563
|
+
@sus = @init_data[:general][:sus]
|
564
|
+
@udid = @init_data[:general][:udid]
|
565
|
+
|
566
|
+
parse_location
|
567
|
+
parse_purchasing
|
568
|
+
parse_ext_attrs
|
569
|
+
|
570
|
+
@configuration_profiles = @init_data[:configuration_profiles]
|
571
|
+
@extension_attributes = @init_data[:extension_attributes]
|
572
|
+
@groups_accounts = @init_data[:groups_accounts]
|
573
|
+
@hardware = @init_data[:hardware]
|
574
|
+
@peripherals = @init_data[:peripherals]
|
575
|
+
@software = @init_data[:software]
|
576
|
+
|
577
|
+
@management_password = nil
|
578
|
+
|
579
|
+
end # initialize
|
580
|
+
|
581
|
+
###
|
582
|
+
### @return [Array] the JSS groups to which thismachine belongs (smart and static)
|
583
|
+
###
|
584
|
+
def computer_groups
|
585
|
+
@groups_accounts[:computer_group_memberships]
|
586
|
+
end
|
587
|
+
|
588
|
+
###
|
589
|
+
### @return [Array<Hash>] all the local accts on the machine.
|
590
|
+
###
|
591
|
+
### Each item has keys :name, :realname, :uid, :home, :home_size, :administrator, :filevault_enabled
|
592
|
+
###
|
593
|
+
def local_accounts
|
594
|
+
@groups_accounts[:local_accounts]
|
595
|
+
end
|
596
|
+
|
597
|
+
|
598
|
+
###
|
599
|
+
### @return [Array<Hash>] each storage device
|
600
|
+
###
|
601
|
+
def drives
|
602
|
+
@hardware[:storage]
|
603
|
+
end
|
604
|
+
|
605
|
+
###
|
606
|
+
### @return [Array<Hash>] each printer on this computer
|
607
|
+
### Keys are :name, :uri, :type, :location
|
608
|
+
###
|
609
|
+
def printers
|
610
|
+
@hardware[:mapped_printers]
|
611
|
+
end
|
612
|
+
|
613
|
+
###
|
614
|
+
### @return [Array<Hash>] all apps installed on this machine.
|
615
|
+
### Hash keys are :name, :path, and :version
|
616
|
+
###
|
617
|
+
def apps ; @software[:applications] ; end
|
618
|
+
|
619
|
+
###
|
620
|
+
### @return [Array<String>] the JSS-defined "licensed software" titles
|
621
|
+
### installed on this machine.
|
622
|
+
###
|
623
|
+
def licensed_sw ; @software[:licensed_software] ; end
|
624
|
+
|
625
|
+
###
|
626
|
+
### Set or unset management acct and password for this computer
|
627
|
+
###
|
628
|
+
### @param name[String] the name of the management acct.
|
629
|
+
###
|
630
|
+
### @param password[String] the password of the management acct
|
631
|
+
###
|
632
|
+
### @return [void]
|
633
|
+
###
|
634
|
+
### The changes will need to be pushed to the server with #update
|
635
|
+
### before they take effect.
|
636
|
+
###
|
637
|
+
### CAUTION: this does nothing to confirm the name and password
|
638
|
+
### will work on the machine!
|
639
|
+
###
|
640
|
+
def set_management_to (name, password)
|
641
|
+
password = nil unless name
|
642
|
+
@management_username = name
|
643
|
+
@management_password = password
|
644
|
+
@managed = name ? true : false
|
645
|
+
@need_to_update = true
|
646
|
+
end
|
647
|
+
|
648
|
+
###
|
649
|
+
### Make the machine unmanaged.
|
650
|
+
###
|
651
|
+
### The same as
|
652
|
+
### #set_management_to nil, nil
|
653
|
+
### followed by
|
654
|
+
### JSS::Computer.send_mdm_command @id, :unmanage_device
|
655
|
+
### which currently isn't working
|
656
|
+
###
|
657
|
+
### @return [void]
|
658
|
+
###
|
659
|
+
def make_unmanaged
|
660
|
+
return nil unless managed?
|
661
|
+
set_management_to(nil, nil)
|
662
|
+
begin
|
663
|
+
self.class.send_mdm_command(@id, :unmanage_device)
|
664
|
+
rescue
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
###
|
669
|
+
def asset_tag= (new_val)
|
670
|
+
return nil if @asset_tag == new_val
|
671
|
+
new_val.strip!
|
672
|
+
@asset_tag = new_val
|
673
|
+
@need_to_update = true
|
674
|
+
end
|
675
|
+
|
676
|
+
###
|
677
|
+
def barcode_1= (new_val)
|
678
|
+
return nil if @barcode_1 == new_val
|
679
|
+
new_val.strip!
|
680
|
+
@barcode_1 = new_val
|
681
|
+
@need_to_update = true
|
682
|
+
end
|
683
|
+
|
684
|
+
###
|
685
|
+
def barcode_2= (new_val)
|
686
|
+
return nil if @barcode_2 == new_val
|
687
|
+
new_val.strip!
|
688
|
+
@barcode_2 = new_val
|
689
|
+
@need_to_update = true
|
690
|
+
end
|
691
|
+
|
692
|
+
###
|
693
|
+
def ip_address= (new_val)
|
694
|
+
return nil if @ip_address == new_val
|
695
|
+
new_val.strip!
|
696
|
+
### this raises an error if its an invalid IP address
|
697
|
+
IPAddr.new new_val
|
698
|
+
@ip_address = new_val
|
699
|
+
@need_to_update = true
|
700
|
+
end
|
701
|
+
|
702
|
+
###
|
703
|
+
### Send changes to the API
|
704
|
+
###
|
705
|
+
### @return [void]
|
706
|
+
###
|
707
|
+
def update
|
708
|
+
id = super
|
709
|
+
@management_password = nil
|
710
|
+
id
|
711
|
+
end
|
712
|
+
|
713
|
+
###
|
714
|
+
### Delete this computer from the JSS
|
715
|
+
###
|
716
|
+
### @return [void]
|
717
|
+
###
|
718
|
+
def delete
|
719
|
+
super
|
720
|
+
@alt_mac_address = nil
|
721
|
+
@asset_tag = nil
|
722
|
+
@barcode_1 = nil
|
723
|
+
@barcode_2 = nil
|
724
|
+
@distribution_point = nil
|
725
|
+
@initial_entry_date = nil
|
726
|
+
@ip_address = nil
|
727
|
+
@jamf_version = nil
|
728
|
+
@last_contact_time = nil
|
729
|
+
@macaddress = nil
|
730
|
+
@managed = nil
|
731
|
+
@management_username = nil
|
732
|
+
@mdm_capable = nil
|
733
|
+
@netboot_server = nil
|
734
|
+
@platform = nil
|
735
|
+
@report_date = nil
|
736
|
+
@serial_number = nil
|
737
|
+
@site = nil
|
738
|
+
@sus = nil
|
739
|
+
@udid = nil
|
740
|
+
|
741
|
+
@building = nil
|
742
|
+
@department = nil
|
743
|
+
@email_address = nil
|
744
|
+
@phone = nil
|
745
|
+
@position = nil
|
746
|
+
@real_name = nil
|
747
|
+
@room = nil
|
748
|
+
@username = nil
|
749
|
+
|
750
|
+
@configuration_profiles = nil
|
751
|
+
@extension_attributes = nil
|
752
|
+
@groups_accounts = nil
|
753
|
+
@hardware = nil
|
754
|
+
@peripherals = nil
|
755
|
+
@purchasing = nil
|
756
|
+
@software = nil
|
757
|
+
end #delete
|
758
|
+
|
759
|
+
|
760
|
+
# Not Functional until I get more docs from JAMF
|
761
|
+
#
|
762
|
+
# ###
|
763
|
+
# ### Send a blank_push MDM command
|
764
|
+
# ###
|
765
|
+
# def blank_push
|
766
|
+
# self.class.send_mdm_command @id, :blank_push
|
767
|
+
# end
|
768
|
+
# alias noop blank_push
|
769
|
+
# alias send_blank_push blank_push
|
770
|
+
#
|
771
|
+
# ###
|
772
|
+
# ### Send a device_lock MDM command
|
773
|
+
# ###
|
774
|
+
# def device_lock
|
775
|
+
# self.class.send_mdm_command @id, :device_lock
|
776
|
+
# end
|
777
|
+
# alias lock device_lock
|
778
|
+
# alias lock_device device_lock
|
779
|
+
#
|
780
|
+
# ###
|
781
|
+
# ### Send an erase_device MDM command
|
782
|
+
# ###
|
783
|
+
# def erase_device
|
784
|
+
# self.class.send_mdm_command @id, :erase_device
|
785
|
+
# end
|
786
|
+
# alias erase erase_device
|
787
|
+
# alias wipe erase_device
|
788
|
+
|
789
|
+
|
790
|
+
### aliases
|
791
|
+
alias alt_macaddress alt_mac_address
|
792
|
+
alias bar_code_1 barcode_1
|
793
|
+
alias bar_code_2 barcode_2
|
794
|
+
alias managed? managed
|
795
|
+
alias mdm? mdm_capable
|
796
|
+
alias last_recon report_date
|
797
|
+
alias sn serial_number
|
798
|
+
alias serialnumber serial_number
|
799
|
+
alias accounts local_accounts
|
800
|
+
alias accts local_accounts
|
801
|
+
alias make_managed set_management_to
|
802
|
+
|
803
|
+
|
804
|
+
|
805
|
+
|
806
|
+
|
807
|
+
##############################
|
808
|
+
### private methods
|
809
|
+
##############################
|
810
|
+
private
|
811
|
+
|
812
|
+
###
|
813
|
+
### Return a String with the XML Resource
|
814
|
+
### for submitting changes to the JSS via
|
815
|
+
### the API
|
816
|
+
###
|
817
|
+
### For Computers, only some items can be changed via the API
|
818
|
+
### In particular, any data gatherd by a Recon cannot be changed
|
819
|
+
###
|
820
|
+
def rest_xml
|
821
|
+
doc = REXML::Document.new APIConnection::XML_HEADER
|
822
|
+
computer = doc.add_element self.class::RSRC_OBJECT_KEY.to_s
|
823
|
+
|
824
|
+
general = computer.add_element('general')
|
825
|
+
general.add_element('name').text = @name
|
826
|
+
general.add_element('alt_mac_address').text = @alt_mac_address
|
827
|
+
general.add_element('asset_tag').text = @asset_tag
|
828
|
+
general.add_element('barcode_1').text = @barcode_1
|
829
|
+
general.add_element('barcode_2').text = @barcode_2
|
830
|
+
general.add_element('ip_address').text = @ip_address
|
831
|
+
general.add_element('mac_address').text = @mac_address
|
832
|
+
general.add_element('udid').text = @udid
|
833
|
+
|
834
|
+
rmgmt = general.add_element('remote_management')
|
835
|
+
rmgmt.add_element('managed').text = @managed
|
836
|
+
rmgmt.add_element('management_username').text = @management_username
|
837
|
+
rmgmt.add_element('management_password').text = @management_password if @management_password
|
838
|
+
|
839
|
+
computer << ext_attr_xml
|
840
|
+
|
841
|
+
if has_location?
|
842
|
+
computer << location_xml
|
843
|
+
end
|
844
|
+
if has_purchasing?
|
845
|
+
computer << purchasing_xml
|
846
|
+
end
|
847
|
+
|
848
|
+
return doc.to_s
|
849
|
+
end
|
850
|
+
|
851
|
+
end # class Computer
|
852
|
+
end # module
|