add service image

Add the manfiests for add service image to glance

Change-Id: I6b19a36f2d4a0755c0f3434ff71b7db810c64d87
This commit is contained in:
Igor Gajsin 2016-08-03 12:57:01 +03:00
parent 7a683204b8
commit ecd6cac77a
9 changed files with 262 additions and 12 deletions

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
notify {'MOUDULAR: fuel-plugin-manila/db': }
notify {'MODULAR: fuel-plugin-manila/db': }
$mysql = hiera_hash('mysql', {})
$manila = hiera_hash('manila', {})

View File

@ -1,5 +1,10 @@
notify {'MODULAR: fuel-plugin-manila/install': }
$manila = hiera_hash('fuel-plugin-manila', {})
$image = manila['fuel-plugin-manila_image']
$master_ip = hiera('master_ip')
$src_image = "wget http://${master_ip}:8080/plugins/fuel-plugin-manila-1.0/repositories/ubuntu/${image}"
$inits = {
'manila-api' => {
desc => 'manila-api init',
@ -36,8 +41,12 @@ package {'python-manila-ui':
ensure => 'installed'
}
class{'::manila_auxiliary::fs': }
class {'::manila_auxiliary::fs': }
create_resources('::manila_auxiliary::initd', $inits)
class {'::manila_auxiliary::image':
image => $image
}
Package['python-pip']->Package['pycrypto']->Package['python-manila']->Package['python-manilaclient']->Package['python-manila-ui']

View File

@ -1,11 +1,28 @@
notify {'MODULAR: fuel-plugin-manila/populate_hiera': }
$manila = hiera_hash('manila', false)
$file = '/etc/hiera/plugins/fuel-plugin-manila.yaml'
$new_password = generate("/bin/bash", "-c", "/bin/date +%s | sha256sum | base64 | head -c 32 ; echo -n")
$db_password = generate("/bin/bash", "-c", "/bin/date +%s | sha256sum | base64 | head -c 32 ; echo -n")
$manila = hiera_hash('manila', {})
$fpg_manila = hiera_hash('fuel-plugin-manila', {})
$file = '/etc/hiera/plugins/fuel-plugin-manila.yaml'
$new_password = generate("/bin/bash", "-c", "/bin/date +%s | sha256sum | base64 | head -c 32 ; echo -n")
sleep 1
$db_password = generate("/bin/bash", "-c", "/bin/date +%s | sha256sum | base64 | head -c 32 ; echo -n")
$image_name = 'manila-service-image'
$service_image = $fpg_manila['fuel-plugin-manila_image']
$img_data = {
container_format => 'bare',
disk_format => 'qcow2',
glance_properties => '',
img_name => $image_name,
img_path => "/tmp/${service_image}",
min_ram => 256,
os_name => 'ubuntu',
public => 'true',
}
if ! $manila {
populate_hiera($file, 'user_password', $new_password)
populate_hiera($file, 'db_password', $db_password)
populate_hiera($file, 'service_vm_image', $img_data)
}

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
notify {'MOUDULAR: fuel-plugin-manila/site': }
notify {'MODULAR: fuel-plugin-manila/site': }
$manila = hiera_hash('manila', {})
$db_user = 'manila'

View File

@ -0,0 +1,186 @@
#!/usr/bin/env ruby
require 'hiera'
ENV['LANG'] = 'C'
hiera = Hiera.new(:config => '/etc/hiera.yaml')
manila = hiera.lookup 'manila', {}, {}
service_vm_images = manila['service_vm_image']
glanced = hiera.lookup 'glance', {} , {}, nil, :hash
management_vip = hiera.lookup 'management_vip', nil, {}
auth_addr = hiera.lookup 'service_endpoint', "#{management_vip}", {}
tenant_name = glanced['tenant'].nil? ? "services" : glanced['tenant']
user_name = glanced['user'].nil? ? "glance" : glanced['user']
endpoint_type = glanced['endpoint_type'].nil? ? "internalURL" : glanced['endpoint_type']
region_name = hiera.lookup 'region', 'RegionOne', {}
ssl_hash = hiera.lookup 'use_ssl', {}, {}
if ssl_hash['keystone_internal']
auth_proto = 'https'
auth_addr = ssl_hash['keystone_internal_hostname'] || auth_addr
else
auth_proto = 'http'
end
puts "Auth URL is #{auth_proto}://#{auth_addr}:5000/v2.0"
ENV['OS_TENANT_NAME']="#{tenant_name}"
ENV['OS_USERNAME']="#{user_name}"
ENV['OS_PASSWORD']="#{glanced['user_password']}"
ENV['OS_AUTH_URL']="#{auth_proto}://#{auth_addr}:5000/v2.0"
ENV['OS_ENDPOINT_TYPE'] = "#{endpoint_type}"
ENV['OS_REGION_NAME']="#{region_name}"
raise 'Not service_vm_image data!' unless [Array, Hash].include?(service_vm_images.class) && service_vm_images.any?
service_vm_images = [service_vm_images] unless service_vm_images.is_a? Array
service_vm_images.each do |image|
%w(
disk_format
img_path
img_name
os_name
public
container_format
min_ram
).each do |f|
raise "Data field '#{f}' is missing!" unless image[f]
end
end
def image_list
stdout = `glance --verbose image-list`
return_code = $?.exitstatus
images = []
stdout.split("\n").each do |line|
fields = line.split('|').map { |f| f.chomp.strip }
next if fields[1] == 'ID'
next unless fields[2]
images << {fields[2] => fields[6]}
end
{:images => images, :exit_code => return_code}
end
def image_create(image_hash)
command = <<-EOF
/usr/bin/glance image-create \
--name '#{image_hash['img_name']}' \
--visibility '#{image_hash['visibility']}' \
--container-format='#{image_hash['container_format']}' \
--disk-format='#{image_hash['disk_format']}' \
--min-ram='#{image_hash['min_ram']}' \
#{image_hash['glance_properties']} \
--file '#{image_hash['img_path']}'
EOF
puts command
stdout = `#{command}`
return_code = $?.exitstatus
[ stdout, return_code ]
end
# check if Glance is online
# waited until the glance is started because when vCenter used as a glance
# backend launch may takes up to 1 minute.
def wait_for_glance
5.times.each do |retries|
sleep 10 if retries > 0
return if image_list[:exit_code] == 0
end
raise 'Could not get a list of glance images!'
end
# upload image to Glance
# if it have not been already uploaded
def upload_image(image)
if check_image(image)
puts "Image '#{image['img_name']}' is already present and active!"
return 0
else
cleanup_image(image)
end
# convert old API v1 'public' property to API v2 'visibility' property
if image['public'] == 'true'
image['visibility'] = 'public'
else
image['visibility'] = 'private'
end
stdout, return_code = image_create(image)
puts stdout
# check to make sure the image is uploaded and active
if return_code == 0
image_ok = check_image(image)
# retry over ~50 seconds to wait to see if it becomes active
5.times.each do |retries|
break if image_ok
sleep 10
image_ok = check_image(image)
end
end
# if the image upload was successful and it's reporting active then success!
upload_result = (return_code == 0 and image_ok)
if upload_result
puts "Image '#{image['img_name']}' was uploaded from '#{image['img_path']}'"
else
puts "Image '#{image['img_name']}' upload from '#{image['img_path']}' FAILED!"
end
return upload_result
end
# return true if image has been uploaded and active
def check_image(image)
list_of_images = image_list
if list_of_images[:exit_code] == 0 && list_of_images[:images].include?(image['img_name'] => "active")
return true
end
return false
end
# remove the image by name if it is in the list of images
# TODO(aschultz): if the image exists by name multiple times we only remove
# the first one
def cleanup_image(image)
list_of_images = image_list
unless list_of_images[:images].select { |img_hash| img_hash.key?(image['img_name']) }.empty?
delete_image(image['img_name'])
end
end
def delete_image(image_name)
command = "/usr/bin/openstack image delete '#{image_name}'"
puts command
stdout = `#{command}`
return_code = $?.exitstatus
[ stdout, return_code ]
end
########################
wait_for_glance
errors = 0
service_vm_images.each do |image|
success = false
# retry upload 5 times with a 1 minute sleep between tries
5.times.each do |retries|
if upload_image(image)
success = true
break
end
sleep 60
end
errors += 1 unless success
end
if errors > 0
service_vm_images.each do |image|
cleanup_image(image)
end
exit 1
end
exit 0

View File

@ -0,0 +1,21 @@
class manila_auxiliary::image (
$src_image = 'http://host/manila-service-image.qcow2',
$image = 'manila-service-image.qcow2',
){
file {'/tmp/upload_cirros.rb':
source => 'puppet:///modules/manila_auxiliary/upload_cirros.rb',
}->
exec {'wget_service_image':
command => "wget ${src_image} -O /tmp/${image}"
path => '/usr/bin',
}->
exec {'upload-service-image':
command => 'ruby /tmp/upload_cirros.rb',
path => '/usr/bin',
}->
exec {'del_service_image':
command => "rm /tmp/${image}",
path => '/usr/bin',
}
}

View File

@ -3,9 +3,9 @@ attributes:
# Settings group can be one of "general", "security", "compute", "network",
# "storage", "logging", "openstack_services" and "other".
group: 'storage'
fuel-plugin-manila_text:
value: 'Set default value'
label: 'Text field'
description: 'Description for text field'
fuel-plugin-manila_image:
value: 'manila-service-image.qcow2'
label: 'Image name'
description: 'Name of the service image for generic driver'
weight: 25
type: "text"

View File

@ -3,7 +3,7 @@ name: fuel-plugin-manila
# Human-readable name for your plugin
title: enable Manila service
# Plugin version
version: '1.0.7'
version: '1.0.0'
# Description
description: Manila is the File Storage as a Service OpenStack project
# Required fuel version

17
post_install.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
cp $MANILA_IMAGE /var/www/nailgun/plugins/fuel-plugin-manila-1.0/repositories/ubuntu/