Code stringlengths 103 85.9k | Summary listlengths 0 94 |
|---|---|
Please provide a description of the function:def preformat_call(self, api_call):
# Remove possible starting slashes or trailing question marks in call.
api_call_formatted = api_call.lstrip('/')
api_call_formatted = api_call_formatted.rstrip('?')
if api_call != api_call_formatted... | [
" Return properly formatted QualysGuard API call.\n\n "
] |
Please provide a description of the function:def format_call(self, api_version, api_call):
# Remove possible starting slashes or trailing question marks in call.
api_call = api_call.lstrip('/')
api_call = api_call.rstrip('?')
logger.debug('api_call post strip =\n%s' % api_call)
... | [
" Return properly formatted QualysGuard API call according to api_version etiquette.\n\n "
] |
Please provide a description of the function:def format_payload(self, api_version, data):
# Check if payload is for API v1 or API v2.
if (api_version in (1, 2)):
# Check if string type.
if type(data) == str:
# Convert to dictionary.
logger... | [
" Return appropriate QualysGuard API call.\n\n "
] |
Please provide a description of the function:def request(self, api_call, data=None, api_version=None, http_method=None, concurrent_scans_retries=0,
concurrent_scans_retry_delay=0):
logger.debug('api_call =\n%s' % api_call)
logger.debug('api_version =\n%s' % api_version)
... | [
" Return QualysGuard API response.\n\n "
] |
Please provide a description of the function:def travis_after(ini, envlist):
# after-all disabled for pull requests
if os.environ.get('TRAVIS_PULL_REQUEST', 'false') != 'false':
return
if not after_config_matches(ini, envlist):
return # This is not the one that needs to wait
gith... | [
"Wait for all jobs to finish, then exit successfully."
] |
Please provide a description of the function:def after_config_matches(ini, envlist):
section = ini.sections.get('travis:after', {})
if not section:
return False # Never wait if it's not configured
if 'envlist' in section or 'toxenv' in section:
if 'toxenv' in section:
pri... | [
"Determine if this job should wait for the others."
] |
Please provide a description of the function:def get_job_statuses(github_token, api_url, build_id,
polling_interval, job_number):
auth = get_json('{api_url}/auth/github'.format(api_url=api_url),
data={'github_token': github_token})['access_token']
while True:
... | [
"Wait for all the travis jobs to complete.\n\n Once the other jobs are complete, return a list of booleans,\n indicating whether or not the job was successful. Ignore jobs\n marked \"allow_failure\".\n "
] |
Please provide a description of the function:def get_json(url, auth=None, data=None):
headers = {
'Accept': 'application/vnd.travis-ci.2+json',
'User-Agent': 'Travis/Tox-Travis-1.0a',
# User-Agent must start with "Travis/" in order to work
}
if auth:
headers['Authorizati... | [
"Make a GET request, and return the response as parsed JSON."
] |
Please provide a description of the function:def detect_envlist(ini):
# Find the envs that tox knows about
declared_envs = get_declared_envs(ini)
# Find all the envs for all the desired factors given
desired_factors = get_desired_factors(ini)
# Reduce desired factors
desired_envs = ['-'.j... | [
"Default envlist automatically based on the Travis environment."
] |
Please provide a description of the function:def autogen_envconfigs(config, envs):
prefix = 'tox' if config.toxinipath.basename == 'setup.cfg' else None
reader = tox.config.SectionReader("tox", config._cfg, prefix=prefix)
distshare_default = "{homedir}/.tox/distshare"
reader.addsubstitutions(toxini... | [
"Make the envconfigs for undeclared envs.\n\n This is a stripped-down version of parseini.__init__ made for making\n an envconfig.\n "
] |
Please provide a description of the function:def get_declared_envs(ini):
tox_section_name = 'tox:tox' if ini.path.endswith('setup.cfg') else 'tox'
tox_section = ini.sections.get(tox_section_name, {})
envlist = split_env(tox_section.get('envlist', []))
# Add additional envs that are declared as sec... | [
"Get the full list of envs from the tox ini.\n\n This notably also includes envs that aren't in the envlist,\n but are declared by having their own testenv:envname section.\n\n The envs are expected in a particular order. First the ones\n declared in the envlist, then the other testenvs in order.\n "... |
Please provide a description of the function:def get_version_info():
overrides = os.environ.get('__TOX_TRAVIS_SYS_VERSION')
if overrides:
version, major, minor = overrides.split(',')[:3]
major, minor = int(major), int(minor)
else:
version, (major, minor) = sys.version, sys.versi... | [
"Get version info from the sys module.\n\n Override from environment for testing.\n "
] |
Please provide a description of the function:def guess_python_env():
version, major, minor = get_version_info()
if 'PyPy' in version:
return 'pypy3' if major == 3 else 'pypy'
return 'py{major}{minor}'.format(major=major, minor=minor) | [
"Guess the default python env to use."
] |
Please provide a description of the function:def get_default_envlist(version):
if version in ['pypy', 'pypy3']:
return version
# Assume single digit major and minor versions
match = re.match(r'^(\d)\.(\d)(?:\.\d+)?$', version or '')
if match:
major, minor = match.groups()
r... | [
"Parse a default tox env based on the version.\n\n The version comes from the ``TRAVIS_PYTHON_VERSION`` environment\n variable. If that isn't set or is invalid, then use\n sys.version_info to come up with a reasonable default.\n "
] |
Please provide a description of the function:def get_desired_factors(ini):
# Find configuration based on known travis factors
travis_section = ini.sections.get('travis', {})
found_factors = [
(factor, parse_dict(travis_section[factor]))
for factor in TRAVIS_FACTORS
if factor in ... | [
"Get the list of desired envs per declared factor.\n\n Look at all the accepted configuration locations, and give a list\n of envlists, one for each Travis factor found.\n\n Look in the ``[travis]`` section for the known Travis factors,\n which are backed by environment variable checking behind the\n ... |
Please provide a description of the function:def match_envs(declared_envs, desired_envs, passthru):
matched = [
declared for declared in declared_envs
if any(env_matches(declared, desired) for desired in desired_envs)
]
return desired_envs if not matched and passthru else matched | [
"Determine the envs that match the desired_envs.\n\n If ``passthru` is True, and none of the declared envs match the\n desired envs, then the desired envs will be used verbatim.\n\n :param declared_envs: The envs that are declared in the tox config.\n :param desired_envs: The envs desired from the tox-t... |
Please provide a description of the function:def env_matches(declared, desired):
desired_factors = desired.split('-')
declared_factors = declared.split('-')
return all(factor in declared_factors for factor in desired_factors) | [
"Determine if a declared env matches a desired env.\n\n Rather than simply using the name of the env verbatim, take a\n closer look to see if all the desired factors are fulfilled. If\n the desired factors are fulfilled, but there are other factors,\n it should still match the env.\n "
] |
Please provide a description of the function:def override_ignore_outcome(ini):
travis_reader = tox.config.SectionReader("travis", ini)
return travis_reader.getbool('unignore_outcomes', False) | [
"Decide whether to override ignore_outcomes."
] |
Please provide a description of the function:def tox_addoption(parser):
parser.add_argument(
'--travis-after', dest='travis_after', action='store_true',
help='Exit successfully after all Travis jobs complete successfully.')
if 'TRAVIS' in os.environ:
pypy_version_monkeypatch()
... | [
"Add arguments and needed monkeypatches."
] |
Please provide a description of the function:def tox_configure(config):
if 'TRAVIS' not in os.environ:
return
ini = config._cfg
# envlist
if 'TOXENV' not in os.environ and not config.option.env:
envlist = detect_envlist(ini)
undeclared = set(envlist) - set(config.envconfig... | [
"Check for the presence of the added options."
] |
Please provide a description of the function:def parse_dict(value):
lines = [line.strip() for line in value.strip().splitlines()]
pairs = [line.split(':', 1) for line in lines if line]
return dict((k.strip(), v.strip()) for k, v in pairs) | [
"Parse a dict value from the tox config.\n\n .. code-block: ini\n\n [travis]\n python =\n 2.7: py27, docs\n 3.5: py{35,36}\n\n With this config, the value of ``python`` would be parsed\n by this function, and would return::\n\n {\n '2.7': 'py27, docs',\... |
Please provide a description of the function:def pypy_version_monkeypatch():
# Travis virtualenv do not provide `pypy3`, which tox tries to execute.
# This doesnt affect Travis python version `pypy3`, as the pyenv pypy3
# is in the PATH.
# https://github.com/travis-ci/travis-ci/issues/6304
# Fo... | [
"Patch Tox to work with non-default PyPy 3 versions."
] |
Please provide a description of the function:def switch_to_output(self, value=False, **kwargs):
self.direction = digitalio.Direction.OUTPUT
self.value = value | [
"Switch the pin state to a digital output with the provided starting\n value (True/False for high or low, default is False/low).\n "
] |
Please provide a description of the function:def switch_to_input(self, pull=None, **kwargs):
self.direction = digitalio.Direction.INPUT
self.pull = pull | [
"Switch the pin state to a digital input with the provided starting\n pull-up resistor state (optional, no pull-up by default). Note that\n pull-down resistors are NOT supported!\n "
] |
Please provide a description of the function:def direction(self):
if _get_bit(self._mcp.iodir, self._pin):
return digitalio.Direction.INPUT
return digitalio.Direction.OUTPUT | [
"The direction of the pin, either True for an input or\n False for an output.\n "
] |
Please provide a description of the function:def pull(self):
if _get_bit(self._mcp.gppu, self._pin):
return digitalio.Pull.UP
return None | [
"Enable or disable internal pull-up resistors for this pin. A\n value of digitalio.Pull.UP will enable a pull-up resistor, and None will\n disable it. Pull-down resistors are NOT supported!\n "
] |
Please provide a description of the function:def get_consumed_read_units_percent(
table_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
lookback_window_start,
lookback_period,
'ConsumedReadCapacityU... | [
" Returns the number of consumed read units in percent\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric\n :type lookback_period: int\n :param lookback_period: N... |
Please provide a description of the function:def get_throttled_read_event_count(
table_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
lookback_window_start,
lookback_period,
'ReadThrottleEvents')
... | [
" Returns the number of throttled read events during a given time frame\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric\n :type lookback_period: int\n :param l... |
Please provide a description of the function:def get_throttled_by_provisioned_read_event_percent(
table_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
lookback_window_start,
lookback_period,
'ReadT... | [
" Returns the number of throttled read events in percent\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric\n :type lookback_period: int\n :param lookback_period:... |
Please provide a description of the function:def get_throttled_by_consumed_read_percent(
table_name, lookback_window_start=15, lookback_period=5):
try:
metrics1 = __get_aws_metric(
table_name,
lookback_window_start,
lookback_period,
'ConsumedRead... | [
" Returns the number of throttled read events in percent of consumption\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric\n :type lookback_period: int\n :param l... |
Please provide a description of the function:def get_consumed_write_units_percent(
table_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
lookback_window_start,
lookback_period,
'ConsumedWriteCapacit... | [
" Returns the number of consumed write units in percent\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric\n :type lookback_period: int\n :param lookback_period: ... |
Please provide a description of the function:def get_throttled_write_event_count(
table_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
lookback_window_start,
lookback_period,
'WriteThrottleEvents')... | [
" Returns the number of throttled write events during a given time frame\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric\n :type lookback_period: int\n :param ... |
Please provide a description of the function:def get_throttled_by_provisioned_write_event_percent(
table_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
lookback_window_start,
lookback_period,
'Writ... | [
" Returns the number of throttled write events during a given time frame\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric\n :type lookback_period: int\n :param ... |
Please provide a description of the function:def get_throttled_by_consumed_write_percent(
table_name, lookback_window_start=15, lookback_period=5):
try:
metrics1 = __get_aws_metric(
table_name,
lookback_window_start,
lookback_period,
'ConsumedWri... | [
" Returns the number of throttled write events in percent of consumption\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric\n :type lookback_period: int\n :param ... |
Please provide a description of the function:def __get_aws_metric(table_name, lookback_window_start, lookback_period,
metric_name):
try:
now = datetime.utcnow()
start_time = now - timedelta(minutes=lookback_window_start)
end_time = now - timedelta(
minut... | [
" Returns a metric list from the AWS CloudWatch service, may return\n None if no metric exists\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type lookback_window_start: int\n :param lookback_window_start: How many minutes to look at\n :type lookback_period: int\n ... |
Please provide a description of the function:def ensure_provisioning(
table_name, table_key, gsi_name, gsi_key,
num_consec_read_checks, num_consec_write_checks):
if get_global_option('circuit_breaker_url') or get_gsi_option(
table_key, gsi_key, 'circuit_breaker_url'):
if cir... | [
" Ensure that provisioning is correct for Global Secondary Indexes\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type table_key: str\n :param table_key: Table configuration option key name\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type gsi_key: s... |
Please provide a description of the function:def __ensure_provisioning_reads(
table_name, table_key, gsi_name, gsi_key, num_consec_read_checks):
if not get_gsi_option(table_key, gsi_key, 'enable_reads_autoscaling'):
logger.info(
'{0} - GSI: {1} - '
'Autoscaling of reads ... | [
" Ensure that provisioning is correct\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type table_key: str\n :param table_key: Table configuration option key name\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type gsi_key: str\n :param gsi_key: Confi... |
Please provide a description of the function:def __ensure_provisioning_writes(
table_name, table_key, gsi_name, gsi_key, num_consec_write_checks):
if not get_gsi_option(table_key, gsi_key, 'enable_writes_autoscaling'):
logger.info(
'{0} - GSI: {1} - '
'Autoscaling of wri... | [
" Ensure that provisioning of writes is correct\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type table_key: str\n :param table_key: Table configuration option key name\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type gsi_key: str\n :param gsi_... |
Please provide a description of the function:def __update_throughput(
table_name, table_key, gsi_name, gsi_key, read_units, write_units):
try:
current_ru = dynamodb.get_provisioned_gsi_read_units(
table_name, gsi_name)
current_wu = dynamodb.get_provisioned_gsi_write_units(
... | [
" Update throughput on the GSI\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type table_key: str\n :param table_key: Table configuration option key name\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type gsi_key: str\n :param gsi_key: Configuratio... |
Please provide a description of the function:def __ensure_provisioning_alarm(table_name, table_key, gsi_name, gsi_key):
lookback_window_start = get_gsi_option(
table_key, gsi_key, 'lookback_window_start')
lookback_period = get_gsi_option(
table_key, gsi_key, 'lookback_period')
consumed_... | [
" Ensure that provisioning alarm threshold is not exceeded\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type table_key: str\n :param table_key: Table configuration option key name\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type gsi_key: str\n ... |
Please provide a description of the function:def is_open(table_name=None, table_key=None, gsi_name=None, gsi_key=None):
logger.debug('Checking circuit breaker status')
# Parse the URL to make sure it is OK
pattern = re.compile(
r'^(?P<scheme>http(s)?://)'
r'((?P<username>.+):(?P<passwo... | [
" Checks whether the circuit breaker is open\n\n :param table_name: Name of the table being checked\n :param table_key: Configuration key for table\n :param gsi_name: Name of the GSI being checked\n :param gsi_key: Configuration key for the GSI\n :returns: bool -- True if the circuit is open\n "
] |
Please provide a description of the function:def __get_connection_cloudwatch():
region = get_global_option('region')
try:
if (get_global_option('aws_access_key_id') and
get_global_option('aws_secret_access_key')):
logger.debug(
'Authenticating to CloudWat... | [
" Ensure connection to CloudWatch "
] |
Please provide a description of the function:def get_consumed_read_units_percent(
table_name, gsi_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
gsi_name,
lookback_window_start,
lookback_period,
... | [
" Returns the number of consumed read units in percent\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metric... |
Please provide a description of the function:def get_throttled_by_provisioned_read_event_percent(
table_name, gsi_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
gsi_name,
lookback_window_start,
loo... | [
" Returns the number of throttled read events in percent\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metr... |
Please provide a description of the function:def get_consumed_write_units_percent(
table_name, gsi_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
gsi_name,
lookback_window_start,
lookback_period,
... | [
" Returns the number of consumed write units in percent\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the CloudWatch metri... |
Please provide a description of the function:def get_throttled_write_event_count(
table_name, gsi_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
gsi_name,
lookback_window_start,
lookback_period,
... | [
" Returns the number of throttled write events during a given time frame\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the... |
Please provide a description of the function:def get_throttled_by_provisioned_write_event_percent(
table_name, gsi_name, lookback_window_start=15, lookback_period=5):
try:
metrics = __get_aws_metric(
table_name,
gsi_name,
lookback_window_start,
lo... | [
" Returns the number of throttled write events during a given time frame\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type lookback_window_start: int\n :param lookback_window_start: Relative start time for the... |
Please provide a description of the function:def get_tables_and_gsis():
table_names = set()
configured_tables = get_configured_tables()
not_used_tables = set(configured_tables)
# Add regexp table names
for table_instance in list_tables():
for key_name in configured_tables:
... | [
" Get a set of tables and gsis and their configuration keys\n\n :returns: set -- A set of tuples (table_name, table_conf_key)\n "
] |
Please provide a description of the function:def get_table(table_name):
try:
table = Table(table_name, connection=DYNAMODB_CONNECTION)
except DynamoDBResponseError as error:
dynamodb_error = error.body['__type'].rsplit('#', 1)[1]
if dynamodb_error == 'ResourceNotFoundException':
... | [
" Return the DynamoDB table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :returns: boto.dynamodb.table.Table\n "
] |
Please provide a description of the function:def get_gsi_status(table_name, gsi_name):
try:
desc = DYNAMODB_CONNECTION.describe_table(table_name)
except JSONResponseError:
raise
for gsi in desc[u'Table'][u'GlobalSecondaryIndexes']:
if gsi[u'IndexName'] == gsi_name:
... | [
" Return the DynamoDB table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :returns: str\n "
] |
Please provide a description of the function:def get_provisioned_gsi_read_units(table_name, gsi_name):
try:
desc = DYNAMODB_CONNECTION.describe_table(table_name)
except JSONResponseError:
raise
for gsi in desc[u'Table'][u'GlobalSecondaryIndexes']:
if gsi[u'IndexName'] == gsi_na... | [
" Returns the number of provisioned read units for the table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :returns: int -- Number of read units\n "
] |
Please provide a description of the function:def get_provisioned_gsi_write_units(table_name, gsi_name):
try:
desc = DYNAMODB_CONNECTION.describe_table(table_name)
except JSONResponseError:
raise
for gsi in desc[u'Table'][u'GlobalSecondaryIndexes']:
if gsi[u'IndexName'] == gsi_n... | [
" Returns the number of provisioned write units for the table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :returns: int -- Number of write units\n "
] |
Please provide a description of the function:def get_provisioned_table_read_units(table_name):
try:
desc = DYNAMODB_CONNECTION.describe_table(table_name)
except JSONResponseError:
raise
read_units = int(
desc[u'Table'][u'ProvisionedThroughput'][u'ReadCapacityUnits'])
logge... | [
" Returns the number of provisioned read units for the table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :returns: int -- Number of read units\n "
] |
Please provide a description of the function:def get_provisioned_table_write_units(table_name):
try:
desc = DYNAMODB_CONNECTION.describe_table(table_name)
except JSONResponseError:
raise
write_units = int(
desc[u'Table'][u'ProvisionedThroughput'][u'WriteCapacityUnits'])
lo... | [
" Returns the number of provisioned write units for the table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :returns: int -- Number of write units\n "
] |
Please provide a description of the function:def get_table_status(table_name):
try:
desc = DYNAMODB_CONNECTION.describe_table(table_name)
except JSONResponseError:
raise
return desc[u'Table'][u'TableStatus'] | [
" Return the DynamoDB table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :returns: str\n "
] |
Please provide a description of the function:def list_tables():
tables = []
try:
table_list = DYNAMODB_CONNECTION.list_tables()
while True:
for table_name in table_list[u'TableNames']:
tables.append(get_table(table_name))
if u'LastEvaluatedTableName... | [
" Return list of DynamoDB tables available from AWS\n\n :returns: list -- List of DynamoDB tables\n "
] |
Please provide a description of the function:def update_table_provisioning(
table_name, key_name, reads, writes, retry_with_only_increase=False):
table = get_table(table_name)
current_reads = int(get_provisioned_table_read_units(table_name))
current_writes = int(get_provisioned_table_write_unit... | [
" Update provisioning for a given table\n\n :type table_name: str\n :param table_name: Name of the table\n :type key_name: str\n :param key_name: Configuration option key name\n :type reads: int\n :param reads: New number of provisioned read units\n :type writes: int\n :param writes: New num... |
Please provide a description of the function:def update_gsi_provisioning(
table_name, table_key, gsi_name, gsi_key,
reads, writes, retry_with_only_increase=False):
current_reads = int(get_provisioned_gsi_read_units(table_name, gsi_name))
current_writes = int(get_provisioned_gsi_write_units(... | [
" Update provisioning on a global secondary index\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type table_key: str\n :param table_key: Table configuration option key name\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type gsi_key: str\n :param gs... |
Please provide a description of the function:def table_gsis(table_name):
try:
desc = DYNAMODB_CONNECTION.describe_table(table_name)[u'Table']
except JSONResponseError:
raise
if u'GlobalSecondaryIndexes' in desc:
return desc[u'GlobalSecondaryIndexes']
return [] | [
" Returns a list of GSIs for the given table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :returns: list -- List of GSI names\n "
] |
Please provide a description of the function:def __get_connection_dynamodb(retries=3):
connected = False
region = get_global_option('region')
while not connected:
if (get_global_option('aws_access_key_id') and
get_global_option('aws_secret_access_key')):
logger.debu... | [
" Ensure connection to DynamoDB\n\n :type retries: int\n :param retries: Number of times to retry to connect to DynamoDB\n "
] |
Please provide a description of the function:def __is_gsi_maintenance_window(table_name, gsi_name, maintenance_windows):
# Example string '00:00-01:00,10:00-11:00'
maintenance_window_list = []
for window in maintenance_windows.split(','):
try:
start, end = window.split('-', 1)
... | [
" Checks that the current time is within the maintenance window\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type gsi_name: str\n :param gsi_name: Name of the GSI\n :type maintenance_windows: str\n :param maintenance_windows: Example: '00:00-01:00,10:00-11:00'\n ... |
Please provide a description of the function:def publish_gsi_notification(
table_key, gsi_key, message, message_types, subject=None):
topic = get_gsi_option(table_key, gsi_key, 'sns_topic_arn')
if not topic:
return
for message_type in message_types:
if (message_type in
... | [
" Publish a notification for a specific GSI\n\n :type table_key: str\n :param table_key: Table configuration option key name\n :type gsi_key: str\n :param gsi_key: Table configuration option key name\n :type message: str\n :param message: Message to send via SNS\n :type message_types: list\n ... |
Please provide a description of the function:def publish_table_notification(table_key, message, message_types, subject=None):
topic = get_table_option(table_key, 'sns_topic_arn')
if not topic:
return
for message_type in message_types:
if message_type in get_table_option(table_key, 'sns... | [
" Publish a notification for a specific table\n\n :type table_key: str\n :param table_key: Table configuration option key name\n :type message: str\n :param message: Message to send via SNS\n :type message_types: list\n :param message_types:\n List with types:\n - scale-up\n -... |
Please provide a description of the function:def __publish(topic, message, subject=None):
try:
SNS_CONNECTION.publish(topic=topic, message=message, subject=subject)
logger.info('Sent SNS notification to {0}'.format(topic))
except BotoServerError as error:
logger.error('Problem sendi... | [
" Publish a message to a SNS topic\n\n :type topic: str\n :param topic: SNS topic to publish the message to\n :type message: str\n :param message: Message to send via SNS\n :type subject: str\n :param subject: Subject to use for e-mail notifications\n :returns: None\n "
] |
Please provide a description of the function:def __get_connection_SNS():
region = get_global_option('region')
try:
if (get_global_option('aws_access_key_id') and
get_global_option('aws_secret_access_key')):
logger.debug(
'Authenticating to SNS using '
... | [
" Ensure connection to SNS "
] |
Please provide a description of the function:def parse():
parser = argparse.ArgumentParser(
description='Dynamic DynamoDB - Auto provisioning AWS DynamoDB')
parser.add_argument(
'-c', '--config',
help='Read configuration from a configuration file')
parser.add_argument(
'... | [
" Parse command line options ",
"How many seconds should we wait between\n the checks (default: 300)",
"Scale up the reads with --increase-reads-with if\n the currently consumed read units reaches this many\n percent (default: 90)",
"Scale up the reads with --incre... |
Please provide a description of the function:def ensure_provisioning(
table_name, key_name,
num_consec_read_checks,
num_consec_write_checks):
if get_global_option('circuit_breaker_url') or get_table_option(
key_name, 'circuit_breaker_url'):
if circuit_breaker.is_ope... | [
" Ensure that provisioning is correct\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type key_name: str\n :param key_name: Configuration option key name\n :type num_consec_read_checks: int\n :param num_consec_read_checks: How many consecutive checks have we had\n :... |
Please provide a description of the function:def __calculate_always_decrease_rw_values(
table_name, read_units, provisioned_reads,
write_units, provisioned_writes):
if read_units <= provisioned_reads and write_units <= provisioned_writes:
return (read_units, write_units)
if read_un... | [
" Calculate values for always-decrease-rw-together\n\n This will only return reads and writes decreases if both reads and writes\n are lower than the current provisioning\n\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type read_units: int\n :param read_units: New re... |
Please provide a description of the function:def __ensure_provisioning_reads(table_name, key_name, num_consec_read_checks):
if not get_table_option(key_name, 'enable_reads_autoscaling'):
logger.info(
'{0} - Autoscaling of reads has been disabled'.format(table_name))
return False, dy... | [
" Ensure that provisioning is correct\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type key_name: str\n :param key_name: Configuration option key name\n :type num_consec_read_checks: int\n :param num_consec_read_checks: How many consecutive checks have we had\n :... |
Please provide a description of the function:def __ensure_provisioning_writes(
table_name, key_name, num_consec_write_checks):
if not get_table_option(key_name, 'enable_writes_autoscaling'):
logger.info(
'{0} - Autoscaling of writes has been disabled'.format(table_name))
ret... | [
" Ensure that provisioning of writes is correct\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type key_name: str\n :param key_name: Configuration option key name\n :type num_consec_write_checks: int\n :param num_consec_write_checks: How many consecutive checks have w... |
Please provide a description of the function:def __update_throughput(table_name, key_name, read_units, write_units):
try:
current_ru = dynamodb.get_provisioned_table_read_units(table_name)
current_wu = dynamodb.get_provisioned_table_write_units(table_name)
except JSONResponseError:
... | [
" Update throughput on the DynamoDB table\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type key_name: str\n :param key_name: Configuration option key name\n :type read_units: int\n :param read_units: New read unit provisioning\n :type write_units: int\n :param... |
Please provide a description of the function:def __ensure_provisioning_alarm(table_name, key_name):
lookback_window_start = get_table_option(
key_name, 'lookback_window_start')
lookback_period = get_table_option(key_name, 'lookback_period')
consumed_read_units_percent = table_stats.get_consume... | [
" Ensure that provisioning alarm threshold is not exceeded\n\n :type table_name: str\n :param table_name: Name of the DynamoDB table\n :type key_name: str\n :param key_name: Configuration option key name\n "
] |
Please provide a description of the function:def get_configuration():
# This is the dict we will return
configuration = {
'global': {},
'logging': {},
'tables': ordereddict()
}
# Read the command line options
cmd_line_options = command_line_parser.parse()
# If a co... | [
" Get the configuration from command line and config files "
] |
Please provide a description of the function:def __get_cmd_table_options(cmd_line_options):
table_name = cmd_line_options['table_name']
options = {table_name: {}}
for option in DEFAULT_OPTIONS['table'].keys():
options[table_name][option] = DEFAULT_OPTIONS['table'][option]
if option in... | [
" Get all table options from the command line\n\n :type cmd_line_options: dict\n :param cmd_line_options: Dictionary with all command line options\n :returns: dict -- E.g. {'table_name': {}}\n "
] |
Please provide a description of the function:def __get_config_table_options(conf_file_options):
options = ordereddict()
if not conf_file_options:
return options
for table_name in conf_file_options['tables']:
options[table_name] = {}
# Regular table options
for option ... | [
" Get all table options from the config file\n\n :type conf_file_options: ordereddict\n :param conf_file_options: Dictionary with all config file options\n :returns: ordereddict -- E.g. {'table_name': {}}\n "
] |
Please provide a description of the function:def __get_global_options(cmd_line_options, conf_file_options=None):
options = {}
for option in DEFAULT_OPTIONS['global'].keys():
options[option] = DEFAULT_OPTIONS['global'][option]
if conf_file_options and option in conf_file_options:
... | [
" Get all global options\n\n :type cmd_line_options: dict\n :param cmd_line_options: Dictionary with all command line options\n :type conf_file_options: dict\n :param conf_file_options: Dictionary with all config file options\n :returns: dict\n "
] |
Please provide a description of the function:def __get_logging_options(cmd_line_options, conf_file_options=None):
options = {}
for option in DEFAULT_OPTIONS['logging'].keys():
options[option] = DEFAULT_OPTIONS['logging'][option]
if conf_file_options and option in conf_file_options:
... | [
" Get all logging options\n\n :type cmd_line_options: dict\n :param cmd_line_options: Dictionary with all command line options\n :type conf_file_options: dict\n :param conf_file_options: Dictionary with all config file options\n :returns: dict\n "
] |
Please provide a description of the function:def __check_gsi_rules(configuration):
for table_name in configuration['tables']:
if 'gsis' not in configuration['tables'][table_name]:
continue
for gsi_name in configuration['tables'][table_name]['gsis']:
gsi = configuration[... | [
" Do some basic checks on the configuration "
] |
Please provide a description of the function:def __check_logging_rules(configuration):
valid_log_levels = [
'debug',
'info',
'warning',
'error'
]
if configuration['logging']['log_level'].lower() not in valid_log_levels:
print('Log level must be one of {0}'.format... | [
" Check that the logging values are proper "
] |
Please provide a description of the function:def __check_table_rules(configuration):
for table_name in configuration['tables']:
table = configuration['tables'][table_name]
# Check that increase/decrease units is OK
valid_units = ['percent', 'units']
if table['increase_reads_unit... | [
" Do some basic checks on the configuration "
] |
Please provide a description of the function:def decrease_reads_in_percent(
current_provisioning, percent, min_provisioned_reads, log_tag):
percent = float(percent)
decrease = int(float(current_provisioning)*(float(percent)/100))
updated_provisioning = current_provisioning - decrease
min_pr... | [
" Decrease the current_provisioning with percent %\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type percent: int\n :param percent: How many percent should we decrease with\n :type min_provisioned_reads: int\n :param min_provisioned_reads: Configur... |
Please provide a description of the function:def decrease_reads_in_units(
current_provisioning, units, min_provisioned_reads, log_tag):
updated_provisioning = int(current_provisioning) - int(units)
min_provisioned_reads = __get_min_reads(
current_provisioning,
min_provisioned_reads,... | [
" Decrease the current_provisioning with units units\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type units: int\n :param units: How many units should we decrease with\n :returns: int -- New provisioning value\n :type min_provisioned_reads: int\n ... |
Please provide a description of the function:def decrease_writes_in_percent(
current_provisioning, percent, min_provisioned_writes, log_tag):
percent = float(percent)
decrease = int(float(current_provisioning)*(float(percent)/100))
updated_provisioning = current_provisioning - decrease
min_... | [
" Decrease the current_provisioning with percent %\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type percent: int\n :param percent: How many percent should we decrease with\n :returns: int -- New provisioning value\n :type min_provisioned_writes: i... |
Please provide a description of the function:def decrease_writes_in_units(
current_provisioning, units, min_provisioned_writes, log_tag):
updated_provisioning = int(current_provisioning) - int(units)
min_provisioned_writes = __get_min_writes(
current_provisioning,
min_provisioned_wr... | [
" Decrease the current_provisioning with units units\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type units: int\n :param units: How many units should we decrease with\n :returns: int -- New provisioning value\n :type min_provisioned_writes: int\n... |
Please provide a description of the function:def increase_reads_in_percent(
current_provisioning, percent, max_provisioned_reads,
consumed_read_units_percent, log_tag):
current_provisioning = float(current_provisioning)
consumed_read_units_percent = float(consumed_read_units_percent)
pe... | [
" Increase the current_provisioning with percent %\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type percent: int\n :param percent: How many percent should we increase with\n :type max_provisioned_reads: int\n :param max_provisioned_reads: Configur... |
Please provide a description of the function:def increase_reads_in_units(
current_provisioning, units, max_provisioned_reads,
consumed_read_units_percent, log_tag):
units = int(units)
current_provisioning = float(current_provisioning)
consumed_read_units_percent = float(consumed_read_un... | [
" Increase the current_provisioning with units units\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type units: int\n :param units: How many units should we increase with\n :returns: int -- New provisioning value\n :type max_provisioned_reads: int\n ... |
Please provide a description of the function:def increase_writes_in_percent(
current_provisioning, percent, max_provisioned_writes,
consumed_write_units_percent, log_tag):
current_provisioning = float(current_provisioning)
consumed_write_units_percent = float(consumed_write_units_percent)
... | [
" Increase the current_provisioning with percent %\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type percent: int\n :param percent: How many percent should we increase with\n :returns: int -- New provisioning value\n :type max_provisioned_writes: i... |
Please provide a description of the function:def increase_writes_in_units(
current_provisioning, units, max_provisioned_writes,
consumed_write_units_percent, log_tag):
units = int(units)
current_provisioning = float(current_provisioning)
consumed_write_units_percent = float(consumed_wri... | [
" Increase the current_provisioning with units units\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type units: int\n :param units: How many units should we increase with\n :returns: int -- New provisioning value\n :type max_provisioned_writes: int\n... |
Please provide a description of the function:def is_consumed_over_proposed(
current_provisioning, proposed_provisioning, consumed_units_percent):
consumption_based_current_provisioning = \
int(math.ceil(current_provisioning*(consumed_units_percent/100)))
return consumption_based_current_pro... | [
"\n Determines if the currently consumed capacity is over the proposed capacity\n for this table\n\n :type current_provisioning: int\n :param current_provisioning: The current provisioning\n :type proposed_provisioning: int\n :param proposed_provisioning: New provisioning\n :type consumed_units... |
Please provide a description of the function:def __get_min_reads(current_provisioning, min_provisioned_reads, log_tag):
# Fallback value to ensure that we always have at least 1 read
reads = 1
if min_provisioned_reads:
reads = int(min_provisioned_reads)
if reads > int(current_provisio... | [
" Get the minimum number of reads to current_provisioning\n\n :type current_provisioning: int\n :param current_provisioning: Current provisioned reads\n :type min_provisioned_reads: int\n :param min_provisioned_reads: Configured min provisioned reads\n :type log_tag: str\n :param log_tag: Prefix f... |
Please provide a description of the function:def __get_min_writes(current_provisioning, min_provisioned_writes, log_tag):
# Fallback value to ensure that we always have at least 1 read
writes = 1
if min_provisioned_writes:
writes = int(min_provisioned_writes)
if writes > int(current_p... | [
" Get the minimum number of writes to current_provisioning\n\n :type current_provisioning: int\n :param current_provisioning: Current provisioned writes\n :type min_provisioned_writes: int\n :param min_provisioned_writes: Configured min provisioned writes\n :type log_tag: str\n :param log_tag: Pre... |
Please provide a description of the function:def restart(self, *args, **kwargs):
self.stop()
try:
self.start(*args, **kwargs)
except IOError:
raise | [
" Restart the daemon "
] |
Please provide a description of the function:def __parse_options(config_file, section, options):
configuration = {}
for option in options:
try:
if option.get('type') == 'str':
configuration[option.get('key')] = \
config_file.get(section, option.get('o... | [
" Parse the section options\n\n :type config_file: ConfigParser object\n :param config_file: The config file object to use\n :type section: str\n :param section: Which section to read in the configuration file\n :type options: list of dicts\n :param options:\n A list of options to parse. Ex... |
Please provide a description of the function:def parse(config_path):
config_path = os.path.expanduser(config_path)
# Read the configuration file
config_file = ConfigParser.RawConfigParser()
config_file.SECTCRE = re.compile(r"\[ *(?P<header>.*) *\]")
config_file.optionxform = lambda option: opt... | [
" Parse the configuration file\n\n :type config_path: str\n :param config_path: Path to the configuration file\n "
] |
Please provide a description of the function:def main():
try:
if get_global_option('show_config'):
print json.dumps(config.get_configuration(), indent=2)
elif get_global_option('daemon'):
daemon = DynamicDynamoDBDaemon(
'{0}/dynamic-dynamodb.{1}.pid'.form... | [
" Main function called from dynamic-dynamodb "
] |
Please provide a description of the function:def execute():
boto_server_error_retries = 3
# Ensure provisioning
for table_name, table_key in sorted(dynamodb.get_tables_and_gsis()):
try:
table_num_consec_read_checks = \
CHECK_STATUS['tables'][table_name]['reads']
... | [
" Ensure provisioning "
] |
Please provide a description of the function:def init_logging(debug=False, logfile=None):
loglevel = logging.DEBUG if debug else logging.INFO
logformat = '%(asctime)s %(name)s: %(levelname)s: %(message)s'
formatter = logging.Formatter(logformat)
stderr = logging.StreamHandler()
stderr.setFormat... | [
"Initialize logging."
] |
Please provide a description of the function:def decode_tve_parameter(data):
(nontve,) = struct.unpack(nontve_header, data[:nontve_header_len])
if nontve == 1023: # customparameter
(size,) = struct.unpack('!H',
data[nontve_header_len:nontve_header_len+2])
(... | [
"Generic byte decoding function for TVE parameters.\n\n Given an array of bytes, tries to interpret a TVE parameter from the\n beginning of the array. Returns the decoded data and the number of bytes\n it read."
] |
Please provide a description of the function:def tagReportCallback(llrpMsg):
global tagReport
tags = llrpMsg.msgdict['RO_ACCESS_REPORT']['TagReportData']
if len(tags):
logger.info('saw tag(s): %s', pprint.pformat(tags))
else:
logger.info('no tags seen')
return
for tag in... | [
"Function to run each time the reader reports seeing tags."
] |
Please provide a description of the function:def tag_report_cb(llrp_msg):
global numtags
tags = llrp_msg.msgdict['RO_ACCESS_REPORT']['TagReportData']
if len(tags):
logger.info('saw tag(s): %s', pprint.pformat(tags))
for tag in tags:
numtags += tag['TagSeenCount'][0]
else... | [
"Function to run each time the reader reports seeing tags."
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.