Class: Vanagon::Platform

Inherits:
Object
  • Object
show all
Includes:
HashableAttributes, Utilities
Defined in:
lib/vanagon/extensions/hashable.rb,
lib/vanagon/platform.rb,
lib/vanagon/platform/deb.rb,
lib/vanagon/platform/dsl.rb,
lib/vanagon/platform/osx.rb,
lib/vanagon/platform/rpm.rb,
lib/vanagon/platform/rpm/aix.rb,
lib/vanagon/platform/rpm/eos.rb,
lib/vanagon/platform/rpm/wrl.rb,
lib/vanagon/platform/windows.rb,
lib/vanagon/platform/rpm/sles.rb,
lib/vanagon/platform/solaris_10.rb,
lib/vanagon/platform/solaris_11.rb

Overview

Vanagon classes generally don’t implement JSON or Hash functionality so those need to be monkey-patched for useful inspection.

Direct Known Subclasses

DEB, OSX, RPM, Solaris10, Solaris11, Windows

Defined Under Namespace

Classes: DEB, DSL, OSX, RPM, Solaris10, Solaris11, Windows

Constant Summary collapse

PLATFORM_REGEX =

Platform names currently contain some information about the platform. Fields within the name are delimited by the ‘-’ character, and this regex can be used to extract those fields.

/^(.*)-(.*)-(.*)$/.freeze
VERSION_REGEX =
/^([=<>]+)\s*([^<>=]*)$/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashableAttributes

#to_hash, #to_json

Methods included from Utilities

#erb_file, #erb_string, #ex, #find_program_on_path, #get_md5sum, #get_sum, #http_request, #http_request_code, #http_request_generic, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command

Constructor Details

#initialize(name) ⇒ Vanagon::Platform

Platform constructor. Takes just the name. Also sets the @name, @os_name, @os_version and @architecture instance attributes as a side effect

Parameters:

  • name (String)

    name of the platform



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/vanagon/platform.rb', line 223

def initialize(name) # rubocop:disable Metrics/AbcSize
  @name = name
  @settings = {}
  @os_name = os_name
  @os_version = os_version
  @architecture = architecture
  @ssh_port = 22
  # Environments are like Hashes but with specific constraints
  # around their keys and values.
  @environment = Vanagon::Environment.new
  @provisioning = []
  @install ||= "install"
  @mktemp ||= "mktemp -d -p /var/tmp"
  @target_user ||= "root"
  @find ||= "find"
  @sed ||= "sed"
  @sort ||= "sort"
  @copy ||= "cp"
  @shasum ||= "sha1sum"

  @use_docker_exec = false

  # Our first attempt at defining metadata about a platform
  @cross_compiled ||= false
  @valid_operators ||= ['<', '>', '<=', '>=', '=']
end

Instance Attribute Details

#abs_resource_nameObject

Always-Be-Scheduling engine specific



111
112
113
# File 'lib/vanagon/platform.rb', line 111

def abs_resource_name
  @abs_resource_name
end

#architectureString

Sets and gets the architecture of the platform. Also has the side effect of setting the @architecture instance attribute

Returns:

  • (String)

    the architecture of the platform



311
312
313
# File 'lib/vanagon/platform.rb', line 311

def architecture
  @architecture
end

#aws_amiObject

AWS engine specific



122
123
124
# File 'lib/vanagon/platform.rb', line 122

def aws_ami
  @aws_ami
end

#aws_instance_typeObject

Returns the value of attribute aws_instance_type.



128
129
130
# File 'lib/vanagon/platform.rb', line 128

def aws_instance_type
  @aws_instance_type
end

#aws_keyObject

Returns the value of attribute aws_key.



127
128
129
# File 'lib/vanagon/platform.rb', line 127

def aws_key
  @aws_key
end

#aws_key_nameObject

Returns the value of attribute aws_key_name.



125
126
127
# File 'lib/vanagon/platform.rb', line 125

def aws_key_name
  @aws_key_name
end

#aws_regionObject

