-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc0979e
commit 8bfe271
Showing
17 changed files
with
1,852 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Lukas Bednar | ||
|
||
Contributors include:: | ||
|
||
Artyom Lukianov | ||
Kobi Hakimi | ||
Martin Pavlik | ||
Meni Yakove | ||
Michal Ovciarik | ||
Ondra Machacek |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# python-rrmngmnt | ||
REmote REsources MaNaGeMeNT | ||
Remote Resources MaNaGeMeNT | ||
|
||
This tool helps you manage remote machines and services running on that. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from rrmngmnt.host import Host | ||
from rrmngmnt.user import ( | ||
User, | ||
RootUser, | ||
Domain, | ||
InternalDomain, | ||
ADUser, | ||
) | ||
from rrmngmnt.db import Database | ||
|
||
|
||
__all__ = [ | ||
Host, | ||
User, | ||
RootUser, | ||
Domain, | ||
InternalDomain, | ||
ADUser, | ||
Database, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import socket | ||
|
||
|
||
def fqdn2ip(fqdn): | ||
""" | ||
translate fqdn to IP | ||
:param fqdn: host name | ||
:type fqdn: string | ||
:return: IP | ||
:rtype: string | ||
""" | ||
try: | ||
return socket.gethostbyname(fqdn) | ||
except (socket.gaierror, socket.herror) as ex: | ||
args = list(ex.args) | ||
message = "%s: %s" % (fqdn, args[1]) | ||
args[1] = message | ||
ex.strerror = message | ||
ex.args = tuple(args) | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from rrmngmnt.service import Service | ||
|
||
|
||
class Database(Service): | ||
|
||
def __init__(self, host, name, user): | ||
""" | ||
:param host: Remote resouce to DB machine | ||
:type host: instance of Host | ||
:param name: database name | ||
:type name: str | ||
:param user: user/role | ||
:type user: instance of User | ||
""" | ||
super(Database, self).__init__(host) | ||
self.name = name | ||
self.user = user | ||
|
||
def psql(self, sql, *args): | ||
""" | ||
Execute psql command on host | ||
:param sql: sql command | ||
:type sql: string | ||
:param args: positional format arguments for command | ||
:type args: list of arguments | ||
:return: list of lines with records | ||
:rtype: list(list(string, string, ...)) | ||
""" | ||
separator = '__RECORD_SEPARATOR__' | ||
sql = sql % tuple(args) | ||
cmd = [ | ||
'export', 'PGPASSWORD=%s;' % self.user.password, | ||
'psql', '-d', self.name, '-U', self.user.name, '-h', 'localhost', | ||
'-R', separator, '-t', '-A', '-c', sql, | ||
] | ||
|
||
executor = self.host.executor() | ||
with executor.session() as ss: | ||
rc, out, err = ss.run_cmd(cmd) | ||
if rc: | ||
raise Exception( | ||
"Failed to exec sql command: %s" % err | ||
) | ||
return [ | ||
a.strip().split('|') for a in out.strip().split(separator) | ||
if a.strip() | ||
] | ||
# NOTE: I am considering to use Psycopg2 to access DB directly. | ||
# I need to think whether it is better or not. | ||
# We need to realize that connection can be forbiden from outside ... | ||
|
||
def restart(self): | ||
self.host.service('postgresql').restart() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from rrmngmnt.service import Service | ||
|
||
|
||
class FileSystem(Service): | ||
""" | ||
Class for working with filesystem. | ||
It has same interface as 'os' module. | ||
""" | ||
def _exec_file_test(self, op, path): | ||
return self.host.executor().run_cmd( | ||
['[', '-%s' % op, path, ']'] | ||
)[0] == 0 | ||
|
||
def exists(self, path): | ||
return self._exec_file_test('e', path) | ||
|
||
def isfile(self, path): | ||
return self._exec_file_test('f', path) | ||
|
||
def isdir(self, path): | ||
return self._exec_file_test('d', path) | ||
|
||
def remove(self, path): | ||
return self.host.executor().run_cmd( | ||
['rm', '-f', path] | ||
)[0] == 0 | ||
unlink = remove | ||
|
||
def rmdir(self, path): | ||
return self.host.executor().run_cmd( | ||
['rm', '-rf', path] | ||
)[0] == 0 |
Oops, something went wrong.