Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/codedeploy/uninstall.py
1567 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
14
import os
15
import sys
16
import errno
17
18
from awscli.customizations.codedeploy.utils import validate_instance, \
19
validate_region
20
from awscli.customizations.commands import BasicCommand
21
22
23
class Uninstall(BasicCommand):
24
NAME = 'uninstall'
25
26
DESCRIPTION = (
27
'Uninstalls the AWS CodeDeploy Agent from the on-premises instance.'
28
)
29
30
def _run_main(self, parsed_args, parsed_globals):
31
params = parsed_args
32
params.session = self._session
33
validate_region(params, parsed_globals)
34
validate_instance(params)
35
params.system.validate_administrator()
36
37
try:
38
self._uninstall_agent(params)
39
self._delete_config_file(params)
40
except Exception as e:
41
sys.stdout.flush()
42
sys.stderr.write(
43
'ERROR\n'
44
'{0}\n'
45
'Uninstall the AWS CodeDeploy Agent on the on-premises '
46
'instance by following the instructions in "Configure '
47
'Existing On-Premises Instances by Using AWS CodeDeploy" in '
48
'the AWS CodeDeploy User Guide.\n'.format(e)
49
)
50
51
def _uninstall_agent(self, params):
52
sys.stdout.write('Uninstalling the AWS CodeDeploy Agent... ')
53
params.system.uninstall(params)
54
sys.stdout.write('DONE\n')
55
56
def _delete_config_file(self, params):
57
sys.stdout.write('Deleting the on-premises instance configuration... ')
58
try:
59
os.remove(params.system.CONFIG_PATH)
60
except OSError as e:
61
if e.errno != errno.ENOENT:
62
raise e
63
sys.stdout.write('DONE\n')
64
65