Class: Vmit::InstallMedia

Inherits:
Object
  • Object
show all
Defined in:
lib/vmit/install_media.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ InstallMedia

Returns a new instance of InstallMedia.



34
35
36
# File 'lib/vmit/install_media.rb', line 34

def initialize(location)
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



32
33
34
# File 'lib/vmit/install_media.rb', line 32

def location
  @location
end

Class Method Details

.alias_to_install_media(key) ⇒ InstallMedia

Returns an install media for an arbitrary string like ‘sles 11 sp2’ or ‘SLED-11_SP3’.

Returns:

  • (InstallMedia)

    an install media for an arbitrary string like ‘sles 11 sp2’ or ‘SLED-11_SP3’

Raises:

  • (ArgumentError)

    if can’t figure out an install media from the string



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/vmit/install_media.rb', line 64

def self.alias_to_install_media(key)
  case key.to_s.downcase.gsub(/[\s_\-]+/, '')
    when /^opensuse(\d+\.\d+)$/
      SUSEInstallMedia.new(
        'http://download.opensuse.org/distribution/$version/repo/oss/'
          .gsub('$version', $1))
    when /^(opensuse)?factory$/
      SUSEInstallMedia.new(
        'http://download.opensuse.org/factory/repo/oss/')
    when /^debian(.+)$/
      DebianInstallMedia.new(
        'http://cdn.debian.net/debian/dists/$version'
          .gsub('$version', $1))
    when /^ubuntu(.+)$/
      UbuntuInstallMedia.new(
        'http://archive.ubuntu.com/ubuntu/dists/$version'
          .gsub('$version', $1))
    when /^fedora(\d+)/
      FedoraInstallMedia.new(
        'http://mirrors.n-ix.net/fedora/linux/releases/$release/Fedora/$arch/os/'
          .gsub('$arch', Vmit::Utils.arch)
          .gsub('$release', $1))
    when /^sle(s|d)?(\d+)(sp(\d+))?$/
      edition = case $1
        when 's' then 'sle-server'
        when 'd' then 'sle-desktop'
        else
          Vmit.logger.warn "SLE given. Assuming server."
          'sle-server'
      end
      release = $2
      sp = $4 || '0'
      klass = if release.to_i > 9
        SUSEInstallMedia
      else
        SUSE9InstallMedia
      end
      suffix = if (release.to_i > 9)
        '/DVD1'
      else
        if (sp.to_i > 0)
          '/CD1'
        else
          ''
        end
      end
      klass.new(
        "http://schnell.suse.de/BY_PRODUCT/$edition-$release-sp$sp-$arch$topdir"
          .gsub('$edition', edition)
          .gsub('$arch', Vmit::Utils.arch)
          .gsub('$release', release)
          .gsub('$sp', sp)
          .gsub('$topdir', suffix))
    else raise ArgumentError.new("Unknown install media '#{key}'")
  end
end

.class_for_media_type(type) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/vmit/install_media.rb', line 49

def self.class_for_media_type(type)
  case type.to_s.downcase
    when /fedora|redhat|centos/ then FedoraInstallMedia
    when /suse/ then SUSEInstallMedia
    when /debian/ then DebianInstallMedia
    else
      raise "Don't know how to bootstrap media #{location}"
  end
end

.scan(key) ⇒ InstallMedia

Returns scans the install media and returns a specific type (suse, debian, etc…).

Returns:

  • (InstallMedia)

    scans the install media and returns a specific type (suse, debian, etc…)



139
140
141
142
143
144
# File 'lib/vmit/install_media.rb', line 139

def self.scan(key)
  case key
    when /^http:\/|ftp:\// then url_to_install_media(key)
    else alias_to_install_media(key)
  end
end

.url_to_install_media(url) ⇒ InstallMedia

Returns an install media for a url. it accesses the network in order to detect the url type.

Returns:

  • (InstallMedia)

    an install media for a url. it accesses the network in order to detect the url type.

Raises:

  • (ArgumentError)

    if can’t figure out an install media from the string



127
128
129
130
131
132
133
134
135
# File 'lib/vmit/install_media.rb', line 127

def self.url_to_install_media(url)
  begin
    media = Vmit::VFS.from(url)
    media.open('/content')
    return SUSEInstallMedia.new(url)
  rescue
    raise ArgumentError.new("Don't know the install media '#{url}'")
  end
end

Instance Method Details

#autoinstall(vm) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/vmit/install_media.rb', line 146

def autoinstall(vm)
  Vmit.logger.debug("Autoinstall from #{location}")
  media = Vmit::VFS.from(location)
  kernel = media.open(kernel_path)
  initrd = media.open(initrd_path)
  opts = {:kernel => kernel.path, :initrd => initrd.path}
  unattended_install.execute_autoinstall(vm, opts)
end

#to_sObject



38
39
40
# File 'lib/vmit/install_media.rb', line 38

def to_s
  "#{super.to_s}:#{location}"
end

#unattended_installObject



42
43
44
45
46
47
# File 'lib/vmit/install_media.rb', line 42

def unattended_install
  unless @unattended_install
    @unattended_install = unattended_install_class.new(location)
  end
  @unattended_install
end