migratio 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +134 -0
- data/Rakefile +2 -0
- data/bin/migratio-client +15 -0
- data/bin/migratio-run +12 -0
- data/config.yml.example +3 -0
- data/config/amazon.conf +1 -0
- data/config/cyfronet-folsom.conf +2 -0
- data/config/cyfronet-icehouse.conf +2 -0
- data/config/vienna.conf +2 -0
- data/lib/migratio/config.rb +33 -0
- data/lib/migratio/runner.rb +10 -0
- data/lib/migratio/worker.rb +16 -0
- data/lib/migratio/worker/migrator.rb +35 -0
- data/lib/migratio/worker/openstack_amazon_migrator.rb +44 -0
- data/lib/migratio/worker/openstack_openstack_migrator.rb +26 -0
- data/lib/migratio/worker/version.rb +5 -0
- data/migratio.gemspec +25 -0
- data/scripts/openstack2amazon-convert.sh +46 -0
- data/scripts/openstack2amazon-import.sh +72 -0
- data/scripts/openstack2amazon-register.sh +103 -0
- data/scripts/openstack2amazon-transfer.sh +51 -0
- data/scripts/openstack2amazon.sh +102 -0
- data/scripts/openstack2openstack-register.sh +85 -0
- data/scripts/openstack2openstack-transfer.sh +70 -0
- data/scripts/openstack2openstack.sh +79 -0
- data/support/upstart/migration-worker-1.conf +31 -0
- data/support/upstart/migration-worker.conf +2 -0
- data/support/upstart/migration.conf +12 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72782d04daa9369d64692d88cbaf87a99c34f142
|
4
|
+
data.tar.gz: 87bb9fc2f18780825e8305eecb87775bd5fc3f92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79d7a6254b2c287e47bd0483affa51dba629a8e86ada70a20aa89db9b59766acd89ab633baeacc458e4e910a2318b41a802fe16324993f1dce47c6f45c00dcec
|
7
|
+
data.tar.gz: 991a54d76b02999d04f30a0f6372fe08043189cca98362a40a3bf653627141c3297b865f84f77258e34da2c0836f397a7ae20278b5f5f835596c107df85ab4a4
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
log/
|
18
|
+
tmp
|
19
|
+
config.yml
|
20
|
+
*.ipr
|
21
|
+
*.iws
|
22
|
+
*.iml
|
23
|
+
.idea/
|
24
|
+
nbproject/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Paweł Suder
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# Migratio
|
2
|
+
|
3
|
+
This gem is used to perform virtual machine template migration between sites.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
**This project is designed for Linux operating systems.**
|
8
|
+
|
9
|
+
- Linux (tested on Ubuntu)
|
10
|
+
- Ruby 2.0+
|
11
|
+
- Redis (can be installed on separate server)
|
12
|
+
|
13
|
+
## Packages / Dependencies
|
14
|
+
|
15
|
+
Update your system (as root):
|
16
|
+
|
17
|
+
aptitude update
|
18
|
+
aptitude upgrade
|
19
|
+
|
20
|
+
Install additional packages (as root):
|
21
|
+
|
22
|
+
aptitude install g++ make autoconf bison build-essential libssl-dev libyaml-dev libreadline6 libreadline6-dev zlib1g zlib1g-dev
|
23
|
+
|
24
|
+
Install ``ruby`` and ``bundler`` (as root):
|
25
|
+
|
26
|
+
mkdir /tmp/ruby
|
27
|
+
pushd /tmp/ruby
|
28
|
+
curl --progress http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz
|
29
|
+
pushd /tmp/ruby/ruby-2.1.2
|
30
|
+
./configure --disable-install-rdoc
|
31
|
+
make
|
32
|
+
make install
|
33
|
+
gem install bundler --no-ri --no-rdoc
|
34
|
+
popd
|
35
|
+
popd
|
36
|
+
|
37
|
+
Install this software (as non-root):
|
38
|
+
|
39
|
+
git clone https://github.com/paoolo/migratio.git /home/atmosphere/migratio
|
40
|
+
cd /home/atmosphere/migratio
|
41
|
+
cp /home/atmosphere/migratio/config.yml.example /home/atmosphere/migratio/config.yml
|
42
|
+
|
43
|
+
Edit config file, set proper ``redis_url`` and name first row in queues with proper, unique name:
|
44
|
+
|
45
|
+
nano /home/atmosphere/migratio/config.yml
|
46
|
+
|
47
|
+
Install gems:
|
48
|
+
|
49
|
+
pushd /home/atmosphere/migratio
|
50
|
+
bundle install --path vendor/bundle
|
51
|
+
popd
|
52
|
+
|
53
|
+
Enable upstart for non-root user (as root):
|
54
|
+
|
55
|
+
nano /etc/dbus-1/system.d/Upstart.conf
|
56
|
+
|
57
|
+
It should looks like this:
|
58
|
+
|
59
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
60
|
+
<!DOCTYPE busconfig PUBLIC
|
61
|
+
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
62
|
+
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
63
|
+
|
64
|
+
<busconfig>
|
65
|
+
<!-- Only the root user can own the Upstart name -->
|
66
|
+
<policy user="root">
|
67
|
+
<allow own="com.ubuntu.Upstart" />
|
68
|
+
</policy>
|
69
|
+
|
70
|
+
<!-- Allow any user to invoke all of the methods on Upstart, its jobs
|
71
|
+
or their instances, and to get and set properties - since Upstart
|
72
|
+
isolates commands by user. -->
|
73
|
+
<policy context="default">
|
74
|
+
<allow send_destination="com.ubuntu.Upstart"
|
75
|
+
send_interface="org.freedesktop.DBus.Introspectable" />
|
76
|
+
<allow send_destination="com.ubuntu.Upstart"
|
77
|
+
send_interface="org.freedesktop.DBus.Properties" />
|
78
|
+
<allow send_destination="com.ubuntu.Upstart"
|
79
|
+
send_interface="com.ubuntu.Upstart0_6" />
|
80
|
+
<allow send_destination="com.ubuntu.Upstart"
|
81
|
+
send_interface="com.ubuntu.Upstart0_6.Job" />
|
82
|
+
<allow send_destination="com.ubuntu.Upstart"
|
83
|
+
send_interface="com.ubuntu.Upstart0_6.Instance" />
|
84
|
+
</policy>
|
85
|
+
</busconfig>
|
86
|
+
|
87
|
+
Install upstart scripts (as non-root, inside migratio directory):
|
88
|
+
|
89
|
+
mkdir -p /home/atmosphere/.init
|
90
|
+
cp -i /home/atmosphere/migratio/support/upstart/*.conf /home/atmosphere/.init/
|
91
|
+
|
92
|
+
Set proper directory for ``migratio/`` and ``migratio/log/``:
|
93
|
+
|
94
|
+
nano /home/atmosphere/.init/migration.conf
|
95
|
+
nano /home/atmosphere/.init/migratio-1.conf
|
96
|
+
|
97
|
+
Update profile files (eg. ``.bash_profile``):
|
98
|
+
|
99
|
+
cat >> /home/atmosphere/.bash_profile <<EOL
|
100
|
+
if [ ! -f /var/run/user/\$(id -u)/upstart/sessions/*.session ]
|
101
|
+
then
|
102
|
+
/sbin/init --user --confdir \${HOME}/.init &
|
103
|
+
fi
|
104
|
+
|
105
|
+
if [ -f /var/run/user/\$(id -u)/upstart/sessions/*.session ]
|
106
|
+
then
|
107
|
+
export \$(cat /var/run/user/\$(id -u)/upstart/sessions/*.session)
|
108
|
+
fi
|
109
|
+
EOL
|
110
|
+
# you need to re-login to apply changes in /home/atmosphere/.bash_profile
|
111
|
+
|
112
|
+
## Usage
|
113
|
+
|
114
|
+
First time run (as non-root, inside ``migratio/`` directory):
|
115
|
+
|
116
|
+
pushd /home/atmosphere/migratio
|
117
|
+
bundle exec ./bin/run
|
118
|
+
popd
|
119
|
+
|
120
|
+
Normal run (as non-root):
|
121
|
+
|
122
|
+
start migration
|
123
|
+
|
124
|
+
Stop (as non-root):
|
125
|
+
|
126
|
+
stop migration
|
127
|
+
|
128
|
+
## Contributing
|
129
|
+
|
130
|
+
1. Fork it!
|
131
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
132
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
133
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
134
|
+
5. Create a new *Pull Request*
|
data/Rakefile
ADDED
data/bin/migratio-client
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'sidekiq'
|
4
|
+
|
5
|
+
require_relative '../lib/migration/worker/openstack_amazon_migrator'
|
6
|
+
require_relative '../lib/migration/worker/openstack_openstack_migrator'
|
7
|
+
require_relative '../lib/migration/config'
|
8
|
+
require_relative '../lib/migration/worker'
|
9
|
+
|
10
|
+
Sidekiq.configure_client do |c|
|
11
|
+
c.redis = { :namespace => Migration::Worker.config.namespace, :url => Migration::Worker.config.redis_url, queue: Migration::Worker.config.queue }
|
12
|
+
end
|
13
|
+
|
14
|
+
Sidekiq::Client.push('queue' => 'cyfronet', 'class' => Migration::Worker::AmazonExporter, 'args' => [])
|
15
|
+
Sidekiq::Client.push('queue' => 'cyfronet', 'class' => Migration::Worker::OpenstackExporter, 'args' => [])
|
data/bin/migratio-run
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'sidekiq'
|
4
|
+
require_relative '../lib/migration/worker'
|
5
|
+
|
6
|
+
RUNNER_PATH = File.join(ROOT_PATH, 'lib', 'migration', 'runner.rb')
|
7
|
+
|
8
|
+
def queue
|
9
|
+
"migration_#{Migration::Worker.config.name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
system "sidekiq -q #{queue} -c 1 -r #{RUNNER_PATH}"
|
data/config.yml.example
ADDED
data/config/amazon.conf
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export AWS_REGION=eu-west-1
|
data/config/vienna.conf
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
4
|
+
|
5
|
+
module Migratio
|
6
|
+
class Config
|
7
|
+
def initialize(path=nil)
|
8
|
+
config_path = path || default_config_path
|
9
|
+
|
10
|
+
if File.exists?(config_path)
|
11
|
+
@config = YAML.load_file(config_path)
|
12
|
+
else
|
13
|
+
@config = {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def redis_url
|
18
|
+
@config['redis_url'] || 'redis://localhost:6379'
|
19
|
+
end
|
20
|
+
|
21
|
+
def namespace
|
22
|
+
@config['namespace'] || 'air'
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
@config['name'] || 'name'
|
27
|
+
end
|
28
|
+
|
29
|
+
def default_config_path
|
30
|
+
File.join(ROOT_PATH, 'config.yml')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sidekiq'
|
3
|
+
|
4
|
+
require_relative 'worker/openstack_amazon_migrator'
|
5
|
+
require_relative 'worker/openstack_openstack_migrator'
|
6
|
+
require_relative 'worker'
|
7
|
+
|
8
|
+
Sidekiq.configure_server do |config|
|
9
|
+
config.redis = { namespace: Migratio::Worker.config.namespace, url:Migratio::Worker.config.redis_url }
|
10
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
|
3
|
+
require_relative 'config'
|
4
|
+
|
5
|
+
module Migratio
|
6
|
+
module Worker
|
7
|
+
def self.config
|
8
|
+
@@config ||= Migratio::Config.new @config_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.config_path
|
12
|
+
@@config_path = config_path
|
13
|
+
@@config = nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
|
3
|
+
module Migratio
|
4
|
+
module Worker
|
5
|
+
class Migrator
|
6
|
+
include Sidekiq::Worker
|
7
|
+
|
8
|
+
def perform(*params)
|
9
|
+
begin
|
10
|
+
perform_action(*params)
|
11
|
+
rescue => e
|
12
|
+
$stderr << "Something bad!\n"
|
13
|
+
$stderr << "#{e}\n"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def perform_action(*params)
|
20
|
+
#by default do nothing
|
21
|
+
end
|
22
|
+
|
23
|
+
def config_file_path(name, type)
|
24
|
+
File.join(config.configs_path, full_name(name, type))
|
25
|
+
end
|
26
|
+
|
27
|
+
def config
|
28
|
+
@config ||= Migratio::Worker.config
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
require_relative 'openstack_amazon_migrator'
|
35
|
+
require_relative 'openstack_openstack_migrator'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'migrator'
|
2
|
+
|
3
|
+
module Migratio
|
4
|
+
module Worker
|
5
|
+
class OpenstackAmazonMigrator < Migrator
|
6
|
+
|
7
|
+
def perform_action(image_uuid, compute_site)
|
8
|
+
dir = File.dirname(__FILE__)
|
9
|
+
output = `#{dir}/../../../scripts/openstack2amazon-convert.sh "#{image_uuid}" "#{dir}/../../../config/#{compute_site}.conf"`
|
10
|
+
Sidekiq::Client.push(
|
11
|
+
'queue' => 'migration_jobs',
|
12
|
+
'class' => 'UpdateMigrationJobStatusWorker',
|
13
|
+
'args' => [image_uuid, config.name, compute_site, output])
|
14
|
+
if $?.exitstatus == 1
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
output = `#{dir}/../../../scripts/openstack2amazon-transfer.sh "#{image_uuid}" "#{dir}/../../../config/#{compute_site}.conf"`
|
19
|
+
Sidekiq::Client.push(
|
20
|
+
'queue' => 'migration_jobs',
|
21
|
+
'class' => 'UpdateMigrationJobStatusWorker',
|
22
|
+
'args' => [image_uuid, config.name, compute_site, output])
|
23
|
+
if $?.exitstatus == 1
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
output = `#{dir}/../../../scripts/openstack2amazon-import.sh "#{image_uuid}" "#{dir}/../../../config/#{compute_site}.conf"`
|
28
|
+
Sidekiq::Client.push(
|
29
|
+
'queue' => 'migration_jobs',
|
30
|
+
'class' => 'UpdateMigrationJobStatusWorker',
|
31
|
+
'args' => [image_uuid, config.name, compute_site, output])
|
32
|
+
if $?.exitstatus == 1
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
36
|
+
output = `#{dir}/../../../scripts/openstack2amazon-register.sh "#{image_uuid}" "#{dir}/../../../config/#{compute_site}.conf"`
|
37
|
+
Sidekiq::Client.push(
|
38
|
+
'queue' => 'migration_jobs',
|
39
|
+
'class' => 'UpdateMigrationJobStatusWorker',
|
40
|
+
'args' => [image_uuid, config.name, compute_site, output])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'migrator'
|
2
|
+
|
3
|
+
module Migratio
|
4
|
+
module Worker
|
5
|
+
class OpenstackOpenstackMigrator < Migrator
|
6
|
+
|
7
|
+
def perform_action(image_uuid, compute_site)
|
8
|
+
dir = File.dirname(__FILE__)
|
9
|
+
output = `#{dir}/../../../scripts/openstack2openstack-transfer.sh "#{image_uuid}" "#{dir}/../../../config/#{compute_site}.conf"`
|
10
|
+
Sidekiq::Client.push(
|
11
|
+
'queue' => 'migration_jobs',
|
12
|
+
'class' => 'UpdateMigrationJobStatusWorker',
|
13
|
+
'args' => [image_uuid, config.name, compute_site, output])
|
14
|
+
if $?.exitstatus == 1
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
output = `#{dir}/../../../scripts/openstack2openstack-register.sh "#{image_uuid}" "#{dir}/../../../config/#{compute_site}.conf"`
|
19
|
+
Sidekiq::Client.push(
|
20
|
+
'queue' => 'migration_jobs',
|
21
|
+
'class' => 'UpdateMigrationJobStatusWorker',
|
22
|
+
'args' => [image_uuid, config.name, compute_site, output])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/migratio.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'migratio/worker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'migratio'
|
8
|
+
spec.version = Migratio::Worker::VERSION
|
9
|
+
spec.authors = ['Paweł Suder']
|
10
|
+
spec.email = ['pawel@suder.info']
|
11
|
+
spec.description = %q{Migration worker}
|
12
|
+
spec.summary = %q{Worker is responsible for migrating virtual machine templates between sites}
|
13
|
+
spec.homepage = 'https://github.com/dice-cyfronet/migratio'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'sidekiq'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
export __dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
4
|
+
|
5
|
+
if [ $# -eq 0 ] || [ $# -eq 1 ]
|
6
|
+
then
|
7
|
+
echo "Bad script params."
|
8
|
+
exit 1
|
9
|
+
fi
|
10
|
+
|
11
|
+
mkdir -p ${__dir}/logs
|
12
|
+
. ~/.creds
|
13
|
+
. $2
|
14
|
+
|
15
|
+
: ${OS_TENANT_NAME:?"Need to set OS_TENANT_NAME non-empty"}
|
16
|
+
: ${OS_USERNAME:?"Need to set OS_USERNAME non-empty"}
|
17
|
+
: ${OS_PASSWORD:?"Need to set OS_PASSWORD non-empty"}
|
18
|
+
: ${OS_AUTH_URL:?"Need to set OS_AUTH_URL non-empty"}
|
19
|
+
|
20
|
+
command -v glance > /dev/null 2>&1 || { echo "No 'glance'" >&2; exit 1; }
|
21
|
+
|
22
|
+
command -v sudo > /dev/null 2>&1 || { echo "No 'sudo'" >&2; exit 1; }
|
23
|
+
command -v qemu-img > /dev/null 2>&1 || { echo "No 'qemu-img'" >&2; exit 1; }
|
24
|
+
|
25
|
+
image_uuid=$1
|
26
|
+
|
27
|
+
image_list=$(glance image-list) &>> ${__dir}/logs/o2a-c.log
|
28
|
+
echo "$(date) [Result for glance image-list]: ${image_list}" &>> ${__dir}/logs/o2a-c.log
|
29
|
+
|
30
|
+
check_local=$(echo "${image_list}" | grep ${image_uuid} | wc -l) &>> ${__dir}/logs/o2a-c.log
|
31
|
+
echo "$(date) [Result for looking for ${image_uuid} in image_list]: ${check_local}" &>> ${__dir}/logs/o2a-c.log
|
32
|
+
|
33
|
+
if [ ${check_local} -eq 1 ]
|
34
|
+
then
|
35
|
+
if [ ! -f /tmp/${image_uuid}.raw ]
|
36
|
+
then
|
37
|
+
__output=$(sudo qemu-img convert -f qcow2 -O raw /var/lib/glance/images/${image_uuid} /tmp/${image_uuid}.raw) &>> ${__dir}/logs/o2a-c.log
|
38
|
+
echo "$(date) [Result for qemu-img convert]: ${__output}" &>> ${__dir}/logs/o2a-c.log
|
39
|
+
fi
|
40
|
+
|
41
|
+
echo "Image converted"
|
42
|
+
exit 0
|
43
|
+
else
|
44
|
+
echo "Requested image not exist."
|
45
|
+
exit 1
|
46
|
+
fi
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
export __dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
4
|
+
|
5
|
+
if [ $# -eq 0 ] || [ $# -eq 1 ]
|
6
|
+
then
|
7
|
+
echo "Usage: $0 <image-uuid> <config-file>"
|
8
|
+
exit 1
|
9
|
+
fi
|
10
|
+
|
11
|
+
mkdir -p ${__dir}/logs
|
12
|
+
. ~/.creds
|
13
|
+
. $2
|
14
|
+
|
15
|
+
: ${AWS_ACCESS_KEY:?"Need to set AWS_ACCESS_KEY non-empty"}
|
16
|
+
: ${AWS_SECRET_KEY:?"Need to set AWS_SECRET_KEY non-empty"}
|
17
|
+
: ${EC2_URL:?"Need to set EC2_URL non-empty"}
|
18
|
+
: ${AWS_REGION:?"Need to set AWS_REGION non-empty"}
|
19
|
+
: ${SOURCE_CS:?"Need to set SOURCE_CS non-empty"}
|
20
|
+
|
21
|
+
command -v ec2-describe-images > /dev/null 2>&1 || { echo "No 'ec2-describe-images' installed" >&2; exit 1; }
|
22
|
+
command -v ec2-describe-conversion-tasks > /dev/null 2>&1 || { echo "No 'ec2-describe-conversion-tasks' installed" >&2; exit 1; }
|
23
|
+
|
24
|
+
image_uuid=$1
|
25
|
+
|
26
|
+
if [ -f /tmp/${image_uuid}.raw ]
|
27
|
+
then
|
28
|
+
check_remote=$(ec2-describe-images | grep IMAGE | grep ${image_uuid} | wc -l) &>> ${__dir}/logs/o2a-i.log
|
29
|
+
echo "$(date) [Result for check_remote]: ${check_remote}" &>> ${__dir}/logs/o2a-i.log
|
30
|
+
|
31
|
+
if [ ${check_remote} -eq 0 ]
|
32
|
+
then
|
33
|
+
__output=$(ec2-describe-conversion-tasks | grep ${image_uuid} | sort -k6 | tail -n 1) &>> ${__dir}/logs/o2a-i.log
|
34
|
+
echo "$(date) [Result for ec2-describe-conversion-tasks]: ${__output}" &>> ${__dir}/logs/o2a-i.log
|
35
|
+
|
36
|
+
if [ ! -z "${__output}" ]
|
37
|
+
then
|
38
|
+
if [[ ${__output} == *Pending* ]]
|
39
|
+
then
|
40
|
+
instance=$(echo ${__output} | cut -f 12 -d " ") &>> ${__dir}/logs/o2a-i.log
|
41
|
+
elif [[ ${__output} == *Progress* ]]
|
42
|
+
then
|
43
|
+
instance=$(echo ${__output} | cut -f 13 -d " ") &>> ${__dir}/logs/o2a-i.log
|
44
|
+
elif [[ ${__output} == *complete* ]]
|
45
|
+
then
|
46
|
+
instance=$(echo ${__output} | cut -f 10 -d " ") &>> ${__dir}/logs/o2a-i.log
|
47
|
+
fi
|
48
|
+
|
49
|
+
echo "$(date) [Result for instance]: ${instance}" &>> ${__dir}/logs/o2a-i.log
|
50
|
+
|
51
|
+
until echo ${__output} | grep -E complete
|
52
|
+
do
|
53
|
+
sleep 30
|
54
|
+
__output=$(ec2-describe-conversion-tasks | grep ${instance}) &>> ${__dir}/logs/o2a-i.log
|
55
|
+
echo "$(date) [Result for ec2-describe-conversion-tasks]: ${__output}" &>> ${__dir}/logs/o2a-i.log
|
56
|
+
done
|
57
|
+
|
58
|
+
sleep 30
|
59
|
+
echo "Image imported"
|
60
|
+
exit 0
|
61
|
+
else
|
62
|
+
echo "Image was not uploaded."
|
63
|
+
exit 1
|
64
|
+
fi
|
65
|
+
else
|
66
|
+
echo "Requested image was uploaded."
|
67
|
+
exit 1
|
68
|
+
fi
|
69
|
+
else
|
70
|
+
echo "Image was not converted."
|
71
|
+
exit 1
|
72
|
+
fi
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
export __dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
4
|
+
|
5
|
+
if [ $# -eq 0 ] || [ $# -eq 1 ]
|
6
|
+
then
|
7
|
+
echo "Usage: $0 <image-uuid> <config-file>"
|
8
|
+
exit 1
|
9
|
+
fi
|
10
|
+
|
11
|
+
mkdir -p ${__dir}/logs
|
12
|
+
. ~/.creds
|
13
|
+
. $2
|
14
|
+
|
15
|
+
: ${AWS_ACCESS_KEY:?"Need to set AWS_ACCESS_KEY non-empty"}
|
16
|
+
: ${AWS_SECRET_KEY:?"Need to set AWS_SECRET_KEY non-empty"}
|
17
|
+
: ${EC2_URL:?"Need to set EC2_URL non-empty"}
|
18
|
+
: ${AWS_REGION:?"Need to set AWS_REGION non-empty"}
|
19
|
+
: ${SOURCE_CS:?"Need to set SOURCE_CS non-empty"}
|
20
|
+
|
21
|
+
command -v glance > /dev/null 2>&1 || { echo "No 'glance'" >&2; exit 1; }
|
22
|
+
|
23
|
+
command -v ec2-describe-images > /dev/null 2>&1 || { echo "No 'ec2-describe-images' installed" >&2; exit 1; }
|
24
|
+
command -v ec2-describe-conversion-tasks > /dev/null 2>&1 || { echo "No 'ec2-describe-conversion-tasks' installed" >&2; exit 1; }
|
25
|
+
|
26
|
+
command -v ec2-import-instance > /dev/null 2>&1 || { echo "No 'ec2-import-instance' installed" >&2; exit 1; }
|
27
|
+
command -v ec2-create-image > /dev/null 2>&1 || { echo "No 'ec2-create-image' installed" >&2; exit 1; }
|
28
|
+
command -v ec2-create-tags > /dev/null 2>&1 || { echo "No 'ec2-create-tags' installed" >&2; exit 1; }
|
29
|
+
|
30
|
+
image_uuid=$1
|
31
|
+
|
32
|
+
image_list=$(glance image-list) &>> ${__dir}/logs/o2a-r.log
|
33
|
+
echo "$(date) [Result for glance image-list]: ${image_list}" &>> ${__dir}/logs/o2a-r.log
|
34
|
+
|
35
|
+
image_name=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $3}' | sed -e 's/^ *//' -e 's/ *$//') &>> ${__dir}/logs/o2a-r.log
|
36
|
+
echo "$(date) [Result for image_name]: ${image_name}" &>> ${__dir}/logs/o2a-r.log
|
37
|
+
|
38
|
+
if [ -f /tmp/${image_uuid}.raw ]
|
39
|
+
then
|
40
|
+
check_remote=$(ec2-describe-images | grep IMAGE | grep ${image_uuid} | wc -l) &>> ${__dir}/logs/o2a-r.log
|
41
|
+
echo "$(date) [Result for check_remote]: ${check_remote}" &>> ${__dir}/logs/o2a-r.log
|
42
|
+
|
43
|
+
if [ ${check_remote} -eq 0 ]
|
44
|
+
then
|
45
|
+
__output=$(ec2-describe-conversion-tasks | grep ${image_uuid} | sort -k6 | tail -n 1) &>> ${__dir}/logs/o2a-r.log
|
46
|
+
echo "$(date) [Result for ec2-describe-conversion-tasks]: ${__output}" &>> ${__dir}/logs/o2a-r.log
|
47
|
+
|
48
|
+
if [ ! -z "${__output}" ]
|
49
|
+
then
|
50
|
+
instance=$(echo ${__output} | cut -f 10 -d " ") &>> ${__dir}/logs/o2a-r.log
|
51
|
+
task_import=$(echo ${__output} | cut -f 4 -d " ") &>> ${__dir}/logs/o2a-r.log
|
52
|
+
__output=$(ec2-create-image -n "${image_name}-${image_uuid}" -d "${image_name}-${image_uuid}" ${instance}) &>> ${__dir}/logs/o2a-r.log
|
53
|
+
echo "$(date) [Result for ec2-create-image]: ${__output}" &>> ${__dir}/logs/o2a-r.log
|
54
|
+
|
55
|
+
sleep 30
|
56
|
+
|
57
|
+
__ami_id=$(ec2-describe-images | grep ${image_uuid} | awk '{print $2}') &>> ${__dir}/logs/o2a-r.log
|
58
|
+
echo "$(date) [Result for ec2-describe-images]: ${__ami_id}" &>> ${__dir}/logs/o2a-r.log
|
59
|
+
|
60
|
+
until [ -n "${__ami_id}" ]
|
61
|
+
do
|
62
|
+
sleep 30
|
63
|
+
__ami_id=$(ec2-describe-images | grep ${image_uuid} | awk '{print $2}') &>> ${__dir}/logs/o2a-r.log
|
64
|
+
echo "$(date) [Result for ec2-describe-images]: ${__ami_id}" &>> ${__dir}/logs/o2a-r.log
|
65
|
+
done
|
66
|
+
|
67
|
+
__output=$(ec2-create-tags ${__ami_id} --tag source_cs=${SOURCE_CS} --tag source_uuid=${image_uuid} --tag Name="${image_name}-${image_uuid}") &>> ${__dir}/logs/o2a-r.log
|
68
|
+
echo "$(date) [Result for ec2-create-tags]: ${__output}" &>> ${__dir}/logs/o2a-r.log
|
69
|
+
|
70
|
+
__output=$(rm -f /tmp/${image_uuid}.raw*) &>> ${__dir}/logs/o2a-r.log
|
71
|
+
echo "$(date) [Result for rm]: ${__output}" &>> ${__dir}/logs/o2a-r.log
|
72
|
+
|
73
|
+
__output=$(ec2-delete-disk-image -t ${task_import} -o ${AWS_ACCESS_KEY} -w ${AWS_SECRET_KEY})
|
74
|
+
echo "$(date) [Result for ec2-delete-disk-image]: ${__output}" &>> ${__dir}/logs/o2a-r.log
|
75
|
+
|
76
|
+
volume=$(ec2-describe-instances ${instance} | grep vol | awk '{print $3}') &>> ${__dir}/logs/o2a-r.log
|
77
|
+
echo "$(date) [Result for ec2-describe-instances]: ${volume}"
|
78
|
+
|
79
|
+
__output=$(ec2-terminate-instances ${instance}) &>> ${__dir}/logs/o2a-r.log
|
80
|
+
echo "$(date) [Result for ec2-terminate-instances]: ${__output}" &>> ${__dir}/logs/o2a-r.log
|
81
|
+
|
82
|
+
sleep 30
|
83
|
+
|
84
|
+
__output=$(ec2-delete-volume ${volume}) &>> ${__dir}/logs/o2a-r.log
|
85
|
+
echo "$(date) [Result for ec2-delete-volume]: ${__output}" &>> ${__dir}/logs/o2a-r.log
|
86
|
+
|
87
|
+
__output=$(aws s3 rm --recursive s3://import-image-${image_uuid}/) &>> ${__dir}/logs/o2a-r.log
|
88
|
+
echo "$(date) [Result for aws s3 rm]: ${__output}" &>> ${__dir}/logs/o2a-r.log
|
89
|
+
|
90
|
+
echo "Registered image"
|
91
|
+
exit 0
|
92
|
+
else
|
93
|
+
echo "Image was not uploaded."
|
94
|
+
exit 1
|
95
|
+
fi
|
96
|
+
else
|
97
|
+
echo "Requested image was uploaded."
|
98
|
+
exit 1
|
99
|
+
fi
|
100
|
+
else
|
101
|
+
echo "Image not converted."
|
102
|
+
exit 1
|
103
|
+
fi
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
export __dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
4
|
+
|
5
|
+
if [ $# -eq 0 ] || [ $# -eq 1 ]
|
6
|
+
then
|
7
|
+
echo "Usage: $0 <image-uuid> <config-file>"
|
8
|
+
exit 1
|
9
|
+
fi
|
10
|
+
|
11
|
+
. ~/.creds
|
12
|
+
. $2
|
13
|
+
|
14
|
+
: ${AWS_ACCESS_KEY:?"Need to set AWS_ACCESS_KEY non-empty"}
|
15
|
+
: ${AWS_SECRET_KEY:?"Need to set AWS_SECRET_KEY non-empty"}
|
16
|
+
: ${EC2_URL:?"Need to set EC2_URL non-empty"}
|
17
|
+
: ${AWS_REGION:?"Need to set AWS_REGION non-empty"}
|
18
|
+
: ${SOURCE_CS:?"Need to set SOURCE_CS non-empty"}
|
19
|
+
|
20
|
+
command -v ec2-describe-images > /dev/null 2>&1 || { echo "No 'ec2-describe-images' installed" >&2; exit 1; }
|
21
|
+
command -v ec2-import-instance > /dev/null 2>&1 || { echo "No 'ec2-import-instance' installed" >&2; exit 1; }
|
22
|
+
|
23
|
+
image_uuid=$1
|
24
|
+
|
25
|
+
image_list=$(glance image-list) &>> ${__dir}/logs/o2a-t.log
|
26
|
+
echo "$(date) [Result for glance image-list]: ${image_list}" &>> ${__dir}/logs/o2a-t.log
|
27
|
+
|
28
|
+
if [ -f /tmp/${image_uuid}.raw ]
|
29
|
+
then
|
30
|
+
check_remote=$(ec2-describe-images | grep IMAGE | grep ${image_uuid} | wc -l) &>> ${__dir}/logs/o2a-t.log
|
31
|
+
echo "$(date) [Result for check_remote]: ${check_remote}" &>> ${__dir}/logs/o2a-t.log
|
32
|
+
|
33
|
+
if [ ${check_remote} -eq 0 ]
|
34
|
+
then
|
35
|
+
image_name=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $3}' | sed -e 's/^ *//' -e 's/ *$//') &>> ${__dir}/logs/o2a-t.log
|
36
|
+
echo "$(date) [Result for image_name]: ${image_name}" &>> ${__dir}/logs/o2a-t.log
|
37
|
+
|
38
|
+
__output=$(ec2-import-instance /tmp/${image_uuid}.raw -f RAW -b import-image-${image_uuid} -p Linux --region ${AWS_REGION} -t m3.medium -a x86_64 -d "${image_name}-${image_uuid}" -o ${AWS_ACCESS_KEY} -w ${AWS_SECRET_KEY}) &>> ${__dir}/logs/o2a-t.log
|
39
|
+
echo "$(date) [Result for ec2-import-instance]: ${__output}" &>> ${__dir}/logs/o2a-t.log
|
40
|
+
|
41
|
+
sleep 30
|
42
|
+
echo "Image transfered"
|
43
|
+
exit 0
|
44
|
+
else
|
45
|
+
echo "Requested image was uploaded."
|
46
|
+
exit 1
|
47
|
+
fi
|
48
|
+
else
|
49
|
+
echo "Image not converted."
|
50
|
+
exit 1
|
51
|
+
fi
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -x
|
4
|
+
|
5
|
+
export __dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
6
|
+
|
7
|
+
if [ $# -eq 0 ] || [ $# -eq 1 ]
|
8
|
+
then
|
9
|
+
echo "Usage: $0 <image-uuid> <config-file>"
|
10
|
+
exit 1
|
11
|
+
fi
|
12
|
+
|
13
|
+
. ~/.creds
|
14
|
+
. $2
|
15
|
+
|
16
|
+
: ${OS_TENANT_NAME:?"Need to set OS_TENANT_NAME non-empty"}
|
17
|
+
: ${OS_USERNAME:?"Need to set OS_USERNAME non-empty"}
|
18
|
+
: ${OS_PASSWORD:?"Need to set OS_PASSWORD non-empty"}
|
19
|
+
: ${OS_AUTH_URL:?"Need to set OS_AUTH_URL non-empty"}
|
20
|
+
|
21
|
+
: ${AWS_ACCESS_KEY:?"Need to set AWS_ACCESS_KEY non-empty"}
|
22
|
+
: ${AWS_SECRET_KEY:?"Need to set AWS_SECRET_KEY non-empty"}
|
23
|
+
: ${EC2_URL:?"Need to set EC2_URL non-empty"}
|
24
|
+
: ${AWS_REGION:?"Need to set AWS_REGION non-empty"}
|
25
|
+
: ${SOURCE_CS:?"Need to set SOURCE_CS non-empty"}
|
26
|
+
|
27
|
+
command -v glance > /dev/null 2>&1 || { echo "Need to have 'glance'" >&2; exit 1; }
|
28
|
+
|
29
|
+
command -v sudo > /dev/null 2>&1 || { echo "Need to have 'sudo'" >&2; exit 1; }
|
30
|
+
command -v qemu-img > /dev/null 2>&1 || { echo "Need to have 'qemu-img'" >&2; exit 1; }
|
31
|
+
|
32
|
+
command -v ec2-import-instance > /dev/null 2>&1 || { echo "Need to have 'ec2-import-instance'" >&2; exit 1; }
|
33
|
+
command -v ec2-describe-conversion-tasks > /dev/null 2>&1 || { echo "Need to have 'ec2-describe-conversion-tasks'" >&2; exit 1; }
|
34
|
+
command -v ec2-create-image > /dev/null 2>&1 || { echo "Need to have 'ec2-create-image'" >&2; exit 1; }
|
35
|
+
command -v ec2-describe-images > /dev/null 2>&1 || { echo "Need to have 'ec2-describe-image'" >&2; exit 1; }
|
36
|
+
command -v ec2-create-tags > /dev/null 2>&1 || { echo "Need to have 'ec2-create-tags'" >&2; exit 1; }
|
37
|
+
|
38
|
+
image_uuid=$1
|
39
|
+
image_list=$(glance image-list)
|
40
|
+
|
41
|
+
check_local=$(echo "${image_list}" | grep ${image_uuid} | wc -l)
|
42
|
+
|
43
|
+
if [ ${check_local} -eq 1 ]
|
44
|
+
then
|
45
|
+
image_name=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $3}' | sed -e 's/^ *//' -e 's/ *$//')
|
46
|
+
hash_sum=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1)
|
47
|
+
|
48
|
+
if [ ! -f /tmp/${image_uuid}.raw ]
|
49
|
+
then
|
50
|
+
sudo qemu-img convert -f qcow2 -O raw /var/lib/glance/images/${image_uuid} /tmp/${image_uuid}.raw
|
51
|
+
fi
|
52
|
+
|
53
|
+
check_remote=$(ec2-describe-images | grep IMAGE | grep ${image_uuid} | wc -l)
|
54
|
+
if [ ${check_remote} -eq 0 ]
|
55
|
+
then
|
56
|
+
ec2-import-instance /tmp/${image_uuid}.raw -f RAW -b imported-images -p Linux --region ${AWS_REGION} -t m3.medium -a x86_64 -d ${image_uuid}-${hash_sum} -o ${AWS_ACCESS_KEY} -w ${AWS_SECRET_KEY}
|
57
|
+
echo "Transfered"
|
58
|
+
|
59
|
+
sleep 30
|
60
|
+
|
61
|
+
__output=$(ec2-describe-conversion-tasks | grep ${image_uuid}-${hash_sum})
|
62
|
+
|
63
|
+
if [ ! -z "${__output}" ]
|
64
|
+
then
|
65
|
+
instance=$(echo ${__output} | cut -f 12 -d " ")
|
66
|
+
|
67
|
+
until echo ${__output} | grep -E complete
|
68
|
+
do
|
69
|
+
sleep 30
|
70
|
+
__output=$(ec2-describe-conversion-tasks | grep ${instance})
|
71
|
+
done
|
72
|
+
|
73
|
+
sleep 30
|
74
|
+
|
75
|
+
ec2-create-image -n ${image_uuid}-${hash_sum} -d "${image_name}-${image_uuid}-${hash_sum}" ${instance}
|
76
|
+
|
77
|
+
sleep 30
|
78
|
+
|
79
|
+
__ami_id=$(ec2-describe-images | grep ${image_uuid}-${hash_sum} | awk '{print $2}')
|
80
|
+
until [ -n "${__ami_id}" ]
|
81
|
+
do
|
82
|
+
sleep 30
|
83
|
+
__ami_id=$(ec2-describe-images | grep ${image_uuid}-${hash_sum} | awk '{print $2}')
|
84
|
+
done
|
85
|
+
|
86
|
+
ec2-create-tags ${__ami_id} --tag source_cs=${SOURCE_CS} --tag source_uuid=${image_uuid} --tag Name="${image_name}-${image_uuid}-${hash_sum}"
|
87
|
+
echo "Registered"
|
88
|
+
|
89
|
+
rm -f /tmp/${image_uuid}.raw
|
90
|
+
exit 0
|
91
|
+
else
|
92
|
+
echo "Image was not uploaded."
|
93
|
+
exit 1
|
94
|
+
fi
|
95
|
+
else
|
96
|
+
echo "Requested image was uploaded."
|
97
|
+
exit 1
|
98
|
+
fi
|
99
|
+
else
|
100
|
+
echo "Requested image not exist."
|
101
|
+
exit 1
|
102
|
+
fi
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
export __dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
4
|
+
|
5
|
+
if [ $# -eq 0 ] || [ $# -eq 1 ]
|
6
|
+
then
|
7
|
+
echo "Usage: $0 <image-uuid> <config-file>"
|
8
|
+
exit 1
|
9
|
+
fi
|
10
|
+
|
11
|
+
mkdir -p ${__dir}/logs
|
12
|
+
. ~/.creds
|
13
|
+
. $2
|
14
|
+
|
15
|
+
: ${OS_TENANT_NAME:?"Need to set OS_TENANT_NAME non-empty"}
|
16
|
+
: ${OS_USERNAME:?"Need to set OS_USERNAME non-empty"}
|
17
|
+
: ${OS_PASSWORD:?"Need to set OS_PASSWORD non-empty"}
|
18
|
+
: ${OS_AUTH_URL:?"Need to set OS_AUTH_URL non-empty"}
|
19
|
+
|
20
|
+
: ${IMAGES_DIR:?"Need to set IMAGES_DIR non-empty"}
|
21
|
+
|
22
|
+
: ${EXTERNAL_USER:?"Need to set EXTERNAL_USER non-empty"}
|
23
|
+
: ${EXTERNAL_HOST:?"Need to set EXTERNAL_HOST non-empty"}
|
24
|
+
: ${SOURCE_CS:?"Need to set SOURCE_CS non-empty"}
|
25
|
+
|
26
|
+
command -v glance > /dev/null 2>&1 || { echo "No 'glance' installed" >&2; exit 1; }
|
27
|
+
command -v rsync > /dev/null 2>&1 || { echo "No 'rsync' installed" >&2; exit 1; }
|
28
|
+
command -v ssh > /dev/null 2>&1 || { echo "No 'ssh' installed" >&2; exit 1; }
|
29
|
+
|
30
|
+
ssh ${EXTERNAL_USER}@${EXTERNAL_HOST} command -v glance > /dev/null 2>&1 || { echo "No 'glance' on external host" >&2; exit 1; }
|
31
|
+
|
32
|
+
image_uuid=$1
|
33
|
+
|
34
|
+
image_list=$(glance image-list) &>> ${__dir}/logs/o2o-r.log
|
35
|
+
echo "$(date) [Result for image_list]: ${image_list}" &>> ${__dir}/logs/o2o-r.log
|
36
|
+
|
37
|
+
check_local=$(echo "${image_list}" | grep ${image_uuid} | wc -l) &>> ${__dir}/logs/o2o-r.log
|
38
|
+
echo "$(date) [Result for check_local]: ${check_local}" &>> ${__dir}/logs/o2o-r.log
|
39
|
+
|
40
|
+
if [ ${check_local} -eq 1 ]
|
41
|
+
then
|
42
|
+
remote_checksums=$(ssh ${EXTERNAL_USER}@${EXTERNAL_HOST} \
|
43
|
+
"source ~/.creds;
|
44
|
+
glance image-list | head -n -1 | tail -n +4 | awk '{print \$2}' | while read remote_image_uuid
|
45
|
+
do
|
46
|
+
glance image-show \${remote_image_uuid} | grep checksum | awk '{print \$4}'
|
47
|
+
done") &>> ${__dir}/logs/o2o-r.log
|
48
|
+
|
49
|
+
checksum=$(glance image-show ${image_uuid} | grep checksum | awk '{print $4}') &>> ${__dir}/logs/o2o-r.log
|
50
|
+
echo "$(date) [Result for checksum]: ${checksum}" &>> ${__dir}/logs/o2o-r.log
|
51
|
+
|
52
|
+
check_remote=$(echo "${remote_checksums}" | grep ${checksum} | wc -l) &>> ${__dir}/logs/o2o-r.log
|
53
|
+
echo "$(date) [Result for check_remote]: ${check_remote}" &>> ${__dir}/logs/o2o-r.log
|
54
|
+
|
55
|
+
if [ ${check_remote} -eq 0 ]
|
56
|
+
then
|
57
|
+
image_name=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $3}' | sed -e 's/^ *//' -e 's/ *$//') &>> ${__dir}/logs/o2o-r.log
|
58
|
+
echo "$(date) [Result for image_name]: ${image_name}" &>> ${__dir}/logs/o2o-r.log
|
59
|
+
|
60
|
+
disk_format=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $4}' | sed -e 's/^ *//' -e 's/ *$//') &>> ${__dir}/logs/o2o-r.log
|
61
|
+
echo "$(date) [Result for disk_format]: ${image_name}" &>> ${__dir}/logs/o2o-r.log
|
62
|
+
|
63
|
+
container_format=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $5}' | sed -e 's/^ *//' -e 's/ *$//') &>> ${__dir}/logs/o2o-r.log
|
64
|
+
echo "$(date) [Result for container_format]: ${container_format}" &>> ${__dir}/logs/o2o-r.log
|
65
|
+
|
66
|
+
ssh ${EXTERNAL_USER}@${EXTERNAL_HOST} \
|
67
|
+
"source ~/.creds;
|
68
|
+
glance image-create \
|
69
|
+
--name \"${image_name}\" \
|
70
|
+
--disk-format ${disk_format} \
|
71
|
+
--container-format ${container_format} \
|
72
|
+
--property source_uuid=${image_uuid} \
|
73
|
+
--property source_cs=${SOURCE_CS} < /tmp/${image_uuid}; \
|
74
|
+
rm -f /tmp/${image_uuid}" &>> ${__dir}/logs/o2o-r.log
|
75
|
+
|
76
|
+
echo "Registered"
|
77
|
+
exit 0
|
78
|
+
else
|
79
|
+
echo "Requested image was uploaded."
|
80
|
+
exit 1
|
81
|
+
fi
|
82
|
+
else
|
83
|
+
echo "Requested image not exist."
|
84
|
+
exit 1
|
85
|
+
fi
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
export __dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
4
|
+
|
5
|
+
if [ $# -eq 0 ] || [ $# -eq 1 ]
|
6
|
+
then
|
7
|
+
echo "Usage: $0 <image-uuid> <config-file>"
|
8
|
+
exit 1
|
9
|
+
fi
|
10
|
+
|
11
|
+
mkdir -p ${__dir}/logs
|
12
|
+
. ~/.creds
|
13
|
+
. $2
|
14
|
+
|
15
|
+
: ${OS_TENANT_NAME:?"Need to set OS_TENANT_NAME non-empty"}
|
16
|
+
: ${OS_USERNAME:?"Need to set OS_USERNAME non-empty"}
|
17
|
+
: ${OS_PASSWORD:?"Need to set OS_PASSWORD non-empty"}
|
18
|
+
: ${OS_AUTH_URL:?"Need to set OS_AUTH_URL non-empty"}
|
19
|
+
|
20
|
+
: ${IMAGES_DIR:?"Need to set IMAGES_DIR non-empty"}
|
21
|
+
|
22
|
+
: ${EXTERNAL_USER:?"Need to set EXTERNAL_USER non-empty"}
|
23
|
+
: ${EXTERNAL_HOST:?"Need to set EXTERNAL_HOST non-empty"}
|
24
|
+
: ${SOURCE_CS:?"Need to set SOURCE_CS non-empty"}
|
25
|
+
|
26
|
+
command -v glance > /dev/null 2>&1 || { echo "No 'glance' installed" >&2; exit 1; }
|
27
|
+
command -v rsync > /dev/null 2>&1 || { echo "No 'rsync' installed" >&2; exit 1; }
|
28
|
+
command -v ssh > /dev/null 2>&1 || { echo "No 'ssh' installed" >&2; exit 1; }
|
29
|
+
|
30
|
+
ssh ${EXTERNAL_USER}@${EXTERNAL_HOST} command -v glance > /dev/null 2>&1 || { echo "No 'glance' on external host" >&2; exit 1; }
|
31
|
+
|
32
|
+
image_uuid=$1
|
33
|
+
|
34
|
+
image_list=$(glance image-list) &>> ${__dir}/logs/o2o-t.log
|
35
|
+
echo "$(date) [Result for image_list]: ${image_list}" &>> ${__dir}/logs/o2o-t.log
|
36
|
+
|
37
|
+
check_local=$(echo "${image_list}" | grep ${image_uuid} | wc -l) &>> ${__dir}/logs/o2o-t.log
|
38
|
+
echo "$(date) [Result for check_local]: ${check_local}" &>> ${__dir}/logs/o2o-t.log
|
39
|
+
|
40
|
+
if [ ${check_local} -eq 1 ]
|
41
|
+
then
|
42
|
+
remote_checksums=$(ssh ${EXTERNAL_USER}@${EXTERNAL_HOST} \
|
43
|
+
"source ~/.creds;
|
44
|
+
glance image-list | head -n -1 | tail -n +4 | awk '{print \$2}' | while read remote_image_uuid
|
45
|
+
do
|
46
|
+
glance image-show \${remote_image_uuid} | grep checksum | awk '{print \$4}'
|
47
|
+
done") &>> ${__dir}/logs/o2o-t.log
|
48
|
+
echo "$(date) [Result for remote_checksums]: ${remote_checksums}" &>> ${__dir}/logs/o2o-t.log
|
49
|
+
|
50
|
+
checksum=$(glance image-show ${image_uuid} | grep checksum | awk '{print $4}') &>> ${__dir}/logs/o2o-t.log
|
51
|
+
echo "$(date) [Result for checksum]: ${checksum}" &>> ${__dir}/logs/o2o-t.log
|
52
|
+
|
53
|
+
check_remote=$(echo "${remote_checksums}" | grep ${checksum} | wc -l) &>> ${__dir}/logs/o2o-t.log
|
54
|
+
echo "$(date) [Result for check_remote]: ${check_remote}" &>> ${__dir}/logs/o2o-t.log
|
55
|
+
|
56
|
+
if [ ${check_remote} -eq 0 ]
|
57
|
+
then
|
58
|
+
rsync ${IMAGES_DIR}/${image_uuid} \
|
59
|
+
${EXTERNAL_USER}@${EXTERNAL_HOST}:/tmp/${image_uuid} &>> ${__dir}/logs/o2o-t.log
|
60
|
+
|
61
|
+
echo "Transfered"
|
62
|
+
exit 0
|
63
|
+
else
|
64
|
+
echo "Requested image was uploaded."
|
65
|
+
exit 1
|
66
|
+
fi
|
67
|
+
else
|
68
|
+
echo "Requested image not exist."
|
69
|
+
exit 1
|
70
|
+
fi
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -x
|
4
|
+
|
5
|
+
export __dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
6
|
+
|
7
|
+
if [ $# -eq 0 ] || [ $# -eq 1 ]
|
8
|
+
then
|
9
|
+
echo "Usage: $0 <image-uuid> <config-file>"
|
10
|
+
exit 1
|
11
|
+
fi
|
12
|
+
|
13
|
+
. ~/.creds
|
14
|
+
. $2
|
15
|
+
|
16
|
+
: ${OS_TENANT_NAME:?"Need to set OS_TENANT_NAME non-empty"}
|
17
|
+
: ${OS_USERNAME:?"Need to set OS_USERNAME non-empty"}
|
18
|
+
: ${OS_PASSWORD:?"Need to set OS_PASSWORD non-empty"}
|
19
|
+
: ${OS_AUTH_URL:?"Need to set OS_AUTH_URL non-empty"}
|
20
|
+
|
21
|
+
: ${IMAGES_DIR:?"Need to set IMAGES_DIR non-empty"}
|
22
|
+
|
23
|
+
: ${EXTERNAL_USER:?"Need to set EXTERNAL_USER non-empty"}
|
24
|
+
: ${EXTERNAL_HOST:?"Need to set EXTERNAL_HOST non-empty"}
|
25
|
+
: ${SOURCE_CS:?"Need to set SOURCE_CS non-empty"}
|
26
|
+
|
27
|
+
command -v glance > /dev/null 2>&1 || { echo "Need to have 'glance'" >&2; exit 1; }
|
28
|
+
command -v rsync > /dev/null 2>&1 || { echo "Need to have 'rsync'" >&2; exit 1; }
|
29
|
+
command -v ssh > /dev/null 2>&1 || { echo "Need to have 'ssh'" >&2; exit 1; }
|
30
|
+
|
31
|
+
ssh ${EXTERNAL_USER}@${EXTERNAL_HOST} command -v glance > /dev/null 2>&1 || { echo "Need to have 'glance' on external host" >&2; exit 1; }
|
32
|
+
|
33
|
+
image_uuid=$1
|
34
|
+
image_list=$(glance image-list)
|
35
|
+
|
36
|
+
check_local=$(echo "${image_list}" | grep ${image_uuid} | wc -l)
|
37
|
+
|
38
|
+
if [ ${check_local} -eq 1 ]
|
39
|
+
then
|
40
|
+
remote_checksums=$(ssh ${EXTERNAL_USER}@${EXTERNAL_HOST} \
|
41
|
+
"source ~/.creds;
|
42
|
+
glance image-list | head -n -1 | tail -n +4 | awk '{print \$2}' | while read remote_image_uuid
|
43
|
+
do
|
44
|
+
glance image-show \${remote_image_uuid} | grep checksum | awk '{print \$4}'
|
45
|
+
done")
|
46
|
+
|
47
|
+
checksum=$(glance image-show ${image_uuid} | grep checksum | awk '{print $4}')
|
48
|
+
check_remote=$(echo "${remote_checksums}" | grep ${checksum} | wc -l)
|
49
|
+
|
50
|
+
if [ ${check_remote} -eq 0 ]
|
51
|
+
then
|
52
|
+
image_name=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $3}' | sed -e 's/^ *//' -e 's/ *$//')
|
53
|
+
disk_format=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $4}' | sed -e 's/^ *//' -e 's/ *$//')
|
54
|
+
container_format=$(echo "${image_list}" | grep ${image_uuid} | awk -F'|' '{print $5}' | sed -e 's/^ *//' -e 's/ *$//')
|
55
|
+
hash_sum=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1)
|
56
|
+
|
57
|
+
rsync ${IMAGES_DIR}/${image_uuid} \
|
58
|
+
${EXTERNAL_USER}@${EXTERNAL_HOST}:/tmp/${image_uuid}-${hash_sum}
|
59
|
+
echo "Transfered"
|
60
|
+
|
61
|
+
ssh ${EXTERNAL_USER}@${EXTERNAL_HOST} \
|
62
|
+
"source ~/.creds;
|
63
|
+
glance image-create \
|
64
|
+
--name \"${image_name}-${hash_sum}\" \
|
65
|
+
--disk-format ${disk_format} \
|
66
|
+
--container-format ${container_format} \
|
67
|
+
--property source_uuid=${image_uuid} \
|
68
|
+
--property source_cs=${SOURCE_CS} < /tmp/${image_uuid}-${hash_sum}; \
|
69
|
+
rm -f /tmp/${image_uuid}-${hash_sum}"
|
70
|
+
echo "Registered"
|
71
|
+
exit 0
|
72
|
+
else
|
73
|
+
echo "Requested image was uploaded."
|
74
|
+
exit 1
|
75
|
+
fi
|
76
|
+
else
|
77
|
+
echo "Requested image not exist."
|
78
|
+
exit 1
|
79
|
+
fi
|
@@ -0,0 +1,31 @@
|
|
1
|
+
start on starting migration-worker
|
2
|
+
stop on stopping migration-worker
|
3
|
+
respawn
|
4
|
+
|
5
|
+
setuid atmosphere
|
6
|
+
chdir /home/atmosphere/migration-worker
|
7
|
+
|
8
|
+
script
|
9
|
+
# this script runs in /bin/sh by default
|
10
|
+
# respawn as bash so we can source in rbenv
|
11
|
+
exec /bin/bash <<EOT
|
12
|
+
# uncomment to use syslog for logging
|
13
|
+
# exec &> /dev/kmsg
|
14
|
+
|
15
|
+
export HOME=/home/atmosphere
|
16
|
+
export PATH="/home/atmosphere/.rbenv/bin:/home/atmosphere/.rbenv/shims:$PATH"
|
17
|
+
|
18
|
+
# Pick your poison :) Or none if you're using a system wide installed Ruby.
|
19
|
+
# rbenv
|
20
|
+
source $HOME/.bash_profile
|
21
|
+
# OR
|
22
|
+
# source /home/apps/.profile
|
23
|
+
# OR system:
|
24
|
+
# source /etc/profile.d/rbenv.sh
|
25
|
+
#
|
26
|
+
# rvm
|
27
|
+
# source /home/apps/.rvm/scripts/rvm
|
28
|
+
|
29
|
+
exec bundle exec ./bin/run >> /home/atmosphere/migration-worker/log/migration-worker.log 2>&1
|
30
|
+
EOT
|
31
|
+
end script
|
@@ -0,0 +1,12 @@
|
|
1
|
+
pre-start script
|
2
|
+
mkdir -p /home/atmosphere/migration-worker/log
|
3
|
+
chown -R atmosphere /home/atmosphere/migration-worker/log
|
4
|
+
end script
|
5
|
+
|
6
|
+
start on (started network-interface
|
7
|
+
or started network-manager
|
8
|
+
or started networking)
|
9
|
+
|
10
|
+
stop on (stopping network-interface
|
11
|
+
or stopping network-manager
|
12
|
+
or stopping networking)
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: migratio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paweł Suder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sidekiq
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Migration worker
|
56
|
+
email:
|
57
|
+
- pawel@suder.info
|
58
|
+
executables:
|
59
|
+
- migratio-client
|
60
|
+
- migratio-run
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/migratio-client
|
70
|
+
- bin/migratio-run
|
71
|
+
- config.yml.example
|
72
|
+
- config/amazon.conf
|
73
|
+
- config/cyfronet-folsom.conf
|
74
|
+
- config/cyfronet-icehouse.conf
|
75
|
+
- config/vienna.conf
|
76
|
+
- lib/migratio/config.rb
|
77
|
+
- lib/migratio/runner.rb
|
78
|
+
- lib/migratio/worker.rb
|
79
|
+
- lib/migratio/worker/migrator.rb
|
80
|
+
- lib/migratio/worker/openstack_amazon_migrator.rb
|
81
|
+
- lib/migratio/worker/openstack_openstack_migrator.rb
|
82
|
+
- lib/migratio/worker/version.rb
|
83
|
+
- migratio.gemspec
|
84
|
+
- scripts/openstack2amazon-convert.sh
|
85
|
+
- scripts/openstack2amazon-import.sh
|
86
|
+
- scripts/openstack2amazon-register.sh
|
87
|
+
- scripts/openstack2amazon-transfer.sh
|
88
|
+
- scripts/openstack2amazon.sh
|
89
|
+
- scripts/openstack2openstack-register.sh
|
90
|
+
- scripts/openstack2openstack-transfer.sh
|
91
|
+
- scripts/openstack2openstack.sh
|
92
|
+
- support/upstart/migration-worker-1.conf
|
93
|
+
- support/upstart/migration-worker.conf
|
94
|
+
- support/upstart/migration.conf
|
95
|
+
homepage: https://github.com/dice-cyfronet/migratio
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.2.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Worker is responsible for migrating virtual machine templates between sites
|
119
|
+
test_files: []
|