Class: Vanagon::Platform::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/vanagon/platform/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(platform_name) ⇒ Vanagon::Platform::DSL

Constructor for the DSL object

Parameters:

  • name (String)

    name of the platform



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

def initialize(platform_name)
  @name = platform_name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

All purpose getter. This object, which is passed to the platform block, won’t have easy access to the attributes of the @platform, so we make a getter for each attribute.

We only magically handle get_ methods, any other methods just get the standard method_missing treatment.



73
74
75
76
77
78
79
80
81
82
# File 'lib/vanagon/platform/dsl.rb', line 73

def method_missing(method_name, *args)
  attribute_match = method_name.to_s.match(/get_(.*)/)
  if attribute_match
    attribute = attribute_match.captures.first
  else
    super
  end

  @platform.send(attribute)
end

Instance Method Details

#_platformVanagon::Platform

Accessor for the platform.

Returns:



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

def _platform
  @platform
end

#abs_resource_name(resource_name) ⇒ Object

Set the name of this platform as always-be-scheduling (ABS) expects it

Parameters:

  • name (String)

    name of the platform to request from always-be-scheduling



298
299
300
# File 'lib/vanagon/platform/dsl.rb', line 298

def abs_resource_name(resource_name)
  @platform.abs_resource_name = resource_name
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



452
453
454
# File 'lib/vanagon/platform/dsl.rb', line 452

def add_build_repository(*args)
  @platform.add_build_repository(*args)
end

#apt_repo(definition, gpg_key = nil) ⇒ Object

Deprecated.

Please use the add_build_repository DSL method instead. apt_repo will be removed in a future vanagon release.

Helper to setup a apt repository on a target system

Parameters:

  • definition (String)

    the repo setup file, must be a valid uri, fetched with curl

  • gpg_key (String) (defaults to: nil)

    optional gpg key to be fetched via curl and installed



425
426
427
428
# File 'lib/vanagon/platform/dsl.rb', line 425

def apt_repo(definition, gpg_key = nil)
  VanagonLogger.info "Please use the add_build_repository DSL method instead. apt_repo will be removed in a future vanagon release."
  self.add_build_repository(definition, gpg_key)
end

#aws_ami(ami_name) ⇒ Object

Set the ami for the platform to use

Parameters:

  • ami (String)

    the ami id used.



330
331
332
# File 'lib/vanagon/platform/dsl.rb', line 330

def aws_ami(ami_name)
  @platform.aws_ami = ami_name
end

#aws_instance_type(instance_type = 't1.micro') ⇒ Object

Set the instaince type. This defaults to t1.micro which is the free instance

Parameters:

  • instance_type (String) (defaults to: 't1.micro')

    a string to define the instaince type



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

def aws_instance_type(instance_type = 't1.micro')
  @platform.aws_instance_type = instance_type
end

#aws_key_name(key_name = 'vanagon') ⇒ Object

Set the key_name used. This should already exist on AWS.

Parameters:

  • key_name (String) (defaults to: 'vanagon')

    this defaults to the keyname vanagon. Can be set to any



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

def aws_key_name(key_name = 'vanagon')
  @platform.aws_key_name = key_name
end

#aws_region(region = 'us-east-1') ⇒ Object

Set the region, this defaults to us-east-1

Parameters:

  • region (String) (defaults to: 'us-east-1')

    a string used to setup the region



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

def aws_region(region = 'us-east-1')
  @platform.aws_region = region
end

#aws_shutdown_behavior(shutdown_behavior = 'terminate') ⇒ Object

Set the shutdown behavior for aws. This will default to terminate the instance on shutdown

Parameters:

  • shutdown_behavior (String) (defaults to: 'terminate')

    a string used to set the shutdown behavior



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

def aws_shutdown_behavior(shutdown_behavior = 'terminate')
  @platform.aws_shutdown_behavior = shutdown_behavior
end

#aws_subnet_id(subnet_id) ⇒ Object

Set the subnet_id. Use this to setup a subnet for your VPC to use.

Parameters:

  • subnet_id (String)

    a string to define the subnet_id in AWS



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

def aws_subnet_id(subnet_id)
  @platform.aws_subnet_id = subnet_id
end

#aws_user_data(userdata) ⇒ Object

Set the user data used in AWS to do setup. Like cloud-config

Parameters:

  • userdata (String)

    a string used to send to the node to do the intial setup



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

def aws_user_data(userdata)
  @platform.aws_user_data = userdata
end

#build_hosts(*args) ⇒ Object Also known as: build_host

Set the list of possible host to perform a build on (when not using pooler or CLI flags)

Parameters:

  • type (Array)

    the names of the hosts (must be resolvable)

Raises:

  • (ArgumentError)


271
272
273
274
# File 'lib/vanagon/platform/dsl.rb', line 271