Returns the value of attribute aws_region.



126
127
128
# File 'lib/vanagon/platform.rb', line 126

def aws_region
  @aws_region
end

#aws_shutdown_behaviorObject

Returns the value of attribute aws_shutdown_behavior.



124
125
126
# File 'lib/vanagon/platform.rb', line 124

def aws_shutdown_behavior
  @aws_shutdown_behavior
end

#aws_subnet_idObject

Returns the value of attribute aws_subnet_id.



130
131
132
# File 'lib/vanagon/platform.rb', line 130

def aws_subnet_id
  @aws_subnet_id
end

#aws_user_dataObject

Returns the value of attribute aws_user_data.



123
124
125
# File 'lib/vanagon/platform.rb', line 123

def aws_user_data
  @aws_user_data
end

#aws_vpc_idObject

Returns the value of attribute aws_vpc_id.



129
130
131
# File 'lib/vanagon/platform.rb', line 129

def aws_vpc_id
  @aws_vpc_id
end

#build_dependenciesObject

Stores an Array of OpenStructs, each representing a complete command to be run to install external the needed toolchains and build dependencies for a given target platform.



72
73
74
# File 'lib/vanagon/platform.rb', line 72

def build_dependencies
  @build_dependencies
end

#build_hostsObject

Hardware engine specific



108
109
110
# File 'lib/vanagon/platform.rb', line 108

def build_hosts
  @build_hosts
end

#cflagsObject

Hold a string containing the values that a given platform should use when a Makefile is run - resolves to the CFLAGS and LDFLAGS variables. This should be changed to take advantage of the Environment, so that we can better leverage Make’s Implicit Variables.

It should also be extended to support CXXFLAGS and CPPFLAGS ASAP.



62
63
64
# File 'lib/vanagon/platform.rb', line 62

def cflags
  @cflags
end

#codenameObject

this is Debian/Ubuntu specific



24
25
26
# File 'lib/vanagon/platform.rb', line 24

def codename
  @codename
end

#copyObject

