def execute_user_command(self): """This is the main function that implements the CLI. Overall flow: 1. Read, validate and process the input arguments. 2. Update configuration files on the host based on user input. 3. Construct the deployment specific command object to execute the the user input command. 4. Log any status, progress and errors along the way to stdout 5. Return to caller with an error code. 0 -- Success Non Zero -- Error """ error_code = 1 host = platform.system() if EdgeDefault.is_host_supported(host) is False: log.error('Unsupported host platform: %s.', host) elif EdgeHostPlatform.is_deployment_supported(EC.DEPLOYMENT_DOCKER) is False: log.error('Docker is not installed or is unavailable. Please ensure docker is installed and is up and running.') else: try: if self._process_cli_args(): self._execute_command() error_code = 0 except edgectl.errors.EdgeError: log.debug('Errors observed running %s command.', self._prog()) if error_code != 0: log.error('Exiting with errors. Return code: %s', str(error_code)) return error_code
def create_command(command, edge_config): """ API to create an Edge command Args: command (str): Edge command name edge_config (obj): A valid instance of the edgectl.config.EdgeHostConfig Returns: Instance of edgectl.deployment.EdgeCommand Raises: edgectl.errors.EdgeValueError if the command or deployment type is unsupported """ result = None if command is None: msg = 'Command cannot be None' log.error(msg) raise edgectl.errors.EdgeValueError(msg) if edge_config is None or isinstance( edge_config, edgectl.config.EdgeHostConfig) is False: msg = 'Invalid Edge config object' log.error(msg) raise edgectl.errors.EdgeValueError(msg) deployment = edge_config.deployment_type if command not in list(EdgeCommandFactory._supported_commands.keys()): msg = 'Unsupported command: ' + command log.error(msg) raise edgectl.errors.EdgeValueError(msg) else: if EdgeHostPlatform.is_deployment_supported(deployment): if deployment == EC.DEPLOYMENT_DOCKER: deployment_cmd_obj = EdgeDeploymentCommandDocker( edge_config) result = EdgeCommandFactory._supported_commands[command]( deployment_cmd_obj) else: msg = 'IoT Edge deployment not supported: {0}'.format( deployment) log.critical(msg) raise edgectl.errors.EdgeValueError(msg) return result