Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/codedeploy/install.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 errno
15
import os
16
import shutil
17
import sys
18
19
from awscli.customizations.commands import BasicCommand
20
from awscli.customizations.codedeploy.utils import \
21
validate_region, validate_s3_location, validate_instance
22
23
24
class Install(BasicCommand):
25
NAME = 'install'
26
27
DESCRIPTION = (
28
'Configures and installs the AWS CodeDeploy Agent on the on-premises '
29
'instance.'
30
)
31
32
ARG_TABLE = [
33
{
34
'name': 'config-file',
35
'synopsis': '--config-file <path>',
36
'required': True,
37
'help_text': (
38
'Required. The path to the on-premises instance configuration '
39
'file.'
40
)
41
},
42
{
43
'name': 'override-config',
44
'action': 'store_true',
45
'default': False,
46
'help_text': (
47
'Optional. Overrides the on-premises instance configuration '
48
'file.'
49
)
50
},
51
{
52
'name': 'agent-installer',
53
'synopsis': '--agent-installer <s3-location>',
54
'required': False,
55
'help_text': (
56
'Optional. The AWS CodeDeploy Agent installer file.'
57
)
58
}
59
]
60
61
def _run_main(self, parsed_args, parsed_globals):
62
params = parsed_args
63
params.session = self._session
64
validate_region(params, parsed_globals)
65
validate_instance(params)
66
params.system.validate_administrator()
67
self._validate_override_config(params)
68
self._validate_agent_installer(params)
69
70
try:
71
self._create_config(params)
72
self._install_agent(params)
73
except Exception as e:
74
sys.stdout.flush()
75
sys.stderr.write(
76
'ERROR\n'
77
'{0}\n'
78
'Install the AWS CodeDeploy Agent on the on-premises instance '
79
'by following the instructions in "Configure Existing '
80
'On-Premises Instances by Using AWS CodeDeploy" in the AWS '
81
'CodeDeploy User Guide.\n'.format(e)
82
)
83
84
def _validate_override_config(self, params):
85
if os.path.isfile(params.system.CONFIG_PATH) and \
86
not params.override_config:
87
raise RuntimeError(
88
'The on-premises instance configuration file already exists. '
89
'Specify --override-config to update the existing on-premises '
90
'instance configuration file.'
91
)
92
93
def _validate_agent_installer(self, params):
94
validate_s3_location(params, 'agent_installer')
95
if 'bucket' not in params:
96
params.bucket = 'aws-codedeploy-{0}'.format(params.region)
97
if 'key' not in params:
98
params.key = 'latest/{0}'.format(params.system.INSTALLER)
99
params.installer = params.system.INSTALLER
100
else:
101
start = params.key.rfind('/') + 1
102
params.installer = params.key[start:]
103
104
def _create_config(self, params):
105
sys.stdout.write(
106
'Creating the on-premises instance configuration file... '
107
)
108
try:
109
os.makedirs(params.system.CONFIG_DIR)
110
except OSError as e:
111
if e.errno != errno.EEXIST:
112
raise e
113
if params.config_file != params.system.CONFIG_PATH:
114
shutil.copyfile(params.config_file, params.system.CONFIG_PATH)
115
sys.stdout.write('DONE\n')
116
117
def _install_agent(self, params):
118
sys.stdout.write('Installing the AWS CodeDeploy Agent... ')
119
params.system.install(params)
120
sys.stdout.write('DONE\n')
121
122