def build_hosts(*args)
  raise ArgumentError, "build_hosts requires at least one host to be a build target." if args.empty?
  @platform.build_hosts = Array(args).flatten
end

#clear_provisioningObject

Clears the provisioning commands array



218
219
220
# File 'lib/vanagon/platform/dsl.rb', line 218

def clear_provisioning
  @platform.provisioning.clear
end

#codename(codename) ⇒ Object

Set any codename this platform may have (debian for example)

Parameters:

  • codename (String)

    codename for this platform (squeeze for example)



408
409
410
# File 'lib/vanagon/platform/dsl.rb', line 408

def codename(codename)
  @platform.codename = codename
end

#copy(copy_cmd) ⇒ Object

Set the path to copy for the platform

Parameters:

  • copy_cmd (String)

    Full path to the copy command for the platform



158
159
160
# File 'lib/vanagon/platform/dsl.rb', line 158

def copy(copy_cmd)
  @platform.copy = copy_cmd
end

#cross_compiled(xcc_flag) ⇒ Object

Set the cross_compiled flag for the platform

Parameters:

  • xcc (Boolean)

    True if this is a cross-compiled platform



165
166
167
# File 'lib/vanagon/platform/dsl.rb', line 165

def cross_compiled(xcc_flag)
  @platform.cross_compiled = !!xcc_flag
end

#defaultdir(dir) ⇒ Object

Set the directory where default or sysconfig files live for the platform

Parameters:

  • dir (String)

    Directory where default or sysconfig files live on the platform



245
246
247
# File 'lib/vanagon/platform/dsl.rb', line 245

def defaultdir(dir)
  @platform.defaultdir = dir
end

#dist(dist_string) ⇒ Object

define an explicit Dist for the platform (most likely used for RPM platforms)

Parameters:

  • dist_string (String)

    the value to use for .dist when building RPMs



172
173
174
# File 'lib/vanagon/platform/dsl.rb', line 172

def dist(dist_string)
  @platform.dist = dist_string
end

#docker_image(image_name) ⇒ Object

Set the name of the docker image to use

Parameters:

  • name (String)

    name of the docker image to use



305
306
307
# File 'lib/vanagon/platform/dsl.rb', line 305

def docker_image(image_name)
  @platform.docker_image = image_name
end

#docker_run_args(args) ⇒ Object

Set additional ‘docker run` arguments to pass when creating containers

Parameters:

  • args (Array<String>)

    array of CLI arguments for ‘docker run`



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

def docker_run_args(args)
  @platform.docker_run_args = Array(args)
end

#environment(key, value) ⇒ Object

Adds an arbitrary environment variable to a Platform, which will be merged with any environment variables defined by the Project into the rendered Makefile



98
99
100
# File 'lib/vanagon/platform/dsl.rb', line 98

def environment(key, value)
  @platform.environment[key] = value
end

#find(find_cmd) ⇒ Object

Set the path to find for the platform

Parameters:

  • find_cmd (String)

    Full path to the find command for the platform



137
138
139
# File 'lib/vanagon/platform/dsl.rb', line 137

def find(find_cmd)
  @platform.find = find_cmd
end

#inherit_from_default(name = @name) ⇒ Object



88
89
90
91
92
93
# File 'lib/vanagon/platform/dsl.rb', line 88

def inherit_from_default(name = @name)
  default_file = File.join(__dir__, 'defaults', "#{name}.rb")
  default_object = Vanagon::Platform::DSL.new(name)

  @platform = default_object.instance_eval(File.read(default_file), default_file, 1)
end

#install(install_cmd) ⇒ Object

Set the path to the install command

Parameters:

  • install_cmd (String)

    Full path to install with arguments to be used by default



185
186
187
# File 'lib/vanagon/platform/dsl.rb', line 185

def install(install_cmd)
  @platform.install = install_cmd
end

#install_build_dependencies_with(command, suffix = nil) ⇒ Object

Set the command to install any needed build dependencies for the target machine

Parameters:

  • command (String)

    Command to install build dependencies for the target machine

  • suffix (String) (defaults to: nil)

    shell to be run after the main command



226
227
228
# File 'lib/vanagon/platform/dsl.rb', line 226

def install_build_dependencies_with(command, suffix = nil)
  @platform.build_dependencies = OpenStruct.new({ :command => command, :suffix => suffix })
end

#make(make_cmd) ⇒ Object

Set the path to make for the platform

Parameters:

  • make_cmd (String)

    Full path to the make command for the platform



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

def make(make_cmd)
  @platform.make = make_cmd
end

#mktemp(command) ⇒ Object

Set the path and options for the mktemp command be used by default

Parameters:

  • command (String)

    Full path (if needed) for the mktemp command with arguments to



192
193
194
# File 'lib/vanagon/platform/dsl.rb', line 192

