Skip to content

Commit

Permalink
treecompose: Add ability to automatically detect atomic host IP
Browse files Browse the repository at this point in the history
When creating imagefactory images, we now detect if there is a "default"
KVM network and if so, we grab its IP and dynamically substitute it into
the KS file.  This prevents a difficult to debug error for users who
use a different IP/subnet scheme on their KVM networks.

If we cannot detect the network and IP, we suggest the user static define
it in the KS file.

packaging/rpm-ostree-toolbox.spec.in: Added libvirt-python as a runtime
dependancy.
  • Loading branch information
baude authored and cgwalters committed Nov 17, 2014
1 parent 8259b24 commit 928ea78
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions packaging/rpm-ostree-toolbox.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Requires: python
Requires: python-iniparse
Requires: pygobject2
Requires: gjs
Requires: libvirt-python
Requires: libguestfs-tools-c
Requires: libguestfs-gobject
# Needed for libguests
Expand Down
13 changes: 11 additions & 2 deletions scripts/ostree-ls-big-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ sizes.sort(function(a,b) {
return 0;
});

for (let i = 0; i < 100 && i < sizes.length; i++) {
let total = 0;
let max = 500;
let i;
for (i = 0; i < sizes.length; i++) {
let [path,size] = sizes[i];
print("" + size + " " + path.get_path());
total += size;
if (i < max)
print("" + size + " " + path.get_path());
}
let rest = sizes.length - max;
if (rest > 0)
print("...and " + rest + " more");
print("total: " + total);



23 changes: 22 additions & 1 deletion src/py/rpmostreecompose/imagefactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import distutils.spawn
from gi.repository import Gio, OSTree, GLib
from iniparse import INIConfig
import libvirt
import xml.etree.ElementTree as ET


from imgfac.PersistentImageManager import PersistentImageManager

Expand Down Expand Up @@ -189,9 +192,11 @@ def create(self, outputdir, name, ksfile, tdl, imageouttypes):

# TODO: Pull kickstart from separate git repo
ksdata = open(flattened_ks).read()
host_ip = getDefaultIP()
substitutions = { 'OSTREE_PORT': httpd_port,
'OSTREE_REF': self.ref,
'OSTREE_OSNAME': self.os_name }
'OSTREE_OSNAME': self.os_name,
'OSTREE_HOST_IP': host_ip }
for subname, subval in substitutions.iteritems():
ksdata = ksdata.replace('@%s@' % (subname, ), subval)

Expand Down Expand Up @@ -257,6 +262,22 @@ def builder(self):

## End Composer

def getDefaultIP():
"""
This method determines returns the IP of the atomic host, which
is used by the kickstart file to find the atomic repository. If it
cannot determine it via the default KVM network, it will fatally
die and suggest the user define it in the KS file.
"""
conn=libvirt.open()
try:
interface = conn.networkLookupByName("default")
except:
print "Unable to automatically determine your default KVM network. You can define the IP address of your atomic host repository in the kickstart file. Simply replace @OSTREE_HOST_IP@ with the IP you want to use."
exit(1)
root = ET.fromstring(interface.XMLDesc())
ip = root.find("ip").get('address')
return ip

def checkoz():
"""
Expand Down

0 comments on commit 928ea78

Please sign in to comment.