I am trying to auto discover BACnet devices in VOLTTRON on a LAN with grab multiple configs.
This message below is from the linux terminal when I am trying run proxy_grab_bacnet_config.py where my args or something is incorrect:
usage: grab_multiple_configs.py [-h] [--use-proxy] [--proxy-id PROXY_ID] [--out-directory OUT_DIRECTORY] [--ini INI] csv_file
This is my BACnet proxy ID: d80cd203-696b-4219-a4f2-b8bb56b7d116
When I run this from terminal:
python grab_multiple_configs.py --out-directory ~/Desktop/volttron/scripts/bacnet/configs/ --use-proxy --proxy-id d80cd203-696b-4219-a4f2-b8bb56b7d116 multie.csv
I get the usage error, is it because my args aren't in the correct order?
usage: grab_multiple_configs.py [-h] [--use-proxy] [--proxy-id PROXY_ID] [--out-directory OUT_DIRECTORY] [--ini INI] csv_file
grab_multiple_configs.py: error: argument csv_file: can't open 'multie.csv': [Errno 2] No such file or directory: 'multie.csv'
EDIT
Snip of vctl status:
The proxy-id should be the vip identity of the proxy you are using. not the uuid. I am guessing that having the - in the uuid is probably why this is an issue. Try " the arguments and see if you get the same error. Though it won't work unless the proxy id is in fact the vip identity.
so i'm trying to run an ansible playbook from python with subprocess.run, the line im using is :
dns = "10.10.10.10"
subprocess.run(["ansible-playbook", f"{playbook_path}", f'-e "os_type=linux"', f'-i {dns},'])
and i'm getting
fatal: [10.10.10.10]: FAILED! => {"msg": "The conditional check 'os_type == 'linux'' failed. The error was: error while evaluating conditional (os_type == 'linux'): 'os_type' is undefined\n\nThe error appears to be in '/home/chaos_project/playbook': line 7, column 11, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n block:\n - name: Create a directory if it does not exist\n ^ here\n"}
as if os_type isnt defined, but when i just run it as a terminal command it works just fine :
ansible-playbook playbook -e 'os_type=linux' -i 10.10.10.10,
eventually im using ansible-runner, but for an easy fix :
subprocess.run(["ansible-playbook", f"{playbook_path}", f'-e os_type=linux', f'-i {dns},'])
worked fine.
I have a problem. I run tests with the help of the question.
In the beginning, the test calls a method that causes me to enter the address of the database (where I am testing). However, I am getting an error:
element = "http://" +sys.stdin.readline()../../python/lib/python3.6/site-packages/_pytest/capture.py:702: in read
raise IOError ("reading from stdin while output is captured")
E OSError: reading from stdin while output is captured
below my code.
#staticmethod
def setAddress():
print("Give database:")
element = "http://"+sys.stdin.readline()
return element
I need to addres add http. How I can change my code? Thanks for help!
Set an environment variable when running tests in your shell:
DB_URL=http://xxx pytest
and then retrieve it in your tests:
import os
…
db_url = os.getenv('DB_URL')
I wanted to create a desktop launcher for my Python application. The application executes various ssh operations over pexpect with publickey-authentication. The problem is however, when I start my app with the .desktop launcher it doesn't work properly. The ssh connections ask for a password and don't use the publickeys. But it works fine via commandline execution.
The .desktop File looks like this:
[Desktop Entry]
Version=1.0
Name=SSH-Manager
Comment=XYZ
Exec=python /home/userx/SSH-Manager/startup.py
Icon=/home/userx/SSH-Manager/resources/icon.png
Path=/home/userx/repos/SSH-Manager
Terminal=true
Type=Application
Categories=Utility;Application;
StartupNotify=false
The desktop environment is KDE and the desktop user is the same as the commandline user.
Can someone explain why I get such strange behavior with the launcher?
Edit: Example function
def run(self):
self.a_signal.emit("Retrieving Data")
try:
session = pxssh()
session.force_password = False
hostname = self.client
username = "root"
session.login(hostname, username)
session.sendline("ls -a")
session.prompt()
session.logout()
except ExceptionPxssh as e:
print ("pxssh failed: ")
self.error_signal.emit("failed", str(e))
print e
return
self.process_output()
self.finish_signal.emit("done")
As Mirosław Zalewski suspected in the comments, the problem was the ssh-agent was not running for the desktop-environment because ssh-add was initially used in the /etc/sources. Executing ssh-add in the X-users ~./profile therefore solves the problem.
I am running a command on the remote machine:
remote_output = run('mysqldump --no-data --user=username --password={0} database'.format(password))
I would like to capture the output, but not have it all printed to the screen. What's the easiest way to do this?
It sounds like Managing output section is what you're looking for.
To hide the output from the console, try something like this:
from __future__ import with_statement
from fabric.api import hide, run, get
with hide('output'):
run('mysqldump --no-data test | tee test.create_table')
get('~/test.create_table', '~/test.create_table')
Belows is the sample results:
No hosts found. Please specify (single) host string for connection: 192.168.6.142
[192.168.6.142] run: mysqldump --no-data test | tee test.create_table
[192.168.6.142] download: /home/quanta/test.create_table <- /home/quanta/test.create_table
Try this if you want to hide everything from log and avoid fabric throwing exceptions when command fails:
from __future__ import with_statement
from fabric.api import env,run,hide,settings
env.host_string = 'username#servernameorip'
env.key_filename = '/path/to/key.pem'
def exec_remote_cmd(cmd):
with hide('output','running','warnings'), settings(warn_only=True):
return run(cmd)
After that, you can check commands result as shown in this example:
cmd_list = ['ls', 'lss']
for cmd in cmd_list:
result = exec_remote_cmd(cmd)
if result.succeeded:
sys.stdout.write('\n* Command succeeded: '+cmd+'\n')
sys.stdout.write(result+"\n")
else:
sys.stdout.write('\n* Command failed: '+cmd+'\n')
sys.stdout.write(result+"\n")
This will be the console output of the program (observe that there aren't log messages from fabric):
* Command succeeded: ls
Desktop espaiorgcats.sql Pictures Public Videos
Documents examples.desktop projectes scripts
Downloads Music prueba Templates
* Command failed: lss
/bin/bash: lss: command not found
For fabric==2.4.0 you can hide output using the following logic
conn = Connection(host="your-host", user="your-user")
result = conn.run('your_command', hide=True)
result.stdout.strip() # here you can get the output
As other answers allude, fabric.api doesn't exist anymore (as of writing, fabric==2.5.0) 8 years after the question. However the next most recent answer here implies providing hide=True to every .run() call is the only/accepted way to do it.
Not being satisfied I went digging for a reasonable equivalent to a context where I can specify it only once. It feels like there should still be a way using an invoke.context.Context but I didn't want to spend any longer on this, and the easiest way I could find was using invoke.config.Config, which we can access via fabric.config.Config without needing any additional imports.
>>> import fabric
>>> c = fabric.Connection(
... "foo.example.com",
... config=fabric.config.Config(overrides={"run": {"hide": True}}),
... )
>>> result = c.run("hostname")
>>> result.stdout.strip()
'foo.example.com'
As of Fabric 2.6.0 hide argument to run is not available.
Expanding on suggestions by #cfillol and #samuel-harmer, using a fabric.Config may be a simpler approach:
>>> import fabric
>>> conf = fabric.Config()
>>> conf.run.hide = True
>>> conf.run.warn = True
>>> c = fabric.Connection(
... "foo.example.com",
... config=conf
... )
>>> result = c.run("hostname")
This way no command output is printed and no exception is thrown on command failure.
As Samuel Harmer also pointed out in his answer, it is possible to manage output of the run command at the connection level.
As of version 2.7.1:
from fabric import Config, Connection
connection = Connection(
host,
config = Config(overrides = {
"run": { "hide": "stdout" }
}),
...
)