--pif A PIF reference within the session.
--pif-uuid The UUID of a PIF.
--force An interface name.
+ --root-prefix=DIR Use DIR as alternate root directory (for testing).
"""
# Notes:
pifrec = db().get_pif_record(pif)
try:
- f = open("/proc/ardence")
+ f = open(root_prefix() + "/proc/ardence")
macline = filter(lambda x: x.startswith("HWaddr:"), f.readlines())
f.close()
if len(macline) == 1:
def get_netdev_mac(device):
try:
- return read1("/sys/class/net/%s/address" % device)
+ return read1("%s/sys/class/net/%s/address" % (root_prefix(), device))
except:
# Probably no such device.
return None
def get_netdev_tx_queue_len(device):
try:
- return int(read1("/sys/class/net/%s/tx_queue_len" % device))
+ return int(read1("%s/sys/class/net/%s/tx_queue_len" % (root_prefix(), device)))
except:
# Probably no such device.
return None
def get_netdev_by_mac(mac):
- for device in os.listdir("/sys/class/net"):
+ for device in os.listdir(root_prefix() + "/sys/class/net"):
dev_mac = get_netdev_mac(device)
if (dev_mac and mac.lower() == dev_mac.lower() and
get_netdev_tx_queue_len(device)):
if not netdev_exists(netdev):
log("ifdown: device %s does not exist, ignoring" % netdev)
return
- if not os.path.exists("/etc/sysconfig/network-scripts/ifcfg-%s" % netdev):
+ if not os.path.exists("%s/etc/sysconfig/network-scripts/ifcfg-%s" % (root_prefix(), netdev)):
log("ifdown: device %s exists but ifcfg-%s does not" % (netdev,netdev))
run_command(["/sbin/ifconfig", netdev, 'down'])
return
def ifup(netdev):
"""Bring up a network interface"""
- if not os.path.exists("/etc/sysconfig/network-scripts/ifcfg-%s" % netdev):
+ if not os.path.exists(root_prefix() + "/etc/sysconfig/network-scripts/ifcfg-%s" % netdev):
raise Error("ifup: device %s exists but ifcfg-%s does not" % (netdev,netdev))
run_command(["/sbin/ifup", netdev])
# The key is not present, i.e. there are no static routes
lines = []
- child = ConfigurationFile("/etc/sysconfig/network-scripts/route-%s" % interface)
+ child = ConfigurationFile("%s/etc/sysconfig/network-scripts/route-%s" % (root_prefix(), interface))
child.write("# DO NOT EDIT: This file (%s) was autogenerated by %s\n" % \
(os.path.basename(child.path()), os.path.basename(sys.argv[0])))
log("Writing network configuration for %s" % ipdev)
- f = ConfigurationFile("/etc/sysconfig/network-scripts/ifcfg-%s" % ipdev)
+ f = ConfigurationFile("%s/etc/sysconfig/network-scripts/ifcfg-%s" % (root_prefix(), ipdev))
f.write("# DO NOT EDIT: This file (%s) was autogenerated by %s\n" % \
(os.path.basename(f.path()), os.path.basename(sys.argv[0])))
is_gatewaydev = defaultroute_pif == pif
if is_dnsdev or is_gatewaydev:
- fnetwork = ConfigurationFile("/etc/sysconfig/network")
+ fnetwork = ConfigurationFile(root_prefix() + "/etc/sysconfig/network")
for line in fnetwork.readlines():
if is_dnsdev and line.lstrip().startswith('DNSDEV='):
fnetwork.write('DNSDEV=%s\n' % ipdev)
dp.post()
# Update /etc/issue (which contains the IP address of the management interface)
- os.system("/sbin/update-issue")
+ os.system(root_prefix() + "/sbin/update-issue")
f.commit()
except Error, e:
log("Configuring %s using %s configuration" % (bridge, mode))
- f = ConfigurationFile(dbcache_file)
+ f = ConfigurationFile(root_prefix() + dbcache_file)
pif_uuid = getUUID()
network_uuid = getUUID()
"force-interface=",
"management",
"mac=", "device=", "mode=", "ip=", "netmask=", "gateway=",
+ "root-prefix=",
"help" ]
arglist, args = getopt.gnu_getopt(argv[1:], shortops, longops)
except getopt.GetoptError, msg:
force_management = True
elif o in ["--mac", "--device", "--mode", "--ip", "--netmask", "--gateway"]:
force_rewrite_config[o[2:]] = a
+ elif o == "--root-prefix":
+ set_root_prefix(a)
elif o == "-h" or o == "--help":
print __doc__ % {'command-name': os.path.basename(argv[0])}
return 0