text_prompt stringlengths 157 13.1k | code_prompt stringlengths 7 19.8k ⌀ |
|---|---|
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def setDatastreamState(self, pid, dsID, dsState):
'''Update datastream state.
:param pid: object pid
:param dsID: datastream id
:param dsState: datastream state
:returns: boolean success
'''
# /objects/{pid}/datastreams/{dsID} ? [dsState]
http_args = {'ds... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def setDatastreamVersionable(self, pid, dsID, versionable):
'''Update datastream versionable setting.
:param pid: object pid
:param dsID: datastream id
:param versionable: boolean
:returns: boolean success
'''
# /objects/{pid}/datastreams/{dsID} ? [versionable]
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def upload(self, data, callback=None, content_type=None,
size=None):
'''
Upload a multi-part file for content to ingest. Returns a
temporary upload id that can be used as a datstream location.
:param data: content string, file-like object, or iterable with
co... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_subjects(self, predicate, object):
""" Search for all subjects related to the specified predicate and object. :param predicate: :param object: :rtype: ge... |
for statement in self.spo_search(predicate=predicate, object=object):
yield str(statement[0]) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_predicates(self, subject, object):
""" Search for all subjects related to the specified subject and object. :param subject: :param object: :rtype: genera... |
for statement in self.spo_search(subject=subject, object=object):
yield str(statement[1]) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_objects(self, subject, predicate):
""" Search for all subjects related to the specified subject and predicate. :param subject: :param object: :rtype: gen... |
for statement in self.spo_search(subject=subject, predicate=predicate):
yield str(statement[2]) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sparql_query(self, query, flush=None, limit=None):
""" Run a Sparql query. :param query: sparql query string :rtype: list of dictionary """ |
return self.find_statements(query, language='sparql', type='tuples',
flush=flush, limit=limit) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sparql_count(self, query, flush=None):
""" Count results for a Sparql query. :param query: sparql query string :rtype: int """ |
return self.count_statements(query, language='sparql', type='tuples',
flush=flush) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_stack(self, stack_name, template_body=None, template_url=None, parameters=[], notification_arns=[], disable_rollback=False, timeout_in_minutes=None, ca... |
params = {'ContentType': "JSON", 'StackName': stack_name,
'DisableRollback': self.encode_bool(disable_rollback)}
if template_body:
params['TemplateBody'] = template_body
if template_url:
params['TemplateURL'] = template_url
if template_body and te... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add_change(self, action, name, type, ttl=600, alias_hosted_zone_id=None, alias_dns_name=None, identifier=None, weight=None):
"""Add a change request""" |
change = Record(name, type, ttl,
alias_hosted_zone_id=alias_hosted_zone_id,
alias_dns_name=alias_dns_name, identifier=identifier,
weight=weight)
self.changes.append([action, change])
return change |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def to_xml(self):
"""Convert this ResourceRecordSet into XML to be saved via the ChangeResourceRecordSetsRequest""" |
changesXML = ""
for change in self.changes:
changeParams = {"action": change[0], "record": change[1].to_xml()}
changesXML += self.ChangeXML % changeParams
params = {"comment": self.comment, "changes": changesXML}
return self.ChangeResourceRecordSetsBody % params |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def commit(self):
"""Commit this change""" |
if not self.connection:
import boto
self.connection = boto.connect_route53()
return self.connection.change_rrsets(self.hosted_zone_id, self.to_xml()) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def endElement(self, name, value, connection):
"""Overwritten to also add the NextRecordName and NextRecordType to the base object""" |
if name == 'NextRecordName':
self.next_record_name = value
elif name == 'NextRecordType':
self.next_record_type = value
else:
return ResultSet.endElement(self, name, value, connection) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_alias(self, alias_hosted_zone_id, alias_dns_name):
"""Make this an alias resource record set""" |
self.alias_hosted_zone_id = alias_hosted_zone_id
self.alias_dns_name = alias_dns_name |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def to_xml(self):
"""Spit this resource record set out as XML""" |
if self.alias_hosted_zone_id != None and self.alias_dns_name != None:
# Use alias
body = self.AliasBody % (self.alias_hosted_zone_id, self.alias_dns_name)
else:
# Use resource record(s)
records = ""
for r in self.resource_records:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def update_from_response(self, response):
""" Update the state of the Table object based on the response data received from Amazon DynamoDB. """ |
if 'Table' in response:
self._dict.update(response['Table'])
elif 'TableDescription' in response:
self._dict.update(response['TableDescription'])
if 'KeySchema' in self._dict:
self._schema = Schema(self._dict['KeySchema']) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def refresh(self, wait_for_active=False, retry_seconds=5):
""" Refresh all of the fields of the Table object by calling the underlying DescribeTable request. :ty... |
done = False
while not done:
response = self.layer2.describe_table(self.name)
self.update_from_response(response)
if wait_for_active:
if self.status == 'ACTIVE':
done = True
else:
time.sleep(retr... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def new_item(self, hash_key, range_key=None, attrs=None):
""" Return an new, unsaved Item which can later be PUT to Amazon DynamoDB. """ |
return Item(self, hash_key, range_key, attrs) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def scan(self, scan_filter=None, attributes_to_get=None, request_limit=None, max_results=None, count=False, exclusive_start_key=None, item_class=Item):
""" Scan ... |
return self.layer2.scan(self, scan_filter, attributes_to_get,
request_limit, max_results,
exclusive_start_key, item_class=item_class) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_by_code(self, code):
""" Retrieve a language by a code. :param code: iso code (any of the three) or its culture code :return: a Language object """ |
if any(x in code for x in ('_', '-')):
cc = CultureCode.objects.get(code=code.replace('_', '-'))
return cc.language
elif len(code) == 2:
return self.get(iso_639_1=code)
elif len(code) == 3:
return self.get(Q(iso_639_2T=code) |
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def state(self, state=vanilla.message.NoState):
""" Returns a `State`_ `Pair`_. *state* if supplied sets the intial state. """ |
return vanilla.message.State(self, state=state) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def Inventory(cls):
""" Returns a list of Server instances, one for each Server object persisted in the db """ |
l = ServerSet()
rs = cls.find()
for server in rs:
l.append(server)
return l |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_config(self, config):
""" Set SDB based config """ |
self._config = config
self._config.dump_to_sdb("botoConfigs", self.id) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def attach_volume(self, volume, device="/dev/sdp"):
""" Attach an EBS volume to this server :param volume: EBS Volume to attach :type volume: boto.ec2.volume.Vol... |
if hasattr(volume, "id"):
volume_id = volume.id
else:
volume_id = volume
return self.ec2.attach_volume(volume_id=volume_id, instance_id=self.instance_id, device=device) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def detach_volume(self, volume):
""" Detach an EBS volume from this server :param volume: EBS Volume to detach :type volume: boto.ec2.volume.Volume """ |
if hasattr(volume, "id"):
volume_id = volume.id
else:
volume_id = volume
return self.ec2.detach_volume(volume_id=volume_id, instance_id=self.instance_id) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _save_tracker_uri_to_file(self):
""" Saves URI to tracker file if one was passed to constructor. """ |
if not self.tracker_file_name:
return
f = None
try:
f = open(self.tracker_file_name, 'w')
f.write(self.tracker_uri)
except IOError, e:
raise ResumableUploadException(
'Couldn\'t write URI tracker file (%s): %s.\nThis can ha... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _set_tracker_uri(self, uri):
""" Called when we start a new resumable upload or get a new tracker URI for the upload. Saves URI and resets upload state. Rais... |
parse_result = urlparse.urlparse(uri)
if (parse_result.scheme.lower() not in ['http', 'https'] or
not parse_result.netloc or not parse_result.query):
raise InvalidUriError('Invalid tracker URI (%s)' % uri)
qdict = cgi.parse_qs(parse_result.query)
if not qdict or ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _query_server_state(self, conn, file_length):
""" Queries server to find out state of given upload. Note that this method really just makes special case use ... |
# Send an empty PUT so that server replies with this resumable
# transfer's state.
put_headers = {}
put_headers['Content-Range'] = (
self._build_content_range_header('*', file_length))
put_headers['Content-Length'] = '0'
return AWSAuthConnection.make_request(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _query_server_pos(self, conn, file_length):
""" Queries server to find out what bytes it currently has. Returns (server_start, server_end), where the values ... |
resp = self._query_server_state(conn, file_length)
if resp.status == 200:
return (0, file_length) # Completed upload.
if resp.status != 308:
# This means the server didn't have any state for the given
# upload ID, which can happen (for example) if the caller... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _start_new_resumable_upload(self, key, headers=None):
""" Starts a new resumable upload. Raises ResumableUploadException if any errors occur. """ |
conn = key.bucket.connection
if conn.debug >= 1:
print 'Starting new resumable upload.'
self.server_has_bytes = 0
# Start a new resumable upload by sending a POST request with an
# empty body and the "X-Goog-Resumable: start" header. Include any
# caller-pro... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _upload_file_bytes(self, conn, http_conn, fp, file_length, total_bytes_uploaded, cb, num_cb):
""" Makes one attempt to upload file bytes, using an existing r... |
buf = fp.read(self.BUFFER_SIZE)
if cb:
if num_cb > 2:
cb_count = file_length / self.BUFFER_SIZE / (num_cb-2)
elif num_cb < 0:
cb_count = -1
else:
cb_count = 0
i = 0
cb(total_bytes_uploaded, file_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _attempt_resumable_upload(self, key, fp, file_length, headers, cb, num_cb):
""" Attempts a resumable upload. Returns etag from server upon success. Raises Re... |
(server_start, server_end) = self.SERVER_HAS_NOTHING
conn = key.bucket.connection
if self.tracker_uri:
# Try to resume existing resumable upload.
try:
(server_start, server_end) = (
self._query_server_pos(conn, file_length))
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_permissions(self, object, replace=False):
""" Sets the S3 ACL grants for the given object to the appropriate value based on the type of Distribution. If ... |
if isinstance(self.config.origin, S3Origin):
if self.config.origin.origin_access_identity:
id = self.config.origin.origin_access_identity.split('/')[-1]
oai = self.connection.get_origin_access_identity_info(id)
policy = object.get_acl()
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_permissions_all(self, replace=False):
""" Sets the S3 ACL grants for all objects in the Distribution to the appropriate value based on the type of Distri... |
bucket = self._get_bucket()
for key in bucket:
self.set_permissions(key, replace) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add_object(self, name, content, headers=None, replace=True):
""" Adds a new content object to the Distribution. The content for the object will be copied to ... |
if self.config.origin.origin_access_identity:
policy = 'private'
else:
policy = 'public-read'
bucket = self._get_bucket()
object = bucket.new_key(name)
object.set_contents_from_file(content, headers=headers, policy=policy)
if self.config.origin.or... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_signed_url(self, url, keypair_id, expire_time=None, valid_after_time=None, ip_address=None, policy_url=None, private_key_file=None, private_key_string=... |
# Get the required parameters
params = self._create_signing_params(
url=url, keypair_id=keypair_id, expire_time=expire_time,
valid_after_time=valid_after_time, ip_address=ip_address,
policy_url=policy_url, private_key_file=private_key_file,... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _create_signing_params(self, url, keypair_id, expire_time=None, valid_after_time=None, ip_address=None, policy_url=None, private_key_file=None, private_key_st... |
params = {}
# Check if we can use a canned policy
if expire_time and not valid_after_time and not ip_address and not policy_url:
# we manually construct this policy string to ensure formatting
# matches signature
policy = self._canned_policy(url, expire_time)... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _custom_policy(resource, expires=None, valid_after=None, ip_address=None):
""" Creates a custom policy string based on the supplied parameters. """ |
condition = {}
if expires:
condition["DateLessThan"] = {"AWS:EpochTime": expires}
if valid_after:
condition["DateGreaterThan"] = {"AWS:EpochTime": valid_after}
if ip_address:
if '/' not in ip_address:
ip_address += "/32"
co... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _sign_string(message, private_key_file=None, private_key_string=None):
""" Signs a string for use with Amazon CloudFront. Requires the M2Crypto library be in... |
try:
from M2Crypto import EVP
except ImportError:
raise NotImplementedError("Boto depends on the python M2Crypto "
"library to generate signed URLs for "
"CloudFront")
# Make sure only one of pri... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _url_base64_encode(msg):
""" Base64 encodes a string using the URL-safe characters specified by Amazon. """ |
msg_base64 = base64.b64encode(msg)
msg_base64 = msg_base64.replace('+', '-')
msg_base64 = msg_base64.replace('=', '_')
msg_base64 = msg_base64.replace('/', '~')
return msg_base64 |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _update_content(sender, instance, created=None, **kwargs):
""" Re-save any content models referencing the just-modified ``FileUpload``. We don't do anything ... |
if created: # a brand new FileUpload won't be referenced
return
for ref in FileUploadReference.objects.filter(upload=instance):
try:
obj = ref.content_object
if obj:
obj.save()
except AttributeError:
pass |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_params(self):
""" Returns a dictionary containing the value of of all of the keyword arguments passed when constructing this connection. """ |
param_names = ['aws_access_key_id', 'aws_secret_access_key',
'is_secure', 'port', 'proxy', 'proxy_port',
'proxy_user', 'proxy_pass',
'debug', 'https_connection_factory']
params = {}
for name in param_names:
params[... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_images(self, image_ids=None, owners=None, executable_by=None, filters=None):
""" Retrieve all the EC2 images available on your account. :type image_i... |
params = {}
if image_ids:
self.build_list_params(params, image_ids, 'ImageId')
if owners:
self.build_list_params(params, owners, 'Owner')
if executable_by:
self.build_list_params(params, executable_by, 'ExecutableBy')
if filters:
s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_kernels(self, kernel_ids=None, owners=None):
""" Retrieve all the EC2 kernels available on your account. Constructs a filter to allow the processing ... |
params = {}
if kernel_ids:
self.build_list_params(params, kernel_ids, 'ImageId')
if owners:
self.build_list_params(params, owners, 'Owner')
filter = {'image-type' : 'kernel'}
self.build_filter_params(params, filter)
return self.get_list('DescribeI... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_ramdisks(self, ramdisk_ids=None, owners=None):
""" Retrieve all the EC2 ramdisks available on your account. Constructs a filter to allow the processi... |
params = {}
if ramdisk_ids:
self.build_list_params(params, ramdisk_ids, 'ImageId')
if owners:
self.build_list_params(params, owners, 'Owner')
filter = {'image-type' : 'ramdisk'}
self.build_filter_params(params, filter)
return self.get_list('Descri... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def register_image(self, name=None, description=None, image_location=None, architecture=None, kernel_id=None, ramdisk_id=None, root_device_name=None, block_device... |
params = {}
if name:
params['Name'] = name
if description:
params['Description'] = description
if architecture:
params['Architecture'] = architecture
if kernel_id:
params['KernelId'] = kernel_id
if ramdisk_id:
p... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def deregister_image(self, image_id, delete_snapshot=False):
""" Unregister an AMI. :type image_id: string :param image_id: the ID of the Image to unregister :ty... |
snapshot_id = None
if delete_snapshot:
image = self.get_image(image_id)
for key in image.block_device_mapping:
if key == "/dev/sda1":
snapshot_id = image.block_device_mapping[key].snapshot_id
break
result = self.ge... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_image(self, instance_id, name, description=None, no_reboot=False):
""" Will create an AMI from the instance in the running or stopped state. :type ins... |
params = {'InstanceId' : instance_id,
'Name' : name}
if description:
params['Description'] = description
if no_reboot:
params['NoReboot'] = 'true'
img = self.get_object('CreateImage', params, Image, verb='POST')
return img.id |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_image_attribute(self, image_id, attribute='launchPermission'):
""" Gets an attribute from an image. :type image_id: string :param image_id: The Amazon im... |
params = {'ImageId' : image_id,
'Attribute' : attribute}
return self.get_object('DescribeImageAttribute', params,
ImageAttribute, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def reset_image_attribute(self, image_id, attribute='launchPermission'):
""" Resets an attribute of an AMI to its default value. :type image_id: string :param im... |
params = {'ImageId' : image_id,
'Attribute' : attribute}
return self.get_status('ResetImageAttribute', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_instances(self, instance_ids=None, filters=None):
""" Retrieve all the instances associated with your account. :type instance_ids: list :param instan... |
params = {}
if instance_ids:
self.build_list_params(params, instance_ids, 'InstanceId')
if filters:
if 'group-id' in filters:
gid = filters.get('group-id')
if not gid.startswith('sg-') or len(gid) != 11:
warnings.warn(
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_instance_status(self, instance_ids=None, max_results=None, next_token=None, filters=None):
""" Retrieve all the instances in your account scheduled f... |
params = {}
if instance_ids:
self.build_list_params(params, instance_ids, 'InstanceId')
if max_results:
params['MaxResults'] = max_results
if next_token:
params['NextToken'] = next_token
if filters:
self.build_filter_params(params,... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def run_instances(self, image_id, min_count=1, max_count=1, key_name=None, security_groups=None, user_data=None, addressing_type=None, instance_type='m1.small', p... |
params = {'ImageId':image_id,
'MinCount':min_count,
'MaxCount': max_count}
if key_name:
params['KeyName'] = key_name
if security_group_ids:
l = []
for group in security_group_ids:
if isinstance(group, Securi... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def terminate_instances(self, instance_ids=None):
""" Terminate the instances specified :type instance_ids: list :param instance_ids: A list of strings of the In... |
params = {}
if instance_ids:
self.build_list_params(params, instance_ids, 'InstanceId')
return self.get_list('TerminateInstances', params,
[('item', Instance)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def stop_instances(self, instance_ids=None, force=False):
""" Stop the instances specified :type instance_ids: list :param instance_ids: A list of strings of the... |
params = {}
if force:
params['Force'] = 'true'
if instance_ids:
self.build_list_params(params, instance_ids, 'InstanceId')
return self.get_list('StopInstances', params,
[('item', Instance)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def start_instances(self, instance_ids=None):
""" Start the instances specified :type instance_ids: list :param instance_ids: A list of strings of the Instance I... |
params = {}
if instance_ids:
self.build_list_params(params, instance_ids, 'InstanceId')
return self.get_list('StartInstances', params,
[('item', Instance)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_console_output(self, instance_id):
""" Retrieves the console output for the specified instance. :type instance_id: string :param instance_id: The instanc... |
params = {}
self.build_list_params(params, [instance_id], 'InstanceId')
return self.get_object('GetConsoleOutput', params,
ConsoleOutput, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def reboot_instances(self, instance_ids=None):
""" Reboot the specified instances. :type instance_ids: list :param instance_ids: The instances to terminate and r... |
params = {}
if instance_ids:
self.build_list_params(params, instance_ids, 'InstanceId')
return self.get_status('RebootInstances', params) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_instance_attribute(self, instance_id, attribute):
""" Gets an attribute from an instance. :type instance_id: string :param instance_id: The Amazon id of ... |
params = {'InstanceId' : instance_id}
if attribute:
params['Attribute'] = attribute
return self.get_object('DescribeInstanceAttribute', params,
InstanceAttribute, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def modify_instance_attribute(self, instance_id, attribute, value):
""" Changes an attribute of an instance :type instance_id: string :param instance_id: The ins... |
# Allow a bool to be passed in for value of disableApiTermination
if attribute == 'disableApiTermination':
if isinstance(value, bool):
if value:
value = 'true'
else:
value = 'false'
params = {'InstanceId' : inst... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def reset_instance_attribute(self, instance_id, attribute):
""" Resets an attribute of an instance to its default value. :type instance_id: string :param instanc... |
params = {'InstanceId' : instance_id,
'Attribute' : attribute}
return self.get_status('ResetInstanceAttribute', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_spot_instance_requests(self, request_ids=None, filters=None):
""" Retrieve all the spot instances requests associated with your account. :type reques... |
params = {}
if request_ids:
self.build_list_params(params, request_ids, 'SpotInstanceRequestId')
if filters:
if 'launch.group-id' in filters:
lgid = filters.get('launch.group-id')
if not lgid.startswith('sg-') or len(lgid) != 11:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_spot_price_history(self, start_time=None, end_time=None, instance_type=None, product_description=None, availability_zone=None):
""" Retrieve the recent h... |
params = {}
if start_time:
params['StartTime'] = start_time
if end_time:
params['EndTime'] = end_time
if instance_type:
params['InstanceType'] = instance_type
if product_description:
params['ProductDescription'] = product_descripti... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def request_spot_instances(self, price, image_id, count=1, type='one-time', valid_from=None, valid_until=None, launch_group=None, availability_zone_group=None, ke... |
params = {'LaunchSpecification.ImageId':image_id,
'Type' : type,
'SpotPrice' : price}
if count:
params['InstanceCount'] = count
if valid_from:
params['ValidFrom'] = valid_from
if valid_until:
params['ValidUntil'] = ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def cancel_spot_instance_requests(self, request_ids):
""" Cancel the specified Spot Instance Requests. :type request_ids: list :param request_ids: A list of stri... |
params = {}
if request_ids:
self.build_list_params(params, request_ids, 'SpotInstanceRequestId')
return self.get_list('CancelSpotInstanceRequests', params,
[('item', Instance)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_spot_datafeed_subscription(self, bucket, prefix):
""" Create a spot instance datafeed subscription for this account. :type bucket: str or unicode :par... |
params = {'Bucket' : bucket}
if prefix:
params['Prefix'] = prefix
return self.get_object('CreateSpotDatafeedSubscription',
params, SpotDatafeedSubscription, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_zones(self, zones=None, filters=None):
""" Get all Availability Zones associated with the current region. :type zones: list :param zones: Optional li... |
params = {}
if zones:
self.build_list_params(params, zones, 'ZoneName')
if filters:
self.build_filter_params(params, filters)
return self.get_list('DescribeAvailabilityZones', params,
[('item', Zone)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def associate_address(self, instance_id, public_ip=None, allocation_id=None):
""" Associate an Elastic IP address with a currently running instance. This require... |
params = { 'InstanceId' : instance_id }
if public_ip is not None:
params['PublicIp'] = public_ip
elif allocation_id is not None:
params['AllocationId'] = allocation_id
return self.get_status('AssociateAddress', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def disassociate_address(self, public_ip=None, association_id=None):
""" Disassociate an Elastic IP address from a currently running instance. :type public_ip: s... |
params = {}
if public_ip is not None:
params['PublicIp'] = public_ip
elif association_id is not None:
params['AssociationId'] = association_id
return self.get_status('DisassociateAddress', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def release_address(self, public_ip=None, allocation_id=None):
""" Free up an Elastic IP address. :type public_ip: string :param public_ip: The public IP address... |
params = {}
if public_ip is not None:
params['PublicIp'] = public_ip
elif allocation_id is not None:
params['AllocationId'] = allocation_id
return self.get_status('ReleaseAddress', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_volumes(self, volume_ids=None, filters=None):
""" Get all Volumes associated with the current credentials. :type volume_ids: list :param volume_ids: ... |
params = {}
if volume_ids:
self.build_list_params(params, volume_ids, 'VolumeId')
if filters:
self.build_filter_params(params, filters)
return self.get_list('DescribeVolumes', params,
[('item', Volume)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_volume(self, size, zone, snapshot=None):
""" Create a new EBS Volume. :type size: int :param size: The size of the new volume, in GiB :type zone: stri... |
if isinstance(zone, Zone):
zone = zone.name
params = {'AvailabilityZone' : zone}
if size:
params['Size'] = size
if snapshot:
if isinstance(snapshot, Snapshot):
snapshot = snapshot.id
params['SnapshotId'] = snapshot
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def attach_volume(self, volume_id, instance_id, device):
""" Attach an EBS volume to an EC2 instance. :type volume_id: str :param volume_id: The ID of the EBS vo... |
params = {'InstanceId' : instance_id,
'VolumeId' : volume_id,
'Device' : device}
return self.get_status('AttachVolume', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_snapshots(self, snapshot_ids=None, owner=None, restorable_by=None, filters=None):
""" Get all EBS Snapshots associated with the current credentials. ... |
params = {}
if snapshot_ids:
self.build_list_params(params, snapshot_ids, 'SnapshotId')
if owner:
params['Owner'] = owner
if restorable_by:
params['RestorableBy'] = restorable_by
if filters:
self.build_filter_params(params, filters... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_snapshot(self, volume_id, description=None):
""" Create a snapshot of an existing EBS Volume. :type volume_id: str :param volume_id: The ID of the vol... |
params = {'VolumeId' : volume_id}
if description:
params['Description'] = description[0:255]
snapshot = self.get_object('CreateSnapshot', params,
Snapshot, verb='POST')
volume = self.get_all_volumes([volume_id])[0]
volume_name = vol... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_snapshot_attribute(self, snapshot_id, attribute='createVolumePermission'):
""" Get information about an attribute of a snapshot. Only one attribute can b... |
params = {'Attribute' : attribute}
if snapshot_id:
params['SnapshotId'] = snapshot_id
return self.get_object('DescribeSnapshotAttribute', params,
SnapshotAttribute, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def reset_snapshot_attribute(self, snapshot_id, attribute='createVolumePermission'):
""" Resets an attribute of a snapshot to its default value. :type snapshot_i... |
params = {'SnapshotId' : snapshot_id,
'Attribute' : attribute}
return self.get_status('ResetSnapshotAttribute', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_key_pairs(self, keynames=None, filters=None):
""" Get all key pairs associated with your account. :type keynames: list :param keynames: A list of the... |
params = {}
if keynames:
self.build_list_params(params, keynames, 'KeyName')
if filters:
self.build_filter_params(params, filters)
return self.get_list('DescribeKeyPairs', params,
[('item', KeyPair)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_key_pair(self, key_name):
""" Create a new key pair for your account. This will create the key pair within the region you are currently connected to. ... |
params = {'KeyName':key_name}
return self.get_object('CreateKeyPair', params, KeyPair, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def import_key_pair(self, key_name, public_key_material):
""" mports the public key from an RSA key pair that you created with a third-party tool. Supported form... |
public_key_material = base64.b64encode(public_key_material)
params = {'KeyName' : key_name,
'PublicKeyMaterial' : public_key_material}
return self.get_object('ImportKeyPair', params, KeyPair, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def delete_security_group(self, name=None, group_id=None):
""" Delete a security group from your account. :type name: string :param name: The name of the securit... |
params = {}
if name is not None:
params['GroupName'] = name
elif group_id is not None:
params['GroupId'] = group_id
return self.get_status('DeleteSecurityGroup', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def authorize_security_group(self, group_name=None, src_security_group_name=None, src_security_group_owner_id=None, ip_protocol=None, from_port=None, to_port=None... |
if src_security_group_name:
if from_port is None and to_port is None and ip_protocol is None:
return self.authorize_security_group_deprecated(
group_name, src_security_group_name,
src_security_group_owner_id)
params = {}
if g... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def authorize_security_group_egress(self, group_id, ip_protocol, from_port=None, to_port=None, src_group_id=None, cidr_ip=None):
""" The action adds one or more ... |
params = {
'GroupId': group_id,
'IpPermissions.1.IpProtocol': ip_protocol
}
if from_port is not None:
params['IpPermissions.1.FromPort'] = from_port
if to_port is not None:
params['IpPermissions.1.ToPort'] = to_port
if src_group_i... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def revoke_security_group(self, group_name=None, src_security_group_name=None, src_security_group_owner_id=None, ip_protocol=None, from_port=None, to_port=None, c... |
if src_security_group_name:
if from_port is None and to_port is None and ip_protocol is None:
return self.revoke_security_group_deprecated(
group_name, src_security_group_name,
src_security_group_owner_id)
params = {}
if group_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_regions(self, region_names=None, filters=None):
""" Get all available regions for the EC2 service. :type region_names: list of str :param region_name... |
params = {}
if region_names:
self.build_list_params(params, region_names, 'RegionName')
if filters:
self.build_filter_params(params, filters)
regions = self.get_list('DescribeRegions', params,
[('item', RegionInfo)], verb='POST')... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def monitor_instances(self, instance_ids):
""" Enable CloudWatch monitoring for the supplied instances. :type instance_id: list of strings :param instance_id: Th... |
params = {}
self.build_list_params(params, instance_ids, 'InstanceId')
return self.get_list('MonitorInstances', params,
[('item', InstanceInfo)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def unmonitor_instances(self, instance_ids):
""" Disable CloudWatch monitoring for the supplied instance. :type instance_id: list of string :param instance_id: T... |
params = {}
self.build_list_params(params, instance_ids, 'InstanceId')
return self.get_list('UnmonitorInstances', params,
[('item', InstanceInfo)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def bundle_instance(self, instance_id, s3_bucket, s3_prefix, s3_upload_policy):
""" Bundle Windows instance. :type instance_id: string :param instance_id: The in... |
params = {'InstanceId' : instance_id,
'Storage.S3.Bucket' : s3_bucket,
'Storage.S3.Prefix' : s3_prefix,
'Storage.S3.UploadPolicy' : s3_upload_policy}
s3auth = boto.auth.get_auth_handler(None, boto.config,
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_bundle_tasks(self, bundle_ids=None, filters=None):
""" Retrieve current bundling tasks. If no bundle id is specified, all tasks are retrieved. :type ... |
params = {}
if bundle_ids:
self.build_list_params(params, bundle_ids, 'BundleId')
if filters:
self.build_filter_params(params, filters)
return self.get_list('DescribeBundleTasks', params,
[('item', BundleInstanceTask)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def cancel_bundle_task(self, bundle_id):
""" Cancel a previously submitted bundle task :type bundle_id: string :param bundle_id: The identifier of the bundle tas... |
params = {'BundleId' : bundle_id}
return self.get_object('CancelBundleTask', params,
BundleInstanceTask, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_password_data(self, instance_id):
""" Get encrypted administrator password for a Windows instance. :type instance_id: string :param instance_id: The iden... |
params = {'InstanceId' : instance_id}
rs = self.get_object('GetPasswordData', params, ResultSet, verb='POST')
return rs.passwordData |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_placement_groups(self, groupnames=None, filters=None):
""" Get all placement groups associated with your account in a region. :type groupnames: list ... |
params = {}
if groupnames:
self.build_list_params(params, groupnames, 'GroupName')
if filters:
self.build_filter_params(params, filters)
return self.get_list('DescribePlacementGroups', params,
[('item', PlacementGroup)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_placement_group(self, name, strategy='cluster'):
""" Create a new placement group for your account. This will create the placement group within the re... |
params = {'GroupName':name, 'Strategy':strategy}
group = self.get_status('CreatePlacementGroup', params, verb='POST')
return group |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_all_tags(self, filters=None):
""" Retrieve all the metadata tags associated with your account. :type filters: dict :param filters: Optional filters that ... |
params = {}
if filters:
self.build_filter_params(params, filters)
return self.get_list('DescribeTags', params,
[('item', Tag)], verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_network_interface(self, subnet_id, private_ip_address=None, description=None, groups=None):
""" Creates a network interface in the specified subnet. :... |
params = {'SubnetId' : subnet_id}
if private_ip_address:
params['PrivateIpAddress'] = private_ip_address
if description:
params['Description'] = description
if groups:
ids = []
for group in groups:
if isinstance(group, Secu... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def attach_network_interface(self, network_interface_id, instance_id, device_index):
""" Attaches a network interface to an instance. :type network_interface_id:... |
params = {'NetworkInterfaceId' : network_interface_id,
'InstanceId' : instance_id,
'Deviceindex' : device_index}
return self.get_status('AttachNetworkInterface', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def detach_network_interface(self, network_interface_id, force=False):
""" Detaches a network interface from an instance. :type network_interface_id: str :param ... |
params = {'NetworkInterfaceId' : network_interface_id}
if force:
params['Force'] = 'true'
return self.get_status('DetachNetworkInterface', params, verb='POST') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_capacity(self, capacity):
""" Set the desired capacity for the group. """ |
params = {'AutoScalingGroupName' : self.name,
'DesiredCapacity' : capacity}
req = self.connection.get_object('SetDesiredCapacity', params,
Request)
self.connection.last_request = req
return req |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def shutdown_instances(self):
""" Convenience method which shuts down all instances associated with this group. """ |
self.min_size = 0
self.max_size = 0
self.desired_capacity = 0
self.update() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def delete(self, force_delete=False):
""" Delete this auto-scaling group if no instances attached or no scaling activities in progress. """ |
return self.connection.delete_auto_scaling_group(self.name, force_delete) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.