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)
|
def self.auth_glance(*args)
|
||||||
begin
|
begin
|
||||||
g = glance_credentials
|
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
|
rescue Exception => e
|
||||||
if (e.message =~ /\[Errno 111\] Connection refused/) or (e.message =~ /\(HTTP 400\)/) or (e.message =~ /HTTP Unable to establish connection/)
|
if (e.message =~ /\[Errno 111\] Connection refused/) or (e.message =~ /\(HTTP 400\)/) or (e.message =~ /HTTP Unable to establish connection/)
|
||||||
sleep 10
|
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
|
else
|
||||||
raise(e)
|
raise(e)
|
||||||
end
|
end
|
||||||
@ -90,7 +90,7 @@ class Puppet::Provider::Glance < Puppet::Provider
|
|||||||
def self.auth_glance_stdin(*args)
|
def self.auth_glance_stdin(*args)
|
||||||
begin
|
begin
|
||||||
g = glance_credentials
|
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
|
# This is a horrible, horrible hack
|
||||||
# Redirect stderr to stdout in order to report errors
|
# Redirect stderr to stdout in order to report errors
|
||||||
@ -109,14 +109,14 @@ class Puppet::Provider::Glance < Puppet::Provider
|
|||||||
private
|
private
|
||||||
def self.list_glance_images
|
def self.list_glance_images
|
||||||
ids = []
|
ids = []
|
||||||
(auth_glance('index').split("\n")[2..-1] || []).collect do |line|
|
(auth_glance('image-list').split("\n")[3..-2] || []).collect do |line|
|
||||||
ids << line.split[0]
|
ids << line.split('|')[1].strip()
|
||||||
end
|
end
|
||||||
return ids
|
return ids
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_glance_image_attr(id, attr)
|
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}:/
|
if line =~ /^#{attr}:/
|
||||||
return line.split(': ')[1..-1]
|
return line.split(': ')[1..-1]
|
||||||
end
|
end
|
||||||
@ -125,8 +125,8 @@ class Puppet::Provider::Glance < Puppet::Provider
|
|||||||
|
|
||||||
def self.get_glance_image_attrs(id)
|
def self.get_glance_image_attrs(id)
|
||||||
attrs = {}
|
attrs = {}
|
||||||
(auth_glance('show', id).split("\n") || []).collect do |line|
|
(auth_glance('image-show', id).split("\n")[3..-2] || []).collect do |line|
|
||||||
attrs[line.split(': ').first.downcase] = line.split(': ')[1..-1].pop
|
attrs[line.split('|')[1].strip()] = line.split('|')[2].strip()
|
||||||
end
|
end
|
||||||
return attrs
|
return attrs
|
||||||
end
|
end
|
||||||
|
@ -21,10 +21,10 @@ Puppet::Type.type(:glance_image).provide(
|
|||||||
new(
|
new(
|
||||||
:ensure => :present,
|
:ensure => :present,
|
||||||
:name => attrs['name'],
|
:name => attrs['name'],
|
||||||
:is_public => attrs['public'],
|
:is_public => attrs['is_public'],
|
||||||
:container_format => attrs['container format'],
|
:container_format => attrs['container_format'],
|
||||||
:id => attrs['id'],
|
:id => attrs['id'],
|
||||||
:disk_format => attrs['disk format']
|
:disk_format => attrs['disk_format']
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -41,13 +41,13 @@ describe Puppet::Provider::Glance do
|
|||||||
mock.expects(:read).with('/etc/glance/glance-api.conf')
|
mock.expects(:read).with('/etc/glance/glance-api.conf')
|
||||||
klass.expects(:sleep).with(10).returns(nil)
|
klass.expects(:sleep).with(10).returns(nil)
|
||||||
klass.expects(:glance).twice.with(
|
klass.expects(:glance).twice.with(
|
||||||
'-T',
|
'--os-tenant-name',
|
||||||
'foo',
|
'foo',
|
||||||
'-I',
|
'--os-username',
|
||||||
'user',
|
'user',
|
||||||
'-K',
|
'--os-password',
|
||||||
'pass',
|
'pass',
|
||||||
'-N',
|
'--os-auth-url',
|
||||||
'http://127.0.0.1:35357/v2.0/',
|
'http://127.0.0.1:35357/v2.0/',
|
||||||
['test_retries']
|
['test_retries']
|
||||||
).raises(Exception, valid_message).then.returns('')
|
).raises(Exception, valid_message).then.returns('')
|
||||||
|
Loading…
Reference in New Issue
Block a user