-
Notifications
You must be signed in to change notification settings - Fork 0
/
automate.rb
executable file
·89 lines (65 loc) · 2.74 KB
/
automate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/opt/rh/ruby193/root/usr/bin/ruby
=begin
#################################################################
automate.rb
This method allow you to sync one of your Cloudforms automation
domain with a GIT repo of your choice.
by Marco Berube
#################################################################
=end
require 'yaml'
yaml_path = File.dirname($0) + '/automate.yaml'
automate_config = YAML.load_file(yaml_path)
# GENERAL CONFIGURATION
BASE = automate_config['general']['base']
DSDUMP_PATH = automate_config['general']['temp']
# GIT CONFIGURATION
GIT_USERNAME = automate_config['git']['username']
GIT_PASSWORD = automate_config['git']['password']
GIT_REPO = automate_config['git']['repo']
GIT_DOMAIN_ROOT = automate_config['git']['domain_root']
GIT_URL = automate_config['git']['url'] + "/#{GIT_USERNAME}/#{GIT_REPO}.git"
GIT_BRANCH = automate_config['git']['branch']
# CFME CONFIGURATION
CFME_DOMAIN = automate_config['cfme']['domain']
#
# EXPORT CLOUDFORMS DATASTORE IN A TEMPORARY FOLDER : #{DSDUMP_PATH}
#
def dsdump()
system ("cd /var/www/miq/vmdb && script/rails runner script/rake evm:automate:backup BACKUP_ZIP_FILE=#{BASE}/backup_exported.zip OVERWRITE=true")
system ("rm -rf #{DSDUMP_PATH}")
system ("mkdir -p #{DSDUMP_PATH}")
system ("unzip /git/backup_exported.zip -d #{DSDUMP_PATH}/")
end
def dsupload()
system ("cd #{DSDUMP_PATH} && zip -r #{BASE}/backup_imported.zip ./*")
system ("cd /var/www/miq/vmdb && script/rails runner script/rake evm:automate:restore BACKUP_ZIP_FILE=#{BASE}/backup_imported.zip")
end
case ARGV[0]
when "dsdump"
dsdump()
when "dsupload"
dsupload()
when "git-pull"
dsdump()
system ("rm -rf #{BASE}/#{GIT_USERNAME}")
system ("mkdir -p #{BASE}/#{GIT_USERNAME}")
system ("cd #{BASE}/#{GIT_USERNAME} && git clone -b #{GIT_BRANCH} https://#{GIT_URL}")
system ("rsync -av #{BASE}/#{GIT_USERNAME}/#{GIT_DOMAIN_ROOT}/#{CFME_DOMAIN} #{DSDUMP_PATH}")
dsupload()
when "git-push"
puts "Enter a comment for this push:"
mycomment = $stdin.gets.chomp
dsdump()
system ("rsync -av #{DSDUMP_PATH}/#{CFME_DOMAIN} #{BASE}/#{GIT_USERNAME}/#{GIT_DOMAIN_ROOT}")
system ("cd #{BASE}/#{GIT_USERNAME}/#{GIT_REPO}/ && git add -A")
system ("cd #{BASE}/#{GIT_USERNAME}/#{GIT_REPO}/ && git commit -m '#{mycomment}'")
system ("cd #{BASE}/#{GIT_USERNAME}/#{GIT_REPO}/ && git remote set-url origin https://#{GIT_USERNAME}:#{GIT_PASSWORD}@#{GIT_URL}")
system ("cd #{BASE}/#{GIT_USERNAME}/#{GIT_REPO}/ && git push")
else
puts "automate <subcommand>"
puts " dsdump Datastore dump in a temporary folder: #{DSDUMP_PATH}"
puts " dsupload Upload datastore from temporary folder to your automate domain"
puts " git-pull Pull git updates into Cloudforms DB"
puts " git-push Push Cloudforms DB updates to git repo"
end