Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imagefactory: Automatically substitute kickstart --url argument #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 45 additions & 24 deletions src/py/rpmostreecompose/imagefactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import json
import os
import sys
import re
import StringIO
import tempfile
import argparse
import shutil
Expand Down Expand Up @@ -252,33 +254,52 @@ def formatKS(self, ksfile):
os.rename(contextdir + '/' + ks_basename, flattened_ks)

# TODO: Pull kickstart from separate git repo
ksdata = open(flattened_ks).read()
substitutions = { 'OSTREE_REF': self.ref,
'OSTREE_OSNAME': self.os_name}

if '@OSTREE_PORT@' in ksdata:
substitutions['OSTREE_PORT'] = self.httpd_port

if '@OSTREE_HOST_IP@' in ksdata:
if not self.ostree_repo_is_remote:
host_ip = getDefaultIP(hostnet=self.virtnetwork)
else:
host_ip = self.httpd_host
substitutions['OSTREE_HOST_IP'] = host_ip

if '@OSTREE_PATH@' in ksdata:
substitutions['OSTREE_PATH'] = self.httpd_path

if '@OSTREE_LOCATION@' in ksdata:
if not self.ostree_repo_is_remote:
ostree_location = "file:///install/ostree"
else:
ostree_location = "http://{0}:{1}:{2}".format(self.httpd_host, self.httpd_port, self.httpd_path)
substitutions['OSTREE_LOCATION'] = ostree_location

for subname, subval in substitutions.iteritems():
ksdata = ksdata.replace('@%s@' % (subname, ), subval)
return ksdata
substitutions['OSTREE_PORT'] = self.httpd_port

if not self.ostree_repo_is_remote:
host_ip = getDefaultIP(hostnet=self.virtnetwork)
else:
host_ip = self.httpd_host

# fallback
if host_ip is None:
log("notice: unable to determine libvirt network, using 192.168.122.1")
host_ip = '192.168.122.1'

substitutions['OSTREE_HOST_IP'] = host_ip

substitutions['OSTREE_PATH'] = self.httpd_path

local_http_location = "http://{0}:{1}/{2}".format(host_ip, self.httpd_port, self.httpd_path)
log("Using local http: {0}".format(local_http_location))

if not self.ostree_repo_is_remote:
ostree_location = "file:///install/ostree"
else:
ostree_location = local_http_location
substitutions['OSTREE_LOCATION'] = ostree_location

# Always replace the URL with the local repo. If we're
# running the imagefactory command here, we expect to be using local.
r = re.compile('^(ostreesetup.*?)--url=[^\s]+(.*)')
newbuf = StringIO.StringIO()
with open(flattened_ks) as f:
for line in f:
for subname, subval in substitutions.iteritems():
line = line.replace('@%s@' % (subname, ), subval)

m = r.match(line)
if not m:
newbuf.write(line)
continue
newbuf.write(m.group(1))
newbuf.write('--url="{0}"'.format(local_http_location))
newbuf.write(m.group(2))

return newbuf.getvalue()


class ImageFactoryTask(AbstractImageFactoryTask):
Expand Down