Each of these holds the path or name of the command in question, e.g. ‘copy = “/usr/local/bin/gcp”`, or `copy = “cp”`



43
44
45
# File 'lib/vanagon/platform.rb', line 43

def copy
  @copy
end

#cross_compiledObject

Determines if a platform should be treated as cross-compiled or natively compiled.



90
91
92
# File 'lib/vanagon/platform.rb', line 90

def cross_compiled
  @cross_compiled
end

#defaultdirObject

Where does a given platform’s init system expect to find something resembling ‘defaults’ files. Most likely to apply to Linux systems that use SysV-ish, upstart, or systemd init systems.



39
40
41
# File 'lib/vanagon/platform.rb', line 39

def defaultdir
  @defaultdir
end

#distString

Get the value of @dist, or derive it from the value of @os_name and @os_version. This is relatively RPM specific but ‘#codename’ is defined in Platform, and that’s just as Deb/Ubuntu specific. All of the accessors in the top-level Platform namespace should be refactored, but #dist will live here for now.

Returns:

  • (String)

    the %dist name that RPM will use to build new RPMs



287
288
289
# File 'lib/vanagon/platform.rb', line 287

def dist
  @dist ||= @os_name.tr('-', '_') + @os_version
end

#docker_imageObject

Docker engine specific



117
118
119
# File 'lib/vanagon/platform.rb', line 117

def docker_image
  @docker_image
end

#docker_run_argsObject

Returns the value of attribute docker_run_args.



118
119
120
# File 'lib/vanagon/platform.rb', line 118

def docker_run_args
  @docker_run_args
end

#environmentObject

The overall Environment that a given platform should pass to each component



67
68
69
# File 'lib/vanagon/platform.rb', line 67

def environment
  @environment
end

#findObject

Returns the value of attribute find.



44
45
46
# File 'lib/vanagon/platform.rb', line 44

def find
  @find
end

#installObject

Returns the value of attribute install.



45
46
47
# File 'lib/vanagon/platform.rb', line 45

def install
  @install
end

#ldflagsObject

Returns the value of attribute ldflags.



63
64
65
# File 'lib/vanagon/platform.rb', line 63

def ldflags
  @ldflags
end

#makeObject

Returns the value of attribute make.



46
47
48
# File 'lib/vanagon/platform.rb', line 46

def make
  @make
end

#mktempObject

Returns the value of attribute mktemp.



47
48
49
# File 'lib/vanagon/platform.rb', line 47

def mktemp
  @mktemp
end

#nameObject

Basic generic information related to a given instance of Platform. e.g. The name we call it, the platform triplet (name-version-arch), etc.



19
20
21
# File 'lib/vanagon/platform.rb', line 19

def name
  @name
end

#num_coresObject

A string, containing the script that will be executed on the remote build target to determine how many CPU cores are available on that platform. Vanagon will use that count to determine how many build threads should be initialized for compilations.



102
103
104
# File 'lib/vanagon/platform.rb', line 102

def num_cores
  @num_cores
end

#os_nameString

Sets and gets the name of the operating system for the platform. Also has the side effect of setting the @os_name instance attribute

Returns:

  • (String)

    the operating system name as specified in the platform



295
296
297
# File 'lib/vanagon/platform.rb', line 295

def os_name
  @os_name
end

#os_versionString

Sets and gets the version of the operating system for the platform. Also has the side effect of setting the @os_version instance attribute

Returns:

  • (String)

    the operating system version as specified in the platform



303
304
305
# File 'lib/vanagon/platform.rb', line 303

def os_version
  @os_version
end

#output_dir(target_repo = "") ⇒ String

Get the output dir for packages. If the output_dir was defined already (by the platform config) then don’t change it.

Parameters:

  • target_repo (String) (defaults to: "")

    optional repo target for built packages defined at the project level

Returns:

  • (String)

    relative path to where packages should be output to



75
76
77
# File 'lib/vanagon/platform.rb', line 75

def output_dir
  @output_dir
end

#package_typeObject

The name of the sort of package type that a given platform expects, e.g. msi, rpm,



29
30
31
# File 'lib/vanagon/platform.rb', line 29

def package_type
  @package_type
end

#patchObject

Returns the value of attribute patch.



48
49
50
# File 'lib/vanagon/platform.rb', line 48

def patch
  @patch
end

#platform_tripleObject

Returns the value of attribute platform_triple.



20
21
22
# File 'lib/vanagon/platform.rb', line 20

def platform_triple
  @platform_triple
end

#provisioningObject

Stores an Array of Strings, which will be passed in as a shell script as part of the provisioning step for a given build target



86
87
88
# File 'lib/vanagon/platform.rb', line 86

def provisioning
  @provisioning
end

#rpmbuildObject

This is RedHat/EL/Fedora/SLES specific



49
50
51
# File 'lib/vanagon/platform.rb', line 49

def rpmbuild
  @rpmbuild
end

#sedObject

Returns the value of attribute sed.



50
51
52
# File 'lib/vanagon/platform.rb', line 50

def sed
  @sed
end

#servicedirObject

Where does a given platform expect to find init scripts/service files? e.g. /etc/init.d, /usr/lib/systemd/system



35
36
37
# File 'lib/vanagon/platform.rb', line 35

def servicedir
  @servicedir
end

#servicetypeObject

The name of the sort of init system that a given platform uses



32
33
34
# File 'lib/vanagon/platform.rb', line 32

def servicetype
  @servicetype
end

#settingsObject

Freeform Hash of leftover settings



133
134
135
# File 'lib/vanagon/platform.rb', line 133

def settings
  @settings
end

#shasumObject

Returns the value of attribute shasum.



53
54
55
# File 'lib/vanagon/platform.rb', line 53

def shasum
  @shasum
end

#shellObject

rubocop:disable Lint/DuplicateMethods



95
96
97
# File 'lib/vanagon/platform.rb', line 95

def shell
  @shell
end

#sortObject

Returns the value of attribute sort.



51
52
53
# File 'lib/vanagon/platform.rb', line 51

def sort
  @sort
end

#source_output_dir(target_repo = "") ⇒ String

Get the source dir for packages. Don’t change it if it was already defined by the platform config. Defaults to output_dir unless specified otherwise (RPM specifies this)

defined at the project level

Parameters:

  • target_repo (String) (defaults to: "")

    optional repo target for built source packages

Returns:

  • (String)

    relative path to where source packages should be output to



78
79
80
# File 'lib/vanagon/platform.rb', line 78

def source_output_dir
  @source_output_dir
end

#ssh_portObject

Generic engine



105
106
107
# File 'lib/vanagon/platform.rb', line 105

def ssh_port
  @ssh_port
end

#tarObject

Returns the value of attribute tar.



52
53
54
# File 'lib/vanagon/platform.rb', line 52

def tar
  @tar
end

#target_userObject

Username to use when connecting to a build target



81
82
83
# File 'lib/vanagon/platform.rb', line 81

def target_user
  @target_user
end

#use_docker_execObject

Returns the value of attribute use_docker_exec.



119
120
121
# File 'lib/vanagon/platform.rb', line 119

def use_docker_exec
  @use_docker_exec
end

#valid_operatorsObject

Returns the value of attribute valid_operators.



135
136
137
# File 'lib/vanagon/platform.rb', line 135

def valid_operators
  @valid_operators
end

#vmpooler_templateObject

VMpooler engine specific



114
115
116
# File 'lib/vanagon/platform.rb', line 114

def vmpooler_template
  @vmpooler_template
end

Class Method Details

.load_platform(name, configdir) ⇒ Vanagon::Platform

Loads a given platform from the configdir

Parameters:

  • name (String)

    the name of the platform

  • configdir (String)

    the path to the platform config file

Returns:

Raises:

  • if the instance_eval on Platform fails, the exception is reraised



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/vanagon/platform.rb', line 150

def self.load_platform(name, configdir)
  platfile = File.join(configdir, "#{name}.rb")
  dsl = Vanagon::Platform::DSL.new(name)
  dsl.instance_eval(File.read(platfile), platfile, 1)
  dsl._platform
rescue StandardError => e
  VanagonLogger.error "Error loading platform '#{name}' using '#{platfile}':"
  VanagonLogger.error(e)
  VanagonLogger.error e.backtrace.join("\n")
  raise e
end

Instance Method Details

#[](key) ⇒ Object

This allows instance variables to be accessed using the hash lookup syntax



255
256
257
258
259
# File 'lib/vanagon/platform.rb', line 255

def [](key)
  if instance_variable_get("@#{key}")
    instance_variable_get("@#{key}")
  end
end

#add_build_repository(*args) ⇒ Object

Generic adder for build repositories

Parameters:

  • *args (Array<String>)

    List of arguments to pass on to the platform specific method

Raises:

  • (Vanagon::Error)

    an arror is raised if the current platform does not define add_repository



475
476
477
478
479
480
481
# File 'lib/vanagon/platform.rb', line 475

def add_build_repository(*args)
  if self.respond_to?(:add_repository)
    self.provision_with self.send(:add_repository, *args)
  else
    raise Vanagon::Error, "Adding a build repository not defined for #{name}"
  end
end

#add_group(user) ⇒ String

Generate the scripts required to add a group to the package generated. This will also update the group if it has changed.

Parameters:

Returns:

  • (String)

    the commands required to add a group to the system



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/vanagon/platform.rb', line 167

def add_group(user)
  cmd_args = ["'#{user.group}'"]
  cmd_args.unshift '--system' if user.is_system

  groupadd_args = cmd_args.join "\s"
  groupmod_args = (cmd_args - ["--system"]).join "\s"

  return <<-HERE.undent
    if getent group '#{user.group}' > /dev/null 2>&1; then
      /usr/sbin/groupmod #{groupmod_args}
    else
      /usr/sbin/groupadd #{groupadd_args}
    fi
  HERE
end

#add_user(user) ⇒ String

Generate the scripts required to add a user to the package generated. This will also update the user if it has changed.

Parameters:

Returns:

  • (String)

    the commands required to add a user to the system



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/vanagon/platform.rb', line 188

def add_user(user) # rubocop:disable Metrics/AbcSize
  cmd_args = ["'#{user.name}'"]
  cmd_args.unshift "--home '#{user.homedir}'" if user.homedir
  if user.shell
    cmd_args.unshift "--shell '#{user.shell}'"
  elsif user.is_system
    cmd_args.unshift "--shell '/usr/sbin/nologin'"
  end
  cmd_args.unshift "--gid '#{user.group}'" if user.group
  cmd_args.unshift '--system' if user.is_system

  # Collapse the cmd_args array into a string that can be used
  # as an argument to `useradd`
  useradd_args = cmd_args.join "\s"

  # Collapse the cmd_args array into a string that can be used
  # as an argument to `usermod`; If this is a system account,
  # then specify it as such for user addition only (strip
  # --system from usermod_args)
  usermod_args = (cmd_args - ["--system"]).join "\s"

  return <<-HERE.undent
    if getent passwd '#{user.name}' > /dev/null 2>&1; then
      /usr/sbin/usermod #{usermod_args}
    else
      /usr/sbin/useradd #{useradd_args}
    fi
  HERE
end

#generate_compiled_archive(project) ⇒ Object

Save the generic compiled archive and relevant metadata as packaging output. This will include a json file with all of the components/versions that were built and a bill of materials when relevant. The archive will be a gzipped tarball.

Parameters:

  • project

    The Vanagon::Project to run this on

Returns:

  • array of commands to be run



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/vanagon/platform.rb', line 490

def generate_compiled_archive(project)
  name_and_version = "#{project.name}-#{project.version}"
  name_and_version_and_platform = "#{name_and_version}.#{name}"
  name_and_platform = "#{project.name}.#{name}"
  final_archive = "output/#{name_and_version_and_platform}.tar.gz"
  archive_directory = "#{project.name}-archive"

  # previously, we weren't properly handling the case of custom BOM paths.
  # If we have a custom BOM path, during Makefile execution, the top-level
  # BOM is moved to the custom path. So, when cleaning up BOMs for non-custom
  # paths we just want to remove the BOM at the top level of the tarball.
  # But, if we have a custom BOM path we want to move it back to where it
  # was prior to the Makefile execution so we can preserve it as an artifact
  # but not leave it to conflict if it's installed in the same custom path
  # as a project using this archive.
  bill_of_materials_command = 'rm -f bill-of-materials'
  if project.bill_of_materials
    bill_of_materials_command = "mv .#{project.bill_of_materials.path}/bill-of-materials ../.."
  end

  [
    "mkdir output",
    "mkdir #{archive_directory}",
    "gunzip -c #{name_and_version}.tar.gz | '#{tar}' -C #{archive_directory} -xf -",
    "rm #{name_and_version}.tar.gz",
    "cd #{archive_directory}/#{name_and_version}; #{bill_of_materials_command}; #{tar} cf ../../#{name_and_version_and_platform}.tar *",
    "gzip -9c #{name_and_version_and_platform}.tar > #{name_and_version_and_platform}.tar.gz",
    "cp build_metadata.#{name_and_platform}.json output/#{name_and_version_and_platform}.json",
    "cp bill-of-materials output/#{name_and_version_and_platform}-bill-of-materials ||:",
    "cp #{name_and_version_and_platform}.tar.gz output",
    "#{shasum} #{final_archive} > #{final_archive}.sha1"
  ]
end

#is_aix?true, false

Utility matcher to determine is the platform is an aix variety

Returns:

  • (true, false)

    true if it is an aix variety, false otherwise



373
374
375
# File 'lib/vanagon/platform.rb', line 373

def is_aix?
  return !!@name.match(/^aix-.*$/)
end

#is_cisco_wrlinux?true, false

Utility matcher to determine is the platform is a cisco-wrlinux variety

otherwise

Returns:

  • (true, false)

    true if it is a cisco-wrlinux variety, false



396
397
398
# File 'lib/vanagon/platform.rb', line 396

def is_cisco_wrlinux?
  return !!@name.match(/^cisco-wrlinux-.*$/)
end

#is_cross_compiled?true, false

Utility matcher to determine if the platform is a cross-compiled variety

Returns:

  • (true, false)

    true if it is a cross-compiled variety, false otherwise



449
450
451
# File 'lib/vanagon/platform.rb', line 449

def is_cross_compiled?
  return @cross_compiled
end

#is_cross_compiled_linux?true, false

Utility matcher to determine if the platform is a cross-compiled Linux variety. Many of the customizations needed to cross-compile for Linux are similar, so it’s useful to group them together vs. other cross-compiled OSes.

Returns:

  • (true, false)

    true if it is a cross-compiled Linux variety, false otherwise



458
459
460
# File 'lib/vanagon/platform.rb', line 458

def is_cross_compiled_linux?
  return (is_cross_compiled? && is_linux?)
end

#is_deb?true, false

Utility matcher to determine is the platform is a debian variety

Returns:

  • (true, false)

    true if it is a debian variety, false otherwise



318
319
320
# File 'lib/vanagon/platform.rb', line 318

def is_deb?
  return !!@name.match(/^(debian|ubuntu|cumulus|huaweios)-.*$/)
end

#is_debian?true, false

Utility matcher to determine is the platform is a debian variety

Returns:

  • (true, false)

    true if it is a debian variety, false otherwise



359
360
361
# File 'lib/vanagon/platform.rb', line 359

def is_debian?
  return !!@name.match(/^debian-.*$/)
end

#is_el8?Boolean

Returns:

  • (Boolean)


338
339
340
# File 'lib/vanagon/platform.rb', line 338

def is_el8?
  return !!@name.match(/^(el|redhat|redhatfips)-8.*$/)
end

#is_el?true, false

Utility matcher to determine is the platform is an enterprise linux variety

Returns:

  • (true, false)

    true if it is a enterprise linux variety, false otherwise



334
335
336
# File 'lib/vanagon/platform.rb', line 334

def is_el?
  return !!@name.match(/^(el|redhat|redhatfips)-.*$/)
end

#is_eos?true, false

Utility matcher to determine is the platform is an eos variety

Returns:

  • (true, false)

    true if it is an eos variety, false otherwise



380
381
382
# File 'lib/vanagon/platform.rb', line 380

def is_eos?
  return !!@name.match(/^eos-.*$/)
end

#is_fedora?true, false

Utility matcher to determine is the platform is a fedora variety

Returns:

  • (true, false)

    true if it is a fedora variety, false otherwise



352
353
354
# File 'lib/vanagon/platform.rb', line 352

def is_fedora?
  return !!@name.match(/^fedora-.*$/)
end

#is_huaweios?true, false

Utility matcher to determine is the platform is a HuaweiOS variety

Returns:

  • (true, false)

    true if it is a HuaweiOS variety, false otherwise



387
388
389
# File 'lib/vanagon/platform.rb', line 387

def is_huaweios?
  return !!@name.match(/^huaweios-.*$/)
end

#is_linux?true, false

Utility matcher to determine is the platform is a linux variety

Returns:

  • (true, false)

    true if it is a linux variety, false otherwise



442
443
444
# File 'lib/vanagon/platform.rb', line 442

def is_linux?
  return (!is_windows? && !is_unix?)
end

#is_macos?true, false

Utility matcher to determine if the platform is a macos or osx variety is_osx is a deprecated method that calls is_macos We still match for osx currently but this will change

Returns:

  • (true, false)

    true if it is a macos or osx variety, false otherwise



414
415
416
# File 'lib/vanagon/platform.rb', line 414

def is_macos?
  !!(@name =~ /^macos-.*$/ || @name =~ /^osx-.*$/)
end

#is_osx?true, false

Deprecated.

Please use is_macos? instead

Utility matcher to determine if the platform is an osx variety

Returns:

  • (true, false)

    true if it is an osx variety, false otherwise



404
405
406
407
# File 'lib/vanagon/platform.rb', line 404

def is_osx?
  VanagonLogger.info "is_osx? is a deprecated method, please use #is_macos? instead."
  is_macos?
end

#is_rpm?true, false

Utility matcher to determine is the platform is a redhat variety or uses rpm under the hood

under the hood, false otherwise

Returns:

  • (true, false)

    true if it is a redhat variety or uses rpm



327
328
329
# File 'lib/vanagon/platform.rb', line 327

def is_rpm?
  return !!@name.match(/^(aix|cisco-wrlinux|el|eos|fedora|sles|redhat|redhatfips)-.*$/)
end

#is_sles?true, false

Utility matcher to determine is the platform is a sles variety

Returns:

  • (true, false)

    true if it is a sles variety, false otherwise



345
346
347
# File 'lib/vanagon/platform.rb', line 345

def is_sles?
  return !!@name.match(/^sles-.*$/)
end

#is_solaris?true, false

Utility matcher to determine is the platform is a solaris variety

Returns:

  • (true, false)

    true if it is an solaris variety, false otherwise



421
422
423
# File 'lib/vanagon/platform.rb', line 421

def is_solaris?
  return !!@name.match(/^solaris-.*$/)
end

#is_ubuntu?true, false

Utility matcher to determine is the platform is a ubuntu variety

Returns:

  • (true, false)

    true if it is a ubuntu variety, false otherwise



366
367
368
# File 'lib/vanagon/platform.rb', line 366

def is_ubuntu?
  return !!@name.match(/^ubuntu-.*$/)
end

#is_unix?true, false

Utility matcher to determine is the platform is a unix variety

Returns:

  • (true, false)

    true if it is a unix variety, false otherwise



428
429
430
# File 'lib/vanagon/platform.rb', line 428

def is_unix?
  return !!@name.match(/^(solaris|aix|osx)-.*$/)
end

#is_windows?true, false

Utility matcher to determine is the platform is a windows variety

Returns:

  • (true, false)

    true if it is a windows variety, false otherwise



435
436
437
# File 'lib/vanagon/platform.rb', line 435

def is_windows?
  return !!@name.match(/^windows.*$/)
end

#package_override(project, var) ⇒ Object

Pass in a packaging override. This needs to be implemented for each individual platform so that this input ends up in the right place.

Parameters:

  • project
  • var

    the string that should be added to the build script.



467
468
469
# File 'lib/vanagon/platform.rb', line 467

def package_override(project, var)
  fail "I don't know how to set package overrides for #{name}, teach me?"
end

#provision_with(command) ⇒ Object

Set the command to turn the target machine into a builder for vanagon

Parameters:

  • command (String)

    Command to enable the target machine to build packages for the platform



527
528
529
530
# File 'lib/vanagon/platform.rb', line 527

def provision_with(command)
  provisioning << command
  provisioning.flatten!
end

#validate_operator(operator_string) ⇒ Object



553
554
555
# File 'lib/vanagon/platform.rb', line 553

def validate_operator(operator_string)
  valid_operators.include?(operator_string)
end

#version_munger(version_string, default: '=') ⇒ Object

version strings for dependencies, conflicts, replaces, etc need some munging based on platform.

Parameters:

  • version_string

    operator(<,>,=,<=,>=) and version to be munged, like ‘<1.2.3’

  • default (deprecated) (defaults to: '=')

    default operator to use if version string doesn’t contain an operator



539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/vanagon/platform.rb', line 539

def version_munger(version_string, default: '=')
  match = version_string.match(VERSION_REGEX)

  if match.nil?
    VanagonLogger.info "Passing a version without an operator is deprecated!"
    operator = default
    version = version_string
  end
  operator ||= match[1]
  version ||= match[2]
  fail "Operator '#{operator}' is invalid" unless validate_operator(operator)
  "#{operator} #{version}"
end