Class: Puppet::Provider::Ironic
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::Ironic
- Defined in:
- lib/puppet/provider/ironic.rb
Class Method Summary collapse
- .auth_ironic(*args) ⇒ Object
- .conf_filename ⇒ Object
- .get_ironic_credentials ⇒ Object
- .get_ironic_resource_attrs(type, id) ⇒ Object
- .get_tenant_id(catalog, name) ⇒ Object
- .ironic_conf ⇒ Object
- .ironic_credentials ⇒ Object
- .list_ironic_resources(type) ⇒ Object
- .parse_creation_output(data) ⇒ Object
- .reset ⇒ Object
- .withenv(hash, &block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.auth_ironic(*args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/puppet/provider/ironic.rb', line 67 def self.auth_ironic(*args) q = ironic_credentials authenv = { :OS_AUTH_URL => q['auth_url'], :OS_USERNAME => q['username'], :OS_PROJECT_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 ironic(args) end rescue Exception => e if (e. =~ /\[Errno 111\] Connection refused/) or (e. =~ /\(HTTP 400\)/) sleep 10 withenv authenv do ironic(args) end else raise(e) end end end |
.conf_filename ⇒ Object
9 10 11 |
# File 'lib/puppet/provider/ironic.rb', line 9 def self.conf_filename '/etc/ironic/ironic.conf' end |
.get_ironic_credentials ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/puppet/provider/ironic.rb', line 31 def self.get_ironic_credentials auth_keys = ['auth_url', 'project_name', 'username', 'password'] conf = ironic_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. Ironic types will not work if ironic is not \ correctly configured.") end end |
.get_ironic_resource_attrs(type, id) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/puppet/provider/ironic.rb', line 113 def self.get_ironic_resource_attrs(type, id) attrs = {} net = auth_ironic("#{type}-show", '--format=shell', id) last_key = nil (net.split("\n") || []).compact.collect do |line| if line.include? '=' k, v = line.split('=', 2) attrs[k] = v.gsub(/\A"|"\Z/, '') last_key = k else # Handle the case of a list of values v = line.gsub(/\A"|"\Z/, '') attrs[last_key] = [attrs[last_key], v] end end return attrs end |
.get_tenant_id(catalog, name) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/puppet/provider/ironic.rb', line 131 def self.get_tenant_id(catalog, name) instance_type = 'keystone_tenant' instance = catalog.resource("#{instance_type.capitalize!}[#{name}]") if ! instance instance = Puppet::Type.type(instance_type).instances.find do |i| i.provider.name == name end end if instance return instance.provider.id else fail("Unable to find #{instance_type} for name #{name}") end end |
.ironic_conf ⇒ Object
60 61 62 63 64 65 |
# File 'lib/puppet/provider/ironic.rb', line 60 def self.ironic_conf return @ironic_conf if @ironic_conf @ironic_conf = Puppet::Util::IniConfig::File.new @ironic_conf.read(conf_filename) @ironic_conf end |
.ironic_credentials ⇒ Object
27 28 29 |
# File 'lib/puppet/provider/ironic.rb', line 27 def self.ironic_credentials @ironic_credentials ||= get_ironic_credentials end |
.list_ironic_resources(type) ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/puppet/provider/ironic.rb', line 103 def self.list_ironic_resources(type) ids = [] list = auth_ironic("#{type}-list", '--format=csv', '--column=id', '--quote=none') (list.split("\n")[1..-1] || []).compact.collect do |line| ids << line.strip end return ids end |
.parse_creation_output(data) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/puppet/provider/ironic.rb', line 146 def self.parse_creation_output(data) hash = {} data.split("\n").compact.each do |line| if line.include? '=' hash[line.split('=').first] = line.split('=', 2)[1].gsub(/\A"|"\Z/, '') end end hash end |
.reset ⇒ Object
98 99 100 101 |
# File 'lib/puppet/provider/ironic.rb', line 98 def self.reset @ironic_conf = nil @ironic_credentials = nil end |
.withenv(hash, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet/provider/ironic.rb', line 13 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_ironic(*args) ⇒ Object
94 95 96 |
# File 'lib/puppet/provider/ironic.rb', line 94 def auth_ironic(*args) self.class.auth_ironic(args) end |
#ironic_credentials ⇒ Object
56 57 58 |
# File 'lib/puppet/provider/ironic.rb', line 56 def ironic_credentials self.class.ironic_credentials end |