desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Cancel an order reference; all authorizations associated with this order reference are also closed.'
@requires(['AmazonOrderReferenceId']) @api_action('OffAmazonPayments', 10, 1) def cancel_order_reference(self, request, response, **kw):
return self._post_request(request, kw, response)
'Confirms that an order reference has been fulfilled (fully or partially) and that you do not expect to create any new authorizations on this order reference.'
@requires(['AmazonOrderReferenceId']) @api_action('OffAmazonPayments', 10, 1) def close_order_reference(self, request, response, **kw):
return self._post_request(request, kw, response)
'Reserves a specified amount against the payment method(s) stored in the order reference.'
@requires(['AmazonOrderReferenceId', 'AuthorizationReferenceId', 'AuthorizationAmount']) @structured_objects('AuthorizationAmount') @api_action('OffAmazonPayments', 10, 1) def authorize(self, request, response, **kw):
return self._post_request(request, kw, response)
'Returns the status of a particular authorization and the total amount captured on the authorization.'
@requires(['AmazonAuthorizationId']) @api_action('OffAmazonPayments', 20, 2) def get_authorization_details(self, request, response, **kw):
return self._post_request(request, kw, response)
'Captures funds from an authorized payment instrument.'
@requires(['AmazonAuthorizationId', 'CaptureReferenceId', 'CaptureAmount']) @structured_objects('CaptureAmount') @api_action('OffAmazonPayments', 10, 1) def capture(self, request, response, **kw):
return self._post_request(request, kw, response)
'Returns the status of a particular capture and the total amount refunded on the capture.'
@requires(['AmazonCaptureId']) @api_action('OffAmazonPayments', 20, 2) def get_capture_details(self, request, response, **kw):
return self._post_request(request, kw, response)
'Closes an authorization.'
@requires(['AmazonAuthorizationId']) @api_action('OffAmazonPayments', 10, 1) def close_authorization(self, request, response, **kw):
return self._post_request(request, kw, response)
'Refunds a previously captured amount.'
@requires(['AmazonCaptureId', 'RefundReferenceId', 'RefundAmount']) @structured_objects('RefundAmount') @api_action('OffAmazonPayments', 10, 1) def refund(self, request, response, **kw):
return self._post_request(request, kw, response)
'Returns the status of a particular refund.'
@requires(['AmazonRefundId']) @api_action('OffAmazonPayments', 20, 2) def get_refund_details(self, request, response, **kw):
return self._post_request(request, kw, response)
'Returns the operational status of the Off-Amazon Payments API section.'
@api_action('OffAmazonPayments', 2, 300, 'GetServiceStatus') def get_offamazonpayments_service_status(self, request, response, **kw):
return self._post_request(request, kw, response)
'Constructor - Create a domain object from a layer1 and data params :type layer1: :class:`boto.cloudsearch2.layer1.Layer1` object :param layer1: A :class:`boto.cloudsearch2.layer1.Layer1` object which is used to perform operations on the domain.'
def __init__(self, layer1, data):
self.layer1 = layer1 self.update_from_data(data)
'Delete this domain and all index data associated with it.'
def delete(self):
return self.layer1.delete_domain(self.name)
'Return a list of Analysis Scheme objects.'
def get_analysis_schemes(self):
return self.layer1.describe_analysis_schemes(self.name)
'Return a :class:`boto.cloudsearch2.option.AvailabilityOptionsStatus` object representing the currently defined availability options for the domain. :return: OptionsStatus object :rtype: :class:`boto.cloudsearch2.option.AvailabilityOptionsStatus` object'
def get_availability_options(self):
return AvailabilityOptionsStatus(self, refresh_fn=self.layer1.describe_availability_options, refresh_key=['DescribeAvailabilityOptionsResponse', 'DescribeAvailabilityOptionsResult', 'AvailabilityOptions'], save_fn=self.layer1.update_availability_options)
'Return a :class:`boto.cloudsearch2.option.ScalingParametersStatus` object representing the currently defined scaling options for the domain. :return: ScalingParametersStatus object :rtype: :class:`boto.cloudsearch2.option.ScalingParametersStatus` object'
def get_scaling_options(self):
return ScalingParametersStatus(self, refresh_fn=self.layer1.describe_scaling_parameters, refresh_key=['DescribeScalingParametersResponse', 'DescribeScalingParametersResult', 'ScalingParameters'], save_fn=self.layer1.update_scaling_parameters)
'Return a :class:`boto.cloudsearch2.option.ServicePoliciesStatus` object representing the currently defined access policies for the domain. :return: ServicePoliciesStatus object :rtype: :class:`boto.cloudsearch2.option.ServicePoliciesStatus` object'
def get_access_policies(self):
return ServicePoliciesStatus(self, refresh_fn=self.layer1.describe_service_access_policies, refresh_key=['DescribeServiceAccessPoliciesResponse', 'DescribeServiceAccessPoliciesResult', 'AccessPolicies'], save_fn=self.layer1.update_service_access_policies)
'Tells the search domain to start indexing its documents using the latest text processing options and IndexFields. This operation must be invoked to make options whose OptionStatus has OptionState of RequiresIndexDocuments visible in search results.'
def index_documents(self):
self.layer1.index_documents(self.name)
'Return a list of index fields defined for this domain. :return: list of IndexFieldStatus objects :rtype: list of :class:`boto.cloudsearch2.option.IndexFieldStatus` object'
def get_index_fields(self, field_names=None):
data = self.layer1.describe_index_fields(self.name, field_names) data = data['DescribeIndexFieldsResponse']['DescribeIndexFieldsResult']['IndexFields'] return [IndexFieldStatus(self, d) for d in data]
'Defines an ``IndexField``, either replacing an existing definition or creating a new one. :type field_name: string :param field_name: The name of a field in the search index. :type field_type: string :param field_type: The type of field. Valid values are int | double | literal | text | date | latlon | int-array | dou...
def create_index_field(self, field_name, field_type, default='', facet=False, returnable=False, searchable=False, sortable=False, highlight=False, source_field=None, analysis_scheme=None):
index = {'IndexFieldName': field_name, 'IndexFieldType': field_type} if (field_type == 'literal'): index['LiteralOptions'] = {'FacetEnabled': facet, 'ReturnEnabled': returnable, 'SearchEnabled': searchable, 'SortEnabled': sortable} if default: index['LiteralOptions']['DefaultValue'] ...
'Return a list of rank expressions defined for this domain. :return: list of ExpressionStatus objects :rtype: list of :class:`boto.cloudsearch2.option.ExpressionStatus` object'
def get_expressions(self, names=None):
fn = self.layer1.describe_expressions data = fn(self.name, names) data = data['DescribeExpressionsResponse']['DescribeExpressionsResult']['Expressions'] return [ExpressionStatus(self, d, fn) for d in data]
'Create a new expression. :type name: string :param name: The name of an expression for processing during a search request. :type value: string :param value: The expression to evaluate for ranking or thresholding while processing a search request. The Expression syntax is based on JavaScript expressions and supports: *...
def create_expression(self, name, value):
data = self.layer1.define_expression(self.name, name, value) data = data['DefineExpressionResponse']['DefineExpressionResult']['Expression'] return ExpressionStatus(self, data, self.layer1.describe_expressions)
'Call Cloudsearch to get the next page of search results :rtype: :class:`boto.cloudsearch2.search.SearchResults` :return: the following page of search results'
def next_page(self):
if (self.query.page <= self.num_pages_needed): self.query.start += self.query.real_size self.query.page += 1 return self.search_service(self.query) else: raise StopIteration
'Transform search parameters from instance properties to a dictionary :rtype: dict :return: search parameters'
def to_params(self):
params = {'start': self.start, 'size': self.real_size} if self.q: params['q'] = self.q if self.parser: params['q.parser'] = self.parser if self.fq: params['fq'] = self.fq if self.expr: for (k, v) in six.iteritems(self.expr): params[('expr.%s' % k)] = v ...
'Transform search parameters from instance properties to a dictionary that CloudSearchDomainConnection can accept :rtype: dict :return: search parameters'
def to_domain_connection_params(self):
params = {'start': self.start, 'size': self.real_size} if self.q: params['q'] = self.q if self.parser: params['query_parser'] = self.parser if self.fq: params['filter_query'] = self.fq if self.expr: expr = {} for (k, v) in six.iteritems(self.expr): ...
'Send a query to CloudSearch Each search query should use at least the q or bq argument to specify the search parameter. The other options are used to specify the criteria of the search. :type q: string :param q: A string to search the default search fields for. :type parser: string :param parser: The parser to use. \'...
def search(self, q=None, parser=None, fq=None, rank=None, return_fields=None, size=10, start=0, facet=None, highlight=None, sort=None, partial=None, options=None):
query = self.build_query(q=q, parser=parser, fq=fq, rank=rank, return_fields=return_fields, size=size, start=start, facet=facet, highlight=highlight, sort=sort, partial=partial, options=options) return self(query)
'Make a call to CloudSearch :type query: :class:`boto.cloudsearch2.search.Query` :param query: A group of search criteria :rtype: :class:`boto.cloudsearch2.search.SearchResults` :return: search results'
def __call__(self, query):
api_version = '2013-01-01' if (self.domain and self.domain.layer1): api_version = self.domain.layer1.APIVersion if self.sign_request: data = self._search_with_auth(query.to_domain_connection_params()) else: r = self._search_without_auth(query.to_params(), api_version) _bo...
'Get a generator to iterate over all pages of search results :type query: :class:`boto.cloudsearch2.search.Query` :param query: A group of search criteria :type per_page: int :param per_page: Number of docs in each :class:`boto.cloudsearch2.search.SearchResults` object. :rtype: generator :return: Generator containing :...
def get_all_paged(self, query, per_page):
query.update_size(per_page) page = 0 num_pages_needed = 0 while (page <= num_pages_needed): results = self(query) num_pages_needed = results.num_pages_needed (yield results) query.start += query.real_size page += 1
'Get a generator to iterate over all search results Transparently handles the results paging from Cloudsearch search results so even if you have many thousands of results you can iterate over all results in a reasonably efficient manner. :type query: :class:`boto.cloudsearch2.search.Query` :param query: A group of sear...
def get_all_hits(self, query):
page = 0 num_pages_needed = 0 while (page <= num_pages_needed): results = self(query) num_pages_needed = results.num_pages_needed for doc in results: (yield doc) query.start += query.real_size page += 1
'Return the total number of hits for query :type query: :class:`boto.cloudsearch2.search.Query` :param query: a group of search criteria :rtype: int :return: Total number of hits for query'
def get_num_hits(self, query):
query.update_size(1) return self(query).hits
'Indexes the search suggestions. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the domains owned by an account within an AWS region. Domain names start with a letter or number and can contain the following characters: a-z (lowercase), 0-9, an...
def build_suggesters(self, domain_name):
params = {'DomainName': domain_name} return self._make_request(action='BuildSuggesters', verb='POST', path='/', params=params)
'Creates a new search domain. For more information, see `Creating a Search Domain`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A name for the domain you are creating. Allowed characters are a-z (lower-case letters), 0-9, and hyphen (-). Domain names must start with a lette...
def create_domain(self, domain_name):
params = {'DomainName': domain_name} return self._make_request(action='CreateDomain', verb='POST', path='/', params=params)
'Configures an analysis scheme that can be applied to a `text` or `text-array` field to define language-specific text processing options. For more information, see `Configuring Analysis Schemes`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A string that represents the name ...
def define_analysis_scheme(self, domain_name, analysis_scheme):
params = {'DomainName': domain_name} self.build_complex_param(params, 'AnalysisScheme', analysis_scheme) return self._make_request(action='DefineAnalysisScheme', verb='POST', path='/', params=params)
'Configures an `Expression` for the search domain. Used to create new expressions and modify existing ones. If the expression exists, the new configuration replaces the old one. For more information, see `Configuring Expressions`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name:...
def define_expression(self, domain_name, expression):
params = {'DomainName': domain_name} self.build_complex_param(params, 'Expression', expression) return self._make_request(action='DefineExpression', verb='POST', path='/', params=params)
'Configures an `IndexField` for the search domain. Used to create new fields and modify existing ones. You must specify the name of the domain you are configuring and an index field configuration. The index field configuration specifies a unique name, the index field type, and the options you want to configure for the ...
def define_index_field(self, domain_name, index_field):
params = {'DomainName': domain_name} self.build_complex_param(params, 'IndexField', index_field) return self._make_request(action='DefineIndexField', verb='POST', path='/', params=params)
'Configures a suggester for a domain. A suggester enables you to display possible matches before users finish typing their queries. When you configure a suggester, you must specify the name of the text field you want to search for possible matches and a unique name for the suggester. For more information, see `Getting ...
def define_suggester(self, domain_name, suggester):
params = {'DomainName': domain_name} self.build_complex_param(params, 'Suggester', suggester) return self._make_request(action='DefineSuggester', verb='POST', path='/', params=params)
'Deletes an analysis scheme. For more information, see `Configuring Analysis Schemes`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the domains owned by an account within an AWS region. Domain name...
def delete_analysis_scheme(self, domain_name, analysis_scheme_name):
params = {'DomainName': domain_name, 'AnalysisSchemeName': analysis_scheme_name} return self._make_request(action='DeleteAnalysisScheme', verb='POST', path='/', params=params)
'Permanently deletes a search domain and all of its data. Once a domain has been deleted, it cannot be recovered. For more information, see `Deleting a Search Domain`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: The name of the domain you want to permanently delete.'
def delete_domain(self, domain_name):
params = {'DomainName': domain_name} return self._make_request(action='DeleteDomain', verb='POST', path='/', params=params)
'Removes an `Expression` from the search domain. For more information, see `Configuring Expressions`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the domains owned by an account within an AWS regi...
def delete_expression(self, domain_name, expression_name):
params = {'DomainName': domain_name, 'ExpressionName': expression_name} return self._make_request(action='DeleteExpression', verb='POST', path='/', params=params)
'Removes an `IndexField` from the search domain. For more information, see `Configuring Index Fields`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the domains owned by an account within an AWS reg...
def delete_index_field(self, domain_name, index_field_name):
params = {'DomainName': domain_name, 'IndexFieldName': index_field_name} return self._make_request(action='DeleteIndexField', verb='POST', path='/', params=params)
'Deletes a suggester. For more information, see `Getting Search Suggestions`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the domains owned by an account within an AWS region. Domain names start w...
def delete_suggester(self, domain_name, suggester_name):
params = {'DomainName': domain_name, 'SuggesterName': suggester_name} return self._make_request(action='DeleteSuggester', verb='POST', path='/', params=params)
'Gets the analysis schemes configured for a domain. An analysis scheme defines language-specific text processing options for a `text` field. Can be limited to specific analysis schemes by name. By default, shows all analysis schemes and includes any pending changes to the configuration. Set the `Deployed` option to `Tr...
def describe_analysis_schemes(self, domain_name, analysis_scheme_names=None, deployed=None):
params = {'DomainName': domain_name} if (analysis_scheme_names is not None): self.build_list_params(params, analysis_scheme_names, 'AnalysisSchemeNames.member') if (deployed is not None): params['Deployed'] = str(deployed).lower() return self._make_request(action='DescribeAnalysisSchemes...
'Gets the availability options configured for a domain. By default, shows the configuration with any pending changes. Set the `Deployed` option to `True` to show the active configuration and exclude pending changes. For more information, see `Configuring Availability Options`_ in the Amazon CloudSearch Developer Guide ...
def describe_availability_options(self, domain_name, deployed=None):
params = {'DomainName': domain_name} if (deployed is not None): params['Deployed'] = str(deployed).lower() return self._make_request(action='DescribeAvailabilityOptions', verb='POST', path='/', params=params)
'Gets information about the search domains owned by this account. Can be limited to specific domains. Shows all domains by default. To get the number of searchable documents in a domain, use the console or submit a `matchall` request to your domain\'s search endpoint: `q=matchall&q.parser=structured&size=0`. For more i...
def describe_domains(self, domain_names=None):
params = {} if (domain_names is not None): self.build_list_params(params, domain_names, 'DomainNames.member') return self._make_request(action='DescribeDomains', verb='POST', path='/', params=params)
'Gets the expressions configured for the search domain. Can be limited to specific expressions by name. By default, shows all expressions and includes any pending changes to the configuration. Set the `Deployed` option to `True` to show the active configuration and exclude pending changes. For more information, see `Co...
def describe_expressions(self, domain_name, expression_names=None, deployed=None):
params = {'DomainName': domain_name} if (expression_names is not None): self.build_list_params(params, expression_names, 'ExpressionNames.member') if (deployed is not None): params['Deployed'] = str(deployed).lower() return self._make_request(action='DescribeExpressions', verb='POST', pa...
'Gets information about the index fields configured for the search domain. Can be limited to specific fields by name. By default, shows all fields and includes any pending changes to the configuration. Set the `Deployed` option to `True` to show the active configuration and exclude pending changes. For more information...
def describe_index_fields(self, domain_name, field_names=None, deployed=None):
params = {'DomainName': domain_name} if (field_names is not None): self.build_list_params(params, field_names, 'FieldNames.member') if (deployed is not None): params['Deployed'] = str(deployed).lower() return self._make_request(action='DescribeIndexFields', verb='POST', path='/', params=...
'Gets the scaling parameters configured for a domain. A domain\'s scaling parameters specify the desired search instance type and replication count. For more information, see `Configuring Scaling Options`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A string that represents...
def describe_scaling_parameters(self, domain_name):
params = {'DomainName': domain_name} return self._make_request(action='DescribeScalingParameters', verb='POST', path='/', params=params)
'Gets information about the access policies that control access to the domain\'s document and search endpoints. By default, shows the configuration with any pending changes. Set the `Deployed` option to `True` to show the active configuration and exclude pending changes. For more information, see `Configuring Access fo...
def describe_service_access_policies(self, domain_name, deployed=None):
params = {'DomainName': domain_name} if (deployed is not None): params['Deployed'] = str(deployed).lower() return self._make_request(action='DescribeServiceAccessPolicies', verb='POST', path='/', params=params)
'Gets the suggesters configured for a domain. A suggester enables you to display possible matches before users finish typing their queries. Can be limited to specific suggesters by name. By default, shows all suggesters and includes any pending changes to the configuration. Set the `Deployed` option to `True` to show t...
def describe_suggesters(self, domain_name, suggester_names=None, deployed=None):
params = {'DomainName': domain_name} if (suggester_names is not None): self.build_list_params(params, suggester_names, 'SuggesterNames.member') if (deployed is not None): params['Deployed'] = str(deployed).lower() return self._make_request(action='DescribeSuggesters', verb='POST', path='...
'Tells the search domain to start indexing its documents using the latest indexing options. This operation must be invoked to activate options whose OptionStatus is `RequiresIndexDocuments`. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the d...
def index_documents(self, domain_name):
params = {'DomainName': domain_name} return self._make_request(action='IndexDocuments', verb='POST', path='/', params=params)
'Lists all search domains owned by an account.'
def list_domain_names(self):
params = {} return self._make_request(action='ListDomainNames', verb='POST', path='/', params=params)
'Configures the availability options for a domain. Enabling the Multi-AZ option expands an Amazon CloudSearch domain to an additional Availability Zone in the same Region to increase fault tolerance in the event of a service disruption. Changes to the Multi-AZ option can take about half an hour to become active. For mo...
def update_availability_options(self, domain_name, multi_az):
params = {'DomainName': domain_name, 'MultiAZ': multi_az} return self._make_request(action='UpdateAvailabilityOptions', verb='POST', path='/', params=params)
'Configures scaling parameters for a domain. A domain\'s scaling parameters specify the desired search instance type and replication count. Amazon CloudSearch will still automatically scale your domain based on the volume of data and traffic, but not below the desired instance type and replication count. If the Multi-A...
def update_scaling_parameters(self, domain_name, scaling_parameters):
params = {'DomainName': domain_name} self.build_complex_param(params, 'ScalingParameters', scaling_parameters) return self._make_request(action='UpdateScalingParameters', verb='POST', path='/', params=params)
'Configures the access rules that control access to the domain\'s document and search endpoints. For more information, see ` Configuring Access for an Amazon CloudSearch Domain`_. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the domains owne...
def update_service_access_policies(self, domain_name, access_policies):
params = {'DomainName': domain_name, 'AccessPolicies': access_policies} return self._make_request(action='UpdateServiceAccessPolicies', verb='POST', path='/', params=params)
'Serialize a structure. For example:: param_type = \'structure\' label = \'IndexField\' value = {\'IndexFieldName\': \'a\', \'IntOptions\': {\'DefaultValue\': 5}} would result in the params dict being updated with these params:: IndexField.IndexFieldName = a IndexField.IntOptions.DefaultValue = 5 :type params: dict :pa...
def build_complex_param(self, params, label, value):
for (k, v) in value.items(): if isinstance(v, dict): for (k2, v2) in v.items(): self.build_complex_param(params, ((label + '.') + k), v) elif isinstance(v, bool): params[('%s.%s' % (label, k))] = ((v and 'true') or 'false') else: params[('%...
'Refresh the local state of the object. You can either pass new state data in as the parameter ``data`` or, if that parameter is omitted, the state data will be retrieved from CloudSearch.'
def refresh(self, data=None):
if (not data): if self.refresh_fn: data = self.refresh_fn(self.domain.name) if (data and self.refresh_key): for key in self.refresh_key: data = data[key] if data: self._update_status(data['Status']) self._update_options(data['Op...
'Return the JSON representation of the options as a string.'
def to_json(self):
return json.dumps(self)
'Write the current state of the local object back to the CloudSearch service.'
def save(self):
if self.save_fn: data = self.save_fn(self.domain.name, self.to_json()) self.refresh(data)
'Returns a new policy statement that will allow access to the service described by ``arn`` by the ip specified in ``ip``. :type arn: string :param arn: The Amazon Resource Notation identifier for the service you wish to provide access to. This would be either the search service or the document service. :type ip: strin...
def new_statement(self, arn, ip):
return {'Effect': 'Allow', 'Action': '*', 'Resource': arn, 'Condition': {'IpAddress': {'aws:SourceIp': [ip]}}}
'Add the provided ip address or CIDR block to the list of allowable address for the search service. :type ip: string :param ip: An IP address or CIDR block you wish to grant access to.'
def allow_search_ip(self, ip):
arn = self.domain.service_arn self._allow_ip(arn, ip)
'Add the provided ip address or CIDR block to the list of allowable address for the document service. :type ip: string :param ip: An IP address or CIDR block you wish to grant access to.'
def allow_doc_ip(self, ip):
arn = self.domain.service_arn self._allow_ip(arn, ip)
'Remove the provided ip address or CIDR block from the list of allowable address for the search service. :type ip: string :param ip: An IP address or CIDR block you wish to grant access to.'
def disallow_search_ip(self, ip):
arn = self.domain.service_arn self._disallow_ip(arn, ip)
'Remove the provided ip address or CIDR block from the list of allowable address for the document service. :type ip: string :param ip: An IP address or CIDR block you wish to grant access to.'
def disallow_doc_ip(self, ip):
arn = self.domain.service_arn self._disallow_ip(arn, ip)
'Add a document to be processed by the DocumentService The document will not actually be added until :func:`commit` is called :type _id: string :param _id: A unique ID used to refer to this document. :type fields: dict :param fields: A dictionary of key-value pairs to be uploaded .'
def add(self, _id, fields):
d = {'type': 'add', 'id': _id, 'fields': fields} self.documents_batch.append(d)
'Schedule a document to be removed from the CloudSearch service The document will not actually be scheduled for removal until :func:`commit` is called :type _id: string :param _id: The unique ID of this document.'
def delete(self, _id):
d = {'type': 'delete', 'id': _id} self.documents_batch.append(d)
'Generate the working set of documents in Search Data Format (SDF) :rtype: string :returns: JSON-formatted string of the documents in SDF'
def get_sdf(self):
return (self._sdf if self._sdf else json.dumps(self.documents_batch))
'Clear the working documents from this DocumentServiceConnection This should be used after :func:`commit` if the connection will be reused for another set of documents.'
def clear_sdf(self):
self._sdf = None self.documents_batch = []
'Load an SDF from S3 Using this method will result in documents added through :func:`add` and :func:`delete` being ignored. :type key_obj: :class:`boto.s3.key.Key` :param key_obj: An S3 key which contains an SDF'
def add_sdf_from_s3(self, key_obj):
self._sdf = key_obj.get_contents_as_string()
'Actually send an SDF to CloudSearch for processing If an SDF file has been explicitly loaded it will be used. Otherwise, documents added through :func:`add` and :func:`delete` will be used. :rtype: :class:`CommitResponse` :returns: A summary of documents added and deleted'
def commit(self):
sdf = self.get_sdf() if (': null' in sdf): boto.log.error('null value in sdf detected. This will probably raise 500 error.') index = sdf.index(': null') boto.log.error(sdf[(index - 100):(index + 100)]) api_version = '2013-01-01' if (self.domain...
'Raise exception if number of ops in response doesn\'t match commit :type type_: str :param type_: Type of commit operation: \'add\' or \'delete\' :type response_num: int :param response_num: Number of adds or deletes in the response. :raises: :class:`boto.cloudsearch2.document.CommitMismatchError`'
def _check_num_ops(self, type_, response_num):
commit_num = len([d for d in self.doc_service.documents_batch if (d['type'] == type_)]) if (response_num != commit_num): if self.signed_request: boto.log.debug(self.response) else: boto.log.debug(self.response.content) exc = CommitMismatchError('Incorrect numbe...
'Return a list of objects for each domain defined in the current account. :rtype: list of :class:`boto.cloudsearch2.domain.Domain`'
def list_domains(self, domain_names=None):
domain_data = self.layer1.describe_domains(domain_names) domain_data = domain_data['DescribeDomainsResponse']['DescribeDomainsResult']['DomainStatusList'] return [Domain(self.layer1, data) for data in domain_data]
'Create a new CloudSearch domain and return the corresponding object. :return: Domain object, or None if the domain isn\'t found :rtype: :class:`boto.cloudsearch2.domain.Domain`'
def create_domain(self, domain_name):
data = self.layer1.create_domain(domain_name) return Domain(self.layer1, data['CreateDomainResponse']['CreateDomainResult']['DomainStatus'])
'Lookup a single domain :param domain_name: The name of the domain to look up :type domain_name: str :return: Domain object, or None if the domain isn\'t found :rtype: :class:`boto.cloudsearch2.domain.Domain`'
def lookup(self, domain_name):
domains = self.list_domains(domain_names=[domain_name]) if (len(domains) > 0): return domains[0]
':type connection: :class:`boto.ec2.EC2Connection` :param connection: Optional connection.'
def __init__(self, connection=None):
dict.__init__(self) self.connection = connection self.current_name = None self.current_value = None
'Init method to create a new connection to EC2 Monitoring Service. B{Note:} The host argument is overridden by the host specified in the boto configuration file.'
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, is_secure=True, port=None, proxy=None, proxy_port=None, proxy_user=None, proxy_pass=None, debug=0, https_connection_factory=None, region=None, path='/', security_token=None, validate_certs=True, profile_name=None):
if (not region): region = RegionInfo(self, self.DefaultRegionName, self.DefaultRegionEndpoint) self.region = region if (self.region.name == 'eu-west-1'): validate_certs = False super(CloudWatchConnection, self).__init__(aws_access_key_id, aws_secret_access_key, is_secure, port, proxy, pr...
'Get time-series data for one or more statistics of a given metric. :type period: integer :param period: The granularity, in seconds, of the returned datapoints. Period must be at least 60 seconds and must be a multiple of 60. The default value is 60. :type start_time: datetime :param start_time: The time stamp to use ...
def get_metric_statistics(self, period, start_time, end_time, metric_name, namespace, statistics, dimensions=None, unit=None):
params = {'Period': period, 'MetricName': metric_name, 'Namespace': namespace, 'StartTime': start_time.isoformat(), 'EndTime': end_time.isoformat()} self.build_list_params(params, statistics, 'Statistics.member.%d') if dimensions: self.build_dimension_param(dimensions, params) if unit: p...
'Returns a list of the valid metrics for which there is recorded data available. :type next_token: str :param next_token: A maximum of 500 metrics will be returned at one time. If more results are available, the ResultSet returned will contain a non-Null next_token attribute. Passing that token as a parameter to list_...
def list_metrics(self, next_token=None, dimensions=None, metric_name=None, namespace=None):
params = {} if next_token: params['NextToken'] = next_token if dimensions: self.build_dimension_param(dimensions, params) if metric_name: params['MetricName'] = metric_name if namespace: params['Namespace'] = namespace return self.get_list('ListMetrics', params, [...
'Publishes metric data points to Amazon CloudWatch. Amazon Cloudwatch associates the data points with the specified metric. If the specified metric does not exist, Amazon CloudWatch creates the metric. If a list is specified for some, but not all, of the arguments, the remaining arguments are repeated a corresponding n...
def put_metric_data(self, namespace, name, value=None, timestamp=None, unit=None, dimensions=None, statistics=None):
params = {'Namespace': namespace} self.build_put_params(params, name, value=value, timestamp=timestamp, unit=unit, dimensions=dimensions, statistics=statistics) return self.get_status('PutMetricData', params, verb='POST')
'Retrieves alarms with the specified names. If no name is specified, all alarms for the user are returned. Alarms can be retrieved by using only a prefix for the alarm name, the alarm state, or a prefix for any action. :type action_prefix: string :param action_prefix: The action name prefix. :type alarm_name_prefix: st...
def describe_alarms(self, action_prefix=None, alarm_name_prefix=None, alarm_names=None, max_records=None, state_value=None, next_token=None):
params = {} if action_prefix: params['ActionPrefix'] = action_prefix if alarm_name_prefix: params['AlarmNamePrefix'] = alarm_name_prefix elif alarm_names: self.build_list_params(params, alarm_names, 'AlarmNames.member.%s') if max_records: params['MaxRecords'] = max_re...
'Retrieves history for the specified alarm. Filter alarms by date range or item type. If an alarm name is not specified, Amazon CloudWatch returns histories for all of the owner\'s alarms. Amazon CloudWatch retains the history of deleted alarms for a period of six weeks. If an alarm has been deleted, its history can st...
def describe_alarm_history(self, alarm_name=None, start_date=None, end_date=None, max_records=None, history_item_type=None, next_token=None):
params = {} if alarm_name: params['AlarmName'] = alarm_name if start_date: params['StartDate'] = start_date.isoformat() if end_date: params['EndDate'] = end_date.isoformat() if history_item_type: params['HistoryItemType'] = history_item_type if max_records: ...
'Retrieves all alarms for a single metric. Specify a statistic, period, or unit to filter the set of alarms further. :type metric_name: string :param metric_name: The name of the metric. :type namespace: string :param namespace: The namespace of the metric. :type period: int :param period: The period in seconds over wh...
def describe_alarms_for_metric(self, metric_name, namespace, period=None, statistic=None, dimensions=None, unit=None):
params = {'MetricName': metric_name, 'Namespace': namespace} if period: params['Period'] = period if statistic: params['Statistic'] = statistic if dimensions: self.build_dimension_param(dimensions, params) if unit: params['Unit'] = unit return self.get_list('Descr...
'Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric. Optionally, this operation can associate one or more Amazon Simple Notification Service resources with the alarm. When this operation creates an alarm, the alarm state is immediately set to INSUFFICIENT_DATA. The alarm is evalua...
def put_metric_alarm(self, alarm):
params = {'AlarmName': alarm.name, 'MetricName': alarm.metric, 'Namespace': alarm.namespace, 'Statistic': alarm.statistic, 'ComparisonOperator': alarm.comparison, 'Threshold': alarm.threshold, 'EvaluationPeriods': alarm.evaluation_periods, 'Period': alarm.period} if (alarm.actions_enabled is not None): ...
'Deletes all specified alarms. In the event of an error, no alarms are deleted. :type alarms: list :param alarms: List of alarm names.'
def delete_alarms(self, alarms):
params = {} self.build_list_params(params, alarms, 'AlarmNames.member.%s') return self.get_status('DeleteAlarms', params)
'Temporarily sets the state of an alarm. When the updated StateValue differs from the previous value, the action configured for the appropriate state is invoked. This is not a permanent change. The next periodic alarm check (in about a minute) will set the alarm to its actual state. :type alarm_name: string :param alar...
def set_alarm_state(self, alarm_name, state_reason, state_value, state_reason_data=None):
params = {'AlarmName': alarm_name, 'StateReason': state_reason, 'StateValue': state_value} if state_reason_data: params['StateReasonData'] = json.dumps(state_reason_data) return self.get_status('SetAlarmState', params)
'Enables actions for the specified alarms. :type alarms: list :param alarms: List of alarm names.'
def enable_alarm_actions(self, alarm_names):
params = {} self.build_list_params(params, alarm_names, 'AlarmNames.member.%s') return self.get_status('EnableAlarmActions', params)
'Disables actions for the specified alarms. :type alarms: list :param alarms: List of alarm names.'
def disable_alarm_actions(self, alarm_names):
params = {} self.build_list_params(params, alarm_names, 'AlarmNames.member.%s') return self.get_status('DisableAlarmActions', params)
'Parses a list of MetricAlarms.'
def __init__(self, connection=None):
list.__init__(self) self.connection = connection
'Creates a new Alarm. :type name: str :param name: Name of alarm. :type metric: str :param metric: Name of alarm\'s associated metric. :type namespace: str :param namespace: The namespace for the alarm\'s metric. :type statistic: str :param statistic: The statistic to apply to the alarm\'s associated metric. Valid valu...
def __init__(self, connection=None, name=None, metric=None, namespace=None, statistic=None, comparison=None, threshold=None, period=None, evaluation_periods=None, unit=None, description='', dimensions=None, alarm_actions=None, insufficient_data_actions=None, ok_actions=None):
self.name = name self.connection = connection self.metric = metric self.namespace = namespace self.statistic = statistic if (threshold is not None): self.threshold = float(threshold) else: self.threshold = None self.comparison = self._cmp_map.get(comparison) if (perio...
'Temporarily sets the state of an alarm. :type value: str :param value: OK | ALARM | INSUFFICIENT_DATA :type reason: str :param reason: Reason alarm set (human readable). :type data: str :param data: Reason data (will be jsonified).'
def set_state(self, value, reason, data=None):
return self.connection.set_alarm_state(self.name, reason, value, data)
'Adds an alarm action, represented as an SNS topic, to this alarm. What do do when alarm is triggered. :type action_arn: str :param action_arn: SNS topics to which notification should be sent if the alarm goes to state ALARM.'
def add_alarm_action(self, action_arn=None):
if (not action_arn): return self.actions_enabled = 'true' self.alarm_actions.append(action_arn)
'Adds an insufficient_data action, represented as an SNS topic, to this alarm. What to do when the insufficient_data state is reached. :type action_arn: str :param action_arn: SNS topics to which notification should be sent if the alarm goes to state INSUFFICIENT_DATA.'
def add_insufficient_data_action(self, action_arn=None):
if (not action_arn): return self.actions_enabled = 'true' self.insufficient_data_actions.append(action_arn)
'Adds an ok action, represented as an SNS topic, to this alarm. What to do when the ok state is reached. :type action_arn: str :param action_arn: SNS topics to which notification should be sent if the alarm goes to state INSUFFICIENT_DATA.'
def add_ok_action(self, action_arn=None):
if (not action_arn): return self.actions_enabled = 'true' self.ok_actions.append(action_arn)
':type start_time: datetime :param start_time: The time stamp to use for determining the first datapoint to return. The value specified is inclusive; results include datapoints with the time stamp specified. :type end_time: datetime :param end_time: The time stamp to use for determining the last datapoint to return. Th...
def query(self, start_time, end_time, statistics, unit=None, period=60):
if (not isinstance(statistics, list)): statistics = [statistics] return self.connection.get_metric_statistics(period, start_time, end_time, self.name, self.namespace, statistics, self.dimensions, unit)
'Creates or updates an alarm and associates it with this metric. Optionally, this operation can associate one or more Amazon Simple Notification Service resources with the alarm. When this operation creates an alarm, the alarm state is immediately set to INSUFFICIENT_DATA. The alarm is evaluated and its StateValue is s...
def create_alarm(self, name, comparison, threshold, period, evaluation_periods, statistic, enabled=True, description=None, dimensions=None, alarm_actions=None, ok_actions=None, insufficient_data_actions=None, unit=None):
if (not dimensions): dimensions = self.dimensions alarm = MetricAlarm(self.connection, name, self.name, self.namespace, statistic, comparison, threshold, period, evaluation_periods, unit, description, dimensions, alarm_actions, insufficient_data_actions, ok_actions) if self.connection.put_metric_ala...
'Retrieves all alarms for this metric. Specify a statistic, period, or unit to filter the set of alarms further. :type period: int :param period: The period in seconds over which the statistic is applied. :type statistic: string :param statistic: The statistic for the metric. :type dimensions: dict :param dimension: A ...
def describe_alarms(self, period=None, statistic=None, dimensions=None, unit=None):
return self.connection.describe_alarms_for_metric(self.name, self.namespace, period, statistic, dimensions, unit)
'Delete the KeyPair. :rtype: bool :return: True if successful, otherwise False.'
def delete(self, dry_run=False):
return self.connection.delete_key_pair(self.name, dry_run=dry_run)
'Save the material (the unencrypted PEM encoded RSA private key) of a newly created KeyPair to a local file. :type directory_path: string :param directory_path: The fully qualified path to the directory in which the keypair will be saved. The keypair file will be named using the name of the keypair as the base name an...
def save(self, directory_path):
if self.material: directory_path = os.path.expanduser(directory_path) file_path = os.path.join(directory_path, ('%s.pem' % self.name)) if os.path.exists(file_path): raise BotoClientError(('%s already exists, it will not be overwritten' % file_path)) f...
'Create a new key pair of the same new in another region. Note that the new key pair will use a different ssh cert than the this key pair. After doing the copy, you will need to save the material associated with the new key pair (use the save method) to a local file. :type region: :class:`boto.ec2.regioninfo.RegionInf...
def copy_to_region(self, region, dry_run=False):
if (region.name == self.region): raise BotoClientError('Unable to copy to the same Region') conn_params = self.connection.get_params() rconn = region.connect(**conn_params) kp = rconn.create_key_pair(self.name, dry_run=dry_run) return kp
'Add a tag to this object. Tags are stored by AWS and can be used to organize and filter resources. Adding a tag involves a round-trip to the EC2 service. :type key: str :param key: The key or name of the tag being stored. :type value: str :param value: An optional value that can be stored with the tag. If you want o...
def add_tag(self, key, value='', dry_run=False):
self.add_tags({key: value}, dry_run)
'Add tags to this object. Tags are stored by AWS and can be used to organize and filter resources. Adding tags involves a round-trip to the EC2 service. :type tags: dict :param tags: A dictionary of key-value pairs for the tags being stored. If for some tags you want only the name and no value, the corresponding valu...
def add_tags(self, tags, dry_run=False):
status = self.connection.create_tags([self.id], tags, dry_run=dry_run) if (self.tags is None): self.tags = TagSet() self.tags.update(tags)
'Remove a tag from this object. Removing a tag involves a round-trip to the EC2 service. :type key: str :param key: The key or name of the tag being stored. :type value: str :param value: An optional value that can be stored with the tag. If a value is provided, it must match the value currently stored in EC2. If not...
def remove_tag(self, key, value=None, dry_run=False):
self.remove_tags({key: value}, dry_run)