def mktemp(command)
  @platform.mktemp = command
end

#num_cores(num_cores_cmd) ⇒ Object

Sets the command to retrieve the number of cores available on a platform.

Parameters:

  • num_cores_cmd (String)

    the command to retrieve the number of available cores on a platform.



206
207
208
# File 'lib/vanagon/platform/dsl.rb', line 206

def num_cores(num_cores_cmd)
  @platform.num_cores = num_cores_cmd
end

#output_dir(directory) ⇒ Object



412
413
414
# File 'lib/vanagon/platform/dsl.rb', line 412

def output_dir(directory)
  @platform.output_dir = directory
end

#package_type(pkg_type) ⇒ Object

Set the type of package we are going to build for this platform

Parameters:

  • pkg_type (String)

    The type of package we are going to build for this platform



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

def package_type(pkg_type)
  @platform.package_type = pkg_type
end

#patch(patch_cmd) ⇒ Object

Set the path to patch for the platform

Parameters:

  • patch_cmd (String)

    Full path to the patch command for the platform



199
200
201
# File 'lib/vanagon/platform/dsl.rb', line 199

def patch(patch_cmd)
  @platform.patch = patch_cmd
end

#platform(platform_name, &block) {|_self| ... } ⇒ Object

Primary way of interacting with the DSL. Also a simple factory to get the right platform object.

Parameters:

  • name (String)

    name of the platform

  • block (Proc)

    DSL definition of the platform to call

Yields:

  • (_self)

Yield Parameters:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vanagon/platform/dsl.rb', line 31

def platform(platform_name, &block)
  @platform = case platform_name
              when /^aix-/
                Vanagon::Platform::RPM::AIX.new(@name)
              when /^(cisco-wrlinux|el|fedora|redhat|redhatfips)-/
                Vanagon::Platform::RPM.new(@name)
              when /^sles-/
                Vanagon::Platform::RPM::SLES.new(@name)
              when /^(cumulus|debian|huaweios|ubuntu)-/
                Vanagon::Platform::DEB.new(@name)
              when /^eos-/
                Vanagon::Platform::RPM::EOS.new(@name)
              when /^osx-/
                Vanagon::Platform::OSX.new(@name)
              when /^solaris-10/
                Vanagon::Platform::Solaris10.new(@name)
              when /^solaris-11/
                Vanagon::Platform::Solaris11.new(@name)
              when /^windows/
                Vanagon::Platform::Windows.new(@name)
              else
                fail "Platform not implemented for '#{@name}' yet. Please go do so..."
              end

  yield(self)
  @platform
end

#platform_triple(triple) ⇒ Object

Set the platform_triple for the platform

tools and cross-compilation

Parameters:

  • triple (String)

    platform_triple for use in building out compiled



401
402
403
# File 'lib/vanagon/platform/dsl.rb', line 401

def platform_triple(triple)
  @platform.platform_triple = triple
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



213
214
215
# File 'lib/vanagon/platform/dsl.rb', line 213

def provision_with(command)
  @platform.provision_with(command)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/vanagon/platform/dsl.rb', line 84

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.start_with?('get_') || super
end

#rpmbuild(rpmbuild_cmd) ⇒ Object

Set the path to rpmbuild for the platform

Parameters:

  • rpmbuild_cmd (String)

    Full path to rpmbuild with arguments to be used by default



179
180
181
# File 'lib/vanagon/platform/dsl.rb', line 179

def rpmbuild(rpmbuild_cmd)
  @platform.rpmbuild = rpmbuild_cmd
end

#sed(command) ⇒ Object

Set the path to sed for the platform

Parameters:

  • command (String)

    full path to the sed command for the platform



144
145
146
# File 'lib/vanagon/platform/dsl.rb', line 144

def sed(command)
  @platform.sed = command
end

#servicedir(dir) ⇒ Object

Set the directory where service files or init scripts live for the platform

Parameters:

  • dir (String)

    Directory where service files live on the platform



233
234
235
236
237
238
239
240
# File 'lib/vanagon/platform/dsl.rb', line 233

def servicedir(dir)
  @platform.servicedir = dir

  # Add to the servicetypes array if we haven't already
  if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty?
    @platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir)
  end
end

#servicetype(type, servicedir: nil) ⇒ Object

Set the servicetype for the platform so that services can be installed correctly.

Parameters:

  • type (String)

    service type for the platform (‘sysv’ for example)

  • servicedir (String) (defaults to: nil)

    service dir for this platform and service type (‘/etc/init.d’ for example). Optional.



253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/vanagon/platform/dsl.rb', line 253

def servicetype(type, servicedir: nil) # rubocop:disable Metrics/AbcSize
  if servicedir
    @platform.servicetypes << OpenStruct.new(:servicetype => type, :servicedir => servicedir)
  else
    @platform.servicetype = type
  end

  # Add to the servicetypes array if we haven't already
  if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty?
    @platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir)
  end
