-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from D10S0VSkY-OSS/refactor/terraform-commands
Refactor/terraform commands
- Loading branch information
Showing
22 changed files
with
372 additions
and
379 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import logging | ||
import subprocess | ||
import redis | ||
|
||
redis_client = redis.Redis(host='localhost', port=6379, db=15) | ||
|
||
|
||
def command(command: str, channel: str): | ||
try: | ||
output_lines = [] | ||
command_description = f"Executing command: {command}" | ||
output_lines.append(command_description) | ||
redis_client.publish(channel, "-" * 80) | ||
redis_client.publish(channel, command_description) | ||
redis_client.publish(channel, "-" * 80) | ||
|
||
process = subprocess.Popen( | ||
command, | ||
shell=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT, | ||
text=True, | ||
) | ||
|
||
logging.info("#" * 80) | ||
for line in process.stdout: | ||
if "[DEBUG]" not in line: | ||
cleaned_line = line.strip() | ||
output_lines.append(cleaned_line) | ||
logging.info(cleaned_line) | ||
try: | ||
redis_client.publish(f'{channel}', cleaned_line) | ||
except Exception as err: | ||
logging.error(f"Error publish redis: {err}") | ||
|
||
logging.info("#" * 80) | ||
|
||
process.wait() | ||
|
||
if process.returncode == 0: | ||
logging.info(f"Command {command} executed successfully.") | ||
else: | ||
logging.error( | ||
f"Error executing the command {command}. Exit code: {process.returncode}" | ||
) | ||
return process.returncode, output_lines | ||
except subprocess.CalledProcessError as err: | ||
logging.error( | ||
f"Error execute command code: {err.returncode}. Error:\n{err.stderr}" | ||
) | ||
return None |
Oops, something went wrong.