forked from redhat-openstack/openshift-on-openstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customize-disk-image
executable file
·129 lines (104 loc) · 4.77 KB
/
customize-disk-image
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/python
import argparse
import distutils.spawn
import os
import subprocess
import sys
import urllib2
description = 'Customize disk image for Openshift.'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--disk', dest='disk', required=True,
help='disk image to modify')
parser.add_argument('--deployment-type', dest='deployment', default='origin',
help='disk image to modify')
parser.add_argument('--memsize', dest='memsize', default='512',
help='memory size to be used by virt-customize')
parser.add_argument('--package', dest="packages", action='append',
default=['deltarpm',
'git',
'httpd-tools',
'iptables',
'iptables-services',
'PyYAML',
'ceph-common',
'glusterfs-fuse',
'nfs-utils',
'libselinux-python',
'firewalld',
'logrotate',
'pcs',
'bash-completion'],
help='additional package to install')
parser.add_argument('--sm-credentials', dest="sm_creds",
help='subscription-manager credentials (user:password)')
parser.add_argument('--sm-pool', dest="sm_pool",
help='subscription-manager pool to attach')
parser.add_argument('--sm-repo', dest="sm_repos", action='append',
default=['rhel-7-server-rpms',
'rhel-7-server-extras-rpms',
'rhel-7-server-optional-rpms',
'rhel-7-server-ose-3.2-rpms'],
help='subscription-manager repository to enable')
parser.add_argument('--no-update', dest="update", action='store_false',
default=True, help='update packages')
parser.add_argument('--repos', dest="repos", action='append',
default=[], help='custom additional YUM repositories')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help='verbose mode')
args = parser.parse_args()
if not distutils.spawn.find_executable('virt-customize'):
print "virt-customize must be installed on the system"
sys.exit(1)
cmd = ["virt-customize", "-a", args.disk]
if args.verbose:
cmd += ["-v"]
# Create set of packages to install
if args.deployment == "enterprise":
args.packages += ["atomic-openshift-master", "atomic-openshift-node",
"tuned-profiles-atomic-openshift-node"]
elif args.deployment == "origin":
args.packages += ["origin-master", "origin-node",
"tuned-profiles-origin-node"]
maxamillion_copr = "https://copr.fedoraproject.org/coprs/maxamillion/" \
"origin-next/repo/epel-7/" \
"maxamillion-origin-next-epel-7.repo"
cmd += ["--write", "/etc/yum.repos.d/maxamillion-origin-next.repo:" +
urllib2.urlopen(maxamillion_copr).read()]
# add custom repositories
for repo in args.repos:
name = os.path.basename(repo)
cmd += ["--write", "/etc/yum.repos.d/%s:" % (name) +
urllib2.urlopen(repo).read()]
# Activate Red Hat subscriptions
if args.sm_creds:
username, password = args.sm_creds.split(':')
cmd += ["--run-command", "subscription-manager register --username %s "
"--password %s" % (username, password)]
if args.sm_pool:
attach_args = "--pool " + args.sm_pool
else:
attach_args = "--auto"
cmd += ["--run-command", "subscription-manager attach " + attach_args,
"--run-command", "subscription-manager repos --disable='*'",
"--run-command", "subscription-manager repos " +
" ".join(map(lambda repo: '--enable=' + repo, args.sm_repos))]
# Run a system update
if args.update:
cmd += ["--update"]
# Set up EPEL
cmd += ["--install", "https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm",
"--run-command", "sed -i -e 's/^enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo"]
# Install ansible
cmd += ["--run-command", "yum -y --enablerepo=epel install ansible"]
# Install required packages
cmd += ["--install", ",".join(args.packages)]
if args.sm_creds:
cmd += ["--run-command", "subscription-manager remove --all",
"--run-command", "subscription-manager unregister"]
if args.verbose:
print "Running command " + " ".join(cmd)
subprocess.call(cmd)
cmd = ["virt-sysprep", "-a", args.disk, "--selinux-relabel"]
if args.verbose:
print "Running command " + " ".join(cmd)
subprocess.call(cmd)