File: loopback.pp

package info (click to toggle)
puppet-module-swift 25.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,400 kB
  • sloc: ruby: 9,593; python: 38; sh: 10; makefile: 10
file content (82 lines) | stat: -rw-r--r-- 2,637 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# follow the instructions for creating a loopback device
# for storage from: https://docs.openstack.org/swift/latest/development_saio.html
#
#
# creates a managed loopback interface
#   - creates a file
#   - formats the file to be an xfs device and mounts it as a loopback device at /srv/node/$name
#   - sets up each mount point as a swift endpoint
# === Parameters:
#
# [*base_dir*]
#   (optional) The directory where the flat files will be stored that house
#   the file system to be loop back mounted.
#   Defaults to '/dev', assumes local disk devices
#
# [*mnt_base_dir*]
#   (optional) The directory where the flat files that store the file system
#   to be loop back mounted are actually mounted at.
#   Defaults to '/srv/node', base directory where disks are mounted to
#
# [*byte_size*]
#   (optional) The byte size that dd uses when it creates the file system.
#   Defaults to '1024', block size for the disk.  For very large partitions, this should be larger
#
# [*seek*]
#   (optional) The size of the file system that will be created.
#    Defaults to 25000.
#
# [*fstype*]
#   (optional) The filesystem type.
#   Defaults to 'xfs'.
#
define swift::storage::loopback(
  $base_dir     = '/srv/loopback-device',
  $mnt_base_dir = '/srv/node',
  $byte_size    = '1024',
  $seek         = '25000',
  $fstype       = 'xfs'
) {

  include swift::deps
  include swift::params

  if(!defined(File[$base_dir])) {
    file { $base_dir:
      ensure  => directory,
      require => Anchor['swift::config::begin'],
      before  => Anchor['swift::config::end'],
    }
  }

  if(!defined(File[$mnt_base_dir])) {
    file { $mnt_base_dir:
      ensure  => directory,
      owner   => 'root',
      group   => 'root',
      require => Anchor['swift::config::begin'],
      before  => Anchor['swift::config::end'],
    }
  }

  exec { "create_partition-${name}":
    command => "dd if=/dev/zero of=${base_dir}/${name} bs=${byte_size} count=0 seek=${seek}",
    path    => ['/usr/bin/', '/bin'],
    creates => "${base_dir}/${name}",
    before  => Anchor['swift::config::end'],
  }

  File<| title == $base_dir |> ~> Exec<| title == "create_partition-${name}" |>

  $storage_params = {
    device       => "${base_dir}/${name}",
    mnt_base_dir => $mnt_base_dir,
    byte_size    => $byte_size,
    subscribe    => Exec["create_partition-${name}"],
    loopback     => true,
  }
  # NOTE(mgagne) Puppet does not allow hash keys to be bare variables.
  #              Keep double-quotes to avoid parse errors.
  $device_config_hash = { "${name}" => $storage_params }
  create_resources("swift::storage::${fstype}", $device_config_hash)
}