Added option to upload images with specified ID
- updated rubocop_todo - added upload_image_id attribute - updated specs Change-Id: I29fd680ca4b16160a015fbf809cdd81860df9eeb
This commit is contained in:
parent
9dd38224a9
commit
d6735b4b5f
|
@ -1,6 +1,6 @@
|
||||||
# This configuration was generated by
|
# This configuration was generated by
|
||||||
# `rubocop --auto-gen-config`
|
# `rubocop --auto-gen-config`
|
||||||
# on 2016-02-04 13:18:09 +0100 using RuboCop version 0.34.2.
|
# on 2017-01-09 12:44:21 +0100 using RuboCop version 0.39.0.
|
||||||
# The point is for the user to remove these configuration records
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
# Note that changes in the inspected code, or installation of new
|
# Note that changes in the inspected code, or installation of new
|
||||||
|
@ -9,25 +9,30 @@
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Configuration parameters: CountComments.
|
# Configuration parameters: CountComments.
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Max: 28
|
Max: 29
|
||||||
|
|
||||||
# Offense count: 6
|
# Offense count: 2
|
||||||
|
# Configuration parameters: CountKeywordArgs.
|
||||||
|
Metrics/ParameterLists:
|
||||||
|
Max: 6
|
||||||
|
|
||||||
|
# Offense count: 5
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
|
# SupportedStyles: nested, compact
|
||||||
Style/ClassAndModuleChildren:
|
Style/ClassAndModuleChildren:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'recipes/api.rb'
|
- 'recipes/api.rb'
|
||||||
- 'recipes/client.rb'
|
|
||||||
- 'recipes/identity_registration.rb'
|
- 'recipes/identity_registration.rb'
|
||||||
- 'recipes/image_upload.rb'
|
- 'recipes/image_upload.rb'
|
||||||
- 'recipes/registry.rb'
|
- 'recipes/registry.rb'
|
||||||
- 'recipes/swift_store.rb'
|
- 'recipes/swift_store.rb'
|
||||||
|
|
||||||
# Offense count: 6
|
# Offense count: 5
|
||||||
# Configuration parameters: Exclude.
|
|
||||||
Style/Documentation:
|
Style/Documentation:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
- 'spec/**/*'
|
||||||
|
- 'test/**/*'
|
||||||
- 'recipes/api.rb'
|
- 'recipes/api.rb'
|
||||||
- 'recipes/client.rb'
|
|
||||||
- 'recipes/identity_registration.rb'
|
- 'recipes/identity_registration.rb'
|
||||||
- 'recipes/image_upload.rb'
|
- 'recipes/image_upload.rb'
|
||||||
- 'recipes/registry.rb'
|
- 'recipes/registry.rb'
|
||||||
|
|
|
@ -80,7 +80,7 @@ default['openstack']['image']['upload_image']['centos'] = 'http://cloud.centos.o
|
||||||
# The following disk format types are supported: qcow vhd vmdk vdi iso raw
|
# The following disk format types are supported: qcow vhd vmdk vdi iso raw
|
||||||
# Bare container format will be used.
|
# Bare container format will be used.
|
||||||
default['openstack']['image']['upload_image_type']['cirros'] = 'qcow'
|
default['openstack']['image']['upload_image_type']['cirros'] = 'qcow'
|
||||||
|
default['openstack']['image']['upload_image_id']['cirros'] = 'e1847f1a-01d2-4957-a067-b56085bf3781'
|
||||||
# logging attribute
|
# logging attribute
|
||||||
default['openstack']['image']['syslog']['use'] = false
|
default['openstack']['image']['syslog']['use'] = false
|
||||||
default['openstack']['image']['syslog']['facility'] = 'LOG_LOCAL2'
|
default['openstack']['image']['syslog']['facility'] = 'LOG_LOCAL2'
|
||||||
|
|
|
@ -30,17 +30,17 @@ action :upload do
|
||||||
@ks_uri = new_resource.identity_uri
|
@ks_uri = new_resource.identity_uri
|
||||||
@domain = new_resource.identity_user_domain_name
|
@domain = new_resource.identity_user_domain_name
|
||||||
@project_domain_name = new_resource.identity_project_domain_name
|
@project_domain_name = new_resource.identity_project_domain_name
|
||||||
|
|
||||||
name = new_resource.image_name
|
name = new_resource.image_name
|
||||||
url = new_resource.image_url
|
url = new_resource.image_url
|
||||||
public = new_resource.image_public
|
public = new_resource.image_public
|
||||||
|
id = new_resource.image_id
|
||||||
|
|
||||||
ep = public_endpoint 'image_api'
|
ep = public_endpoint 'image_api'
|
||||||
api = ep.to_s.gsub(ep.path, '') # remove trailing /v2
|
api = ep.to_s.gsub(ep.path, '') # remove trailing /v2
|
||||||
|
|
||||||
type = new_resource.image_type
|
type = new_resource.image_type
|
||||||
type = _determine_type(url) if type == 'unknown'
|
type = _determine_type(url) if type == 'unknown'
|
||||||
_upload_image(type, name, api, url, public ? 'public' : 'private')
|
_upload_image(type, name, api, url, public ? 'public' : 'private', id)
|
||||||
new_resource.updated_by_last_action(true)
|
new_resource.updated_by_last_action(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,18 +58,18 @@ def _determine_type(url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def _upload_image(type, name, api, url, public)
|
def _upload_image(type, name, api, url, public, id)
|
||||||
case type
|
case type
|
||||||
when 'ami'
|
when 'ami'
|
||||||
_upload_ami(name, api, url, public)
|
_upload_ami(name, api, url, public, id)
|
||||||
when 'qcow'
|
when 'qcow'
|
||||||
_upload_image_bare(name, api, url, public, 'qcow2')
|
_upload_image_bare(name, api, url, public, 'qcow2', id)
|
||||||
else
|
else
|
||||||
_upload_image_bare(name, api, url, public, type)
|
_upload_image_bare(name, api, url, public, type, id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def _upload_image_bare(name, api, url, public, type)
|
def _upload_image_bare(name, api, url, public, type, id)
|
||||||
glance_cmd = "glance --insecure --os-username #{@user} --os-password #{@pass} --os-project-name #{@tenant} --os-image-url #{api} --os-auth-url #{@ks_uri} --os-user-domain-name #{@domain} --os-project-domain-name #{@project_domain_name}"
|
glance_cmd = "glance --insecure --os-username #{@user} --os-password #{@pass} --os-project-name #{@tenant} --os-image-url #{api} --os-auth-url #{@ks_uri} --os-user-domain-name #{@domain} --os-project-domain-name #{@project_domain_name}"
|
||||||
c_fmt = '--container-format bare'
|
c_fmt = '--container-format bare'
|
||||||
d_fmt = "--disk-format #{type}"
|
d_fmt = "--disk-format #{type}"
|
||||||
|
@ -77,13 +77,13 @@ def _upload_image_bare(name, api, url, public, type)
|
||||||
execute "Uploading #{type} image #{name}" do # :pragma-foodcritic: ~FC041
|
execute "Uploading #{type} image #{name}" do # :pragma-foodcritic: ~FC041
|
||||||
cwd '/tmp'
|
cwd '/tmp'
|
||||||
|
|
||||||
command "curl -L #{url} | #{glance_cmd} image-create --name #{name} --visibility #{public} #{c_fmt} #{d_fmt}"
|
command "curl -L #{url} | #{glance_cmd} image-create --name #{name} #{"--id #{id}" unless id == ''} --visibility #{public} #{c_fmt} #{d_fmt}"
|
||||||
not_if "#{glance_cmd} image-list | grep #{name}"
|
not_if "#{glance_cmd} image-list | grep #{name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO(chrislaco) This refactor is in the works via Craig Tracey
|
# TODO(chrislaco) This refactor is in the works via Craig Tracey
|
||||||
def _upload_ami(name, api, url, public)
|
def _upload_ami(name, api, url, public, id)
|
||||||
glance_cmd = "glance --insecure --os-username #{@user} --os-password #{@pass} --os-project-name #{@tenant} --os-image-url #{api} --os-auth-url #{@ks_uri} --os-user-domain-name #{@domain} --os-project-domain-name #{@project_domain_name}"
|
glance_cmd = "glance --insecure --os-username #{@user} --os-password #{@pass} --os-project-name #{@tenant} --os-image-url #{api} --os-auth-url #{@ks_uri} --os-user-domain-name #{@domain} --os-project-domain-name #{@project_domain_name}"
|
||||||
aki_fmt = '--container-format aki --disk-format aki'
|
aki_fmt = '--container-format aki --disk-format aki'
|
||||||
ari_fmt = '--container-format ari --disk-format ari'
|
ari_fmt = '--container-format ari --disk-format ari'
|
||||||
|
@ -116,7 +116,7 @@ def _upload_ami(name, api, url, public)
|
||||||
|
|
||||||
kid=$(#{glance_cmd} image-create --name "${image_name}-kernel" --visibility #{public} #{aki_fmt} < ${kernel_file} | grep -m 1 '^|[ ]*id[ ]*|' | cut -d'|' -f3 | sed 's/ //')
|
kid=$(#{glance_cmd} image-create --name "${image_name}-kernel" --visibility #{public} #{aki_fmt} < ${kernel_file} | grep -m 1 '^|[ ]*id[ ]*|' | cut -d'|' -f3 | sed 's/ //')
|
||||||
rid=$(#{glance_cmd} image-create --name "${image_name}-initrd" --visibility #{public} #{ari_fmt} < ${ramdisk} | grep -m 1 '^|[ ]*id[ ]*|' | cut -d'|' -f3 | sed 's/ //')
|
rid=$(#{glance_cmd} image-create --name "${image_name}-initrd" --visibility #{public} #{ari_fmt} < ${ramdisk} | grep -m 1 '^|[ ]*id[ ]*|' | cut -d'|' -f3 | sed 's/ //')
|
||||||
#{glance_cmd} image-create --name "#{name}" --visibility #{public} #{ami_fmt} --property "kernel_id=$kid" --property "ramdisk_id=$rid" < ${kernel}
|
#{glance_cmd} image-create --name "#{name}" #{"--id #{id}" unless id == ''} --visibility #{public} #{ami_fmt} --property "kernel_id=$kid" --property "ramdisk_id=$rid" < ${kernel}
|
||||||
EOH
|
EOH
|
||||||
not_if "#{glance_cmd} image-list | grep #{name}"
|
not_if "#{glance_cmd} image-list | grep #{name}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,12 +44,14 @@ admin_domain = node['openstack']['image_api']['conf']['keystone_authtoken']['use
|
||||||
node['openstack']['image']['upload_images'].each do |img|
|
node['openstack']['image']['upload_images'].each do |img|
|
||||||
type = 'unknown'
|
type = 'unknown'
|
||||||
type = node['openstack']['image']['upload_image_type'][img.to_sym] if node['openstack']['image']['upload_image_type'][img.to_sym]
|
type = node['openstack']['image']['upload_image_type'][img.to_sym] if node['openstack']['image']['upload_image_type'][img.to_sym]
|
||||||
|
id = ''
|
||||||
|
id = node['openstack']['image']['upload_image_id'][img.to_sym] if node['openstack']['image']['upload_image_id'][img.to_sym]
|
||||||
openstack_image_image "Image setup for #{img}" do
|
openstack_image_image "Image setup for #{img}" do
|
||||||
image_url node['openstack']['image']['upload_image'][img.to_sym]
|
image_url node['openstack']['image']['upload_image'][img.to_sym]
|
||||||
image_name img
|
image_name img
|
||||||
image_type type
|
image_type type
|
||||||
image_public true
|
image_public true
|
||||||
|
image_id id
|
||||||
identity_user admin_user
|
identity_user admin_user
|
||||||
identity_pass admin_pass
|
identity_pass admin_pass
|
||||||
identity_tenant admin_project_name
|
identity_tenant admin_project_name
|
||||||
|
|
|
@ -33,6 +33,7 @@ attribute :image_url, kind_of: String
|
||||||
attribute :image_type, kind_of: String, default: 'unknown', equal_to: %w(unknown ami qcow vhd vmdk vdi iso raw)
|
attribute :image_type, kind_of: String, default: 'unknown', equal_to: %w(unknown ami qcow vhd vmdk vdi iso raw)
|
||||||
attribute :image_name, kind_of: String, default: 'default'
|
attribute :image_name, kind_of: String, default: 'default'
|
||||||
attribute :image_public, kind_of: BOOLEAN, default: true
|
attribute :image_public, kind_of: BOOLEAN, default: true
|
||||||
|
attribute :image_id, kind_of: String, default: ''
|
||||||
attribute :identity_user, kind_of: String
|
attribute :identity_user, kind_of: String
|
||||||
attribute :identity_pass, kind_of: String
|
attribute :identity_pass, kind_of: String
|
||||||
attribute :identity_tenant, kind_of: String
|
attribute :identity_tenant, kind_of: String
|
||||||
|
|
|
@ -23,6 +23,7 @@ describe 'openstack-image::image_upload' do
|
||||||
image_name: 'cirros',
|
image_name: 'cirros',
|
||||||
image_type: 'qcow',
|
image_type: 'qcow',
|
||||||
image_public: true,
|
image_public: true,
|
||||||
|
image_id: 'e1847f1a-01d2-4957-a067-b56085bf3781',
|
||||||
identity_user: 'admin',
|
identity_user: 'admin',
|
||||||
identity_pass: 'admin-pass',
|
identity_pass: 'admin-pass',
|
||||||
identity_tenant: 'admin',
|
identity_tenant: 'admin',
|
||||||
|
|
|
@ -64,7 +64,7 @@ shared_context 'image-stubs' do
|
||||||
.with('image')
|
.with('image')
|
||||||
.and_return('rabbit://guest:mypass@127.0.0.1:5672')
|
.and_return('rabbit://guest:mypass@127.0.0.1:5672')
|
||||||
allow(Chef::Application).to receive(:fatal!)
|
allow(Chef::Application).to receive(:fatal!)
|
||||||
stub_command('glance --insecure --os-username admin --os-password admin-pass --os-project-name admin --os-image-url http://127.0.0.1:9292 --os-auth-url http://127.0.0.1:5000/v3 --os-user-domain-name Default --os-project-domain-name Default image-list | grep cirros').and_return('')
|
stub_command('glance --insecure --os-username admin --os-password admin-pass --os-project-name admin --os-image-url http://127.0.0.1:9292 --os-auth-url http://127.0.0.1:5000/v3 --os-user-domain-name Default --os-project-domain-name Default image-list --id e1847f1a-01d2-4957-a067-b56085bf3781 | grep cirros').and_return('')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue