~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to boto/support/layer1.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2013-05-10 23:38:14 UTC
  • mfrom: (1.1.10) (14.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130510233814-701dvlop7xfh88i7
Tags: 2.9.2-1
New upstream release (Closes: #700743).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2013 Amazon.com, Inc. or its affiliates.  All Rights Reserved
 
2
#
 
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-
 
9
# lowing conditions:
 
10
#
 
11
# The above copyright notice and this permission notice shall be included
 
12
# in all copies or substantial portions of the Software.
 
13
#
 
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
 
20
# IN THE SOFTWARE.
 
21
#
 
22
 
 
23
import json
 
24
import boto
 
25
from boto.connection import AWSQueryConnection
 
26
from boto.regioninfo import RegionInfo
 
27
from boto.exception import JSONResponseError
 
28
from boto.support import exceptions
 
29
 
 
30
 
 
31
class SupportConnection(AWSQueryConnection):
 
32
    """
 
33
    AWS Support
 
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.
 
40
 
 
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.
 
45
 
 
46
    The following list describes the AWS Support case management
 
47
    actions:
 
48
 
 
49
 
 
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.
 
61
 
 
62
 
 
63
    The following list describes the actions available from the AWS
 
64
    Support service for Trusted Advisor:
 
65
 
 
66
 
 
67
    + `DescribeTrustedAdviserChecks`_    returns the list of checks that you can run against your AWS
 
68
    resources.
 
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.
 
77
 
 
78
 
 
79
    For authentication of requests, the AWS Support uses `Signature
 
80
    Version 4 Signing Process`_.
 
81
 
 
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
 
85
    resources.
 
86
    """
 
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
 
93
 
 
94
    _faults = {
 
95
        "CaseIdNotFound": exceptions.CaseIdNotFound,
 
96
        "CaseCreationLimitExceeded": exceptions.CaseCreationLimitExceeded,
 
97
        "InternalServerError": exceptions.InternalServerError,
 
98
    }
 
99
 
 
100
 
 
101
    def __init__(self, **kwargs):
 
102
        region = kwargs.pop('region', None)
 
103
        if not region:
 
104
            region = RegionInfo(self, self.DefaultRegionName,
 
105
                                self.DefaultRegionEndpoint)
 
106
        kwargs['host'] = region.endpoint
 
107
        AWSQueryConnection.__init__(self, **kwargs)
 
108
        self.region = region
 
109
 
 
110
    def _required_auth_capability(self):
 
111
        return ['hmac-v4']
 
112
 
 
113
    def add_communication_to_case(self, communication_body, case_id=None,
 
114
                                  cc_email_addresses=None):
 
115
        """
 
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.
 
122
 
 
123
        This action's response indicates the success or failure of the
 
124
        request.
 
125
 
 
126
        This action implements a subset of the behavior on the AWS
 
127
        Support `Your Support Cases`_ web form.
 
128
 
 
129
        :type case_id: string
 
130
        :param case_id:
 
131
 
 
132
        :type communication_body: string
 
133
        :param communication_body:
 
134
 
 
135
        :type cc_email_addresses: list
 
136
        :param cc_email_addresses:
 
137
 
 
138
        """
 
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))
 
146
 
 
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):
 
150
        """
 
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:
 
155
 
 
156
 
 
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
 
174
           and Japanese.
 
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`_.
 
182
 
 
183
 
 
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.
 
187
 
 
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.
 
191
 
 
192
        :type subject: string
 
193
        :param subject:
 
194
 
 
195
        :type service_code: string
 
196
        :param service_code:
 
197
 
 
198
        :type severity_code: string
 
199
        :param severity_code:
 
200
 
 
201
        :type category_code: string
 
202
        :param category_code:
 
203
 
 
204
        :type communication_body: string
 
205
        :param communication_body:
 
206
 
 
207
        :type cc_email_addresses: list
 
208
        :param cc_email_addresses:
 
209
 
 
210
        :type language: string
 
211
        :param language:
 
212
 
 
213
        :type issue_type: string
 
214
        :param issue_type:
 
215
 
 
216
        """
 
217
        params = {
 
218
            'subject': subject,
 
219
            'serviceCode': service_code,
 
220
            'categoryCode': category_code,
 
221
            'communicationBody': communication_body,
 
222
        }
 
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))
 
233
 
 
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):
 
238
        """
 
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:
 
244
 
 
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 .
 
248
 
 
249
        :type case_id_list: list
 
250
        :param case_id_list:
 
251
 
 
252
        :type display_id: string
 
253
        :param display_id:
 
254
 
 
255
        :type after_time: string
 
256
        :param after_time:
 
257
 
 
258
        :type before_time: string
 
259
        :param before_time:
 
260
 
 
261
        :type include_resolved_cases: boolean
 
262
        :param include_resolved_cases:
 
263
 
 
264
        :type next_token: string
 
265
        :param next_token:
 
266
 
 
267
        :type max_results: integer
 
268
        :param max_results:
 
269
 
 
270
        :type language: string
 
271
        :param language:
 
272
 
 
273
        """
 
274
        params = {}
 
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))
 
