Class: Puppet::Provider::Gnocchi
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::Gnocchi
- Defined in:
- lib/puppet/provider/gnocchi.rb
Class Method Summary collapse
- .auth_gnocchi(*args) ⇒ Object
- .conf_filename ⇒ Object
- .get_gnocchi_credentials ⇒ Object
- .get_gnocchi_resource_attrs(type, id) ⇒ Object
- .gnocchi_conf ⇒ Object
- .gnocchi_credentials ⇒ Object
- .list_gnocchi_resources(type, *args) ⇒ Object
- .reset ⇒ Object
- .withenv(hash, &block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.auth_gnocchi(*args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/puppet/provider/gnocchi.rb', line 64 def self.auth_gnocchi(*args) q = gnocchi_credentials authenv = { :OS_AUTH_URL => q['auth_url'], :OS_USERNAME => q['username'], :OS_TENANT_NAME => q['project_name'], :OS_PASSWORD => q['password'], :OS_PROJECT_DOMAIN_NAME => q['project_domain_name'], :OS_USER_DOMAIN_NAME => q['user_domain_name'], } begin withenv authenv do gnocchi(args) end rescue Exception => e if (e. =~ /\[Errno 111\] Connection refused/) or (e. =~ /\(HTTP 400\)/) sleep 10 withenv authenv do gnocchi(args) end else raise(e) end end end |
.conf_filename ⇒ Object
6 7 8 |
# File 'lib/puppet/provider/gnocchi.rb', line 6 def self.conf_filename '/etc/gnocchi/gnocchi.conf' end |
.get_gnocchi_credentials ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet/provider/gnocchi.rb', line 28 def self.get_gnocchi_credentials auth_keys = ['auth_url', 'project_name', 'username', 'password'] conf = gnocchi_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']['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. Gnocchi types will not work if gnocchi is not \ correctly configured.") end end |
.get_gnocchi_resource_attrs(type, id) ⇒ Object
111 112 113 114 |
# File 'lib/puppet/provider/gnocchi.rb', line 111 def self.get_gnocchi_resource_attrs(type, id) json = auth_gnocchi("--json", "#{type}-show", id) return JSON.parse(json) end |
.gnocchi_conf ⇒ Object
57 58 59 60 61 62 |
# File 'lib/puppet/provider/gnocchi.rb', line 57 def self.gnocchi_conf return @gnocchi_conf if @gnocchi_conf @gnocchi_conf = Puppet::Util::IniConfig::File.new @gnocchi_conf.read(conf_filename) @gnocchi_conf end |
.gnocchi_credentials ⇒ Object
24 25 26 |
# File 'lib/puppet/provider/gnocchi.rb', line 24 def self.gnocchi_credentials @gnocchi_credentials ||= get_gnocchi_credentials end |
.list_gnocchi_resources(type, *args) ⇒ Object
106 107 108 109 |
# File 'lib/puppet/provider/gnocchi.rb', line 106 def self.list_gnocchi_resources(type, *args) json = auth_gnocchi("--json", "#{type}-list", *args) return JSON.parse(json) end |
.reset ⇒ Object
101 102 103 104 |
# File 'lib/puppet/provider/gnocchi.rb', line 101 def self.reset @gnocchi_conf = nil @gnocchi_credentials = nil end |
.withenv(hash, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/puppet/provider/gnocchi.rb', line 10 def self.withenv(hash, &block) saved = ENV.to_hash hash.each do |name, val| ENV[name.to_s] = val end yield ensure ENV.clear saved.each do |name, val| ENV[name] = val end end |
Instance Method Details
#auth_gnocchi(*args) ⇒ Object
91 92 93 |
# File 'lib/puppet/provider/gnocchi.rb', line 91 def auth_gnocchi(*args) self.class.auth_gnocchi(args) end |
#gnocchi_credentials ⇒ Object
53 54 55 |
# File 'lib/puppet/provider/gnocchi.rb', line 53 def gnocchi_credentials self.class.gnocchi_credentials end |
#gnocchi_manage(*args) ⇒ Object
95 96 97 98 99 |
# File 'lib/puppet/provider/gnocchi.rb', line 95 def gnocchi_manage(*args) cmd = args.join(" ") output = `#{cmd}` $?.exitstatus end |