aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2021-06-04 11:55:23 -0400
committerJohn Snow <jsnow@redhat.com>2021-06-18 16:10:06 -0400
commite75f516ac131dbc3c82ac52ef527680c4745add3 (patch)
tree6563f6d7e8f49d11ef2150431e98158fec85047f
parent9510e4fb6967c39871b149676e09bb7ee875bc18 (diff)
downloadqemu-e75f516ac131dbc3c82ac52ef527680c4745add3.zip
qemu-e75f516ac131dbc3c82ac52ef527680c4745add3.tar.gz
qemu-e75f516ac131dbc3c82ac52ef527680c4745add3.tar.bz2
scripts/qemu-ga-client: apply (most) flake8 rules
- Line length should be < 80 - You shouldn't perform unscoped imports except at the top of the module Notably, the sys.path hack creates problems with the import rule. This will be fixed later. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210604155532.1499282-3-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
-rwxr-xr-xscripts/qmp/qemu-ga-client28
1 files changed, 16 insertions, 12 deletions
diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client
index 97f4047..566bddc 100755
--- a/scripts/qmp/qemu-ga-client
+++ b/scripts/qmp/qemu-ga-client
@@ -12,7 +12,8 @@
# Start QEMU with:
#
# # qemu [...] -chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0 \
-# -device virtio-serial -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
+# -device virtio-serial \
+# -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
#
# Run the script:
#
@@ -37,6 +38,7 @@
#
import base64
+import optparse
import os
import random
import sys
@@ -94,9 +96,11 @@ class QemuGuestAgentClient:
msgs = []
msgs.append('version: ' + info['version'])
msgs.append('supported_commands:')
- enabled = [c['name'] for c in info['supported_commands'] if c['enabled']]
+ enabled = [c['name'] for c in info['supported_commands']
+ if c['enabled']]
msgs.append('\tenabled: ' + ', '.join(enabled))
- disabled = [c['name'] for c in info['supported_commands'] if not c['enabled']]
+ disabled = [c['name'] for c in info['supported_commands']
+ if not c['enabled']]
msgs.append('\tdisabled: ' + ', '.join(disabled))
return '\n'.join(msgs)
@@ -119,11 +123,11 @@ class QemuGuestAgentClient:
if ipaddr['ip-address-type'] == 'ipv4':
addr = ipaddr['ip-address']
mask = self.__gen_ipv4_netmask(int(ipaddr['prefix']))
- msgs.append("\tinet %s netmask %s" % (addr, mask))
+ msgs.append(f"\tinet {addr} netmask {mask}")
elif ipaddr['ip-address-type'] == 'ipv6':
addr = ipaddr['ip-address']
prefix = ipaddr['prefix']
- msgs.append("\tinet6 %s prefixlen %s" % (addr, prefix))
+ msgs.append(f"\tinet6 {addr} prefixlen {prefix}")
if nif['hardware-address'] != '00:00:00:00:00:00':
msgs.append("\tether " + nif['hardware-address'])
@@ -237,6 +241,8 @@ def _cmd_suspend(client, args):
def _cmd_shutdown(client, args):
client.shutdown()
+
+
_cmd_powerdown = _cmd_shutdown
@@ -280,17 +286,15 @@ def main(address, cmd, args):
if __name__ == '__main__':
- import optparse
- import os
- import sys
-
- address = os.environ['QGA_CLIENT_ADDRESS'] if 'QGA_CLIENT_ADDRESS' in os.environ else None
+ address = os.environ.get('QGA_CLIENT_ADDRESS')
- usage = "%prog [--address=<unix_path>|<ipv4_address>] <command> [args...]\n"
+ usage = ("%prog [--address=<unix_path>|<ipv4_address>]"
+ " <command> [args...]\n")
usage += '<command>: ' + ', '.join(commands)
parser = optparse.OptionParser(usage=usage)
parser.add_option('--address', action='store', type='string',
- default=address, help='Specify a ip:port pair or a unix socket path')
+ default=address,
+ help='Specify a ip:port pair or a unix socket path')
options, args = parser.parse_args()
address = options.address