293
 
 
294
    def describe_communications(self, case_id, before_time=None,
 
295
                                after_time=None, next_token=None,
 
296
                                max_results=None):
 
297
        """
 
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.
 
302
 
 
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.
 
307
 
 
308
        :type case_id: string
 
309
        :param case_id:
 
310
 
 
311
        :type before_time: string
 
312
        :param before_time:
 
313
 
 
314
        :type after_time: string
 
315
        :param after_time:
 
316
 
 
317
        :type next_token: string
 
318
        :param next_token:
 
319
 
 
320
        :type max_results: integer
 
321
        :param max_results:
 
322
 
 
323
        """
 
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))
 
335
 
 
336
    def describe_services(self, service_code_list=None, language=None):
 
337
        """
 
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.
 
342
 
 
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
 
351
        category codes.
 
352
 
 
353
        :type service_code_list: list
 
354
        :param service_code_list:
 
355
 
 
356
        :type language: string
 
357
        :param language:
 
358
 
 
359
        """
 
360
        params = {}
 
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))
 
367
 
 
368
    def describe_severity_levels(self, language=None):
 
369
        """
 
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.
 
374
 
 
375
        :type language: string
 
376
        :param language:
 
377
 
 
378
        """
 
379
        params = {}
 
380
        if language is not None:
 
381
            params['language'] = language
 
382
        return self.make_request(action='DescribeSeverityLevels',
 
383
                                 body=json.dumps(params))
 
384
 
 
385
    def resolve_case(self, case_id=None):
 
386
        """
 
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`_
 
389
        completed.
 
390
 
 
391
        :type case_id: string
 
392
        :param case_id:
 
393
 
 
394
        """
 
395
        params = {}
 
396
        if case_id is not None:
 
397
            params['caseId'] = case_id
 
398
        return self.make_request(action='ResolveCase',
 
399
                                 body=json.dumps(params))
 
400
 
 
401
    def describe_trusted_advisor_check_refresh_statuses(self, check_ids):
 
402
        """
 
403
        Returns the status of all refresh requests Trusted Advisor
 
404
        checks called using `RefreshTrustedAdvisorCheck`_.
 
405
 
 
406
        :type check_ids: list
 
407
        :param check_ids:
 
408
 
 
409
        """
 
410
        params = {'checkIds': check_ids, }
 
411
        return self.make_request(action='DescribeTrustedAdvisorCheckRefreshStatuses',
 
412
                                 body=json.dumps(params))
 
413
 
 
414
    def describe_trusted_advisor_check_result(self, check_id, language=None):
 
415
        """
 
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
 
420
        AWS Support.
 
421
 
 
422
        The response for this action contains a JSON-formatted
 
423
        `TrustedAdvisorCheckResult`_ object
 
424
        , which is a container for the following three objects:
 
425
 
 
426
 
 
427
 
 
428
        #. `TrustedAdvisorCategorySpecificSummary`_
 
429
        #. `TrustedAdvisorResourceDetail`_
 
430
        #. `TrustedAdvisorResourcesSummary`_
 
431
 
 
432
 
 
433
        In addition, the response contains the following fields:
 
434
 
 
435
 
 
436
        #. **Status**. Overall status of the check.
 
437
        #. **Timestamp**. Time at which Trusted Advisor last ran the
 
438
           check.
 
439
        #. **CheckId**. Unique identifier for the specific check
 
440
           returned by the request.
 
441
 
 
442
        :type check_id: string
 
443
        :param check_id:
 
444
 
 
445
        :type language: string
 
446
        :param language:
 
447
 
 
448
        """
 
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))
 
454
 
 
455
    def describe_trusted_advisor_check_summaries(self, check_ids):
 
456
        """
 
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.
 
462
 
 
463
        The response body contains an array of
 
464
        `TrustedAdvisorCheckSummary`_ objects.
 
465
 
 
466
        :type check_ids: list
 
467
        :param check_ids:
 
468
 
 
469
        """
 
470
        params = {'checkIds': check_ids, }
 
471
        return self.make_request(action='DescribeTrustedAdvisorCheckSummaries',
 
472
                                 body=json.dumps(params))
 
473
 
 
474
    def describe_trusted_advisor_checks(self, language):
 
475
        """
 
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`_
 
480
        objects.
 
481
 
 
482
        :type language: string
 
483
        :param language:
 
484
 
 
485
        """
 
486
        params = {'language': language, }
 
487
        return self.make_request(action='DescribeTrustedAdvisorChecks',
 
488
                                 body=json.dumps(params))
 
489
 
 
490
    def refresh_trusted_advisor_check(self, check_id):
 
491
        """
 
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.
 
497
 
 
498
        :type check_id: string
 
499
        :param check_id:
 
500
 
 
501
        """
 
502
        params = {'checkId': check_id, }
 
503
        return self.make_request(action='RefreshTrustedAdvisorCheck',
 
504
                                 body=json.dumps(params))
 
505
 
 
506
    def make_request(self, action, body):
 
507
        headers = {
 
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)),
 
512
        }
 
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:
 
521
            if response_body:
 
522
                return json.loads(response_body)
 
523
        else:
 
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,
 
528
                                  body=json_body)
 
529