Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def failed(failure):
Message.new(message_type=u"acceptance:http_query_failed",
reason=unicode(failure)).write()
return False
request.addCallbacks(content, failed)
def filter_results(zones):
Message.log(zone_names=list(zone.name for zone in zones))
for zone in zones:
# XXX Bleuch zone.name should be a Name!
if Name(zone.name) == name:
d = route53.list_resource_record_sets(zone_id=zone.identifier)
d.addCallback(
lambda rrsets, zone=zone: _ZoneState(
zone=zone,
rrsets=rrsets,
),
)
return d
raise KeyError(name)
d.addCallback(filter_results)
from __future__ import unicode_literals
import sys
import time
from eliot import Message, Logger, addDestination
def stdout(message):
sys.stdout.write(message + "\n")
addDestination(stdout)
logger = Logger()
Message.new(value="hello", another=1).write(logger)
time.sleep(0.2)
Message.new(value="goodbye", another=2).write(logger)
'headers':response.headers
}
}
success = True
if 'find_in_headers' in opts:
headers = ''
for header in response.headers:
headers += '{}: {}\n'.format(header, response.headers[header])
keyword = opts['find_in_headers']
success = (keyword in headers)
if not success:
Message.log(
level='status',
message="==> Not found in HEADERS: '%s'" % color.cyan(keyword))
return success, scope
else:
Message.log(
level='status',
message="==> Found in HEADERS: '%s'" % color.cyan(keyword))
if 'extract' in opts:
scope[name]['extracted'] = extract(response.text, opts['extract'])
if 'find' in opts:
keyword = opts['find']
success = (keyword in response.text)
def pretty_print_response(res):
""" Print a response """
# Status line
output = color.yellow('HTTP') + color.grayscale[14]('/1.1 %s %s\n' % (res.status_code, res.reason))
# Headers
for name, value in res.headers.items():
output += '%s: %s\n' % (color.grayscale[14](name), color.cyan(value))
output += '\n'
# Body
output += res.text
Message.log(level='response', message=output)
def pollable():
Message.new(
message_type=_TRY_RETRYING,
).write()
try:
result = function(*args, **kwargs)
except Exception as e:
saved_result[0] = exc_info()
should_retry(*saved_result[0])
Message.new(
message_type=_TRY_FAILURE,
exception=str(e),
).write()
return False
else:
Message.new(
message_type=_TRY_SUCCESS,
result=result,
).write()
saved_result[0] = result
return True
def _converge_replicasets(actual, config, subscriptions, k8s, aws):
# We don't ever have to create a ReplicaSet. We'll just delete the ones
# we don't need anymore.
deletes = []
for replicaset in actual.replicasets:
sid = replicaset.metadata.annotations[u"subscription"]
if sid not in actual.subscriptions:
Message.log(condition=u"undesired", subscription=sid)
deletes.append(replicaset.metadata)
def delete(metadata):
return k8s.delete(k8s.k8s.model.v1beta1.ReplicaSet(metadata=metadata))
return list(partial(delete, metadata) for metadata in deletes)
def _get_device_path_api(self, volume):
"""
Return the device path reported by the Cinder API.
:param volume: The Cinder ``Volume`` which is attached.
:returns: ``FilePath`` of the device created by the virtio_blk
driver.
"""
if volume.attachments:
attachment = volume.attachments[0]
if len(volume.attachments) > 1:
# As far as we know you can not have more than one attachment,
# but, perhaps we're wrong and there should be a test for the
# multiple attachment case. FLOC-1854.
# Log a message if this ever happens.
Message.new(
message_type=(
u'flocker:node:agents:blockdevice:openstack:'
u'get_device_path:'
u'unexpected_multiple_attachments'
),
volume_id=unicode(volume.id),
attachment_devices=u','.join(
unicode(a['device']) for a in volume.attachments
),
).write()
else:
raise UnattachedVolume(volume.id)
return FilePath(attachment['device'])
from eliot import start_action, to_file, Message
to_file(sys.stdout)
rider1 = "Alice"
rider2 = "Bob"
wildcat = "Whiskers the Wildcat"
with start_action(action_type="outside", weather="cold",
location="distance"):
with start_action(action_type="approach",
who=[rider1, rider2]):
with start_action(action_type="growl", who=wildcat):
pass
Message.log(message_type="wind:howl")
def _image_data(self, image):
"""
Supply data about an image, by either inspecting it or returning
cached data if available.
:param unicode image: The ID of the image.
:return: ``dict`` representing data about the image properties.
"""
cached_image = self._image_cache.get(image)
if cached_image is not None:
LOG_CACHED_IMAGE(image=image).write()
return cached_image
try:
image_data = self._client.inspect_image(image)
Message.new(
message_type="flocker:node:docker:image_inspected",
image=image
).write()
except APIError as e:
if e.response.status_code == NOT_FOUND:
# Image has been deleted, so just fill in some
# stub data so we can return *something*. This
# should happen only for stopped containers so
# some inaccuracy is acceptable.
# We won't cache stub data though.
Message.new(
message_type="flocker:node:docker:image_not_found",
image=image
).write()
image_data = {u"Config": {u"Env": [], u"Cmd": []}}
else: