Class: PuavoRest::Device

Inherits:
Host show all
Defined in:
resources/devices.rb

Constant Summary

Constant Summary

Constants inherited from LdapModel

LdapModel::ESCAPES, LdapModel::ESCAPE_RE, LdapModel::KRB_LOCK, LdapModel::PROF

Instance Attribute Summary

Attributes inherited from LdapModel

#ldap_attr_store, #serialize_attrs

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Host

#boot_duration, #grub_boot_configuration, #grub_configuration, #grub_header, #grub_kernel_arguments, #grub_kernel_version, #grub_type, #instance_key, #localboot?, #netboot?, #organisation, #preferred_boot_image, #save_boot_time, specialized_instance!

Methods included from LocalStore

close_connection, included, #local_store, #local_store_del, #local_store_expire, #local_store_get, #local_store_set

Methods inherited from LdapModel

#[], #[]=, _class_store, #add, #add_validation_error, after, all, #as_json, #assert_validation, base_filter, before, by_attr, by_attr!, by_dn, by_dn!, by_dn_array, by_id, by_id!, by_ldap_attr, by_ldap_attr!, callable_from_instance, #changed?, class_store, clear_setup, computed_attr, connection, #create!, create_connection, create_filter_lambda, #dirty?, dn_bind, #empty?, escape, filter, from_ldap_hash, #get_own, #get_raw, inherited, #initialize, is_dn, is_not_found?, ldap_attrs, ldap_map, #ldap_merge!, ldap_op, #ldap_set, #link, #merge, #new?, #object_model, organisation, organisation?, pretty_attrs_to_ldap, raw_by_dn, raw_filter, sasl_bind, #save!, search, #set, settings, settings=, setup, skip_serialize, #to_hash, #to_json, #to_ldap_hash, #transform, #update!, #validate, #validate!, #validate_unique, #write_raw

Constructor Details

This class inherits a constructor from LdapModel

Class Method Details

+ (Object) by_hostname(hostname)



38
39
40
# File 'resources/devices.rb', line 38

def self.by_hostname(hostname)
  by_attr(:hostname, hostname)
end

+ (Object) by_hostname!(hostname)



42
43
44
# File 'resources/devices.rb', line 42

def self.by_hostname!(hostname)
  by_attr!(:hostname, hostname)
end

+ (Object) by_mac_address!(mac_address)

Find device by it's mac address



47
48
49
# File 'resources/devices.rb', line 47

def self.by_mac_address!(mac_address)
  by_attr!(:hostname, mac_address)
end

+ (Object) ldap_base



33
34
35
# File 'resources/devices.rb', line 33

def self.ldap_base
  "ou=Devices,ou=Hosts,#{ organisation["base"] }"
end

+ (Object) search_filters



170
171
172
173
174
175
176
177
178
# File 'resources/devices.rb', line 170

def self.search_filters
  [
    create_filter_lambda(:hostname) { |v| "*#{ v }*" },

    # Our ldap schema does not allow wildcards in the 'macAddress' field. So
    # we must match only with excact filters
    create_filter_lambda(:mac_address) { |v| v },
  ]
end

Instance Method Details

- (Object) allow_guest



109
110
111
112
113
114
115
# File 'resources/devices.rb', line 109

def allow_guest
   if get_own(:allow_guest).nil?
      school.allow_guest
    else
      get_own(:allow_guest)
    end
end

- (Object) automatic_image_updates



117
118
119
120
121
122
123
# File 'resources/devices.rb', line 117

def automatic_image_updates
   if get_own(:automatic_image_updates).nil?
      school.automatic_image_updates
    else
      get_own(:automatic_image_updates)
    end
end

- (Object) autopoweroff_attr_with_school_fallback(attr)



204
205
206
207
208
# File 'resources/devices.rb', line 204

def autopoweroff_attr_with_school_fallback(attr)
  [ nil, 'default' ].include?( get_own(:autopoweroff_mode) ) \
    ? school.send(attr)                                      \
    : get_own(attr)
end

- (Object) homepage



