Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1b60107c
authored
Mar 08, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rhel support
parent
262b6add
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
agent.py
+23
-2
No files found.
agent.py
View file @
1b60107c
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment