_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q17900 | assure_snapshot | train | def assure_snapshot(fnc):
"""
Converts a snapshot ID passed as the snapshot to a CloudBlockStorageSnapshot
object.
"""
@wraps(fnc)
def _wrapped(self, snapshot, *args, **kwargs):
if not isinstance(snapshot, CloudBlockStorageSnapshot):
# Must be the ID
| python | {
"resource": ""
} |
q17901 | CloudBlockStorageSnapshot.delete | train | def delete(self):
"""
Adds a check to make sure that the snapshot is able to be deleted.
"""
if self.status not in ("available", "error"):
raise exc.SnapshotNotAvailable("Snapshot must be in 'available' "
"or 'error' status before deleting. Current status: %s" %
self.status)
# When there are more thann one snapshot for a given volume, attempting to
# delete them all will throw a 409 exception. This will help by retrying
# such an error once after a RETRY_INTERVAL second delay.
try:
| python | {
"resource": ""
} |
q17902 | CloudBlockStorageSnapshot.update | train | def update(self, display_name=None, display_description=None):
"""
Update the specified values on this snapshot. You may specify one or
more values to update. | python | {
"resource": ""
} |
q17903 | CloudBlockStorageVolume.attach_to_instance | train | def attach_to_instance(self, instance, mountpoint):
"""
Attaches this volume to the cloud server instance at the
specified mountpoint. This requires a call to the cloud servers
API; it cannot be done directly.
"""
instance_id = _resolve_id(instance)
| python | {
"resource": ""
} |
q17904 | CloudBlockStorageVolume.detach | train | def detach(self):
"""
Detaches this volume from any device it may be attached to. If it
is not attached, nothing happens.
"""
attachments = self.attachments
if not attachments:
# Not attached; no error needed, just return
| python | {
"resource": ""
} |
q17905 | CloudBlockStorageVolume.create_snapshot | train | def create_snapshot(self, name=None, description=None, force=False):
"""
Creates a snapshot of this volume, with an optional name and
description.
Normally snapshots will not happen if the volume is attached. To
override this default behavior, pass force=True.
| python | {
"resource": ""
} |
q17906 | CloudBlockStorageVolume.list_snapshots | train | def list_snapshots(self):
"""
Returns a list of all snapshots of this volume.
"""
| python | {
"resource": ""
} |
q17907 | CloudBlockStorageManager._create_body | train | def _create_body(self, name, size=None, volume_type=None, description=None,
metadata=None, snapshot_id=None, clone_id=None,
availability_zone=None, image=None):
"""
Used to create the dict required to create a new volume
"""
if not isinstance(size, six.integer_types):
raise exc.InvalidSize("Volume sizes must be integers")
if volume_type is None:
volume_type = "SATA"
if description is None:
description = ""
if metadata is None:
metadata = {}
if image is not None:
image = utils.get_id(image)
body = {"volume": {
"size": size,
"snapshot_id": snapshot_id,
| python | {
"resource": ""
} |
q17908 | CloudBlockStorageManager.create | train | def create(self, *args, **kwargs):
"""
Catches errors that may be returned, and raises more informational
exceptions.
"""
try:
return super(CloudBlockStorageManager, self).create(*args,
**kwargs)
except exc.BadRequest as e:
| python | {
"resource": ""
} |
q17909 | CloudBlockStorageSnapshotManager._create_body | train | def _create_body(self, name, description=None, volume=None, force=False):
"""
Used to create the dict required to create a new snapshot
"""
body = {"snapshot": {
"display_name": name,
| python | {
"resource": ""
} |
q17910 | CloudBlockStorageClient._configure_manager | train | def _configure_manager(self):
"""
Create the manager to handle the instances, and also another
to handle flavors.
"""
self._manager = CloudBlockStorageManager(self,
resource_class=CloudBlockStorageVolume, response_key="volume",
uri_base="volumes")
self._types_manager = BaseManager(self,
| python | {
"resource": ""
} |
q17911 | CloudBlockStorageClient.create_snapshot | train | def create_snapshot(self, volume, name=None, description=None, force=False):
"""
Creates a snapshot of the volume, with an optional name and description.
| python | {
"resource": ""
} |
q17912 | CloudBlockStorageClient.update_snapshot | train | def update_snapshot(self, snapshot, display_name=None,
display_description=None):
"""
Update the specified values on the specified snapshot. You may specify
one or more values to update.
"""
| python | {
"resource": ""
} |
q17913 | assure_check | train | def assure_check(fnc):
"""
Converts an checkID passed as the check to a CloudMonitorCheck object.
"""
@wraps(fnc)
def _wrapped(self, check, *args, **kwargs):
if not isinstance(check, CloudMonitorCheck):
# Must be the ID
| python | {
"resource": ""
} |
q17914 | assure_entity | train | def assure_entity(fnc):
"""
Converts an entityID passed as the entity to a CloudMonitorEntity object.
"""
@wraps(fnc)
def _wrapped(self, entity, *args, **kwargs):
if not isinstance(entity, CloudMonitorEntity):
# Must be the ID
| python | {
"resource": ""
} |
q17915 | CloudMonitorEntity.get_check | train | def get_check(self, check):
"""
Returns an instance of the specified check.
"""
| python | {
"resource": ""
} |
q17916 | CloudMonitorEntity.list_checks | train | def list_checks(self, limit=None, marker=None, return_next=False):
"""
Returns a list of the checks defined for this account. By default the
number returned is limited to 100; you can define the number to return
by optionally passing a value for the 'limit' parameter. The value for
limit must be at least 1, and can be up to 1000.
For pagination, you must also specify | python | {
"resource": ""
} |
q17917 | CloudMonitorEntity.create_check | train | def create_check(self, label=None, name=None, check_type=None,
disabled=False, metadata=None, details=None,
monitoring_zones_poll=None, timeout=None, period=None,
target_alias=None, target_hostname=None, target_receiver=None,
test_only=False, include_debug=False):
"""
Creates a check on this entity with the specified attributes. The
'details' parameter should be a dict with the keys as the option name,
and the value as the desired setting.
"""
return self._check_manager.create_check(label=label, name=name,
check_type=check_type, disabled=disabled, metadata=metadata, | python | {
"resource": ""
} |
q17918 | CloudMonitorEntity.create_alarm | train | def create_alarm(self, check, notification_plan, criteria=None,
disabled=False, label=None, name=None, metadata=None):
"""
Creates an alarm that binds the check on this entity with a
notification plan.
"""
return | python | {
"resource": ""
} |
q17919 | CloudMonitorEntity.update_alarm | train | def update_alarm(self, alarm, criteria=None, disabled=False,
label=None, name=None, metadata=None):
"""
Updates an existing alarm on this entity.
"""
| python | {
"resource": ""
} |
q17920 | CloudMonitorEntity.list_alarms | train | def list_alarms(self, limit=None, marker=None, return_next=False):
"""
Returns a list of all the alarms created on this entity.
"""
| python | {
"resource": ""
} |
q17921 | _PaginationManager.list | train | def list(self, limit=None, marker=None, return_next=False):
"""
This is necessary to handle pagination correctly, as the Monitoring
service defines 'marker' differently than most other services. For
monitoring, 'marker' represents the first item in the next page,
whereas other services define it as the ID of the last item in the
current page.
"""
kwargs = {}
if return_next:
kwargs["other_keys"] | python | {
"resource": ""
} |
q17922 | CloudMonitorNotificationManager.update_notification | train | def update_notification(self, notification, details):
"""
Updates the specified notification with the supplied details.
"""
if isinstance(notification, CloudMonitorNotification):
nid = notification.id
ntyp = notification.type
else:
# Supplied an ID
nfcn = self.get(notification)
nid = notification
| python | {
"resource": ""
} |
q17923 | CloudMonitorNotificationManager.list_types | train | def list_types(self):
"""
Returns a list of all available notification types.
"""
uri = "/notification_types"
resp, resp_body = self.api.method_get(uri)
| python | {
"resource": ""
} |
q17924 | CloudMonitorNotificationManager.get_type | train | def get_type(self, notification_type_id):
"""
Returns a CloudMonitorNotificationType object for the given ID.
"""
uri = "/notification_types/%s" % utils.get_id(notification_type_id)
| python | {
"resource": ""
} |
q17925 | CloudMonitorAlarmManager.create | train | def create(self, check, notification_plan, criteria=None,
disabled=False, label=None, name=None, metadata=None):
"""
Creates an alarm that binds the check on the given entity with a
notification plan.
Note that the 'criteria' parameter, if supplied, should be a string
representing the DSL for describing alerting conditions and their
output states. Pyrax does not do any validation of these criteria
statements; it is up to you as the developer to understand the language
and correctly form | python | {
"resource": ""
} |
q17926 | CloudMonitorCheckManager.create_check | train | def create_check(self, label=None, name=None, check_type=None,
details=None, disabled=False, metadata=None,
monitoring_zones_poll=None, timeout=None, period=None,
target_alias=None, target_hostname=None, target_receiver=None,
test_only=False, include_debug=False):
"""
Creates a check on the entity with the specified attributes. The
'details' parameter should be a dict with the keys as the option name,
and the value as the desired setting.
If the 'test_only' parameter is True, then the check is not created;
instead, the check is run and the results of the test run returned. If
'include_debug' is True, additional debug information is returned.
According to the current Cloud Monitoring docs:
"Currently debug information is only available for the
remote.http check and includes the response body."
"""
if details is None:
raise exc.MissingMonitoringCheckDetails("The required 'details' "
"parameter was not passed to the create_check() method.")
ctype = utils.get_id(check_type)
is_remote = ctype.startswith("remote")
monitoring_zones_poll = utils.coerce_to_list(monitoring_zones_poll)
monitoring_zones_poll = [utils.get_id(mzp)
for mzp in monitoring_zones_poll]
# only require monitoring_zones and targets for remote checks
if is_remote:
if not monitoring_zones_poll:
raise exc.MonitoringZonesPollMissing("You must specify the "
"'monitoring_zones_poll' parameter for remote checks.")
if not (target_alias or target_hostname):
raise exc.MonitoringCheckTargetNotSpecified("You must "
"specify either the 'target_alias' or 'target_hostname' "
"when creating a remote check.")
body = {"label": label or name,
"details": details,
"disabled": disabled,
"type": utils.get_id(check_type),
}
params = ("monitoring_zones_poll", "timeout", "period",
"target_alias", "target_hostname", "target_receiver")
body = _params_to_dict(params, body, locals())
if test_only:
uri = "/%s/test-check" % self.uri_base
if include_debug:
uri = "%s?debug=true" % uri
| python | {
"resource": ""
} |
q17927 | _EntityFilteringManger.list | train | def list(self, entity=None):
"""
Returns a dictionary of data, optionally filtered for a given entity.
"""
uri = "/%s" % self.uri_base
if entity:
uri = "%s?entityId=%s" % | python | {
"resource": ""
} |
q17928 | CloudMonitorEntityManager._create_body | train | def _create_body(self, name, label=None, agent=None, ip_addresses=None,
metadata=None):
"""
Used to create the dict required to create various resources. Accepts
either 'label' or 'name' as the keyword parameter for the label
attribute for entities.
"""
label = label or name
if ip_addresses is not None:
body = {"label": label}
| python | {
"resource": ""
} |
q17929 | CloudMonitorEntityManager.update_entity | train | def update_entity(self, entity, agent=None, metadata=None):
"""
Updates the specified entity's values with the supplied parameters.
"""
body = {}
if agent:
body["agent_id"] = utils.get_id(agent)
if metadata:
| python | {
"resource": ""
} |
q17930 | CloudMonitorCheck.get | train | def get(self):
"""Reloads the check with its current values."""
new = self.manager.get(self)
| python | {
"resource": ""
} |
q17931 | CloudMonitorCheck.list_metrics | train | def list_metrics(self, limit=None, marker=None, return_next=False):
"""
Returns a list of all the metrics associated with this check.
"""
| python | {
"resource": ""
} |
q17932 | CloudMonitorCheck.create_alarm | train | def create_alarm(self, notification_plan, criteria=None, disabled=False,
label=None, name=None, metadata=None):
"""
Creates an alarm that binds this check with a notification plan.
"""
| python | {
"resource": ""
} |
q17933 | CloudMonitorAlarm.get | train | def get(self):
"""
Fetches the current state of the alarm from the API and updates the
object.
| python | {
"resource": ""
} |
q17934 | CloudMonitorClient.list_metrics | train | def list_metrics(self, entity, check, limit=None, marker=None,
return_next=False):
"""
Returns a list of all the metrics associated with the specified check.
| python | {
"resource": ""
} |
q17935 | CloudMonitorClient.create_notification_plan | train | def create_notification_plan(self, label=None, name=None,
critical_state=None, ok_state=None, warning_state=None):
"""
Creates a notification plan to be executed | python | {
"resource": ""
} |
q17936 | CloudMonitorClient.update_alarm | train | def update_alarm(self, entity, alarm, criteria=None, disabled=False,
label=None, name=None, metadata=None):
"""
| python | {
"resource": ""
} |
q17937 | CloudMonitorClient.list_alarms | train | def list_alarms(self, entity, limit=None, marker=None, return_next=False):
"""
Returns a list of all the alarms created on the specified entity.
"""
| python | {
"resource": ""
} |
q17938 | assure_container | train | def assure_container(fnc):
"""
Assures that whether a Container or a name of a container is passed, a
Container object is available.
"""
@wraps(fnc)
def _wrapped(self, container, *args, **kwargs):
if not isinstance(container, Container):
# Must be | python | {
"resource": ""
} |
q17939 | _massage_metakeys | train | def _massage_metakeys(dct, prfx):
"""
Returns a copy of the supplied dictionary, prefixing any keys that do
not begin with the specified prefix accordingly.
"""
lowprefix = prfx.lower()
ret = {}
for k, v in list(dct.items()):
| python | {
"resource": ""
} |
q17940 | get_file_size | train | def get_file_size(fileobj):
"""
Returns the size of a file-like object.
"""
| python | {
"resource": ""
} |
q17941 | Container._set_cdn_defaults | train | def _set_cdn_defaults(self):
"""Sets all the CDN-related attributes to default values."""
if self._cdn_enabled is FAULT:
self._cdn_enabled = False | python | {
"resource": ""
} |
q17942 | Container._fetch_cdn_data | train | def _fetch_cdn_data(self):
"""Fetches the container's CDN data from the CDN service"""
if self._cdn_enabled is FAULT:
headers = self.manager.fetch_cdn_data(self)
else:
headers = {}
# Set defaults in case not all headers are present.
self._set_cdn_defaults()
if not headers:
# Not CDN enabled; return
return
else:
self._cdn_enabled = True
| python | {
"resource": ""
} |
q17943 | Container.get_object | train | def get_object(self, item):
"""
Returns a StorageObject matching the specified item. If no such object
exists, a NotFound exception is raised. If 'item' is not a string, that
item is returned unchanged.
"""
| python | {
"resource": ""
} |
q17944 | Container.store_object | train | def store_object(self, obj_name, data, content_type=None, etag=None,
content_encoding=None, ttl=None, return_none=False,
headers=None, extra_info=None):
"""
Creates a new object in this container, and populates it with the given
data. A StorageObject reference to the uploaded file will be returned,
| python | {
"resource": ""
} |
q17945 | Container.upload_file | train | def upload_file(self, file_or_path, obj_name=None, content_type=None,
etag=None, return_none=False, content_encoding=None, ttl=None,
content_length=None, headers=None):
"""
Uploads the specified file to this container. If no name is supplied,
the file's name will be used. Either a file path or an open file-like
object may be supplied. A StorageObject reference to the uploaded file
will be returned, unless 'return_none' is set to True.
You may optionally set the `content_type` and `content_encoding`
parameters; pyrax will create the appropriate headers when the object
is stored.
If the size of the file is known, it can be passed as `content_length`.
If you wish for the object to be temporary, specify the time it should
| python | {
"resource": ""
} |
q17946 | Container.delete | train | def delete(self, del_objects=False):
"""
Deletes this Container. If the container contains objects, the
command will fail unless 'del_objects' is passed as True. In that
case, | python | {
"resource": ""
} |
q17947 | Container.delete_object_in_seconds | train | def delete_object_in_seconds(self, obj, seconds, extra_info=None):
"""
Sets the object in this container to be deleted after the specified
number of seconds.
The 'extra_info' parameter is included for backwards compatibility. It
is | python | {
"resource": ""
} |
q17948 | Container.change_object_content_type | train | def change_object_content_type(self, obj, new_ctype, guess=False):
"""
Copies object to itself, but applies a new content-type. The guess
feature requires this container to be CDN-enabled. If not, then the
content-type must be supplied. If using guess with a CDN-enabled
container, new_ctype can be set to | python | {
"resource": ""
} |
q17949 | Container.get_temp_url | train | def get_temp_url(self, obj, seconds, method="GET", key=None, cached=True):
"""
Given a storage object in this container, returns a URL that can be
used to access that object. The URL will expire after `seconds`
seconds.
The only methods supported are GET and PUT. Anything else will raise an
`InvalidTemporaryURLMethod` exception.
If you have your Temporary URL key, you can pass | python | {
"resource": ""
} |
q17950 | ContainerManager.list | train | def list(self, limit=None, marker=None, end_marker=None, prefix=None):
"""
Swift doesn't return listings in the same format as the rest of
OpenStack, so this method has to be overriden.
"""
uri = "/%s" % self.uri_base
qs = utils.dict_to_qs({"marker": marker, "limit": limit,
"prefix": prefix, | python | {
"resource": ""
} |
q17951 | ContainerManager.get | train | def get(self, container):
"""
Returns a Container matching the specified container name. If no such
container exists, a NoSuchContainer exception is raised.
"""
name = utils.get_name(container)
uri = "/%s" % name
resp, resp_body = self.api.method_head(uri)
hdrs = resp.headers | python | {
"resource": ""
} |
q17952 | ContainerManager.create | train | def create(self, name, metadata=None, prefix=None, *args, **kwargs):
"""
Creates a new container, and returns a Container object that represents
that contianer. If a container by the same name already exists, no
exception is raised; instead, a reference to that existing container is
returned.
"""
uri = "/%s" % name
headers = {}
if prefix is None:
prefix = CONTAINER_META_PREFIX
if metadata:
metadata = _massage_metakeys(metadata, prefix)
headers = metadata
resp, resp_body = self.api.method_put(uri, headers=headers)
if resp.status_code in (201, 202):
hresp, hresp_body = self.api.method_head(uri) | python | {
"resource": ""
} |
q17953 | ContainerManager.fetch_cdn_data | train | def fetch_cdn_data(self, container):
"""
Returns a dict containing the CDN information for the specified
container. If the container is not CDN-enabled, returns an empty dict.
"""
name = utils.get_name(container)
uri = "/%s" % | python | {
"resource": ""
} |
q17954 | ContainerManager.get_headers | train | def get_headers(self, container):
"""
Return the headers for the specified container.
"""
uri | python | {
"resource": ""
} |
q17955 | ContainerManager.get_account_metadata | train | def get_account_metadata(self, prefix=None):
"""
Returns a dictionary containing metadata about the account.
"""
headers = self.get_account_headers()
if prefix is None:
prefix = ACCOUNT_META_PREFIX
low_prefix = prefix.lower()
ret = {}
for hkey, hval in | python | {
"resource": ""
} |
q17956 | ContainerManager.delete_account_metadata | train | def delete_account_metadata(self, prefix=None):
"""
Removes all metadata matching the specified prefix from the account.
By default, the standard account metadata prefix ('X-Account-Meta-') is
prepended to the header name if it isn't present. For non-standard
headers, you must include a non-None prefix, such as an empty string.
"""
# Add the metadata prefix, if needed.
if prefix is None:
prefix = ACCOUNT_META_PREFIX
curr_meta = self.get_account_metadata(prefix=prefix)
| python | {
"resource": ""
} |
q17957 | ContainerManager.remove_metadata_key | train | def remove_metadata_key(self, container, key):
"""
Removes the specified key from the container's metadata. If the key
does not exist in the metadata, nothing | python | {
"resource": ""
} |
q17958 | ContainerManager.delete_metadata | train | def delete_metadata(self, container, prefix=None):
"""
Removes all of the container's metadata.
By default, all metadata beginning with the standard container metadata
prefix ('X-Container-Meta-') is removed. If you wish to remove all
metadata beginning with a different prefix, you must specify that
prefix.
"""
# Add the metadata prefix, if needed.
if prefix is None:
prefix = CONTAINER_META_PREFIX
new_meta | python | {
"resource": ""
} |
q17959 | ContainerManager.get_cdn_metadata | train | def get_cdn_metadata(self, container):
"""
Returns a dictionary containing the CDN metadata for the container. If
the container does not exist, a NotFound exception is raised. If the
container exists, but is not CDN-enabled, a NotCDNEnabled exception is
raised.
"""
uri = "%s/%s" % (self.uri_base, utils.get_name(container)) | python | {
"resource": ""
} |
q17960 | ContainerManager.list_public_containers | train | def list_public_containers(self):
"""
Returns a list of the names of all CDN-enabled containers.
"""
| python | {
"resource": ""
} |
q17961 | ContainerManager._set_cdn_access | train | def _set_cdn_access(self, container, public, ttl=None):
"""
Enables or disables CDN access for the specified container, and
optionally sets the TTL for the container when enabling access.
"""
headers = {"X-Cdn-Enabled": "%s" % public}
if | python | {
"resource": ""
} |
q17962 | ContainerManager.get_cdn_log_retention | train | def get_cdn_log_retention(self, container):
"""
Returns the status of the setting for CDN log retention for the
specified container.
"""
resp, resp_body = self.api.cdn_request("/%s" %
| python | {
"resource": ""
} |
q17963 | ContainerManager.set_cdn_log_retention | train | def set_cdn_log_retention(self, container, enabled):
"""
Enables or disables whether CDN access logs for the specified container
| python | {
"resource": ""
} |
q17964 | ContainerManager.get_container_streaming_uri | train | def get_container_streaming_uri(self, container):
"""
Returns the URI for streaming content, or None if CDN is not enabled.
"""
resp, resp_body = self.api.cdn_request("/%s" %
| python | {
"resource": ""
} |
q17965 | ContainerManager.set_web_index_page | train | def set_web_index_page(self, container, page):
"""
Sets the header indicating the index page in a container
when creating a static website.
Note: the container must be CDN-enabled for this to have
any effect.
"""
| python | {
"resource": ""
} |
q17966 | ContainerManager.list_objects | train | def list_objects(self, container, limit=None, marker=None, prefix=None,
delimiter=None, end_marker=None, full_listing=False):
"""
Return a list of StorageObjects representing the objects in this
container. You can use the marker, end_marker, and limit params to
handle pagination, and the prefix and delimiter params to filter the
objects returned. By default only the first 10,000 objects are
| python | {
"resource": ""
} |
q17967 | ContainerManager.list_object_names | train | def list_object_names(self, container, marker=None, limit=None, prefix=None,
delimiter=None, end_marker=None, full_listing=False):
"""
Return a list of then names of the objects in this container. You can
use the marker, end_marker, and limit params to handle pagination, and
the prefix and delimiter params to filter the objects returned. By
default only the first 10,000 objects are | python | {
"resource": ""
} |
q17968 | ContainerManager.change_object_content_type | train | def change_object_content_type(self, container, obj, new_ctype,
guess=False):
"""
Copies object to itself, but applies a new content-type. The guess
feature requires the container to be CDN-enabled. If not, then the
content-type must be supplied. If using guess with a CDN-enabled
container, new_ctype can be set to None. Failure during the put will
result in an exception.
"""
cname = utils.get_name(container)
oname = utils.get_name(obj)
if guess and container.cdn_enabled:
| python | {
"resource": ""
} |
q17969 | StorageObject.copy | train | def copy(self, new_container, new_obj_name=None, extra_info=None):
"""
Copies this object to the new container, optionally giving it a new
name. If you copy to the same container, you must supply a different
name.
| python | {
"resource": ""
} |
q17970 | StorageObject.move | train | def move(self, new_container, new_obj_name=None, extra_info=None):
"""
Works just like copy_object, except that this object is deleted after a
| python | {
"resource": ""
} |
q17971 | StorageObject.get_temp_url | train | def get_temp_url(self, seconds, method="GET"):
"""
Returns a URL that can be used to access this object. The URL will
expire after `seconds` seconds.
| python | {
"resource": ""
} |
q17972 | StorageObjectManager.get | train | def get(self, obj):
"""
Gets the information about the specified object.
This overrides the base behavior, since Swift uses HEAD to get
information, and GET to download the object.
"""
name = utils.get_name(obj)
uri = "/%s/%s" % (self.uri_base, name)
resp, resp_body = self.api.method_head(uri)
hdrs = resp.headers
try:
content_length = int(hdrs.get("content-length"))
except (TypeError, ValueError):
content_length = None
data = {"name": name, | python | {
"resource": ""
} |
q17973 | StorageObjectManager._upload | train | def _upload(self, obj_name, content, content_type, content_encoding,
content_length, etag, chunked, chunk_size, headers):
"""
Handles the uploading of content, including working around the 5GB
maximum file size.
"""
if content_type is not None:
headers["Content-Type"] = content_type
if content_encoding is not None:
headers["Content-Encoding"] = content_encoding
if isinstance(content, six.string_types):
fsize = len(content)
else:
if chunked:
fsize = None
elif content_length is None:
fsize = get_file_size(content)
else:
fsize = content_length
if fsize is None or fsize <= MAX_FILE_SIZE:
# We can just upload it as-is.
return self._store_object(obj_name, content=content, etag=etag,
chunked=chunked, chunk_size=chunk_size, headers=headers)
# Files larger than MAX_FILE_SIZE must be segmented
# and uploaded separately.
num_segments = int(math.ceil(float(fsize) / MAX_FILE_SIZE))
digits = int(math.log10(num_segments)) + 1
# NOTE: This could be greatly improved with threading or other
# async design.
for segment in range(num_segments):
sequence = str(segment + 1).zfill(digits)
| python | {
"resource": ""
} |
q17974 | StorageObjectManager._store_object | train | def _store_object(self, obj_name, content, etag=None, chunked=False,
chunk_size=None, headers=None):
"""
Handles the low-level creation of a storage object and the uploading of
the contents of that object.
"""
head_etag = headers.pop("ETag", "")
if chunked:
headers.pop("Content-Length", "")
headers["Transfer-Encoding"] = "chunked"
elif etag is None and content is not None:
etag = utils.get_checksum(content)
if etag:
| python | {
"resource": ""
} |
q17975 | StorageObjectManager._fetch_chunker | train | def _fetch_chunker(self, uri, chunk_size, size, obj_size):
"""
Returns a generator that returns an object in chunks.
"""
pos = 0
total_bytes = 0
size = size or obj_size
max_size = min(size, obj_size)
while True:
endpos = min(obj_size, pos + chunk_size - 1)
headers = {"Range": "bytes=%s-%s" % (pos, endpos)}
resp, resp_body = self.api.method_get(uri, headers=headers,
raw_content=True)
| python | {
"resource": ""
} |
q17976 | StorageObjectManager.remove_metadata_key | train | def remove_metadata_key(self, obj, key):
"""
Removes the specified key from the object's metadata. If the key does
not exist in the metadata, nothing | python | {
"resource": ""
} |
q17977 | StorageClient._configure_cdn | train | def _configure_cdn(self):
"""
Initialize CDN-related endpoints, if available.
"""
ident = self.identity
| python | {
"resource": ""
} |
q17978 | StorageClient._backwards_aliases | train | def _backwards_aliases(self):
"""
In order to keep this backwards-compatible with previous versions,
alias the old names to the new methods.
"""
self.list_containers = self.list_container_names
self.get_all_containers = self.list
self.get_container = self.get
self.create_container = self.create
| python | {
"resource": ""
} |
q17979 | StorageClient.get | train | def get(self, item):
"""
Returns the container whose name is provided as 'item'. If 'item' is
not a string, the original item is returned unchanged.
"""
| python | {
"resource": ""
} |
q17980 | StorageClient._configure_manager | train | def _configure_manager(self):
"""
Creates a manager to handle interacting with Containers.
"""
| python | {
"resource": ""
} |
q17981 | StorageClient.get_account_details | train | def get_account_details(self):
"""
Returns a dictionary containing information about the account.
"""
headers = self._manager.get_account_headers()
acct_prefix = "x-account-"
meta_prefix = ACCOUNT_META_PREFIX.lower()
ret = {}
for hkey, hval in list(headers.items()):
| python | {
"resource": ""
} |
q17982 | StorageClient.get_account_info | train | def get_account_info(self):
"""
Returns a tuple for the number of containers and total bytes in the
account.
"""
| python | {
"resource": ""
} |
q17983 | StorageClient.get_temp_url_key | train | def get_temp_url_key(self, cached=True):
"""
Returns the current TempURL key, or None if it has not been set.
By default the value returned is cached. To force an API call to get
the current value on the server, pass `cached=False`.
"""
meta = self._cached_temp_url_key | python | {
"resource": ""
} |
q17984 | StorageClient.set_temp_url_key | train | def set_temp_url_key(self, key=None):
"""
Sets the key for the Temporary URL for the account. It should be a key
that is secret to the owner.
If no key is provided, a UUID value will be generated and used. It can
later be obtained by calling get_temp_url_key().
"""
| python | {
"resource": ""
} |
q17985 | StorageClient.list | train | def list(self, limit=None, marker=None, end_marker=None, prefix=None):
"""
List the containers in this account, using the parameters to control
the pagination of containers, since by default only the first 10,000
containers are returned.
| python | {
"resource": ""
} |
q17986 | StorageClient.list_container_object_names | train | def list_container_object_names(self, container, limit=None, marker=None,
prefix=None, delimiter=None, full_listing=False):
"""
Returns the names of all the objects in the specified container,
optionally limited by the pagination parameters.
"""
return | python | {
"resource": ""
} |
q17987 | StorageClient.delete_container_metadata | train | def delete_container_metadata(self, container, prefix=None):
"""
Removes all of thethe container's metadata.
By default, all metadata beginning with the standard container metadata | python | {
"resource": ""
} |
q17988 | StorageClient.list_container_objects | train | def list_container_objects(self, container, limit=None, marker=None,
prefix=None, delimiter=None, end_marker=None, full_listing=False):
"""
Return a list of StorageObjects representing the objects in the
container. You can use the marker, end_marker, and limit params to
handle pagination, and the prefix and delimiter params to filter the
objects returned. Also, by default only the first 10,000 objects are
returned; if you set full_listing to True, an iterator to return all
the objects in the container is returned. In this case, only the
'prefix' parameter is used; if you specify any others, they are
| python | {
"resource": ""
} |
q17989 | StorageClient.store_object | train | def store_object(self, container, obj_name, data, content_type=None,
etag=None, content_encoding=None, ttl=None, return_none=False,
chunk_size=None, headers=None, metadata=None, extra_info=None):
"""
Creates a new object in the specified container, and populates it with
the given data. A StorageObject reference to the uploaded file
will be returned, unless 'return_none' is set to True.
The 'extra_info' parameter is included for backwards compatibility. It
is no longer used at all, and will not be modified with swiftclient
info, since swiftclient is not used any more.
| python | {
"resource": ""
} |
q17990 | StorageClient.upload_file | train | def upload_file(self, container, file_or_path, obj_name=None,
content_type=None, etag=None, content_encoding=None, ttl=None,
content_length=None, return_none=False, headers=None,
metadata=None, extra_info=None):
"""
Uploads the specified file to the container. If no name is supplied,
the file's name will be used. Either a file path or an open file-like
object may be supplied. A StorageObject reference to the uploaded file
will be returned, unless 'return_none' is set to True.
You may optionally set the `content_type` and `content_encoding`
parameters; pyrax will create the appropriate headers when the object
is stored.
If the size of the file is known, it can be passed as `content_length`.
If you wish for the object to be temporary, specify the time it | python | {
"resource": ""
} |
q17991 | StorageClient.fetch_partial | train | def fetch_partial(self, container, obj, size):
"""
Returns the first 'size' bytes of an object. If the object is smaller
than the specified 'size' value, the | python | {
"resource": ""
} |
q17992 | StorageClient.upload_folder | train | def upload_folder(self, folder_path, container=None, ignore=None, ttl=None):
"""
Convenience method for uploading an entire folder, including any
sub-folders, to Cloud Files.
All files will be uploaded to objects with the same name as the file.
In the case of nested folders, files will be named with the full path
relative to the base folder. E.g., if the folder you specify contains a
folder named 'docs', and 'docs' contains a file named 'install.html',
that file will be uploaded to an object named 'docs/install.html'.
If 'container' is specified, the folder's contents will be uploaded to
that container. If it is not specified, a new container with the same
name as the specified folder will be created, and the files uploaded to
this new container.
You can selectively ignore files by passing either a single pattern or
a list of patterns; these will be applied to the individual folder and
file names, and any names that match any of the 'ignore' patterns will
not be uploaded. The patterns should be standard *nix-style shell
patterns; e.g., '*pyc' will ignore all files ending in 'pyc', such as
'program.pyc' and 'abcpyc'.
The upload will happen asynchronously; in other words, the call to
upload_folder() will generate a UUID and return a 2-tuple of (UUID,
total_bytes) immediately. Uploading will happen in the background; your
app can call get_uploaded(uuid) to get the current status of the
upload. When the upload is complete, the value returned by
| python | {
"resource": ""
} |
q17993 | StorageClient._upload_folder_in_background | train | def _upload_folder_in_background(self, folder_path, container, ignore,
upload_key, ttl=None):
"""Runs the | python | {
"resource": ""
} |
q17994 | StorageClient._sync_folder_to_container | train | def _sync_folder_to_container(self, folder_path, container, prefix, delete,
include_hidden, ignore, ignore_timestamps, object_prefix, verbose):
"""
This is the internal method that is called recursively to handle
nested folder structures.
"""
fnames = os.listdir(folder_path)
ignore = utils.coerce_to_list(ignore)
log = logging.getLogger("pyrax")
if not include_hidden:
ignore.append(".*")
for fname in fnames:
if utils.match_pattern(fname, ignore):
self._sync_summary["ignored"] += 1
continue
pth = os.path.join(folder_path, fname)
if os.path.isdir(pth):
subprefix = fname
if prefix:
subprefix = os.path.join(prefix, subprefix)
self._sync_folder_to_container(pth, container, prefix=subprefix,
delete=delete, include_hidden=include_hidden,
ignore=ignore, ignore_timestamps=ignore_timestamps,
object_prefix=object_prefix, verbose=verbose)
continue
self._local_files.append(os.path.join(object_prefix, prefix,
fname))
local_etag = utils.get_checksum(pth)
if object_prefix:
prefix = os.path.join(object_prefix, prefix)
object_prefix = ""
fullname_with_prefix = os.path.join(prefix, fname)
try:
obj | python | {
"resource": ""
} |
q17995 | StorageClient._delete_objects_not_in_list | train | def _delete_objects_not_in_list(self, cont, object_prefix=""):
"""
Finds all the objects in the specified container that are not present
in the self._local_files list, and deletes them.
"""
objnames = set(cont.get_object_names(prefix=object_prefix,
full_listing=True))
localnames = set(self._local_files)
| python | {
"resource": ""
} |
q17996 | StorageClient.bulk_delete | train | def bulk_delete(self, container, object_names, async_=False):
"""
Deletes multiple objects from a container in a single call.
The bulk deletion call does not return until all of the specified
objects have been processed. For large numbers of objects, this can
take quite a while, so there is an 'async_' parameter to give you the
option to have this call return immediately. If 'async_' is True, an
object is returned with a 'completed' attribute that will be set to
True as soon as the bulk deletion is complete, and a 'results'
attribute that will contain a dictionary (described below) with the
results of the bulk deletion.
When deletion is complete the bulk deletion object's 'results'
attribute will be populated with the information returned from the API
call. In synchronous mode this is the value that is returned when the
call completes. It is a dictionary with the following keys:
deleted - the number of objects deleted
not_found - the number of objects not found
status - the | python | {
"resource": ""
} |
q17997 | StorageClient.cdn_request | train | def cdn_request(self, uri, method, *args, **kwargs):
"""
If the service supports CDN, use this method to access CDN-specific
URIs.
"""
if not self.cdn_management_url:
raise exc.NotCDNEnabled("CDN is not enabled for this service.")
cdn_uri = "%s%s" % (self.cdn_management_url, uri)
mthd = self.method_dict.get(method.upper())
try:
resp, resp_body = mthd(cdn_uri, *args, **kwargs)
except exc.NotFound as e:
# This could be due to either the container does not exist, or that
| python | {
"resource": ""
} |
q17998 | FolderUploader.upload_files_in_folder | train | def upload_files_in_folder(self, dirname, fnames):
"""Handles the iteration across files within a folder."""
if utils.match_pattern(dirname, self.ignore):
return False
good_names = (nm for nm in fnames
if not utils.match_pattern(nm, self.ignore))
for fname in good_names:
if self.client._should_abort_folder_upload(self.upload_key):
return
full_path = os.path.join(dirname, fname)
obj_name = os.path.relpath(full_path, self.root_folder)
| python | {
"resource": ""
} |
q17999 | FolderUploader.run | train | def run(self):
"""Starts the uploading thread."""
root_path, folder_name = os.path.split(self.root_folder)
self.root_folder = os.path.join(root_path, folder_name)
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.