desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Get a list of bootstrap actions for an Elastic MapReduce cluster :type cluster_id: str :param cluster_id: The cluster id of interest :type marker: str :param marker: Pagination marker'
def list_bootstrap_actions(self, cluster_id, marker=None):
params = {'ClusterId': cluster_id} if marker: params['Marker'] = marker return self.get_object('ListBootstrapActions', params, BootstrapActionList)
'List Elastic MapReduce clusters with optional filtering :type created_after: datetime :param created_after: Bound on cluster creation time :type created_before: datetime :param created_before: Bound on cluster creation time :type cluster_states: list :param cluster_states: Bound on cluster states :type marker: str :pa...
def list_clusters(self, created_after=None, created_before=None, cluster_states=None, marker=None):
params = {} if created_after: params['CreatedAfter'] = created_after.strftime(boto.utils.ISO8601) if created_before: params['CreatedBefore'] = created_before.strftime(boto.utils.ISO8601) if marker: params['Marker'] = marker if cluster_states: self.build_list_params(pa...
'List EC2 instance groups in a cluster :type cluster_id: str :param cluster_id: The cluster id of interest :type marker: str :param marker: Pagination marker'
def list_instance_groups(self, cluster_id, marker=None):
params = {'ClusterId': cluster_id} if marker: params['Marker'] = marker return self.get_object('ListInstanceGroups', params, InstanceGroupList)
'List EC2 instances in a cluster :type cluster_id: str :param cluster_id: The cluster id of interest :type instance_group_id: str :param instance_group_id: The EC2 instance group id of interest :type instance_group_types: list :param instance_group_types: Filter by EC2 instance group type :type marker: str :param marke...
def list_instances(self, cluster_id, instance_group_id=None, instance_group_types=None, marker=None):
params = {'ClusterId': cluster_id} if instance_group_id: params['InstanceGroupId'] = instance_group_id if marker: params['Marker'] = marker if instance_group_types: self.build_list_params(params, instance_group_types, 'InstanceGroupTypes.member') return self.get_object('ListI...
'List cluster steps :type cluster_id: str :param cluster_id: The cluster id of interest :type step_states: list :param step_states: Filter by step states :type marker: str :param marker: Pagination marker'
def list_steps(self, cluster_id, step_states=None, marker=None):
params = {'ClusterId': cluster_id} if marker: params['Marker'] = marker if step_states: self.build_list_params(params, step_states, 'StepStates.member') return self.get_object('ListSteps', params, StepSummaryList)
'Create new metadata tags for the specified resource id. :type resource_id: str :param resource_id: The cluster id :type tags: dict :param tags: A dictionary containing the name/value pairs. If you want to create only a tag name, the value for that tag should be the empty string (e.g. \'\') or None.'
def add_tags(self, resource_id, tags):
assert isinstance(resource_id, six.string_types) params = {'ResourceId': resource_id} params.update(self._build_tag_list(tags)) return self.get_status('AddTags', params, verb='POST')
'Remove metadata tags for the specified resource id. :type resource_id: str :param resource_id: The cluster id :type tags: list :param tags: A list of tag names to remove.'
def remove_tags(self, resource_id, tags):
params = {'ResourceId': resource_id} params.update(self._build_string_list('TagKeys', tags)) return self.get_status('RemoveTags', params, verb='POST')
'Terminate an Elastic MapReduce job flow :type jobflow_id: str :param jobflow_id: A jobflow id'
def terminate_jobflow(self, jobflow_id):
self.terminate_jobflows([jobflow_id])
'Terminate an Elastic MapReduce job flow :type jobflow_ids: list :param jobflow_ids: A list of job flow IDs'
def terminate_jobflows(self, jobflow_ids):
params = {} self.build_list_params(params, jobflow_ids, 'JobFlowIds.member') return self.get_status('TerminateJobFlows', params, verb='POST')
'Adds steps to a jobflow :type jobflow_id: str :param jobflow_id: The job flow id :type steps: list(boto.emr.Step) :param steps: A list of steps to add to the job'
def add_jobflow_steps(self, jobflow_id, steps):
if (not isinstance(steps, list)): steps = [steps] params = {} params['JobFlowId'] = jobflow_id step_args = [self._build_step_args(step) for step in steps] params.update(self._build_step_list(step_args)) return self.get_object('AddJobFlowSteps', params, JobFlowStepList, verb='POST')
'Adds instance groups to a running cluster. :type jobflow_id: str :param jobflow_id: The id of the jobflow which will take the new instance groups :type instance_groups: list(boto.emr.InstanceGroup) :param instance_groups: A list of instance groups to add to the job'
def add_instance_groups(self, jobflow_id, instance_groups):
if (not isinstance(instance_groups, list)): instance_groups = [instance_groups] params = {} params['JobFlowId'] = jobflow_id params.update(self._build_instance_group_list_args(instance_groups)) return self.get_object('AddInstanceGroups', params, AddInstanceGroupsResponse, verb='POST')
'Modify the number of nodes and configuration settings in an instance group. :type instance_group_ids: list(str) :param instance_group_ids: A list of the ID\'s of the instance groups to be modified :type new_sizes: list(int) :param new_sizes: A list of the new sizes for each instance group'
def modify_instance_groups(self, instance_group_ids, new_sizes):
if (not isinstance(instance_group_ids, list)): instance_group_ids = [instance_group_ids] if (not isinstance(new_sizes, list)): new_sizes = [new_sizes] instance_groups = zip(instance_group_ids, new_sizes) params = {} for (k, ig) in enumerate(instance_groups): params[('Instance...
'Runs a job flow :type name: str :param name: Name of the job flow :type log_uri: str :param log_uri: URI of the S3 bucket to place logs :type ec2_keyname: str :param ec2_keyname: EC2 key used for the instances :type availability_zone: str :param availability_zone: EC2 availability zone of the cluster :type master_inst...
def run_jobflow(self, name, log_uri=None, ec2_keyname=None, availability_zone=None, master_instance_type='m1.small', slave_instance_type='m1.small', num_instances=1, action_on_failure='TERMINATE_JOB_FLOW', keep_alive=False, enable_debugging=False, hadoop_version=None, steps=None, bootstrap_actions=[], instance_groups=N...
steps = (steps or []) params = {} if action_on_failure: params['ActionOnFailure'] = action_on_failure if log_uri: params['LogUri'] = log_uri params['Name'] = name common_params = self._build_instance_common_args(ec2_keyname, availability_zone, keep_alive, hadoop_version) para...
'Set termination protection on specified Elastic MapReduce job flows :type jobflow_ids: list or str :param jobflow_ids: A list of job flow IDs :type termination_protection_status: bool :param termination_protection_status: Termination protection status'
def set_termination_protection(self, jobflow_id, termination_protection_status):
assert (termination_protection_status in (True, False)) params = {} params['TerminationProtected'] = ((termination_protection_status and 'true') or 'false') self.build_list_params(params, [jobflow_id], 'JobFlowIds.member') return self.get_status('SetTerminationProtection', params, verb='POST')
'Set whether specified Elastic Map Reduce job flows are visible to all IAM users :type jobflow_ids: list or str :param jobflow_ids: A list of job flow IDs :type visibility: bool :param visibility: Visibility'
def set_visible_to_all_users(self, jobflow_id, visibility):
assert (visibility in (True, False)) params = {} params['VisibleToAllUsers'] = ((visibility and 'true') or 'false') self.build_list_params(params, [jobflow_id], 'JobFlowIds.member') return self.get_status('SetVisibleToAllUsers', params, verb='POST')
'Takes a number of parameters used when starting a jobflow (as specified in run_jobflow() above). Returns a comparable dict for use in making a RunJobFlow request.'
def _build_instance_common_args(self, ec2_keyname, availability_zone, keep_alive, hadoop_version):
params = {'Instances.KeepJobFlowAliveWhenNoSteps': str(keep_alive).lower()} if hadoop_version: params['Instances.HadoopVersion'] = hadoop_version if ec2_keyname: params['Instances.Ec2KeyName'] = ec2_keyname if availability_zone: params['Instances.Placement.AvailabilityZone'] = av...
'Takes a master instance type (string), a slave instance type (string), and a number of instances. Returns a comparable dict for use in making a RunJobFlow request.'
def _build_instance_count_and_type_args(self, master_instance_type, slave_instance_type, num_instances):
params = {'Instances.MasterInstanceType': master_instance_type, 'Instances.SlaveInstanceType': slave_instance_type, 'Instances.InstanceCount': num_instances} return params
'Takes an InstanceGroup; returns a dict that, when its keys are properly prefixed, can be used for describing InstanceGroups in RunJobFlow or AddInstanceGroups requests.'
def _build_instance_group_args(self, instance_group):
params = {'InstanceCount': instance_group.num_instances, 'InstanceRole': instance_group.role, 'InstanceType': instance_group.type, 'Name': instance_group.name, 'Market': instance_group.market} if (instance_group.market == 'SPOT'): params['BidPrice'] = instance_group.bidprice return params
'Takes a list of InstanceGroups, or a single InstanceGroup. Returns a comparable dict for use in making a RunJobFlow or AddInstanceGroups request.'
def _build_instance_group_list_args(self, instance_groups):
if (not isinstance(instance_groups, list)): instance_groups = [instance_groups] params = {} for (i, instance_group) in enumerate(instance_groups): ig_dict = self._build_instance_group_args(instance_group) for (key, value) in six.iteritems(ig_dict): params[('InstanceGroups...
':rtype: str :return: URI to the jar'
def jar(self):
raise NotImplemented()
':rtype: list(str) :return: List of arguments for the step'
def args(self):
raise NotImplemented()
':rtype: str :return: The main class name'
def main_class(self):
raise NotImplemented()
'A elastic mapreduce step that executes a jar :type name: str :param name: The name of the step :type jar: str :param jar: S3 URI to the Jar file :type main_class: str :param main_class: The class to execute in the jar :type action_on_failure: str :param action_on_failure: An action, defined in the EMR docs to take on ...
def __init__(self, name, jar, main_class=None, action_on_failure='TERMINATE_JOB_FLOW', step_args=None):
self.name = name self._jar = jar self._main_class = main_class self.action_on_failure = action_on_failure if isinstance(step_args, six.string_types): step_args = [step_args] self.step_args = step_args
'A hadoop streaming elastic mapreduce step :type name: str :param name: The name of the step :type mapper: str :param mapper: The mapper URI :type reducer: str :param reducer: The reducer URI :type combiner: str :param combiner: The combiner URI. Only works for Hadoop 0.20 and later! :type action_on_failure: str :param...
def __init__(self, name, mapper, reducer=None, combiner=None, action_on_failure='TERMINATE_JOB_FLOW', cache_files=None, cache_archives=None, step_args=None, input=None, output=None, jar='/home/hadoop/contrib/streaming/hadoop-streaming.jar'):
self.name = name self.mapper = mapper self.reducer = reducer self.combiner = combiner self.action_on_failure = action_on_failure self.cache_files = cache_files self.cache_archives = cache_archives self.input = input self.output = output self._jar = jar if isinstance(step_args...
'Delete this domain and all index data associated with it.'
def delete(self):
return self.layer1.delete_domain(self.name)
'Return a :class:`boto.cloudsearch.option.OptionStatus` object representing the currently defined stemming options for the domain.'
def get_stemming(self):
return OptionStatus(self, None, self.layer1.describe_stemming_options, self.layer1.update_stemming_options)
'Return a :class:`boto.cloudsearch.option.OptionStatus` object representing the currently defined stopword options for the domain.'
def get_stopwords(self):
return OptionStatus(self, None, self.layer1.describe_stopword_options, self.layer1.update_stopword_options)
'Return a :class:`boto.cloudsearch.option.OptionStatus` object representing the currently defined synonym options for the domain.'
def get_synonyms(self):
return OptionStatus(self, None, self.layer1.describe_synonym_options, self.layer1.update_synonym_options)
'Return a :class:`boto.cloudsearch.option.OptionStatus` object representing the currently defined access policies for the domain.'
def get_access_policies(self):
return ServicePoliciesStatus(self, None, self.layer1.describe_service_access_policies, 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 OptioState 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.'
def get_index_fields(self, field_names=None):
data = self.layer1.describe_index_fields(self.name, field_names) 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 uint | literal | text :type default: string or int :param defau...
def create_index_field(self, field_name, field_type, default='', facet=False, result=False, searchable=False, source_attributes=[]):
data = self.layer1.define_index_field(self.name, field_name, field_type, default=default, facet=facet, result=result, searchable=searchable, source_attributes=source_attributes) return IndexFieldStatus(self, data, self.layer1.describe_index_fields)
'Return a list of rank expressions defined for this domain.'
def get_rank_expressions(self, rank_names=None):
fn = self.layer1.describe_rank_expressions data = fn(self.name, rank_names) return [RankExpressionStatus(self, d, fn) for d in data]
'Create a new rank expression. :type rank_name: string :param rank_name: The name of an expression computed for ranking while processing a search request. :type rank_expression: string :param rank_expression: The expression to evaluate for ranking or thresholding while processing a search request. The RankExpression sy...
def create_rank_expression(self, name, expression):
data = self.layer1.define_rank_expression(self.name, name, expression) return RankExpressionStatus(self, data, self.layer1.describe_rank_expressions)
'Call Cloudsearch to get the next page of search results :rtype: :class:`boto.cloudsearch.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.bq: params['bq'] = self.bq if self.rank: params['rank'] = ','.join(self.rank) if self.return_fields: params['return-fields'] = ','.join(self.return_fields) if self.facet...
'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 bq: string :param bq: A string to perform a Boolean...
def search(self, q=None, bq=None, rank=None, return_fields=None, size=10, start=0, facet=None, facet_constraints=None, facet_sort=None, facet_top_n=None, t=None):
query = self.build_query(q=q, bq=bq, rank=rank, return_fields=return_fields, size=size, start=start, facet=facet, facet_constraints=facet_constraints, facet_sort=facet_sort, facet_top_n=facet_top_n, t=t) return self(query)
'Make a call to CloudSearch :type query: :class:`boto.cloudsearch.search.Query` :param query: A group of search criteria :rtype: :class:`boto.cloudsearch.search.SearchResults` :return: search results'
def __call__(self, query):
url = ('http://%s/2011-02-01/search' % self.endpoint) params = query.to_params() r = requests.get(url, params=params) body = r.content.decode('utf-8') try: data = json.loads(body) except ValueError as e: if (r.status_code == 403): msg = '' import re ...
'Get a generator to iterate over all pages of search results :type query: :class:`boto.cloudsearch.search.Query` :param query: A group of search criteria :type per_page: int :param per_page: Number of docs in each :class:`boto.cloudsearch.search.SearchResults` object. :rtype: generator :return: Generator containing :cl...
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.cloudsearch.search.Query` :param query: A group of searc...
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.cloudsearch.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
'Create a new search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the following characters: a-z (lowercase), 0-...
def create_domain(self, domain_name):
doc_path = ('create_domain_response', 'create_domain_result', 'domain_status') params = {'DomainName': domain_name} return self.get_response(doc_path, 'CreateDomain', params, verb='POST')
'Defines an ``IndexField``, either replacing an existing definition or creating a new one. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number...
def define_index_field(self, domain_name, field_name, field_type, default='', facet=False, result=False, searchable=False, source_attributes=None):
doc_path = ('define_index_field_response', 'define_index_field_result', 'index_field') params = {'DomainName': domain_name, 'IndexField.IndexFieldName': field_name, 'IndexField.IndexFieldType': field_type} if (field_type == 'literal'): params['IndexField.LiteralOptions.DefaultValue'] = default ...
'Defines a RankExpression, either replacing an existing definition or creating a new one. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number ...
def define_rank_expression(self, domain_name, rank_name, rank_expression):
doc_path = ('define_rank_expression_response', 'define_rank_expression_result', 'rank_expression') params = {'DomainName': domain_name, 'RankExpression.RankExpression': rank_expression, 'RankExpression.RankName': rank_name} return self.get_response(doc_path, 'DefineRankExpression', params, verb='POST')
'Delete a search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the following characters: a-z (lowercase), 0-9, a...
def delete_domain(self, domain_name):
doc_path = ('delete_domain_response', 'delete_domain_result', 'domain_status') params = {'DomainName': domain_name} return self.get_response(doc_path, 'DeleteDomain', params, verb='POST')
'Deletes an existing ``IndexField`` from the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the following ...
def delete_index_field(self, domain_name, field_name):
doc_path = ('delete_index_field_response', 'delete_index_field_result', 'index_field') params = {'DomainName': domain_name, 'IndexFieldName': field_name} return self.get_response(doc_path, 'DeleteIndexField', params, verb='POST')
'Deletes an existing ``RankExpression`` from the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the follow...
def delete_rank_expression(self, domain_name, rank_name):
doc_path = ('delete_rank_expression_response', 'delete_rank_expression_result', 'rank_expression') params = {'DomainName': domain_name, 'RankName': rank_name} return self.get_response(doc_path, 'DeleteRankExpression', params, verb='POST')
'Describes options defining the default search field used by indexing for the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or numb...
def describe_default_search_field(self, domain_name):
doc_path = ('describe_default_search_field_response', 'describe_default_search_field_result', 'default_search_field') params = {'DomainName': domain_name} return self.get_response(doc_path, 'DescribeDefaultSearchField', params, verb='POST')
'Describes the domains (optionally limited to one or more domains by name) owned by this account. :type domain_names: list :param domain_names: Limits the response to the specified domains. :raises: BaseException, InternalException'
def describe_domains(self, domain_names=None):
doc_path = ('describe_domains_response', 'describe_domains_result', 'domain_status_list') params = {} if domain_names: for (i, domain_name) in enumerate(domain_names, 1): params[('DomainNames.member.%d' % i)] = domain_name return self.get_response(doc_path, 'DescribeDomains', params,...
'Describes index fields in the search domain, optionally limited to a single ``IndexField``. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or numb...
def describe_index_fields(self, domain_name, field_names=None):
doc_path = ('describe_index_fields_response', 'describe_index_fields_result', 'index_fields') params = {'DomainName': domain_name} if field_names: for (i, field_name) in enumerate(field_names, 1): params[('FieldNames.member.%d' % i)] = field_name return self.get_response(doc_path, 'D...
'Describes RankExpressions in the search domain, optionally limited to a single expression. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or numbe...
def describe_rank_expressions(self, domain_name, rank_names=None):
doc_path = ('describe_rank_expressions_response', 'describe_rank_expressions_result', 'rank_expressions') params = {'DomainName': domain_name} if rank_names: for (i, rank_name) in enumerate(rank_names, 1): params[('RankNames.member.%d' % i)] = rank_name return self.get_response(doc_p...
'Describes the resource-based policies controlling access to the services in this search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or ...
def describe_service_access_policies(self, domain_name):
doc_path = ('describe_service_access_policies_response', 'describe_service_access_policies_result', 'access_policies') params = {'DomainName': domain_name} return self.get_response(doc_path, 'DescribeServiceAccessPolicies', params, verb='POST')
'Describes stemming options used by indexing for the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the fo...
def describe_stemming_options(self, domain_name):
doc_path = ('describe_stemming_options_response', 'describe_stemming_options_result', 'stems') params = {'DomainName': domain_name} return self.get_response(doc_path, 'DescribeStemmingOptions', params, verb='POST')
'Describes stopword options used by indexing for the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the fo...
def describe_stopword_options(self, domain_name):
doc_path = ('describe_stopword_options_response', 'describe_stopword_options_result', 'stopwords') params = {'DomainName': domain_name} return self.get_response(doc_path, 'DescribeStopwordOptions', params, verb='POST')
'Describes synonym options used by indexing for the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the fol...
def describe_synonym_options(self, domain_name):
doc_path = ('describe_synonym_options_response', 'describe_synonym_options_result', 'synonyms') params = {'DomainName': domain_name} return self.get_response(doc_path, 'DescribeSynonymOptions', params, verb='POST')
'Tells the search domain to start scanning its documents using the latest text processing options and ``IndexFields``. This operation must be invoked to make visible in searches any options whose <a>OptionStatus</a> has ``OptionState`` of ``RequiresIndexDocuments``. :type domain_name: string :param domain_name: A stri...
def index_documents(self, domain_name):
doc_path = ('index_documents_response', 'index_documents_result', 'field_names') params = {'DomainName': domain_name} return self.get_response(doc_path, 'IndexDocuments', params, verb='POST', list_marker='FieldNames')
'Updates options defining the default search field used by indexing for the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number...
def update_default_search_field(self, domain_name, default_search_field):
doc_path = ('update_default_search_field_response', 'update_default_search_field_result', 'default_search_field') params = {'DomainName': domain_name, 'DefaultSearchField': default_search_field} return self.get_response(doc_path, 'UpdateDefaultSearchField', params, verb='POST')
'Updates the policies controlling access to the services in this search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can co...
def update_service_access_policies(self, domain_name, access_policies):
doc_path = ('update_service_access_policies_response', 'update_service_access_policies_result', 'access_policies') params = {'AccessPolicies': access_policies, 'DomainName': domain_name} return self.get_response(doc_path, 'UpdateServiceAccessPolicies', params, verb='POST')
'Updates stemming options used by indexing for the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the foll...
def update_stemming_options(self, domain_name, stems):
doc_path = ('update_stemming_options_response', 'update_stemming_options_result', 'stems') params = {'DomainName': domain_name, 'Stems': stems} return self.get_response(doc_path, 'UpdateStemmingOptions', params, verb='POST')
'Updates stopword options used by indexing for the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the foll...
def update_stopword_options(self, domain_name, stopwords):
doc_path = ('update_stopword_options_response', 'update_stopword_options_result', 'stopwords') params = {'DomainName': domain_name, 'Stopwords': stopwords} return self.get_response(doc_path, 'UpdateStopwordOptions', params, verb='POST')
'Updates synonym options used by indexing for the search domain. :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the follo...
def update_synonym_options(self, domain_name, synonyms):
doc_path = ('update_synonym_options_response', 'update_synonym_options_result', 'synonyms') params = {'DomainName': domain_name, 'Synonyms': synonyms} return self.get_response(doc_path, 'UpdateSynonymOptions', params, verb='POST')
'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: self._update_status(data['status']) self._update_options(data['options'])
'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)
'Performs polling of CloudSearch to wait for the ``state`` of this object to change to the provided state.'
def wait_for_state(self, state):
while (self.state != state): time.sleep(5) self.refresh()
'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.search_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.doc_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.search_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.doc_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 version: int :param version: Version of the document being indexed. If a file is being reindexed, the version shou...
def add(self, _id, version, fields, lang='en'):
d = {'type': 'add', 'id': _id, 'version': version, 'lang': lang, '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. :type version: int :param version: Version of the document to remove. The delete will only occur if this ve...
def delete(self, _id, version):
d = {'type': 'delete', 'id': _id, 'version': version} 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)]) url = ('http://%s/2011-02-01/documents/bat...
'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.cloudsearch.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): raise CommitMismatchError('Incorrect number of {0}s returned. Commit: {1} Response: {2}'.format(type_, commit_num, response_num))
'Return a list of :class:`boto.cloudsearch.domain.Domain` objects for each domain defined in the current account.'
def list_domains(self, domain_names=None):
domain_data = self.layer1.describe_domains(domain_names) return [Domain(self.layer1, data) for data in domain_data]
'Create a new CloudSearch domain and return the corresponding :class:`boto.cloudsearch.domain.Domain` object.'
def create_domain(self, domain_name):
data = self.layer1.create_domain(domain_name) return Domain(self.layer1, data)
'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.cloudsearch.domain.Domain`'
def lookup(self, domain_name):
domains = self.list_domains(domain_names=[domain_name]) if (len(domains) > 0): return domains[0]
'Instantiate an anonymous file-based Bucket around a single key.'
def __init__(self, name, contained_key):
self.name = name self.contained_key = contained_key
'Deletes a key from the bucket. :type key_name: string :param key_name: The key name to delete :type version_id: string :param version_id: Unused in this subclass. :type mfa_token: tuple or list of strings :param mfa_token: Unused in this subclass.'
def delete_key(self, key_name, headers=None, version_id=None, mfa_token=None):
os.remove(key_name)
'This method returns the single key around which this anonymous Bucket was instantiated. :rtype: SimpleResultSet :return: The result from file system listing the keys requested'
def get_all_keys(self, headers=None, **params):
key = Key(self.name, self.contained_key) return SimpleResultSet([key])
'Check to see if a particular key exists within the bucket. Returns: An instance of a Key object or None :type key_name: string :param key_name: The name of the key to retrieve :type version_id: string :param version_id: Unused in this subclass. :type stream_type: integer :param stream_type: Type of the Key - Regular F...
def get_key(self, key_name, headers=None, version_id=None, key_type=Key.KEY_REGULAR_FILE):
if (key_name == '-'): return Key(self.name, '-', key_type=Key.KEY_STREAM_READABLE) else: fp = open(key_name, 'rb') return Key(self.name, key_name, fp)
'Creates a new key :type key_name: string :param key_name: The name of the key to create :rtype: :class:`boto.file.key.Key` :returns: An instance of the newly created key object'
def new_key(self, key_name=None, key_type=Key.KEY_REGULAR_FILE):
if (key_name == '-'): return Key(self.name, '-', key_type=Key.KEY_STREAM_WRITABLE) else: dir_name = os.path.dirname(key_name) if (dir_name and (not os.path.exists(dir_name))): os.makedirs(dir_name) fp = open(key_name, 'wb') return Key(self.name, key_name, fp)
'Retrieves a file from a Key :type fp: file :param fp: File pointer to put the data into :type headers: string :param: ignored in this subclass. :type cb: function :param cb: ignored in this subclass. :type cb: int :param num_cb: ignored in this subclass.'
def get_file(self, fp, headers=None, cb=None, num_cb=10, torrent=False):
if (self.key_type & self.KEY_STREAM_WRITABLE): raise BotoClientError('Stream is not readable') elif (self.key_type & self.KEY_STREAM_READABLE): key_file = self.fp else: key_file = open(self.full_path, 'rb') try: shutil.copyfileobj(key_file, fp) finally: ...
'Store an object in a file using the name of the Key object as the key in file URI and the contents of the file pointed to by \'fp\' as the contents. :type fp: file :param fp: the file whose contents to upload :type headers: dict :param headers: ignored in this subclass. :type replace: bool :param replace: If this para...
def set_contents_from_file(self, fp, headers=None, replace=True, cb=None, num_cb=10, policy=None, md5=None):
if (self.key_type & self.KEY_STREAM_READABLE): raise BotoClientError('Stream is not writable') elif (self.key_type & self.KEY_STREAM_WRITABLE): key_file = self.fp else: if ((not replace) and os.path.exists(self.full_path)): return key_file = open(self.ful...
'Copy contents from the current file to the file pointed to by \'fp\'. :type fp: File-like object :param fp: :type headers: dict :param headers: Unused in this subclass. :type cb: function :param cb: Unused in this subclass. :type cb: int :param num_cb: Unused in this subclass. :type torrent: bool :param torrent: Unuse...
def get_contents_to_file(self, fp, headers=None, cb=None, num_cb=None, torrent=False, version_id=None, res_download_handler=None, response_headers=None):
shutil.copyfileobj(self.fp, fp)
'Retrieve file data from the Key, and return contents as a string. :type headers: dict :param headers: ignored in this subclass. :type cb: function :param cb: ignored in this subclass. :type cb: int :param num_cb: ignored in this subclass. :type cb: int :param num_cb: ignored in this subclass. :type torrent: bool :para...
def get_contents_as_string(self, headers=None, cb=None, num_cb=10, torrent=False):
fp = StringIO() self.get_contents_to_file(fp) return fp.getvalue()
'Closes fp associated with underlying file. Caller should call this method when done with this class, to avoid using up OS resources (e.g., when iterating over a large number of files).'
def close(self):
self.fp.close()
'Serialize a parameter \'name\' which value is a \'dictionary\' into a list of parameters. See: http://docs.aws.amazon.com/sns/latest/api/API_SetPlatformApplicationAttributes.html For example:: dictionary = {\'PlatformPrincipal\': \'foo\', \'PlatformCredential\': \'bar\'} name = \'Attributes\' would result in params di...
def _build_dict_as_list_params(self, params, dictionary, name):
items = sorted(dictionary.items(), key=(lambda x: x[0])) for (kv, index) in zip(items, list(range(1, (len(items) + 1)))): (key, value) = kv prefix = ('%s.entry.%s' % (name, index)) params[('%s.key' % prefix)] = key params[('%s.value' % prefix)] = value
':type next_token: string :param next_token: Token returned by the previous call to this method.'
def get_all_topics(self, next_token=None):
params = {} if next_token: params['NextToken'] = next_token return self._make_request('ListTopics', params)
'Get attributes of a Topic :type topic: string :param topic: The ARN of the topic.'
def get_topic_attributes(self, topic):
params = {'TopicArn': topic} return self._make_request('GetTopicAttributes', params)
'Get attributes of a Topic :type topic: string :param topic: The ARN of the topic. :type attr_name: string :param attr_name: The name of the attribute you want to set. Only a subset of the topic\'s attributes are mutable. Valid values: Policy | DisplayName :type attr_value: string :param attr_value: The new value for t...
def set_topic_attributes(self, topic, attr_name, attr_value):
params = {'TopicArn': topic, 'AttributeName': attr_name, 'AttributeValue': attr_value} return self._make_request('SetTopicAttributes', params)
'Adds a statement to a topic\'s access control policy, granting access for the specified AWS accounts to the specified actions. :type topic: string :param topic: The ARN of the topic. :type label: string :param label: A unique identifier for the new policy statement. :type account_ids: list of strings :param account_id...
def add_permission(self, topic, label, account_ids, actions):
params = {'TopicArn': topic, 'Label': label} self.build_list_params(params, account_ids, 'AWSAccountId.member') self.build_list_params(params, actions, 'ActionName.member') return self._make_request('AddPermission', params)
'Removes a statement from a topic\'s access control policy. :type topic: string :param topic: The ARN of the topic. :type label: string :param label: A unique identifier for the policy statement to be removed.'
def remove_permission(self, topic, label):
params = {'TopicArn': topic, 'Label': label} return self._make_request('RemovePermission', params)
'Create a new Topic. :type topic: string :param topic: The name of the new topic.'
def create_topic(self, topic):
params = {'Name': topic} return self._make_request('CreateTopic', params)
'Delete an existing topic :type topic: string :param topic: The ARN of the topic'
def delete_topic(self, topic):
params = {'TopicArn': topic} return self._make_request('DeleteTopic', params, '/', 'GET')
'Sends a message to all of a topic\'s subscribed endpoints :type topic: string :param topic: The topic you want to publish to. :type message: string :param message: The message you want to send to the topic. Messages must be UTF-8 encoded strings and be at most 4KB in size. :type message_structure: string :param messag...
def publish(self, topic=None, message=None, subject=None, target_arn=None, message_structure=None, message_attributes=None):
if (message is None): raise TypeError("'message' is a required parameter") params = {'Message': message} if (subject is not None): params['Subject'] = subject if (topic is not None): params['TopicArn'] = topic if (target_arn is not None): params['TargetArn...
'Subscribe to a Topic. :type topic: string :param topic: The ARN of the new topic. :type protocol: string :param protocol: The protocol used to communicate with the subscriber. Current choices are: email|email-json|http|https|sqs|sms|application :type endpoint: string :param endpoint: The location of the endpoint for ...
def subscribe(self, topic, protocol, endpoint):
params = {'TopicArn': topic, 'Protocol': protocol, 'Endpoint': endpoint} return self._make_request('Subscribe', params)