Commit 1b60107c by Bach Dániel

add rhel support

parent 262b6add
...@@ -21,6 +21,11 @@ fstab_template = ('sshfs#%(username)s@%(host)s:home /home/cloud/sshfs ' ...@@ -21,6 +21,11 @@ fstab_template = ('sshfs#%(username)s@%(host)s:home /home/cloud/sshfs '
system = platform.system() system = platform.system()
distros = {'Scientific Linux': 'rhel',
'CentOS': 'rhel',
'Debian': 'debian',
'Ubuntu': 'debian'}
distro = distros[platform.linux_distribution()[0]]
# http://stackoverflow.com/questions/12081310/ # http://stackoverflow.com/questions/12081310/
...@@ -60,12 +65,19 @@ class Context(object): ...@@ -60,12 +65,19 @@ class Context(object):
@staticmethod @staticmethod
def restart_networking(): def restart_networking():
if system == 'Linux': if system == 'Linux':
if distro == 'debian':
with open('/etc/network/interfaces', 'w') as f: with open('/etc/network/interfaces', 'w') as f:
f.write('auto lo\n' f.write('auto lo\n'
'iface lo inet loopback\n' 'iface lo inet loopback\n'
'auto eth0\n' 'auto eth0\n'
'iface eth0 inet dhcp\n') 'iface eth0 inet dhcp\n')
subprocess.call(['/etc/init.d/networking', 'restart']) subprocess.call(['/etc/init.d/networking', 'restart'])
elif distro == 'rhel':
with open('/etc/sysconfig/network-scripts/ifcfg-eth0', 'w') as f:
f.write('DEVICE=eth0\n'
'BOOTPROTO=dhcp\n'
'ONBOOT=yes\n')
elif system == 'Windows': elif system == 'Windows':
import wmi import wmi
w = wmi.WMI() w = wmi.WMI()
...@@ -77,7 +89,7 @@ class Context(object): ...@@ -77,7 +89,7 @@ class Context(object):
if system == 'Linux': if system == 'Linux':
linux_set_time(float(new_time)) linux_set_time(float(new_time))
try: try:
subprocess.call(['/etc/init.d/openntpd', 'restart']) subprocess.call(['/etc/init.d/ntp', 'restart'])
except: except:
pass pass
elif system == 'Windows': elif system == 'Windows':
...@@ -89,12 +101,21 @@ class Context(object): ...@@ -89,12 +101,21 @@ class Context(object):
@staticmethod @staticmethod
def set_hostname(new_hostname): def set_hostname(new_hostname):
if system == 'Linux': if system == 'Linux':
if distro == 'debian':
with open('/etc/hostname', 'w') as f: with open('/etc/hostname', 'w') as f:
f.write(new_hostname) f.write(new_hostname)
elif distro == 'rhel':
for line in fileinput.input('/etc/sysconfig/network',
inplace=1):
if line.startswith('HOSTNAME='):
print 'HOSTNAME=%s' % new_hostname
else:
print line.rstrip()
with open('/etc/hosts', 'w') as f: with open('/etc/hosts', 'w') as f:
f.write('127.0.0.1 localhost' f.write('127.0.0.1 localhost'
'127.0.1.1 %s\n' % new_hostname) '127.0.1.1 %s\n' % new_hostname)
# set hostname
subprocess.call(['/bin/hostname', new_hostname]) subprocess.call(['/bin/hostname', new_hostname])
elif system == 'Windows': elif system == 'Windows':
import wmi import wmi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment