Class: Operatingsystem

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Authorization
Defined in:
app/models/operatingsystem.rb

Direct Known Subclasses

Archlinux, Debian, Gentoo, Redhat, Solaris, Suse, Windows

Defined Under Namespace

Classes: Jail

Constant Summary collapse

FAMILIES =
{ 'Debian'  => %r{Debian|Ubuntu}i,
'Redhat'  => %r{RedHat|Centos|Fedora|Scientific|SLC}i,
'Suse'    => %r{OpenSuSE|SLES|SLED}i,
'Windows' => %r{Windows}i,
'Archlinux' => %r{Archlinux}i,
'Gentoo' => %r{Gentoo}i,
'Solaris' => %r{Solaris}i }

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authorization

#enforce_create_permissions, #enforce_destroy_permissions, #enforce_edit_permissions, #enforce_permissions, included, #permission_failed?

Class Method Details

.familiesObject


68
69
70
# File 'app/models/operatingsystem.rb', line 68

def self.families
  FAMILIES.keys.sort
end

.families_as_collectionObject


72
73
74
# File 'app/models/operatingsystem.rb', line 72

def self.families_as_collection
  families.map{|e| OpenStruct.new(:name => e, :value => e) }
end

Instance Method Details

#as_json(options = {}) ⇒ Object


136
137
138
# File 'app/models/operatingsystem.rb', line 136

def as_json(options={})
  {:operatingsystem => {:name => to_s, :id => id, :media => media, :architectures => architectures, :ptables => ptables, :config_templates => config_templates}}
end

#boot_filename(host = nil) ⇒ Object

handle things like gpxelinux/ gpxe / pxelinux here


168
169
170
# File 'app/models/operatingsystem.rb', line 168

def boot_filename host=nil
  "pxelinux.0"
end

#bootfile(arch, type) ⇒ Object


148
149
150
# File 'app/models/operatingsystem.rb', line 148

def bootfile arch, type
  pxe_prefix(arch) + "-" + eval("#{self.family}::PXEFILES[:#{type}]")
end

#familyObject

As Rails loads an object it casts it to the class in the 'type' field. If we ensure that the type and family are the same thing then rails converts the record to a Debian or a solaris object as required. Manually managing the 'type' field allows us to control the inheritance chain and the available methods


60
61
62
# File 'app/models/operatingsystem.rb', line 60

def family
  read_attribute(:type)
end

#family=(value) ⇒ Object


64
65
66
# File 'app/models/operatingsystem.rb', line 64

def family=(value)
  self.type = value
end

#fullnameObject


121
122
123
# File 'app/models/operatingsystem.rb', line 121

def fullname
  to_label
end

#image_extensionObject


177
178
179
# File 'app/models/operatingsystem.rb', line 177

def image_extension
  raise ::Foreman::Exception.new(N_("Attempting to construct an operating system image filename but %s cannot be built from an image"), family)
end

#initrd(arch) ⇒ Object


144
145
146
# File 'app/models/operatingsystem.rb', line 144

def initrd arch
  bootfile(arch,:initrd)
end

#interpolate_medium_vars(path, arch, os) ⇒ Object


98
99
100
101
102
103
104
105
106
# File 'app/models/operatingsystem.rb', line 98

def interpolate_medium_vars path, arch, os
  return "" if path.empty?

  path.gsub('$arch',  arch).
       gsub('$major',  os.major).
       gsub('$minor',  os.minor).
       gsub('$version', [os.major, os.minor ].compact.join('.')).
       gsub('$release', os.release_name ? os.release_name : "" )
end

#kernel(arch) ⇒ Object


140
141
142
# File 'app/models/operatingsystem.rb', line 140

def kernel arch
  bootfile(arch,:kernel)
end

#medium_uri(host, url = nil) ⇒ Object


89
90
91
92
# File 'app/models/operatingsystem.rb', line 89

def medium_uri host, url = nil
  url ||= host.medium.path
  medium_vars_to_uri(url, host.architecture.name, host.os)
end

#medium_vars_to_uri(url, arch, os) ⇒ Object


94
95
96
# File 'app/models/operatingsystem.rb', line 94

def medium_vars_to_uri (url, arch, os)
  URI.parse(interpolate_medium_vars(url, arch, os)).normalize
end

#pxe_files(medium, arch) ⇒ Object


130
131
132
133
134
# File 'app/models/operatingsystem.rb', line 130

def pxe_files(medium, arch)
  boot_files_uri(medium, arch).collect do |img|
    { pxe_prefix(arch).to_sym => img.to_s}
  end
end

#pxe_prefix(arch) ⇒ Object

sets the prefix for the tfp files based on the os / arch combination


126
127
128
# File 'app/models/operatingsystem.rb', line 126

def pxe_prefix(arch)
  "boot/#{to_s}-#{arch}".gsub(" ","-")
end

#pxe_variantObject

override in sub operatingsystem classes as required.


158
159
160
# File 'app/models/operatingsystem.rb', line 158

def pxe_variant
  "syslinux"
end

#releaseObject


113
114
115
# File 'app/models/operatingsystem.rb', line 113

def release
  "#{major}#{('.' + minor) unless minor.empty?}"
end

#repos(host) ⇒ Object

Operating system family can override this method to provide an array of hashes, each describing a repository. For example, to describe a yum repo, the following structure can be returned by the method: [{ :baseurl => “dl.thesource.com/get/it/here”,

  :name => "awesome",
  :description => "awesome product repo"",
  :enabled => 1,
  :gpgcheck => 1
}]

85
86
87
# File 'app/models/operatingsystem.rb', line 85

def repos host
  []
end

#require_nfs_access_to_mediumObject

If this OS family requires access to its media via NFS


182
183
184
# File 'app/models/operatingsystem.rb', line 182

def require_nfs_access_to_medium
  false
end

#supports_imageObject

Does this OS family support a build variant that is constructed from a prebuilt archive


153
154
155
# File 'app/models/operatingsystem.rb', line 153

def supports_image
  false
end

#template_kindObject

The kind of PXE configuration template used. PXELinux and PXEGrub are currently supported


163
164
165
# File 'app/models/operatingsystem.rb', line 163

def template_kind
  "PXELinux"
end

#to_labelObject

The OS is usually represented as the concatenation of the OS and the revision


109
110
111
# File 'app/models/operatingsystem.rb', line 109

def to_label
  "#{name} #{release}"
end

#to_sObject


117
118
119
# File 'app/models/operatingsystem.rb', line 117

def to_s
  to_label
end

#use_release_name?Boolean

Does this OS family use release_name in its naming scheme

Returns:

  • (Boolean)

173
174
175
# File 'app/models/operatingsystem.rb', line 173

def use_release_name?
  false
end