Class: Puppet::Provider::Openstack
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::Openstack
- Defined in:
- lib/puppet/provider/openstack.rb
Direct Known Subclasses
Class Method Summary collapse
-
.authenticate_request(service, action, *args) ⇒ Object
Returns an array of hashes, where the keys are the downcased CSV headers with underscores instead of spaces.
- .request(service, action, object, *properties) ⇒ Object
Instance Method Summary collapse
- #authenticate_request(service, action, *args) ⇒ Object
- #request(service, action, object, credentials, *properties) ⇒ Object
Class Method Details
.authenticate_request(service, action, *args) ⇒ Object
Returns an array of hashes, where the keys are the downcased CSV headers with underscores instead of spaces
47 48 49 50 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/puppet/provider/openstack.rb', line 47 def self.authenticate_request(service, action, *args) rv = nil timeout = 10 end_time = Time.now.to_i + timeout loop do begin if(action == 'list') response = openstack(service, action, '--quiet', '--format', 'csv', args) response = parse_csv(response) keys = response.delete_at(0) # ID,Name,Description,Enabled rv = response.collect do |line| hash = {} keys.each_index do |index| key = keys[index].downcase.gsub(/ /, '_').to_sym hash[key] = line[index] end hash end elsif(action == 'show' || action == 'create') rv = {} # shell output is name="value"\nid="value2"\ndescription="value3" etc. openstack(service, action, '--format', 'shell', args).split("\n").each do |line| # key is everything before the first "=" key, val = line.split("=", 2) next unless val # Ignore warnings # value is everything after the first "=", with leading and trailing double quotes stripped val = val.gsub(/\A"|"\Z/, '') rv[key.downcase.to_sym] = val end else rv = openstack(service, action, args) end break rescue Puppet::ExecutionFailure => e if e. =~ /HTTP 401/ raise(Puppet::Error::OpenstackUnauthorizedError, 'Could not authenticate.') elsif e. =~ /Unable to establish connection/ current_time = Time.now.to_i if current_time > end_time break else wait = end_time - current_time Puppet::debug("Non-fatal error: \"#{e.}\"; retrying for #{wait} more seconds.") if wait > timeout - 2 # Only notice the first time notice("#{service} service is unavailable. Will retry for up to #{wait} seconds.") end end sleep(2) else raise e end end end return rv end |
.request(service, action, object, *properties) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppet/provider/openstack.rb', line 34 def self.request(service, action, object, *properties) if env_vars_set? # noop; auth needs no extra arguments auth_args = nil else # All authentication efforts failed raise(Puppet::Error::OpenstackAuthInputError, 'No credentials provided.') end args = [object, properties, auth_args].flatten.compact authenticate_request(service, action, args) end |
Instance Method Details
#authenticate_request(service, action, *args) ⇒ Object
103 104 105 |
# File 'lib/puppet/provider/openstack.rb', line 103 def authenticate_request(service, action, *args) self.class.authenticate_request(service, action, *args) end |
#request(service, action, object, credentials, *properties) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/puppet/provider/openstack.rb', line 16 def request(service, action, object, credentials, *properties) if password_credentials_set?(credentials) auth_args = password_auth_args(credentials) elsif openrc_set?(credentials) credentials = get_credentials_from_openrc(credentials['openrc']) auth_args = password_auth_args(credentials) elsif service_credentials_set?(credentials) auth_args = token_auth_args(credentials) elsif env_vars_set? # noop; auth needs no extra arguments auth_args = nil else # All authentication efforts failed raise(Puppet::Error::OpenstackAuthInputError, 'No credentials provided.') end args = [object, properties, auth_args].flatten.compact authenticate_request(service, action, args) end |