Path: blob/develop/awscli/customizations/codedeploy/uninstall.py
1567 views
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.1213import os14import sys15import errno1617from awscli.customizations.codedeploy.utils import validate_instance, \18validate_region19from awscli.customizations.commands import BasicCommand202122class Uninstall(BasicCommand):23NAME = 'uninstall'2425DESCRIPTION = (26'Uninstalls the AWS CodeDeploy Agent from the on-premises instance.'27)2829def _run_main(self, parsed_args, parsed_globals):30params = parsed_args31params.session = self._session32validate_region(params, parsed_globals)33validate_instance(params)34params.system.validate_administrator()3536try:37self._uninstall_agent(params)38self._delete_config_file(params)39except Exception as e:40sys.stdout.flush()41sys.stderr.write(42'ERROR\n'43'{0}\n'44'Uninstall the AWS CodeDeploy Agent on the on-premises '45'instance by following the instructions in "Configure '46'Existing On-Premises Instances by Using AWS CodeDeploy" in '47'the AWS CodeDeploy User Guide.\n'.format(e)48)4950def _uninstall_agent(self, params):51sys.stdout.write('Uninstalling the AWS CodeDeploy Agent... ')52params.system.uninstall(params)53sys.stdout.write('DONE\n')5455def _delete_config_file(self, params):56sys.stdout.write('Deleting the on-premises instance configuration... ')57try:58os.remove(params.system.CONFIG_PATH)59except OSError as e:60if e.errno != errno.ENOENT:61raise e62sys.stdout.write('DONE\n')636465