-
Notifications
You must be signed in to change notification settings - Fork 18
Make config properties script Python3 compatible #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
remibergsma
wants to merge
1
commit into
master
Choose a base branch
from
config_properties_python3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 +1,4 @@ | ||
| #!/usr/bin/python2 | ||
| #!/usr/bin/python3 | ||
|
|
||
| # This script connects to the system vm Qemu Guest Agent and writes the | ||
| # authorized_keys and cmdline data to /var/cache/cloud. The system VM then | ||
|
|
@@ -27,7 +27,7 @@ | |
|
|
||
| def EXE(param): | ||
| cmd = """virsh qemu-agent-command %s '%s' """ % (arguments.name, param) | ||
| print "Exe command:%s" % cmd | ||
| print("Exe command:%s" % cmd) | ||
| stream = os.popen(cmd).read() | ||
| return None if not stream else json.loads(stream) | ||
|
|
||
|
|
@@ -37,10 +37,10 @@ def write_guest_file(path, content): | |
| try: | ||
| file_handle = EXE(FILE_OPEN_WRITE % path)["return"] | ||
| write_count = EXE(FILE_WRITE % (file_handle, content))["return"]["count"] | ||
| print "Write count: " + str(write_count) | ||
| print("Write count: " + str(write_count)) | ||
| except Exception as ex: | ||
| print Exception, ":", ex | ||
| print "ERROR: Something went wrong, exiting." | ||
| print(Exception, ":", ex) | ||
| print("ERROR: Something went wrong, exiting.") | ||
| sys.exit(1) | ||
| finally: | ||
| if file_handle > -1: | ||
|
|
@@ -53,11 +53,11 @@ def read_guest_file(path, write_count): | |
| file_handle = EXE(FILE_OPEN_READ % path)["return"] | ||
| result = EXE(FILE_READ % (file_handle, write_count)) | ||
| read_count = result["return"]["count"] | ||
| print "Read count: " + str(read_count) | ||
| print "Content from read-back: " + base64.b64decode(result["return"]["buf-b64"]) | ||
| print("Read count: " + str(read_count)) | ||
| print("Content from read-back: " + base64.b64decode(result["return"]["buf-b64"])) | ||
| except Exception as ex: | ||
| print Exception, ":", ex | ||
| print "ERROR: Something went wrong, exiting." | ||
| print(Exception, ":", ex) | ||
| print("ERROR: Something went wrong, exiting.") | ||
| sys.exit(1) | ||
| finally: | ||
| if file_handle > -1: | ||
|
|
@@ -66,16 +66,16 @@ def read_guest_file(path, write_count): | |
|
|
||
| def get_key(key_file): | ||
| if not os.path.exists(key_file): | ||
| print("ERROR: ssh public key not found on host at {0}".format(key_file)) | ||
| print "ERROR: Something went wrong, exiting." | ||
| print(("ERROR: ssh public key not found on host at {0}".format(key_file))) | ||
| print("ERROR: Something went wrong, exiting.") | ||
| sys.exit(1) | ||
|
|
||
| try: | ||
| with open(key_file, "r") as f: | ||
| pub_key = f.read() | ||
| except IOError as e: | ||
| print("ERROR: unable to open {0} - {1}".format(key_file, e.strerror)) | ||
| print "ERROR: Something went wrong, exiting." | ||
| print(("ERROR: unable to open {0} - {1}".format(key_file, e.strerror))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the double round brackets be removed? |
||
| print("ERROR: Something went wrong, exiting.") | ||
| sys.exit(1) | ||
|
|
||
| return pub_key | ||
|
|
@@ -87,15 +87,15 @@ def write_file(file_in_vm, data): | |
| write_count = write_guest_file(file_in_vm, content) | ||
| return write_count | ||
| except Exception as ex: | ||
| print "Warning: it was not possible to write to the Qemu Guest Agent at this time. Will try again later." | ||
| print("Warning: it was not possible to write to the Qemu Guest Agent at this time. Will try again later.") | ||
|
|
||
|
|
||
| def compare_write_read(file, write_count, read_count): | ||
| print "Result for %s: write %d read %d" % (file, write_count, read_count) | ||
| print("Result for %s: write %d read %d" % (file, write_count, read_count)) | ||
| if write_count != read_count: | ||
| print "ERROR: Write count count doesn't match read count. File wasn't written successfully. Aborting." | ||
| print("ERROR: Write count count doesn't match read count. File wasn't written successfully. Aborting.") | ||
| sys.exit(1) | ||
| print "All fine for %s, read count matches write count." % (file) | ||
| print("All fine for %s, read count matches write count." % (file)) | ||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description="Send configuration to system VM socket") | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the double round brackets be removed?