bootstrap-vz/bootstrapvz/common/tasks/network.py

39 lines
1.1 KiB
Python
Raw Normal View History

2013-07-01 23:54:18 +02:00
from base import Task
from common import phases
2014-02-19 22:14:17 +01:00
import os
2013-07-01 23:54:18 +02:00
class RemoveDNSInfo(Task):
description = 'Removing resolv.conf'
phase = phases.system_modification
@classmethod
def run(cls, info):
if os.path.isfile(os.path.join(info.root, 'etc/resolv.conf')):
2014-02-19 22:14:17 +01:00
os.remove(os.path.join(info.root, 'etc/resolv.conf'))
2013-07-01 23:54:18 +02:00
2013-09-22 15:41:43 +02:00
class RemoveHostname(Task):
description = 'Removing the hostname file'
phase = phases.system_modification
@classmethod
def run(cls, info):
if os.path.isfile(os.path.join(info.root, 'etc/hostname')):
2014-02-19 22:14:17 +01:00
os.remove(os.path.join(info.root, 'etc/hostname'))
2013-09-22 15:41:43 +02:00
2013-07-01 23:54:18 +02:00
class ConfigureNetworkIF(Task):
description = 'Configuring network interfaces'
phase = phases.system_modification
@classmethod
def run(cls, info):
network_config_path = os.path.join(os.path.dirname(__file__), 'network-configuration.json')
from common.tools import config_get
if_config = config_get(network_config_path, [info.release_codename])
2013-07-01 23:54:18 +02:00
interfaces_path = os.path.join(info.root, 'etc/network/interfaces')
with open(interfaces_path, 'a') as interfaces:
interfaces.write('\n'.join(if_config) + '\n')