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>
This commit is contained in:
John Snow 2021-06-04 11:55:23 -04:00
parent 9510e4fb69
commit e75f516ac1
1 changed files with 16 additions and 12 deletions

View File

@ -12,7 +12,8 @@
# Start QEMU with: # Start QEMU with:
# #
# # qemu [...] -chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0 \ # # 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: # Run the script:
# #
@ -37,6 +38,7 @@
# #
import base64 import base64
import optparse
import os import os
import random import random
import sys import sys
@ -94,9 +96,11 @@ class QemuGuestAgentClient:
msgs = [] msgs = []
msgs.append('version: ' + info['version']) msgs.append('version: ' + info['version'])
msgs.append('supported_commands:') 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)) 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)) msgs.append('\tdisabled: ' + ', '.join(disabled))
return '\n'.join(msgs) return '\n'.join(msgs)
@ -119,11 +123,11 @@ class QemuGuestAgentClient:
if ipaddr['ip-address-type'] == 'ipv4': if ipaddr['ip-address-type'] == 'ipv4':
addr = ipaddr['ip-address'] addr = ipaddr['ip-address']
mask = self.__gen_ipv4_netmask(int(ipaddr['prefix'])) 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': elif ipaddr['ip-address-type'] == 'ipv6':
addr = ipaddr['ip-address'] addr = ipaddr['ip-address']
prefix = ipaddr['prefix'] 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': if nif['hardware-address'] != '00:00:00:00:00:00':
msgs.append("\tether " + nif['hardware-address']) msgs.append("\tether " + nif['hardware-address'])
@ -237,6 +241,8 @@ def _cmd_suspend(client, args):
def _cmd_shutdown(client, args): def _cmd_shutdown(client, args):
client.shutdown() client.shutdown()
_cmd_powerdown = _cmd_shutdown _cmd_powerdown = _cmd_shutdown
@ -280,17 +286,15 @@ def main(address, cmd, args):
if __name__ == '__main__': if __name__ == '__main__':
import optparse address = os.environ.get('QGA_CLIENT_ADDRESS')
import os
import sys
address = os.environ['QGA_CLIENT_ADDRESS'] if 'QGA_CLIENT_ADDRESS' in os.environ else None usage = ("%prog [--address=<unix_path>|<ipv4_address>]"
" <command> [args...]\n")
usage = "%prog [--address=<unix_path>|<ipv4_address>] <command> [args...]\n"
usage += '<command>: ' + ', '.join(commands) usage += '<command>: ' + ', '.join(commands)
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--address', action='store', type='string', 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() options, args = parser.parse_args()
address = options.address address = options.address