Update deprecated Glance CLI
Since this patch has been merged in python-glanceclient 0.14.1:
1dfce5301c
We have to update the way to call Glance Client.
This patch updates for glance image-list, image-show and the way to get
a token, and also the way the glance command output is parsed.
Change-Id: If3e1e42b1245dd064fa00e07037535afc9caa04c
This commit is contained in:
parent
3c074d708c
commit
f377c0229c
@ -72,11 +72,11 @@ class Puppet::Provider::Glance < Puppet::Provider
|
||||
def self.auth_glance(*args)
|
||||
begin
|
||||
g = glance_credentials
|
||||
remove_warnings(glance('-T', g['admin_tenant_name'], '-I', g['admin_user'], '-K', g['admin_password'], '-N', auth_endpoint, args))
|
||||
remove_warnings(glance('--os-tenant-name', g['admin_tenant_name'], '--os-username', g['admin_user'], '--os-password', g['admin_password'], '--os-auth-url', auth_endpoint, args))
|
||||
rescue Exception => e
|
||||
if (e.message =~ /\[Errno 111\] Connection refused/) or (e.message =~ /\(HTTP 400\)/) or (e.message =~ /HTTP Unable to establish connection/)
|
||||
sleep 10
|
||||
remove_warnings(glance('-T', g['admin_tenant_name'], '-I', g['admin_user'], '-K', g['admin_password'], '-N', auth_endpoint, args))
|
||||
remove_warnings(glance('--os-tenant-name', g['admin_tenant_name'], '--os-username', g['admin_user'], '--os-password', g['admin_password'], '--os-auth-url', auth_endpoint, args))
|
||||
else
|
||||
raise(e)
|
||||
end
|
||||
@ -90,7 +90,7 @@ class Puppet::Provider::Glance < Puppet::Provider
|
||||
def self.auth_glance_stdin(*args)
|
||||
begin
|
||||
g = glance_credentials
|
||||
command = "glance -T #{g['admin_tenant_name']} -I #{g['admin_user']} -K #{g['admin_password']} -N #{auth_endpoint} #{args.join(' ')}"
|
||||
command = "glance --os-tenant-name #{g['admin_tenant_name']} --os-username #{g['admin_user']} --os-password #{g['admin_password']} --os-auth-url #{auth_endpoint} #{args.join(' ')}"
|
||||
|
||||
# This is a horrible, horrible hack
|
||||
# Redirect stderr to stdout in order to report errors
|
||||
@ -109,14 +109,14 @@ class Puppet::Provider::Glance < Puppet::Provider
|
||||
private
|
||||
def self.list_glance_images
|
||||
ids = []
|
||||
(auth_glance('index').split("\n")[2..-1] || []).collect do |line|
|
||||
ids << line.split[0]
|
||||
(auth_glance('image-list').split("\n")[3..-2] || []).collect do |line|
|
||||
ids << line.split('|')[1].strip()
|
||||
end
|
||||
return ids
|
||||
end
|
||||
|
||||
def self.get_glance_image_attr(id, attr)
|
||||
(auth_glance('show', id).split("\n") || []).collect do |line|
|
||||
(auth_glance('image-show', id).split("\n") || []).collect do |line|
|
||||
if line =~ /^#{attr}:/
|
||||
return line.split(': ')[1..-1]
|
||||
end
|
||||
@ -125,8 +125,8 @@ class Puppet::Provider::Glance < Puppet::Provider
|
||||
|
||||
def self.get_glance_image_attrs(id)
|
||||
attrs = {}
|
||||
(auth_glance('show', id).split("\n") || []).collect do |line|
|
||||
attrs[line.split(': ').first.downcase] = line.split(': ')[1..-1].pop
|
||||
(auth_glance('image-show', id).split("\n")[3..-2] || []).collect do |line|
|
||||
attrs[line.split('|')[1].strip()] = line.split('|')[2].strip()
|
||||
end
|
||||
return attrs
|
||||
end
|
||||
|
@ -21,10 +21,10 @@ Puppet::Type.type(:glance_image).provide(
|
||||
new(
|
||||
:ensure => :present,
|
||||
:name => attrs['name'],
|
||||
:is_public => attrs['public'],
|
||||
:container_format => attrs['container format'],
|
||||
:is_public => attrs['is_public'],
|
||||
:container_format => attrs['container_format'],
|
||||
:id => attrs['id'],
|
||||
:disk_format => attrs['disk format']
|
||||
:disk_format => attrs['disk_format']
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -41,13 +41,13 @@ describe Puppet::Provider::Glance do
|
||||
mock.expects(:read).with('/etc/glance/glance-api.conf')
|
||||
klass.expects(:sleep).with(10).returns(nil)
|
||||
klass.expects(:glance).twice.with(
|
||||
'-T',
|
||||
'--os-tenant-name',
|
||||
'foo',
|
||||
'-I',
|
||||
'--os-username',
|
||||
'user',
|
||||
'-K',
|
||||
'--os-password',
|
||||
'pass',
|
||||
'-N',
|
||||
'--os-auth-url',
|
||||
'http://127.0.0.1:35357/v2.0/',
|
||||
['test_retries']
|
||||
).raises(Exception, valid_message).then.returns('')
|
||||
|
Loading…
Reference in New Issue
Block a user