Class: PuavoRest::Host

Inherits:
LdapModel show all
Includes:
LocalStore
Defined in:
resources/hosts.rb

Direct Known Subclasses

Device, LtspServer, UnregisteredDevice

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 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, search_filters, #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)



39
40
41
42
# File 'resources/hosts.rb', line 39

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

+ (Object) by_mac_address!(mac_address)



34
35
36
37
# File 'resources/hosts.rb', line 34

def self.by_mac_address!(mac_address)
  host = by_attr!(:mac_address, mac_address)
  specialized_instance!(host)
end

+ (Object) ldap_base



30
31
32
# File 'resources/hosts.rb', line 30

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

+ (Object) specialized_instance!(host)



44
45
46
47
48
49
50
# File 'resources/hosts.rb', line 44

def self.specialized_instance!(host)
  if host.type == "ltspserver"
    LtspServer.by_dn!(host.dn)
  else
    Device.by_dn!(host.dn)
  end
end

Instance Method Details

- (Object) boot_duration



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

def boot_duration
  t = local_store_get("boottime")
  Time.now.to_i - t.to_i if t
end

- (Object) grub_boot_configuration



120
121
122
# File 'resources/hosts.rb', line 120

def grub_boot_configuration
  grub_header + grub_configuration
end

- (Object) grub_configuration



145
146
147
148
149
150
151
152
153
154
155
# File 'resources/hosts.rb', line 145

def grub_configuration
  return <<EOF

label ltsp-NBD
menu label LTSP, using NBD
menu default
kernel ltsp/#{preferred_boot_image}/vmlinuz#{grub_kernel_version}
append ro initrd=ltsp/#{preferred_boot_image}/initrd.img#{grub_kernel_version} init=/sbin/init-puavo puavo.hosttype=#{grub_type} root=/dev/nbd0 nbdroot=:#{preferred_boot_image} #{grub_kernel_arguments}
ipappend 2
EOF
end

- (Object) grub_header



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'resources/hosts.rb', line 124

def grub_header
  if boot_mode == "dualboot"
    header =<<EOF
default menu.c32
menu title Choose a system
prompt 0
timeout 100

label local
menu label Local OS
localboot 0
EOF
  else
    header =<<EOF
default ltsp-NBD
ontimeout ltsp-NBD

EOF
  end
end

- (Object) grub_kernel_arguments



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'resources/hosts.rb', line 103

def grub_kernel_arguments
  if ["unregistered", "laptop", "wirelessaccesspoint"].include?(grub_type)
    return ""
  end

  retval = "quiet splash"
  if get_own(:kernel_arguments)
    retval = kernel_arguments
  end

  if ["thinclient", "fatclient"].include?(grub_type)
    retval += " usbcore.autosuspend=-1"
  end

  return retval
end

- (Object) grub_kernel_version



89
90
91
92
93
94
# File 'resources/hosts.rb', line 89

def grub_kernel_version
  if kernel_version.to_s.empty?
    return ""
  end
  "-" + kernel_version.to_s
end

- (Object) grub_type



96
97
98
99
100
101
# File 'resources/hosts.rb', line 96

def grub_type
  if type.to_s.empty?
    return "unregistered"
  end
  type.to_s
end

- (Object) instance_key



52
53
54
# File 'resources/hosts.rb', line 52

def instance_key
  "host:" + hostname
end

- (Boolean) localboot?

Returns:

  • (Boolean)


26
27
28
# File 'resources/hosts.rb', line 26

def localboot?
  object_classes.include?("puavoLocalbootDevice")
end

- (Boolean) netboot?

Returns:

  • (Boolean)


22
23
24
# File 'resources/hosts.rb', line 22

def netboot?
  object_classes.include?("puavoNetbootDevice")
end

- (Object) organisation

Cached organisation query



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

def organisation
  return @organisation if @organisation
  @organisation = Organisation.by_dn(self.class.organisation["base"])
end

- (Object) preferred_boot_image



79
80
81
82
83
84
85
86
87
# File 'resources/hosts.rb', line 79

def preferred_boot_image
  # preferred_boot_image is only used for thinclients. In fatclients and ltsp
  # servers the boot image is always the same as the main image
  if type == "thinclient" && get_own(:preferred_boot_image)
    return get_own(:preferred_boot_image)
  end

  preferred_image
end

- (Object) preferred_image



75
76
77
# File 'resources/hosts.rb', line 75

def preferred_image
  raise "not implemented"
end

- (Object) save_boot_time



56
57
58
59
60
61
62
# File 'resources/hosts.rb', line 56

def save_boot_time
  local_store_set("boottime", Time.now.to_i)

  # Expire boottime log after 1h. If boot takes longer than this we can
  # assume has been failed for some reason.
  local_store_expire("boottime", 60 * 60)
end