Class: Puppet::Util::PulpUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/util/pulp_util.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_path = '/etc/pulp/admin/admin.conf') ⇒ PulpUtil

Returns a new instance of PulpUtil.



10
11
12
13
14
15
16
17
18
19
# File 'lib/puppet/util/pulp_util.rb', line 10

def initialize (config_path = '/etc/pulp/admin/admin.conf')
  config               = parse_config(config_path)
  @config              = {}
  @config[:host]       = config['server']['host']                 || Facter['fqdn'].value
  @config[:port]       = config['server']['port']                 || 443
  @config[:api_prefix] = config['server']['api_prefix']           || "/pulp/api"
  @config[:verify_ssl] = config['server']['verify_ssl']           || true
  @config[:cert_dir]   = config['filesystem']['id_cert_dir']      || "~/.pulp"
  @config[:cert_file]  = config['filesystem']['id_cert_filename'] || "user-cert.pem"
end

Instance Method Details

#get_repo_info(repo_id) ⇒ Object



48
49
50
51
# File 'lib/puppet/util/pulp_util.rb', line 48

def get_repo_info(repo_id)
  raise '[get_repo_info] Repo id should never be nil.' unless repo_id and repo_id != ''
  request_api("/v2/repositories/#{repo_id}/?distributors=True&importers=True")
end

#get_repo_syncs(repo_id) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/puppet/util/pulp_util.rb', line 27

def get_repo_syncs(repo_id)
  # returns an array with 2 values: an array of sync schedules and the repo type
  raise '[get_repo_syncs] Repo id should never be nil' unless repo_id and repo_id != ''
  info = request_api("/v2/repositories/#{repo_id}/")
  return nil unless info

  # we need to see the repo type first
  case info['notes']['_repo-type']
  when 'rpm-repo'
    importer = 'yum_importer'
  when 'puppet-repo'
    importer = 'puppet_importer'
  when 'iso-repo'
    importer = 'iso_importer'
  else
    Puppet.debug "[get_repo_syncs] Unknown repo type #{info['notes']['_repo-type']} for repo #{repo_id}.\n"
    return nil
  end
  [request_api("/v2/repositories/#{repo_id}/importers/#{importer}/schedules/sync/?details=True"), info['notes']['_repo-type']]
end

#get_repos(type = nil) ⇒ Object



21
22
23
24
25
# File 'lib/puppet/util/pulp_util.rb', line 21

def get_repos(type=nil)
  repos = request_api('/v2/repositories/')
  return repos.select { |repo| repo['notes']['_repo-type'] == type } if type
  repos
end

#get_role_info(role_id) ⇒ Object



53
54
55
56
# File 'lib/puppet/util/pulp_util.rb', line 53

def get_role_info(role_id)
  raise '[get_role_info] Role id should never be nil.' unless role_id
  request_api("/v2/roles/#{role_id}/")
end

#get_role_permissions(role_id) ⇒ Object



64
65
66
67
68
# File 'lib/puppet/util/pulp_util.rb', line 64

def get_role_permissions(role_id)
  raise '[get_role_users] Role id should never be nil.' unless role_id
  r = get_role_info(role_id)
  r['permissions']
end

#get_role_users(role_id) ⇒ Object



58
59
60
61
62
# File 'lib/puppet/util/pulp_util.rb', line 58

def get_role_users(role_id)
  raise '[get_role_users] Role id should never be nil.' unless role_id
  r = get_role_info(role_id)
  r['users']
end