1
# Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved
3
# Permission is hereby granted, free of charge, to any person obtaining a
4
# copy of this software and associated documentation files (the
5
# "Software"), to deal in the Software without restriction, including
6
# without limitation the rights to use, copy, modify, merge, publish, dis-
7
# tribute, sublicense, and/or sell copies of the Software, and to permit
8
# persons to whom the Software is furnished to do so, subject to the fol-
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
from boto.connection import AWSQueryConnection
26
from boto.regioninfo import RegionInfo
27
from boto.exception import JSONResponseError
28
from boto.support import exceptions
31
class SupportConnection(AWSQueryConnection):
34
The AWS Support API reference is intended for programmers who need
35
detailed information about the AWS Support actions and data types.
36
This service enables you to manage with your AWS Support cases
37
programmatically. It is built on the AWS Query API programming
38
model and provides HTTP methods that take parameters and return
39
results in JSON format.
41
The AWS Support service also exposes a set of `Trusted Advisor`_
42
features. You can retrieve a list of checks you can run on your
43
resources, specify checks to run and refresh, and check the status
44
of checks you have submitted.
46
The following list describes the AWS Support case management
50
+ **Service names, issue categories, and available severity
51
levels. **The actions `DescribeServices`_ and
52
`DescribeSeverityLevels`_ enable you to obtain AWS service names,
53
service codes, service categories, and problem severity levels.
54
You use these values when you call the `CreateCase`_ action.
55
+ **Case Creation, case details, and case resolution**. The
56
actions `CreateCase`_, `DescribeCases`_, and `ResolveCase`_ enable
57
you to create AWS Support cases, retrieve them, and resolve them.
58
+ **Case communication**. The actions
59
`DescribeCaseCommunications`_ and `AddCommunicationToCase`_ enable
60
you to retrieve and add communication to AWS Support cases.
63
The following list describes the actions available from the AWS
64
Support service for Trusted Advisor:
67
+ `DescribeTrustedAdviserChecks`_ returns the list of checks that you can run against your AWS
69
+ Using the CheckId for a specific check returned by
70
DescribeTrustedAdviserChecks, you can call
71
`DescribeTrustedAdvisorCheckResult`_ and obtain a new result for the check you specified.
72
+ Using `DescribeTrustedAdvisorCheckSummaries`_, you can get
73
summaries for a set of Trusted Advisor checks.
74
+ `RefreshTrustedAdvisorCheck`_ enables you to request that
75
Trusted Advisor run the check again.
76
+ ``_ gets statuses on the checks you are running.
79
For authentication of requests, the AWS Support uses `Signature
80
Version 4 Signing Process`_.
82
See the AWS Support Developer Guide for information about how to
83
use this service to manage create and manage your support cases,
84
and how to call Trusted Advisor for results of checks on your
87
APIVersion = "2012-12-15"
88
DefaultRegionName = "us-east-1"
89
DefaultRegionEndpoint = "support.us-east-1.amazonaws.com"
90
ServiceName = "Support"
91
TargetPrefix = "AWSSupport_20130415"
92
ResponseError = JSONResponseError
95
"CaseIdNotFound": exceptions.CaseIdNotFound,
96
"CaseCreationLimitExceeded": exceptions.CaseCreationLimitExceeded,
97
"InternalServerError": exceptions.InternalServerError,
101
def __init__(self, **kwargs):
102
region = kwargs.pop('region', None)
104
region = RegionInfo(self, self.DefaultRegionName,
105
self.DefaultRegionEndpoint)
106
kwargs['host'] = region.endpoint
107
AWSQueryConnection.__init__(self, **kwargs)
110
def _required_auth_capability(self):
113
def add_communication_to_case(self, communication_body, case_id=None,
114
cc_email_addresses=None):
116
This action adds additional customer communication to an AWS
117
Support case. You use the CaseId value to identify the case to
118
which you want to add communication. You can list a set of
119
email addresses to copy on the communication using the
120
CcEmailAddresses value. The CommunicationBody value contains
121
the text of the communication.
123
This action's response indicates the success or failure of the
126
This action implements a subset of the behavior on the AWS
127
Support `Your Support Cases`_ web form.
129
:type case_id: string
132
:type communication_body: string
133
:param communication_body:
135
:type cc_email_addresses: list
136
:param cc_email_addresses:
139
params = {'communicationBody': communication_body, }
140
if case_id is not None:
141
params['caseId'] = case_id
142
if cc_email_addresses is not None:
143
params['ccEmailAddresses'] = cc_email_addresses
144
return self.make_request(action='AddCommunicationToCase',
145
body=json.dumps(params))
147
def create_case(self, subject, service_code, category_code,
148
communication_body, severity_code=None,
149
cc_email_addresses=None, language=None, issue_type=None):
151
Creates a new case in the AWS Support Center. This action is
152
modeled on the behavior of the AWS Support Center `Open a new
153
case`_ page. Its parameters require you to specify the
154
following information:
157
#. **ServiceCode.** Represents a code for an AWS service. You
158
obtain the ServiceCode by calling `DescribeServices`_.
159
#. **CategoryCode**. Represents a category for the service
160
defined for the ServiceCode value. You also obtain the
161
cateogory code for a service by calling `DescribeServices`_.
162
Each AWS service defines its own set of category codes.
163
#. **SeverityCode**. Represents a value that specifies the
164
urgency of the case, and the time interval in which your
165
service level agreement specifies a response from AWS Support.
166
You obtain the SeverityCode by calling
167
`DescribeSeverityLevels`_.
168
#. **Subject**. Represents the **Subject** field on the AWS
169
Support Center `Open a new case`_ page.
170
#. **CommunicationBody**. Represents the **Description** field
171
on the AWS Support Center `Open a new case`_ page.
172
#. **Language**. Specifies the human language in which AWS
173
Support handles the case. The API currently supports English
175
#. **CcEmailAddresses**. Represents the AWS Support Center
176
**CC** field on the `Open a new case`_ page. You can list
177
email addresses to be copied on any correspondence about the
178
case. The account that opens the case is already identified by
179
passing the AWS Credentials in the HTTP POST method or in a
180
method or function call from one of the programming languages
181
supported by an `AWS SDK`_.
184
The AWS Support API does not currently support the ability to
185
add attachments to cases. You can, however, call
186
`AddCommunicationToCase`_ to add information to an open case.
188
A successful `CreateCase`_ request returns an AWS Support case
189
number. Case numbers are used by `DescribeCases`_ request to
190
retrieve existing AWS Support support cases.
192
:type subject: string
195
:type service_code: string
198
:type severity_code: string
199
:param severity_code:
201
:type category_code: string
202
:param category_code:
204
:type communication_body: string
205
:param communication_body:
207
:type cc_email_addresses: list
208
:param cc_email_addresses:
210
:type language: string
213
:type issue_type: string
219
'serviceCode': service_code,
220
'categoryCode': category_code,
221
'communicationBody': communication_body,
223
if severity_code is not None:
224
params['severityCode'] = severity_code
225
if cc_email_addresses is not None:
226
params['ccEmailAddresses'] = cc_email_addresses
227
if language is not None:
228
params['language'] = language
229
if issue_type is not None:
230
params['issueType'] = issue_type
231
return self.make_request(action='CreateCase',
232
body=json.dumps(params))
234
def describe_cases(self, case_id_list=None, display_id=None,
235
after_time=None, before_time=None,
236
include_resolved_cases=None, next_token=None,
237
max_results=None, language=None):
239
This action returns a list of cases that you specify by
240
passing one or more CaseIds. In addition, you can filter the
241
cases by date by setting values for the AfterTime and
242
BeforeTime request parameters.
243
The response returns the following in JSON format:
245
#. One or more `CaseDetails`_ data types.
246
#. One or more NextToken objects, strings that specifies where
247
to paginate the returned records represented by CaseDetails .
249
:type case_id_list: list
252
:type display_id: string
255
:type after_time: string
258
:type before_time: string
261
:type include_resolved_cases: boolean
262
:param include_resolved_cases:
264
:type next_token: string
267
:type max_results: integer
270
:type language: string
275
if case_id_list is not None:
276
params['caseIdList'] = case_id_list
277
if display_id is not None:
278
params['displayId'] = display_id
279
if after_time is not None:
280
params['afterTime'] = after_time
281
if before_time is not None:
282
params['beforeTime'] = before_time
283
if include_resolved_cases is not None:
284
params['includeResolvedCases'] = include_resolved_cases
285
if next_token is not None:
286
params['nextToken'] = next_token
287
if max_results is not None:
288
params['maxResults'] = max_results
289
if language is not None:
290
params['language'] = language
291
return self.make_request(action='DescribeCases',
292
body=json.dumps(params))
294
def describe_communications(self, case_id, before_time=None,
295
after_time=None, next_token=None,
298
This action returns communications regarding the support case.
299
You can use the AfterTime and BeforeTime parameters to filter
300
by date. The CaseId parameter enables you to identify a
301
specific case by its CaseId number.
303
The MaxResults and NextToken parameters enable you to control
304
the pagination of the result set. Set MaxResults to the number
305
of cases you want displayed on each page, and use NextToken to
306
specify the resumption of pagination.
308
:type case_id: string
311
:type before_time: string
314
:type after_time: string
317
:type next_token: string
320
:type max_results: integer
324
params = {'caseId': case_id, }
325
if before_time is not None:
326
params['beforeTime'] = before_time
327
if after_time is not None:
328
params['afterTime'] = after_time
329
if next_token is not None:
330
params['nextToken'] = next_token
331
if max_results is not None:
332
params['maxResults'] = max_results
333
return self.make_request(action='DescribeCommunications',
334
body=json.dumps(params))
336
def describe_services(self, service_code_list=None, language=None):
338
Returns the current list of AWS services and a list of service
339
categories that applies to each one. You then use service
340
names and categories in your `CreateCase`_ requests. Each AWS
341
service has its own set of categories.
343
The service codes and category codes correspond to the values
344
that are displayed in the **Service** and **Category** drop-
345
down lists on the AWS Support Center `Open a new case`_ page.
346
The values in those fields, however, do not necessarily match
347
the service codes and categories returned by the
348
`DescribeServices` request. Always use the service codes and
349
categories obtained programmatically. This practice ensures
350
that you always have the most recent set of service and
353
:type service_code_list: list
354
:param service_code_list:
356
:type language: string
361
if service_code_list is not None:
362
params['serviceCodeList'] = service_code_list
363
if language is not None:
364
params['language'] = language
365
return self.make_request(action='DescribeServices',
366
body=json.dumps(params))
368
def describe_severity_levels(self, language=None):
370
This action returns the list of severity levels that you can
371
assign to an AWS Support case. The severity level for a case
372
is also a field in the `CaseDetails`_ data type included in
373
any `CreateCase`_ request.
375
:type language: string
380
if language is not None:
381
params['language'] = language
382
return self.make_request(action='DescribeSeverityLevels',
383
body=json.dumps(params))
385
def resolve_case(self, case_id=None):
387
Takes a CaseId and returns the initial state of the case along
388
with the state of the case after the call to `ResolveCase`_
391
:type case_id: string
396
if case_id is not None:
397
params['caseId'] = case_id
398
return self.make_request(action='ResolveCase',
399
body=json.dumps(params))
401
def describe_trusted_advisor_check_refresh_statuses(self, check_ids):
403
Returns the status of all refresh requests Trusted Advisor
404
checks called using `RefreshTrustedAdvisorCheck`_.
406
:type check_ids: list
410
params = {'checkIds': check_ids, }
411
return self.make_request(action='DescribeTrustedAdvisorCheckRefreshStatuses',
412
body=json.dumps(params))
414
def describe_trusted_advisor_check_result(self, check_id, language=None):
416
This action responds with the results of a Trusted Advisor
417
check. Once you have obtained the list of available Trusted
418
Advisor checks by calling `DescribeTrustedAdvisorChecks`_, you
419
specify the CheckId for the check you want to retrieve from
422
The response for this action contains a JSON-formatted
423
`TrustedAdvisorCheckResult`_ object
424
, which is a container for the following three objects:
428
#. `TrustedAdvisorCategorySpecificSummary`_
429
#. `TrustedAdvisorResourceDetail`_
430
#. `TrustedAdvisorResourcesSummary`_
433
In addition, the response contains the following fields:
436
#. **Status**. Overall status of the check.
437
#. **Timestamp**. Time at which Trusted Advisor last ran the
439
#. **CheckId**. Unique identifier for the specific check
440
returned by the request.
442
:type check_id: string
445
:type language: string
449
params = {'checkId': check_id, }
450
if language is not None:
451
params['language'] = language
452
return self.make_request(action='DescribeTrustedAdvisorCheckResult',
453
body=json.dumps(params))
455
def describe_trusted_advisor_check_summaries(self, check_ids):
457
This action enables you to get the latest summaries for
458
Trusted Advisor checks that you specify in your request. You
459
submit the list of Trusted Advisor checks for which you want
460
summaries. You obtain these CheckIds by submitting a
461
`DescribeTrustedAdvisorChecks`_ request.
463
The response body contains an array of
464
`TrustedAdvisorCheckSummary`_ objects.
466
:type check_ids: list
470
params = {'checkIds': check_ids, }
471
return self.make_request(action='DescribeTrustedAdvisorCheckSummaries',
472
body=json.dumps(params))
474
def describe_trusted_advisor_checks(self, language):
476
This action enables you to get a list of the available Trusted
477
Advisor checks. You must specify a language code. English
478
("en") and Japanese ("jp") are currently supported. The
479
response contains a list of `TrustedAdvisorCheckDescription`_
482
:type language: string
486
params = {'language': language, }
487
return self.make_request(action='DescribeTrustedAdvisorChecks',
488
body=json.dumps(params))
490
def refresh_trusted_advisor_check(self, check_id):
492
This action enables you to query the service to request a
493
refresh for a specific Trusted Advisor check. Your request
494
body contains a CheckId for which you are querying. The
495
response body contains a `RefreshTrustedAdvisorCheckResult`_
496
object containing Status and TimeUntilNextRefresh fields.
498
:type check_id: string
502
params = {'checkId': check_id, }
503
return self.make_request(action='RefreshTrustedAdvisorCheck',
504
body=json.dumps(params))
506
def make_request(self, action, body):
508
'X-Amz-Target': '%s.%s' % (self.TargetPrefix, action),
509
'Host': self.region.endpoint,
510
'Content-Type': 'application/x-amz-json-1.1',
511
'Content-Length': str(len(body)),
513
http_request = self.build_base_http_request(
514
method='POST', path='/', auth_path='/', params={},
515
headers=headers, data=body)
516
response = self._mexe(http_request, sender=None,
517
override_num_retries=10)
518
response_body = response.read()
519
boto.log.debug(response_body)
520
if response.status == 200:
522
return json.loads(response_body)
524
json_body = json.loads(response_body)
525
fault_name = json_body.get('__type', None)
526
exception_class = self._faults.get(fault_name, self.ResponseError)
527
raise exception_class(response.status, response.reason,