end

#setting(name, value) ⇒ Object



456
457
458
# File 'lib/vanagon/platform/dsl.rb', line 456

def setting(name, value)
  @platform.settings[name] = value
end

#settingsObject



460
461
462
# File 'lib/vanagon/platform/dsl.rb', line 460

def settings
  @platform.settings
end

#shasum(sha1sum_command) ⇒ Object



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

def shasum(sha1sum_command)
  @platform.shasum = sha1sum_command
end

#shell(shell_path) ⇒ Object

Set the path for Make’s SHELL for the platform

Parameters:

  • shell_path (String)

    Full path to the shell Make should use



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

def shell(shell_path)
  @platform.shell = shell_path
end

#sort(sort_cmd) ⇒ Object

Set the path to sort for the platform

Parameters:

  • sort_cmd (String)

    Full path to the sort command for the platform



151
152
153
# File 'lib/vanagon/platform/dsl.rb', line 151

def sort(sort_cmd)
  @platform.sort = sort_cmd
end

#source_output_dir(directory) ⇒ Object



416
417
418
# File 'lib/vanagon/platform/dsl.rb', line 416

def source_output_dir(directory)
  @platform.source_output_dir = directory
end

#ssh_port(port = 22) ⇒ Object

Set the port for ssh to use if it’s not 22

Parameters:

  • port (Integer) (defaults to: 22)

    port number for ssh



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

def ssh_port(port = 22)
  @platform.ssh_port = port
end

#tar(tar_cmd) ⇒ Object

Set the path to tar for the platform

Parameters:

  • tar (String)

    Full path to the tar command for the platform



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

def tar(tar_cmd)
  @platform.tar = tar_cmd
end

#target_host(target_host) ⇒ Object

Set the target ip address or hostname to start build

Parameters:

  • target_host (String)

    a host string to login with.



393
394
395
# File 'lib/vanagon/platform/dsl.rb', line 393

def target_host(target_host)
  @platform.target_host = target_host
end

#target_user(user = "root") ⇒ Object

Set the target user to login with. Defaults to root.

Parameters:

  • user (String) (defaults to: "root")

    a user string to login with.



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

def target_user(user = "root")
  @platform.target_user = user
end

#use_docker_exec(bool) ⇒ Object

Specify whether to use Docker exec instead of SSH to run commands

This also causes Vanagon to use ‘docker cp` instead of `rsync` when copying files.

Parameters:

  • bool (Boolean)

    a boolean value indicating whether to use ‘docker exec` and `docker cp` over `ssh` and `rsync`.



323
324
325
# File 'lib/vanagon/platform/dsl.rb', line 323

def use_docker_exec(bool)
  @platform.use_docker_exec = bool
end

#vcloud_name(cloud_name) ⇒ Object

Deprecated.

Please use vmpooler_template instead, this will be removed in a future vanagon release.

Set the name of this platform as the vm pooler expects it

Parameters:

  • name (String)

    name that the pooler uses for this platform



290
291
292
293
# File 'lib/vanagon/platform/dsl.rb', line 290

def vcloud_name(cloud_name)
  VanagonLogger.info "vcloud_name is a deprecated platform DSL method, and will be removed in a future vanagon release. Please use vmpooler_template instead."
  self.vmpooler_template(cloud_name)
end

#vmpooler_template(template_name) ⇒ Object

Set the name of this platform as the vm pooler expects it

Parameters:

  • name (String)

    name of the target template to use from the vmpooler



282
283
284
# File 'lib/vanagon/platform/dsl.rb', line 282

def vmpooler_template(template_name)
  @platform.vmpooler_template = template_name
end

#yum_repo(definition) ⇒ Object

Deprecated.

Please use the add_build_repository DSL method instead. yum_repo will be removed in a future vanagon release.

Helper to setup a yum repository on a target system

Parameters:

  • definition (String)

    the repo setup URI or RPM file



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

def yum_repo(definition)
  VanagonLogger.info "Please use the add_build_repository DSL method instead. yum_repo will be removed in a future vanagon release."
  self.add_build_repository(definition)
end

#zypper_repo(definition) ⇒ Object

Deprecated.

Please use the add_build_repository DSL method instead. zypper_repo will be removed in a future vanagon release.

Helper to setup a zypper repository on a target system

Parameters:

  • definition (String)

    the repo setup URI or RPM file



443
444
445
446
# File 'lib/vanagon/platform/dsl.rb', line 443

def zypper_repo(definition)
  VanagonLogger.info "Please use the add_build_repository DSL method instead. zypper_repo will be removed in a future vanagon release."
  self.add_build_repository(definition)
end