-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ec2_os actions, enable os level burn_cpu,network,kill process fun…
…ction via aws ssm Signed-off-by: Liu, Xiaopeng (133) <[email protected]>
- Loading branch information
Liu, Xiaopeng (133)
committed
May 25, 2020
1 parent
a05a04c
commit 544f687
Showing
23 changed files
with
1,964 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
|
||
from logzero import logger | ||
from chaoslib.exceptions import FailedActivity | ||
|
||
from .constants import OS_WINDOWS, OS_LINUX | ||
|
||
|
||
def construct_script_content(action: str = None, | ||
os_type: str = None, | ||
parameters: dict = None): | ||
""" | ||
As for now, no Windows action supported except burn CPU | ||
:param action: | ||
:param os_type: { OS_LINUX | OS_WINDOWS } | ||
:param parameters: | ||
:return: | ||
""" | ||
|
||
cmd_param = "" | ||
if os_type == OS_LINUX: | ||
file_suffix = ".sh" | ||
p_delimiter = "" | ||
cmdline_delimiter = " && " | ||
elif os_type == OS_WINDOWS: | ||
file_suffix = ".ps1" | ||
p_delimiter = "$" | ||
cmdline_delimiter = "\n" | ||
else: | ||
raise FailedActivity( | ||
"Cannot find corresponding script for {} on OS: {}".format( | ||
action, os_type)) | ||
|
||
if action == "run_cmd": | ||
cmdline_param = cmdline_delimiter.join(parameters['cmd']) | ||
# parameters.pop('cmd') | ||
del parameters['cmd'] | ||
else: | ||
cmdline_param = "" | ||
|
||
if parameters is not None: | ||
param_list = list() | ||
for k, v in parameters.items(): | ||
param_list.append('='.join([p_delimiter + k, "'" + v + "'"])) | ||
cmd_param = '\n'.join(param_list) | ||
else: | ||
logger.info("No parameter parsed, return default script content") | ||
|
||
script_name = action + file_suffix | ||
|
||
with open(os.path.join(os.path.dirname(__file__), | ||
"scripts", script_name)) as file: | ||
script_content = file.read() | ||
# merge duration | ||
script_content = cmd_param + "\n" + cmdline_param + "\n" + script_content | ||
return script_content |
Oops, something went wrong.