Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _deployment_manifest(path):
return DeploymentManifest(envvars, output, utility, path, True)
def test_get_image_placeholder():
assert DeploymentManifest.get_image_placeholder("filtermodule") == "${MODULES.filtermodule}"
assert DeploymentManifest.get_image_placeholder("filtermodule", True) == "${MODULES.filtermodule.debug}"
github_source = "https://github.com/Azure/cookiecutter-azure-iot-edge-module"
branch = "master"
cmd = "cookiecutter --no-input {0} module_name={1} image_repository={2} --checkout {3}".format(github_source, name, repo, branch)
self.output.header(cmd)
self.utility.exe_proc(cmd.split(), cwd=cwd)
elif template == "csharpfunction":
dotnet = DotNet(self.output, self.utility)
dotnet.install_function_template()
dotnet.create_function_module(name, repo, cwd)
deployment_manifest.add_module_template(name)
deployment_manifest.dump()
debug_create_options = self._get_debug_create_options(template)
if os.path.exists(self.envvars.DEPLOYMENT_CONFIG_DEBUG_TEMPLATE_FILE):
deployment_manifest_debug = DeploymentManifest(self.envvars, self.output, self.utility, self.envvars.DEPLOYMENT_CONFIG_DEBUG_TEMPLATE_FILE, True)
deployment_manifest_debug.add_module_template(name, debug_create_options, True)
deployment_manifest_debug.dump()
self._update_launch_json(name, template, group_id)
self.output.footer("ADD COMPLETE")
def remove_modules(self):
self.output.info(
"Removing Edge Modules Containers and Images from Docker")
deployment_manifest = DeploymentManifest(self.envvars, self.output, self.utility, self.envvars.DEPLOYMENT_CONFIG_FILE_PATH, False)
modules_in_config = list(deployment_manifest.get_user_modules().keys())
for module in modules_in_config:
self.output.info("Searching for {0} Containers".format(module))
containers = self.docker_client.containers.list(
filters={"name": module})
for container in containers:
self.output.info("Removing Container: " + str(container))
container.remove(force=True)
self.output.info("Searching for {0} Images".format(module))
for image in self.docker_client.images.list():
if module in str(image):
self.output.info(
"Removing Module Image: " + str(image))
self.docker_client.images.remove(
self.output.header("BUILDING MODULES", suppress=no_build)
template_file_folder = os.path.dirname(template_file)
bypass_modules = self.utility.get_bypass_modules()
validation_success = True
# map image placeholder to tag.
# sample: ('${MODULES.filtermodule.amd64}', 'localhost:5000/filtermodule:0.0.1-amd64')
placeholder_tag_map = {}
# map image tag to BuildProfile object
tag_build_profile_map = {}
# image tags to build
# sample: 'localhost:5000/filtermodule:0.0.1-amd64'
tags_to_build = set()
deployment_manifest = DeploymentManifest(self.envvars, self.output, self.utility, template_file, True, True)
# get image tags for ${MODULES.modulename.xxx} placeholder
modules_path = os.path.join(template_file_folder, self.envvars.MODULES_PATH)
if os.path.isdir(modules_path):
for folder_name in os.listdir(modules_path):
project_folder = os.path.join(modules_path, folder_name)
if os.path.exists(os.path.join(project_folder, "module.json")):
module = Module(self.envvars, self.utility, project_folder)
self._update_module_maps("MODULES.{0}".format(folder_name), module, placeholder_tag_map, tag_build_profile_map, default_platform)
# get image tags for ${MODULEDIR.xxx} placeholder
user_modules = deployment_manifest.get_user_modules()
for module_name, module_info in user_modules.items():
image = module_info["settings"]["image"]
match_result = re.search(Constants.moduledir_placeholder_pattern, image)
if (match_result is not None):
def add_module_template(self, module_name, create_options={}, is_debug=False):
"""Add a module template to the deployment manifest"""
new_module = {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": DeploymentManifest.get_image_placeholder(module_name, is_debug),
"createOptions": create_options
}
}
try:
self.utility.nested_set(self._get_module_content(), ["$edgeAgent", "properties.desired", "modules", module_name], new_module)
except KeyError as err:
raise KeyError("Missing key {0} in file {1}".format(err, self.path))
self.add_default_route(module_name)
def handle_logs_cmd(self, show, save):
# Create LOGS_PATH dir if it doesn't exist
if save:
self.utility.ensure_dir(self.envvars.LOGS_PATH)
deployment_manifest = DeploymentManifest(self.envvars, self.output, self.utility, self.envvars.DEPLOYMENT_CONFIG_FILE_PATH, False)
modules_in_config = list(deployment_manifest.get_all_modules().keys())
for module in modules_in_config:
if show:
try:
command = self.envvars.LOGS_CMD.format(module)
os.system(command)
except Exception as ex:
self.output.error(
"Error while trying to open module log '{0}' with command '{1}'. Try `iotedgedev docker log --save` instead.".format(module, command))
self.output.error(str(ex))
if save:
try:
self.utility.exe_proc(["docker", "logs", module, ">",
os.path.join(self.envvars.LOGS_PATH, module + ".log")], True)
except Exception as ex: