Class: PuppetX::Pulp::RepoProvider

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet/util/repo_provider.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource = {}) ⇒ RepoProvider

Implementers must:

# Set the repo type (iso, puppet, rpm) def self.repo_type

'x'

end

def self.get_resource_properties(repo_id)

# Get a hash of the current repo

end

def params_hash

# Convert resource to a hash of params

end



24
25
26
27
# File 'lib/puppet/util/repo_provider.rb', line 24

def initialize(resource={})
  super(resource)
  @property_flush = {}
end

Class Method Details

.instancesObject



29
30
31
32
# File 'lib/puppet/util/repo_provider.rb', line 29

def self.instances
  @pulp = Puppet::Util::PulpUtil.new
  @pulp.get_repos("#{repo_type}-repo").map { |repo| new(get_resource_properties(repo['id'])) }
end

.prefetch(resources) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/puppet/util/repo_provider.rb', line 46

def self.prefetch(resources)
  repos = instances
  return if repos.nil?
  resources.each do |name, resource|
    provider = repos.find { |repo| repo.name == name }
    resource.provider = provider if provider
  end
end

Instance Method Details

#createObject



38
39
40
# File 'lib/puppet/util/repo_provider.rb', line 38

def create
  @property_flush[:ensure] = :present
end

#destroyObject



42
43
44
# File 'lib/puppet/util/repo_provider.rb', line 42

def destroy
  @property_flush[:ensure] = :absent
end

#exists?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/puppet/util/repo_provider.rb', line 34

def exists?
  @property_hash[:ensure] == :present
end

#flushObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puppet/util/repo_provider.rb', line 71

def flush
  if @property_flush[:ensure] == :absent
    action = 'delete'
    params = []
  elsif @property_flush[:ensure] == :present
    action = 'create'
    params = hash_to_params(params_hash)
  else
    action = 'update'
    params = hash_to_params(params_hash)
  end

  arr = [self.class.repo_type, 'repo', action, '--repo-id', resource[:name], params]
  pulp_admin(arr.flatten)

  # Collect the resources again once they've been changed (that way `puppet
  # resource` will show the correct values after changes have been made).
  @property_hash = self.class.get_resource_properties(resource[:name])
end

#hash_to_params(params_hash) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puppet/util/repo_provider.rb', line 55

def hash_to_params(params_hash)
  params = []
  params_hash.each do |k, v|
    if v.kind_of?(Array)
      params << [k, v.join(',')]
    elsif v.kind_of?(Hash)
      v.to_a.each do |pair|
        params << [k, pair.join('=')]
      end
    elsif !v.nil?
      params << [k, v]
    end
  end
  params
end