-
Notifications
You must be signed in to change notification settings - Fork 23
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
Showing
123 changed files
with
2,032 additions
and
404 deletions.
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,34 @@ | ||
LOGGER: | ||
PATH: ./logs | ||
RAW_LOG: True | ||
DEBUG_LEVEL: TRACE | ||
DATE_FORMAT: "%d %H:%M:%S" | ||
|
||
DEVICES: | ||
DEFAULT_CONNECTION: | ||
CONNECTION_DESC: | ||
io_type: terminal | ||
variant: threaded | ||
|
||
MyMachine: | ||
DEVICE_CLASS: moler.device.unixremote.UnixLocal | ||
|
||
RebexTestMachine: | ||
DEVICE_CLASS: moler.device.unixremote.UnixRemote | ||
STATE_PARAMS: # modify defaults | ||
UNIX_LOCAL: | ||
newline: \n # default (may be skipped) | ||
UNIX_REMOTE: | ||
newline: \r\n | ||
CONNECTION_HOPS: | ||
UNIX_LOCAL: # from state | ||
UNIX_REMOTE: # to state | ||
execute_command: ssh # via command | ||
command_params: # with params | ||
expected_prompt: demo@ | ||
host: test.rebex.net | ||
login: demo | ||
password: password | ||
set_timeout: False # remote doesn't support: export TMOUT | ||
|
||
|
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,31 @@ | ||
from moler.config import load_config | ||
from moler.device.device import DeviceFactory | ||
|
||
load_config(path='my_devices.yml') | ||
|
||
remote_unix = DeviceFactory.get_device(name='RebexTestMachine') # it starts in local shell | ||
remote_unix.goto_state(state="UNIX_REMOTE") # make it go to remote shell | ||
|
||
ls_cmd = remote_unix.get_cmd(cmd_name="ls", cmd_params={"options": "-l"}) | ||
ls_cmd.connection.newline = '\r\n' # tweak since rebex remote console uses such one | ||
|
||
remote_files = ls_cmd() | ||
|
||
if 'readme.txt' in remote_files['files']: | ||
print("readme.txt file:") | ||
readme_file_info = remote_files['files']['readme.txt'] | ||
for attr in readme_file_info: | ||
print(" {:<18}: {}".format(attr, readme_file_info[attr])) | ||
|
||
# result: | ||
""" | ||
readme.txt file: | ||
permissions : -rw------- | ||
hard_links_count : 1 | ||
owner : demo | ||
group : users | ||
size_raw : 403 | ||
size_bytes : 403 | ||
date : Apr 08 2014 | ||
name : readme.txt | ||
""" |
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,25 @@ | ||
import time | ||
from moler.cmd.unix.ping import Ping | ||
from moler.connection import get_connection | ||
|
||
host = 'www.google.com' | ||
terminal = get_connection(io_type='terminal', variant='threaded') | ||
with terminal: | ||
ping_cmd = Ping(connection=terminal.moler_connection, | ||
destination=host, options="-w 6") | ||
print("Start pinging {} ...".format(host)) | ||
ping_cmd.start() | ||
print("Doing other stuff while pinging {} ...".format(host)) | ||
time.sleep(3) | ||
ping_stats = ping_cmd.await_done(timeout=4) | ||
print("ping {}: {}={}, {}={} [{}]".format(host,'packet_loss', | ||
ping_stats['packet_loss'], | ||
'time_avg', | ||
ping_stats['time_avg'], | ||
ping_stats['time_unit'])) | ||
# result: | ||
""" | ||
Start pinging www.google.com ... | ||
Doing other stuff while pinging www.google.com ... | ||
ping www.google.com: packet_loss=0, time_avg=50.000 [ms] | ||
""" |
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,36 @@ | ||
from moler.config import load_config | ||
from moler.device.device import DeviceFactory | ||
|
||
load_config(path='my_devices.yml') | ||
|
||
my_unix = DeviceFactory.get_device(name='MyMachine') | ||
host = 'www.google.com' | ||
ping_cmd = my_unix.get_cmd(cmd_name="ping", cmd_params={"destination": host, "options": "-w 6"}) | ||
|
||
remote_unix = DeviceFactory.get_device(name='RebexTestMachine') | ||
remote_unix.goto_state(state="UNIX_REMOTE") | ||
ls_cmd = remote_unix.get_cmd(cmd_name="ls", cmd_params={"options": "-l"}) | ||
ls_cmd.connection.newline = '\r\n' # tweak since rebex remote console uses such one | ||
|
||
print("Start pinging {} ...".format(host)) | ||
ping_cmd.start() # run command in background | ||
print("Let's check readme.txt at {} while pinging {} ...".format(remote_unix.name, host)) | ||
|
||
remote_files = ls_cmd() # foreground "run in the meantime" | ||
file_info = remote_files['files']['readme.txt'] | ||
print("readme.txt file: owner={fi[owner]}, size={fi[size_bytes]}".format(fi=file_info)) | ||
|
||
ping_stats = ping_cmd.await_done(timeout=6) # await background command | ||
print("ping {}: {}={}, {}={} [{}]".format(host,'packet_loss', | ||
ping_stats['packet_loss'], | ||
'time_avg', | ||
ping_stats['time_avg'], | ||
ping_stats['time_unit'])) | ||
|
||
# result: | ||
""" | ||
Start pinging www.google.com ... | ||
Let's check readme.txt at RebexTestMachine while pinging www.google.com ... | ||
readme.txt file: owner=demo, size=403 | ||
ping www.google.com: packet_loss=0, time_avg=49.686 [ms] | ||
""" |
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,25 @@ | ||
from moler.cmd.unix.ps import Ps | ||
from moler.connection import ObservableConnection, get_connection | ||
from moler.io.raw.terminal import ThreadedTerminal | ||
|
||
# v.1 - combine all manually | ||
# moler_conn = ObservableConnection() | ||
# terminal = ThreadedTerminal(moler_connection=moler_conn) | ||
# v.2 - let factory combine | ||
# terminal = get_connection(io_type='terminal', variant='threaded') | ||
# v.3 - let factory select default variant | ||
terminal = get_connection(io_type='terminal') | ||
terminal.open() | ||
ps_cmd = Ps(connection=terminal.moler_connection, options="-ef") | ||
|
||
processes = ps_cmd() | ||
for proc in processes: | ||
if 'python' in proc['CMD']: | ||
print("PID: {} CMD: {}".format(proc['PID'], proc['CMD'])) | ||
terminal.close() | ||
|
||
# result: | ||
""" | ||
PID: 1817 CMD: /usr/bin/python /usr/share/system-config-printer/applet.py | ||
PID: 21825 CMD: /usr/bin/python /home/gl/moler/examples/command/unix_ps.py | ||
""" |
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,17 @@ | ||
from moler.config import load_config | ||
from moler.device.device import DeviceFactory | ||
|
||
load_config(path='my_devices.yml') # description of available devices | ||
my_unix = DeviceFactory.get_device(name='MyMachine') # take specific device out of available ones | ||
ps_cmd = my_unix.get_cmd(cmd_name="ps", # take command of that device | ||
cmd_params={"options": "-ef"}) | ||
|
||
processes_info = ps_cmd() # run the command, it returns result | ||
for proc_info in processes_info: | ||
if 'python' in proc_info['CMD']: | ||
print("PID: {info[PID]} CMD: {info[CMD]}".format(info=proc_info)) | ||
|
||
""" | ||
PID: 1817 CMD: /usr/bin/python /usr/share/system-config-printer/applet.py | ||
PID: 21825 CMD: /usr/bin/python /home/gl/moler/examples/command/unix_ps.py | ||
""" |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.