Class: Puppet::Provider::Neutron
- Inherits:
-
Openstack
- Object
- Openstack
- Puppet::Provider::Neutron
- Extended by:
- Openstack::Auth
- Defined in:
- lib/puppet/provider/neutron.rb
Class Method Summary collapse
- .auth_endpoint ⇒ Object
- .conf_filename ⇒ Object
- .get_auth_endpoint ⇒ Object
- .get_network_name(id) ⇒ Object
- .get_neutron_credentials ⇒ Object
- .get_subnet_name(id) ⇒ Object
- .neutron_conf ⇒ Object
- .neutron_credentials ⇒ Object
- .neutron_request(service, action, error, properties = nil) ⇒ Object
- .parse_availability_zone_hint(value) ⇒ Object
- .parse_subnet_id(value) ⇒ Object
- .request(service, action, properties = nil) ⇒ Object
- .reset ⇒ Object
Instance Method Summary collapse
Class Method Details
.auth_endpoint ⇒ Object
97 98 99 |
# File 'lib/puppet/provider/neutron.rb', line 97 def self.auth_endpoint @auth_endpoint ||= get_auth_endpoint end |
.conf_filename ⇒ Object
40 41 42 |
# File 'lib/puppet/provider/neutron.rb', line 40 def self.conf_filename '/etc/neutron/neutron.conf' end |
.get_auth_endpoint ⇒ Object
92 93 94 95 |
# File 'lib/puppet/provider/neutron.rb', line 92 def self.get_auth_endpoint q = neutron_credentials "#{q['auth_url']}" end |
.get_network_name(id) ⇒ Object
107 108 109 110 |
# File 'lib/puppet/provider/neutron.rb', line 107 def self.get_network_name(id) network = self.request('network', 'show', [id]) return network[:name] end |
.get_neutron_credentials ⇒ Object
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 |
# File 'lib/puppet/provider/neutron.rb', line 59 def self.get_neutron_credentials #needed keys for authentication auth_keys = ['auth_url', 'project_name', 'username', 'password'] conf = neutron_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. Neutron types will not work if neutron is not " + "correctly configured.") end end |
.get_subnet_name(id) ⇒ Object
112 113 114 115 |
# File 'lib/puppet/provider/neutron.rb', line 112 def self.get_subnet_name(id) subnet = self.request('subnet', 'show', [id]) return subnet[:name] end |
.neutron_conf ⇒ Object
44 45 46 47 48 49 |
# File 'lib/puppet/provider/neutron.rb', line 44 def self.neutron_conf return @neutron_conf if @neutron_conf @neutron_conf = Puppet::Util::IniConfig::File.new @neutron_conf.read(conf_filename) @neutron_conf end |
.neutron_credentials ⇒ Object
51 52 53 |
# File 'lib/puppet/provider/neutron.rb', line 51 def self.neutron_credentials @neutron_credentials ||= get_neutron_credentials end |
.neutron_request(service, action, error, properties = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/puppet/provider/neutron.rb', line 24 def self.neutron_request(service, action, error, properties=nil) warning('Usage of keystone_authtoken parameters is deprecated.') properties ||= [] @credentials.username = neutron_credentials['username'] @credentials.password = neutron_credentials['password'] @credentials.project_name = neutron_credentials['project_name'] @credentials.auth_url = auth_endpoint @credentials.user_domain_name = neutron_credentials['user_domain_name'] @credentials.project_domain_name = neutron_credentials['project_domain_name'] if neutron_credentials['region_name'] @credentials.region_name = neutron_credentials['region_name'] end raise error unless @credentials.set? Puppet::Provider::Openstack.request(service, action, properties, @credentials) end |
.parse_availability_zone_hint(value) ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/puppet/provider/neutron.rb', line 131 def self.parse_availability_zone_hint(value) hints = JSON.parse(value.gsub(/\\"/,'"').gsub('u\'', '"').gsub('\'','"')) if hints.length > 1 hints else hints.first end end |
.parse_subnet_id(value) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/puppet/provider/neutron.rb', line 117 def self.parse_subnet_id(value) fixed_ips = JSON.parse(value.gsub(/\\"/,'"').gsub('u\'', '"').gsub('\'','"')) subnet_ids = [] fixed_ips.each do |fixed_ip| subnet_ids << fixed_ip['subnet_id'] end if subnet_ids.length > 1 subnet_ids else subnet_ids.first end end |
.request(service, action, properties = nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/puppet/provider/neutron.rb', line 16 def self.request(service, action, properties=nil) begin super rescue Puppet::Error::OpenstackAuthInputError => error neutron_request(service, action, error, properties) end end |
.reset ⇒ Object
101 102 103 104 105 |
# File 'lib/puppet/provider/neutron.rb', line 101 def self.reset @neutron_conf = nil @neutron_credentials = nil @auth_endpoint = nil end |
Instance Method Details
#neutron_credentials ⇒ Object
55 56 57 |
# File 'lib/puppet/provider/neutron.rb', line 55 def neutron_credentials self.class.neutron_credentials end |