146
147
148
# File 'resources/devices.rb', line 146

def homepage
  school.homepage
end

- (Object) image_series_source_url



133
134
135
136
137
138
139
# File 'resources/devices.rb', line 133

def image_series_source_url
  if get_own(:image_series_source_url).nil?
    school.image_series_source_url
  else
    get_own(:image_series_source_url)
  end
end

- (Object) keyboard_layout



188
189
190
191
192
193
194
# File 'resources/devices.rb', line 188

def keyboard_layout
  if get_own(:keyboard_layout).nil?
    school.keyboard_layout
  else
    get_own(:keyboard_layout)
  end
end

- (Object) keyboard_variant



196
197
198
199
200
201
202
# File 'resources/devices.rb', line 196

def keyboard_variant
  if get_own(:keyboard_variant).nil?
    school.keyboard_variant
  else
    get_own(:keyboard_variant)
  end
end

- (Object) locale



70
71
72
# File 'resources/devices.rb', line 70

def locale
  school.locale
end

- (Object) messages



150
151
152
153
# File 'resources/devices.rb', line 150

def messages
  # TODO: merge with devices own messages
  school.messages
end

- (Object) mountpoints

Merge device's and school's mountpoints. Use device's mountpoint if it is same that at school



157
158
159
160
161
162
163
164
165
166
167
168
# File 'resources/devices.rb', line 157

def mountpoints
  device_mounts = get_own(:mountpoints).map{ |m| JSON.parse(m) }
  school_mounts = school.mountpoints
  mountpoints = device_mounts.map{ |m| m["mountpoint"] }

  school_mounts.each do |mounts|
    next if mountpoints.include?(mounts["mountpoint"])

    device_mounts.push(mounts)
  end
  device_mounts
end

- (Object) personal_device



125
126
127
128
129
130
131
# File 'resources/devices.rb', line 125

def personal_device
   if get_own(:personal_device).nil?
     school.personal_device
   else
     get_own(:personal_device)
   end
end

- (Object) preferred_image



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'resources/devices.rb', line 91

def preferred_image
   image = get_own(:preferred_image)

   # Always fallback to school's preferred image
   image ||= school.get_own(:preferred_image)

   # Bootserver's preferred image is used only for netboot devices
   # so that localboot devices get always consistent settings
   if !image and netboot?
     image = BootServer.current_image
   end

   # Organisation fallback
   image ||= school.organisation.preferred_image

   image.strip if image
end

- (Object) preferred_language



65
66
67
# File 'resources/devices.rb', line 65

def preferred_language
  school.preferred_language
end

- (Object) primary_user



75
76
77
78
79
80
81
82
83
# File 'resources/devices.rb', line 75

def primary_user
  if user_dn = get_own(:primary_user_dn)
    begin
      return User.by_dn!(user_dn, ["username"]).username
    rescue NotFound
      return ""
    end
  end
end

- (Object) primary_user=(username)



85
86
87
88
89
# File 'resources/devices.rb', line 85

def primary_user=(username)
  user = User.by_username!(username, ["username"])
  self.primary_user_dn = user.dn
  username
end

- (Object) printer_ppd



51
52
53
# File 'resources/devices.rb', line 51

def printer_ppd
  Array(self.class.raw_by_dn(dn, ["puavoPrinterPPD"])["puavoPrinterPPD"]).first
end

- (Object) printer_queues



60
61
62
# File 'resources/devices.rb', line 60

def printer_queues
  @printer_queues ||= PrinterQueue.by_dn_array(printer_queue_dns)
end

- (Object) school

Cached school query



56
57
58
# File 'resources/devices.rb', line 56

def school
  @school ||= School.by_dn(school_dn)
end

- (Object) tags



141
142
143
# File 'resources/devices.rb', line 141

def tags
  school.tags.concat(get_own(:tags)).uniq.sort
end

- (Object) timezone



180
181
182
183
184
185
186
# File 'resources/devices.rb', line 180

def timezone
  if get_own(:timezone).nil?
    school.timezone
  else
    get_own(:timezone)
  end
end