Class: Puppet::Provider::Glance

Inherits:
Openstack
  • Object
show all
Extended by:
Openstack::Auth
Defined in:
lib/puppet/provider/glance.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.auth_endpointObject



89
90
91
# File 'lib/puppet/provider/glance.rb', line 89

def self.auth_endpoint
  @auth_endpoint ||= get_auth_endpoint
end

.conf_filenameObject



36
37
38
# File 'lib/puppet/provider/glance.rb', line 36

def self.conf_filename
  '/etc/glance/glance-api.conf'
end

.get_auth_endpointObject



84
85
86
87
# File 'lib/puppet/provider/glance.rb', line 84

def self.get_auth_endpoint
  g = glance_credentials
  "#{g['auth_url']}"
end

.get_glance_credentialsObject



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
# File 'lib/puppet/provider/glance.rb', line 51

def self.get_glance_credentials
  #needed keys for authentication
  auth_keys = ['auth_url', 'project_name', 'username', 'password']
  conf = glance_conf
  if conf and conf['keystone_authtoken'] and
      auth_keys.all?{|k| !conf['keystone_authtoken'][k].nil?}
    creds = Hash[ auth_keys.map \
                 { |k| [k, conf['keystone_authtoken'][k].strip] } ]

    if !conf['keystone_authtoken']['region_name'].nil?
      creds['region_name'] = conf['keystone_authtoken']['region_name'].strip
    end

    if !conf['keystone_authtoken']['project_domain_name'].nil?
      creds['project_domain_name'] = conf['keystone_authtoken']['project_domain_name'].strip
    else
      creds['project_domain_name'] = 'Default'
    end

    if !conf['keystone_authtoken']['user_domain_name'].nil?
      creds['user_domain_name'] = conf['keystone_authtoken']['user_domain_name'].strip
    else
      creds['user_domain_name'] = 'Default'
    end

    return creds
  else
    raise(Puppet::Error, "File: #{conf_filename} does not contain all " +
          "required sections.  Glance types will not work if glance is not " +
          "correctly configured.")
  end
end

.glance_confObject



40
41
42
43
44
45
# File 'lib/puppet/provider/glance.rb', line 40

def self.glance_conf
  return @glance_conf if @glance_conf
  @glance_conf = Puppet::Util::IniConfig::File.new
  @glance_conf.read(conf_filename)
  @glance_conf
end

.glance_credentialsObject



47
48
49
# File 'lib/puppet/provider/glance.rb', line 47

def self.glance_credentials
  @glance_credentials ||= get_glance_credentials
end

.glance_fileObject

To keep backward compatibility



100
101
102
# File 'lib/puppet/provider/glance.rb', line 100

def self.glance_file
  self.class.glance_conf
end

.glance_hashObject



104
105
106
# File 'lib/puppet/provider/glance.rb', line 104

def self.glance_hash
  @glance_hash ||= build_glance_hash
end

.glance_request(service, action, error, properties = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet/provider/glance.rb', line 20

def self.glance_request(service, action, error, properties=nil)
  warning('Usage of keystone_authtoken parameters is deprecated.')
  properties ||= []
  @credentials.username = glance_credentials['username']
  @credentials.password = glance_credentials['password']
  @credentials.project_name = glance_credentials['project_name']
  @credentials.auth_url = auth_endpoint
  @credentials.user_domain_name = glance_credentials['user_domain_name']
  @credentials.project_domain_name = glance_credentials['project_domain_name']
  if glance_credentials['region_name']
    @credentials.region_name = glance_credentials['region_name']
  end
  raise error unless @credentials.set?
  Puppet::Provider::Openstack.request(service, action, properties, @credentials)
end

.request(service, action, properties = nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/puppet/provider/glance.rb', line 12

def self.request(service, action, properties=nil)
  begin
    super
  rescue Puppet::Error::OpenstackAuthInputError => error
    glance_request(service, action, error, properties)
  end
end

.resetObject



93
94
95
96
97
# File 'lib/puppet/provider/glance.rb', line 93

def self.reset
  @glance_conf = nil
  @glance_credentials = nil
  @auth_endpoint = nil
end

Instance Method Details

#bool_to_sym(bool) ⇒ Object



108
109
110
# File 'lib/puppet/provider/glance.rb', line 108

def bool_to_sym(bool)
  bool == true ? :true : :false
end