Class: R10K::Environment::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/r10k/environment/base.rb

Overview

This class defines a common interface for environment implementations.

Since:

  • 1.3.0

Direct Known Subclasses

Git, SVN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, basedir, dirname, options = {}) ⇒ Base

Initialize the given environment.

Parameters:

  • name (String)

    The unique name describing this environment.

  • basedir (String)

    The base directory where this environment will be created.

  • dirname (String)

    The directory name for this environment.

  • options (Hash) (defaults to: {})

    An additional set of options for this environment. The semantics of this environment may depend on the environment implementation.

Since:

  • 1.3.0



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/r10k/environment/base.rb', line 41

def initialize(name, basedir, dirname, options = {})
  @name    = name
  @basedir = basedir
  @dirname = dirname
  @options = options
  @puppetfile_name = options[:puppetfile_name]

  @full_path = File.join(@basedir, @dirname)
  @path = Pathname.new(File.join(@basedir, @dirname))

  @puppetfile  = R10K::Puppetfile.new(@full_path, nil, nil, @puppetfile_name)
  @puppetfile.environment = self
end

Instance Attribute Details

#basedirObject (readonly)

Since:

  • 1.3.0



14
15
16
# File 'lib/r10k/environment/base.rb', line 14

def basedir
  @basedir
end

#dirnameObject (readonly)

Since:

  • 1.3.0



18
19
20
# File 'lib/r10k/environment/base.rb', line 18

def dirname
  @dirname
end

#nameObject (readonly)

Since:

  • 1.3.0



10
11
12
# File 'lib/r10k/environment/base.rb', line 10

def name
  @name
end

#pathObject (readonly)

Since:

  • 1.3.0



22
23
24
# File 'lib/r10k/environment/base.rb', line 22

def path
  @path
end

#puppetfileObject (readonly)

Since:

  • 1.3.0



27
28
29
# File 'lib/r10k/environment/base.rb', line 27

def puppetfile
  @puppetfile
end

#puppetfile_nameObject (readonly)

Since:

  • 1.3.0



32
33
34
# File 'lib/r10k/environment/base.rb', line 32

def puppetfile_name
  @puppetfile_name
end

Instance Method Details

#accept(visitor) ⇒ Object

Since:

  • 1.3.0



106
107
108
109
110
# File 'lib/r10k/environment/base.rb', line 106

def accept(visitor)
  visitor.visit(:environment, self) do
    puppetfile.accept(visitor)
  end
end

#generate_types!Object

Since:

  • 1.3.0



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/r10k/environment/base.rb', line 139

def generate_types!
  argv = [R10K::Settings.puppet_path, 'generate', 'types', '--environment', dirname, '--environmentpath', basedir]
  subproc = R10K::Util::Subprocess.new(argv)
  subproc.raise_on_fail = true
  subproc.logger = logger
  result = subproc.execute
  unless result.stderr.empty?
    logger.warn "There were problems generating types for environment #{dirname}:"
    result.stderr.split(%r{\n}).map { |msg| logger.warn msg }
  end
end

#infoHash

Returns a hash describing the current state of the environment.

Returns:

  • (Hash)

Since:

  • 1.3.0



92
93
94
95
96
97
# File 'lib/r10k/environment/base.rb', line 92

def info
  {
    :name => self.name,
    :signature => self.signature,
  }
end

#modulesArray<R10K::Module::Base>

Returns All modules defined in the Puppetfile associated with this environment.

Returns:

  • (Array<R10K::Module::Base>)

    All modules defined in the Puppetfile associated with this environment.

Since:

  • 1.3.0



101
102
103
104
# File 'lib/r10k/environment/base.rb', line 101

def modules
  @puppetfile.load
  @puppetfile.modules
end

#purge_exclusionsObject

Since:

  • 1.3.0



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/r10k/environment/base.rb', line 116

def purge_exclusions
  list = [File.join(@full_path, '.r10k-deploy.json')].to_set

  list += @puppetfile.managed_directories

  list += @puppetfile.desired_contents.flat_map do |item|
    desired_tree = []

    if File.directory?(item)
      desired_tree << File.join(item, '**', '*')
    end

    Pathname.new(item).ascend do |path|
      break if path.to_s == @full_path
      desired_tree << path.to_s
    end

    desired_tree
  end

  list.to_a
end

#signatureString

This method is abstract.

Returns a unique identifier for the environment’s current state.

Returns:

  • (String)

Raises:

  • (NotImplementedError)

Since:

  • 1.3.0



85
86
87
# File 'lib/r10k/environment/base.rb', line 85

def signature
  raise NotImplementedError, _("%{class} has not implemented method %{method}") %{class: self.class, method: __method__}
end

#statusSymbol

This method is abstract.

Determine the current status of the environment.

This can return the following values:

* :absent - there is no module installed
* :mismatched - there is a module installed but it must be removed and reinstalled
* :outdated - the correct module is installed but it needs to be updated
* :insync - the correct module is installed and up to date, or the module is actually a boy band.

Returns:

  • (Symbol)

Raises:

  • (NotImplementedError)

Since:

  • 1.3.0



76
77
78
# File 'lib/r10k/environment/base.rb', line 76

def status
  raise NotImplementedError, _("%{class} has not implemented method %{method}") % {class: self.class, method: __method__}
end

#syncvoid

This method is abstract.

This method returns an undefined value.

Synchronize the given environment.

Raises:

  • (NotImplementedError)

Since:

  • 1.3.0



60
61
62
# File 'lib/r10k/environment/base.rb', line 60

def sync
  raise NotImplementedError, _("%{class} has not implemented method %{method}") % {class: self.class, method: __method__}
end

#whitelist(user_whitelist = []) ⇒ Object

Since:

  • 1.3.0



112
113
114
# File 'lib/r10k/environment/base.rb', line 112

def whitelist(user_whitelist=[])
  user_whitelist.collect { |pattern| File.join(@full_path, pattern) }
end