id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
17,900
pycontribs/pyrax
pyrax/cloudblockstorage.py
assure_snapshot
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 snapshot = self._snapshot_manager.get(snapshot) return fnc(self, snapshot, *args, **kwargs) return _wrapped
python
def assure_snapshot(fnc): @wraps(fnc) def _wrapped(self, snapshot, *args, **kwargs): if not isinstance(snapshot, CloudBlockStorageSnapshot): # Must be the ID snapshot = self._snapshot_manager.get(snapshot) return fnc(self, snapshot, *args, **kwargs) return _wrapped
[ "def", "assure_snapshot", "(", "fnc", ")", ":", "@", "wraps", "(", "fnc", ")", "def", "_wrapped", "(", "self", ",", "snapshot", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "snapshot", ",", "CloudBlockStorageSnap...
Converts a snapshot ID passed as the snapshot to a CloudBlockStorageSnapshot object.
[ "Converts", "a", "snapshot", "ID", "passed", "as", "the", "snapshot", "to", "a", "CloudBlockStorageSnapshot", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L59-L70
17,901
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageSnapshot.delete
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: super(CloudBlockStorageSnapshot, self).delete() except exc.ClientException as e: if "Request conflicts with in-progress 'DELETE" in str(e): time.sleep(RETRY_INTERVAL) # Try again; if it fails, oh, well... super(CloudBlockStorageSnapshot, self).delete()
python
def delete(self): 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: super(CloudBlockStorageSnapshot, self).delete() except exc.ClientException as e: if "Request conflicts with in-progress 'DELETE" in str(e): time.sleep(RETRY_INTERVAL) # Try again; if it fails, oh, well... super(CloudBlockStorageSnapshot, self).delete()
[ "def", "delete", "(", "self", ")", ":", "if", "self", ".", "status", "not", "in", "(", "\"available\"", ",", "\"error\"", ")", ":", "raise", "exc", ".", "SnapshotNotAvailable", "(", "\"Snapshot must be in 'available' \"", "\"or 'error' status before deleting. Current ...
Adds a check to make sure that the snapshot is able to be deleted.
[ "Adds", "a", "check", "to", "make", "sure", "that", "the", "snapshot", "is", "able", "to", "be", "deleted", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L78-L95
17,902
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageSnapshot.update
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. If no values are specified as non-None, the call is a no-op; no exception will be raised. """ return self.manager.update(self, display_name=display_name, display_description=display_description)
python
def update(self, display_name=None, display_description=None): return self.manager.update(self, display_name=display_name, display_description=display_description)
[ "def", "update", "(", "self", ",", "display_name", "=", "None", ",", "display_description", "=", "None", ")", ":", "return", "self", ".", "manager", ".", "update", "(", "self", ",", "display_name", "=", "display_name", ",", "display_description", "=", "displ...
Update the specified values on this snapshot. You may specify one or more values to update. If no values are specified as non-None, the call is a no-op; no exception will be raised.
[ "Update", "the", "specified", "values", "on", "this", "snapshot", ".", "You", "may", "specify", "one", "or", "more", "values", "to", "update", ".", "If", "no", "values", "are", "specified", "as", "non", "-", "None", "the", "call", "is", "a", "no", "-",...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L98-L105
17,903
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageVolume.attach_to_instance
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) try: resp = self._nova_volumes.create_server_volume(instance_id, self.id, mountpoint) except Exception as e: raise exc.VolumeAttachmentFailed("%s" % e)
python
def attach_to_instance(self, instance, mountpoint): instance_id = _resolve_id(instance) try: resp = self._nova_volumes.create_server_volume(instance_id, self.id, mountpoint) except Exception as e: raise exc.VolumeAttachmentFailed("%s" % e)
[ "def", "attach_to_instance", "(", "self", ",", "instance", ",", "mountpoint", ")", ":", "instance_id", "=", "_resolve_id", "(", "instance", ")", "try", ":", "resp", "=", "self", ".", "_nova_volumes", ".", "create_server_volume", "(", "instance_id", ",", "self"...
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.
[ "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", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L153-L164
17,904
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageVolume.detach
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 return # A volume can only be attached to one device at a time, but for some # reason this is a list instead of a singular value att = attachments[0] instance_id = att["server_id"] attachment_id = att["id"] try: self._nova_volumes.delete_server_volume(instance_id, attachment_id) except Exception as e: raise exc.VolumeDetachmentFailed("%s" % e)
python
def detach(self): attachments = self.attachments if not attachments: # Not attached; no error needed, just return return # A volume can only be attached to one device at a time, but for some # reason this is a list instead of a singular value att = attachments[0] instance_id = att["server_id"] attachment_id = att["id"] try: self._nova_volumes.delete_server_volume(instance_id, attachment_id) except Exception as e: raise exc.VolumeDetachmentFailed("%s" % e)
[ "def", "detach", "(", "self", ")", ":", "attachments", "=", "self", ".", "attachments", "if", "not", "attachments", ":", "# Not attached; no error needed, just return", "return", "# A volume can only be attached to one device at a time, but for some", "# reason this is a list ins...
Detaches this volume from any device it may be attached to. If it is not attached, nothing happens.
[ "Detaches", "this", "volume", "from", "any", "device", "it", "may", "be", "attached", "to", ".", "If", "it", "is", "not", "attached", "nothing", "happens", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L167-L184
17,905
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageVolume.create_snapshot
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. """ name = name or "" description = description or "" # Note that passing in non-None values is required for the _create_body # method to distinguish between this and the request to create and # instance. return self.manager.create_snapshot(volume=self, name=name, description=description, force=force)
python
def create_snapshot(self, name=None, description=None, force=False): name = name or "" description = description or "" # Note that passing in non-None values is required for the _create_body # method to distinguish between this and the request to create and # instance. return self.manager.create_snapshot(volume=self, name=name, description=description, force=force)
[ "def", "create_snapshot", "(", "self", ",", "name", "=", "None", ",", "description", "=", "None", ",", "force", "=", "False", ")", ":", "name", "=", "name", "or", "\"\"", "description", "=", "description", "or", "\"\"", "# Note that passing in non-None values ...
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.
[ "Creates", "a", "snapshot", "of", "this", "volume", "with", "an", "optional", "name", "and", "description", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L223-L237
17,906
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageVolume.list_snapshots
def list_snapshots(self): """ Returns a list of all snapshots of this volume. """ return [snap for snap in self.manager.list_snapshots() if snap.volume_id == self.id]
python
def list_snapshots(self): return [snap for snap in self.manager.list_snapshots() if snap.volume_id == self.id]
[ "def", "list_snapshots", "(", "self", ")", ":", "return", "[", "snap", "for", "snap", "in", "self", ".", "manager", ".", "list_snapshots", "(", ")", "if", "snap", ".", "volume_id", "==", "self", ".", "id", "]" ]
Returns a list of all snapshots of this volume.
[ "Returns", "a", "list", "of", "all", "snapshots", "of", "this", "volume", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L240-L245
17,907
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageManager._create_body
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, "source_volid": clone_id, "display_name": name, "display_description": description, "volume_type": volume_type, "metadata": metadata, "availability_zone": availability_zone, "imageRef": image, }} return body
python
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): 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, "source_volid": clone_id, "display_name": name, "display_description": description, "volume_type": volume_type, "metadata": metadata, "availability_zone": availability_zone, "imageRef": image, }} return body
[ "def", "_create_body", "(", "self", ",", "name", ",", "size", "=", "None", ",", "volume_type", "=", "None", ",", "description", "=", "None", ",", "metadata", "=", "None", ",", "snapshot_id", "=", "None", ",", "clone_id", "=", "None", ",", "availability_z...
Used to create the dict required to create a new volume
[ "Used", "to", "create", "the", "dict", "required", "to", "create", "a", "new", "volume" ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L279-L307
17,908
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageManager.create
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: msg = e.message if "Clones currently must be >= original volume size" in msg: raise exc.VolumeCloneTooSmall(msg) else: raise
python
def create(self, *args, **kwargs): try: return super(CloudBlockStorageManager, self).create(*args, **kwargs) except exc.BadRequest as e: msg = e.message if "Clones currently must be >= original volume size" in msg: raise exc.VolumeCloneTooSmall(msg) else: raise
[ "def", "create", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "try", ":", "return", "super", "(", "CloudBlockStorageManager", ",", "self", ")", ".", "create", "(", "*", "args", ",", "*", "*", "kwargs", ")", "except", "exc", "."...
Catches errors that may be returned, and raises more informational exceptions.
[ "Catches", "errors", "that", "may", "be", "returned", "and", "raises", "more", "informational", "exceptions", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L310-L323
17,909
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageSnapshotManager._create_body
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, "display_description": description, "volume_id": volume.id, "force": str(force).lower(), }} return body
python
def _create_body(self, name, description=None, volume=None, force=False): body = {"snapshot": { "display_name": name, "display_description": description, "volume_id": volume.id, "force": str(force).lower(), }} return body
[ "def", "_create_body", "(", "self", ",", "name", ",", "description", "=", "None", ",", "volume", "=", "None", ",", "force", "=", "False", ")", ":", "body", "=", "{", "\"snapshot\"", ":", "{", "\"display_name\"", ":", "name", ",", "\"display_description\"",...
Used to create the dict required to create a new snapshot
[ "Used", "to", "create", "the", "dict", "required", "to", "create", "a", "new", "snapshot" ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L367-L377
17,910
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageClient._configure_manager
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, resource_class=CloudBlockStorageVolumeType, response_key="volume_type", uri_base="types") self._snapshot_manager = CloudBlockStorageSnapshotManager(self, resource_class=CloudBlockStorageSnapshot, response_key="snapshot", uri_base="snapshots")
python
def _configure_manager(self): self._manager = CloudBlockStorageManager(self, resource_class=CloudBlockStorageVolume, response_key="volume", uri_base="volumes") self._types_manager = BaseManager(self, resource_class=CloudBlockStorageVolumeType, response_key="volume_type", uri_base="types") self._snapshot_manager = CloudBlockStorageSnapshotManager(self, resource_class=CloudBlockStorageSnapshot, response_key="snapshot", uri_base="snapshots")
[ "def", "_configure_manager", "(", "self", ")", ":", "self", ".", "_manager", "=", "CloudBlockStorageManager", "(", "self", ",", "resource_class", "=", "CloudBlockStorageVolume", ",", "response_key", "=", "\"volume\"", ",", "uri_base", "=", "\"volumes\"", ")", "sel...
Create the manager to handle the instances, and also another to handle flavors.
[ "Create", "the", "manager", "to", "handle", "the", "instances", "and", "also", "another", "to", "handle", "flavors", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L438-L451
17,911
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageClient.create_snapshot
def create_snapshot(self, volume, name=None, description=None, force=False): """ Creates a snapshot of the 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. """ return self._snapshot_manager.create(volume=volume, name=name, description=description, force=force)
python
def create_snapshot(self, volume, name=None, description=None, force=False): return self._snapshot_manager.create(volume=volume, name=name, description=description, force=force)
[ "def", "create_snapshot", "(", "self", ",", "volume", ",", "name", "=", "None", ",", "description", "=", "None", ",", "force", "=", "False", ")", ":", "return", "self", ".", "_snapshot_manager", ".", "create", "(", "volume", "=", "volume", ",", "name", ...
Creates a snapshot of the 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.
[ "Creates", "a", "snapshot", "of", "the", "volume", "with", "an", "optional", "name", "and", "description", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L501-L509
17,912
pycontribs/pyrax
pyrax/cloudblockstorage.py
CloudBlockStorageClient.update_snapshot
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. """ return snapshot.update(display_name=display_name, display_description=display_description)
python
def update_snapshot(self, snapshot, display_name=None, display_description=None): return snapshot.update(display_name=display_name, display_description=display_description)
[ "def", "update_snapshot", "(", "self", ",", "snapshot", ",", "display_name", "=", "None", ",", "display_description", "=", "None", ")", ":", "return", "snapshot", ".", "update", "(", "display_name", "=", "display_name", ",", "display_description", "=", "display_...
Update the specified values on the specified snapshot. You may specify one or more values to update.
[ "Update", "the", "specified", "values", "on", "the", "specified", "snapshot", ".", "You", "may", "specify", "one", "or", "more", "values", "to", "update", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudblockstorage.py#L526-L533
17,913
pycontribs/pyrax
pyrax/cloudmonitoring.py
assure_check
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 check = self._check_manager.get(check) return fnc(self, check, *args, **kwargs) return _wrapped
python
def assure_check(fnc): @wraps(fnc) def _wrapped(self, check, *args, **kwargs): if not isinstance(check, CloudMonitorCheck): # Must be the ID check = self._check_manager.get(check) return fnc(self, check, *args, **kwargs) return _wrapped
[ "def", "assure_check", "(", "fnc", ")", ":", "@", "wraps", "(", "fnc", ")", "def", "_wrapped", "(", "self", ",", "check", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "check", ",", "CloudMonitorCheck", ")", "...
Converts an checkID passed as the check to a CloudMonitorCheck object.
[ "Converts", "an", "checkID", "passed", "as", "the", "check", "to", "a", "CloudMonitorCheck", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L42-L52
17,914
pycontribs/pyrax
pyrax/cloudmonitoring.py
assure_entity
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 entity = self._entity_manager.get(entity) return fnc(self, entity, *args, **kwargs) return _wrapped
python
def assure_entity(fnc): @wraps(fnc) def _wrapped(self, entity, *args, **kwargs): if not isinstance(entity, CloudMonitorEntity): # Must be the ID entity = self._entity_manager.get(entity) return fnc(self, entity, *args, **kwargs) return _wrapped
[ "def", "assure_entity", "(", "fnc", ")", ":", "@", "wraps", "(", "fnc", ")", "def", "_wrapped", "(", "self", ",", "entity", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "entity", ",", "CloudMonitorEntity", ")",...
Converts an entityID passed as the entity to a CloudMonitorEntity object.
[ "Converts", "an", "entityID", "passed", "as", "the", "entity", "to", "a", "CloudMonitorEntity", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L55-L65
17,915
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorEntity.get_check
def get_check(self, check): """ Returns an instance of the specified check. """ chk = self._check_manager.get(check) chk.set_entity(self) return chk
python
def get_check(self, check): chk = self._check_manager.get(check) chk.set_entity(self) return chk
[ "def", "get_check", "(", "self", ",", "check", ")", ":", "chk", "=", "self", ".", "_check_manager", ".", "get", "(", "check", ")", "chk", ".", "set_entity", "(", "self", ")", "return", "chk" ]
Returns an instance of the specified check.
[ "Returns", "an", "instance", "of", "the", "specified", "check", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L89-L95
17,916
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorEntity.list_checks
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 the 'marker' parameter. This is the ID of the first item to return. To get this, pass True for the 'return_next' parameter, and the response will be a 2-tuple, with the first element being the list of checks, and the second the ID of the next item. If there is no next item, the second element will be None. """ checks = self._check_manager.list(limit=limit, marker=marker, return_next=return_next) for check in checks: check.set_entity(self) return checks
python
def list_checks(self, limit=None, marker=None, return_next=False): checks = self._check_manager.list(limit=limit, marker=marker, return_next=return_next) for check in checks: check.set_entity(self) return checks
[ "def", "list_checks", "(", "self", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "return_next", "=", "False", ")", ":", "checks", "=", "self", ".", "_check_manager", ".", "list", "(", "limit", "=", "limit", ",", "marker", "=", "marker", ...
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 the 'marker' parameter. This is the ID of the first item to return. To get this, pass True for the 'return_next' parameter, and the response will be a 2-tuple, with the first element being the list of checks, and the second the ID of the next item. If there is no next item, the second element will be None.
[ "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"...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L98-L115
17,917
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorEntity.create_check
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, details=details, monitoring_zones_poll=monitoring_zones_poll, timeout=timeout, period=period, target_alias=target_alias, target_hostname=target_hostname, target_receiver=target_receiver, test_only=test_only, include_debug=include_debug)
python
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): return self._check_manager.create_check(label=label, name=name, check_type=check_type, disabled=disabled, metadata=metadata, details=details, monitoring_zones_poll=monitoring_zones_poll, timeout=timeout, period=period, target_alias=target_alias, target_hostname=target_hostname, target_receiver=target_receiver, test_only=test_only, include_debug=include_debug)
[ "def", "create_check", "(", "self", ",", "label", "=", "None", ",", "name", "=", "None", ",", "check_type", "=", "None", ",", "disabled", "=", "False", ",", "metadata", "=", "None", ",", "details", "=", "None", ",", "monitoring_zones_poll", "=", "None", ...
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.
[ "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",...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L131-L147
17,918
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorEntity.create_alarm
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 self._alarm_manager.create(check, notification_plan, criteria=criteria, disabled=disabled, label=label, name=name, metadata=metadata)
python
def create_alarm(self, check, notification_plan, criteria=None, disabled=False, label=None, name=None, metadata=None): return self._alarm_manager.create(check, notification_plan, criteria=criteria, disabled=disabled, label=label, name=name, metadata=metadata)
[ "def", "create_alarm", "(", "self", ",", "check", ",", "notification_plan", ",", "criteria", "=", "None", ",", "disabled", "=", "False", ",", "label", "=", "None", ",", "name", "=", "None", ",", "metadata", "=", "None", ")", ":", "return", "self", ".",...
Creates an alarm that binds the check on this entity with a notification plan.
[ "Creates", "an", "alarm", "that", "binds", "the", "check", "on", "this", "entity", "with", "a", "notification", "plan", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L213-L221
17,919
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorEntity.update_alarm
def update_alarm(self, alarm, criteria=None, disabled=False, label=None, name=None, metadata=None): """ Updates an existing alarm on this entity. """ return self._alarm_manager.update(alarm, criteria=criteria, disabled=disabled, label=label, name=name, metadata=metadata)
python
def update_alarm(self, alarm, criteria=None, disabled=False, label=None, name=None, metadata=None): return self._alarm_manager.update(alarm, criteria=criteria, disabled=disabled, label=label, name=name, metadata=metadata)
[ "def", "update_alarm", "(", "self", ",", "alarm", ",", "criteria", "=", "None", ",", "disabled", "=", "False", ",", "label", "=", "None", ",", "name", "=", "None", ",", "metadata", "=", "None", ")", ":", "return", "self", ".", "_alarm_manager", ".", ...
Updates an existing alarm on this entity.
[ "Updates", "an", "existing", "alarm", "on", "this", "entity", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L224-L230
17,920
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorEntity.list_alarms
def list_alarms(self, limit=None, marker=None, return_next=False): """ Returns a list of all the alarms created on this entity. """ return self._alarm_manager.list(limit=limit, marker=marker, return_next=return_next)
python
def list_alarms(self, limit=None, marker=None, return_next=False): return self._alarm_manager.list(limit=limit, marker=marker, return_next=return_next)
[ "def", "list_alarms", "(", "self", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "return_next", "=", "False", ")", ":", "return", "self", ".", "_alarm_manager", ".", "list", "(", "limit", "=", "limit", ",", "marker", "=", "marker", ",", ...
Returns a list of all the alarms created on this entity.
[ "Returns", "a", "list", "of", "all", "the", "alarms", "created", "on", "this", "entity", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L233-L238
17,921
pycontribs/pyrax
pyrax/cloudmonitoring.py
_PaginationManager.list
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"] = "metadata" ret = super(_PaginationManager, self).list(limit=limit, marker=marker, **kwargs) if return_next: ents, meta = ret return (ents, meta[0].get("next_marker")) else: return ret
python
def list(self, limit=None, marker=None, return_next=False): kwargs = {} if return_next: kwargs["other_keys"] = "metadata" ret = super(_PaginationManager, self).list(limit=limit, marker=marker, **kwargs) if return_next: ents, meta = ret return (ents, meta[0].get("next_marker")) else: return ret
[ "def", "list", "(", "self", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "return_next", "=", "False", ")", ":", "kwargs", "=", "{", "}", "if", "return_next", ":", "kwargs", "[", "\"other_keys\"", "]", "=", "\"metadata\"", "ret", "=", "...
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.
[ "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", "...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L264-L281
17,922
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorNotificationManager.update_notification
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 ntyp = nfcn.type uri = "/%s/%s" % (self.uri_base, nid) body = {"type": ntyp, "details": details} resp, resp_body = self.api.method_put(uri, body=body)
python
def update_notification(self, notification, details): if isinstance(notification, CloudMonitorNotification): nid = notification.id ntyp = notification.type else: # Supplied an ID nfcn = self.get(notification) nid = notification ntyp = nfcn.type uri = "/%s/%s" % (self.uri_base, nid) body = {"type": ntyp, "details": details} resp, resp_body = self.api.method_put(uri, body=body)
[ "def", "update_notification", "(", "self", ",", "notification", ",", "details", ")", ":", "if", "isinstance", "(", "notification", ",", "CloudMonitorNotification", ")", ":", "nid", "=", "notification", ".", "id", "ntyp", "=", "notification", ".", "type", "else...
Updates the specified notification with the supplied details.
[ "Updates", "the", "specified", "notification", "with", "the", "supplied", "details", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L327-L342
17,923
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorNotificationManager.list_types
def list_types(self): """ Returns a list of all available notification types. """ uri = "/notification_types" resp, resp_body = self.api.method_get(uri) return [CloudMonitorNotificationType(self, info) for info in resp_body["values"]]
python
def list_types(self): uri = "/notification_types" resp, resp_body = self.api.method_get(uri) return [CloudMonitorNotificationType(self, info) for info in resp_body["values"]]
[ "def", "list_types", "(", "self", ")", ":", "uri", "=", "\"/notification_types\"", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_get", "(", "uri", ")", "return", "[", "CloudMonitorNotificationType", "(", "self", ",", "info", ")", "for", "...
Returns a list of all available notification types.
[ "Returns", "a", "list", "of", "all", "available", "notification", "types", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L345-L352
17,924
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorNotificationManager.get_type
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) resp, resp_body = self.api.method_get(uri) return CloudMonitorNotificationType(self, resp_body)
python
def get_type(self, notification_type_id): uri = "/notification_types/%s" % utils.get_id(notification_type_id) resp, resp_body = self.api.method_get(uri) return CloudMonitorNotificationType(self, resp_body)
[ "def", "get_type", "(", "self", ",", "notification_type_id", ")", ":", "uri", "=", "\"/notification_types/%s\"", "%", "utils", ".", "get_id", "(", "notification_type_id", ")", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_get", "(", "uri", ...
Returns a CloudMonitorNotificationType object for the given ID.
[ "Returns", "a", "CloudMonitorNotificationType", "object", "for", "the", "given", "ID", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L355-L361
17,925
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorAlarmManager.create
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 the statement. This alarm language is documented online in the Cloud Monitoring section of http://docs.rackspace.com. """ uri = "/%s" % self.uri_base body = {"check_id": utils.get_id(check), "notification_plan_id": utils.get_id(notification_plan), } if criteria: body["criteria"] = criteria if disabled is not None: body["disabled"] = disabled label_name = label or name if label_name: body["label"] = label_name if metadata: body["metadata"] = metadata resp, resp_body = self.api.method_post(uri, body=body) if resp.status_code == 201: alarm_id = resp.headers["x-object-id"] return self.get(alarm_id)
python
def create(self, check, notification_plan, criteria=None, disabled=False, label=None, name=None, metadata=None): uri = "/%s" % self.uri_base body = {"check_id": utils.get_id(check), "notification_plan_id": utils.get_id(notification_plan), } if criteria: body["criteria"] = criteria if disabled is not None: body["disabled"] = disabled label_name = label or name if label_name: body["label"] = label_name if metadata: body["metadata"] = metadata resp, resp_body = self.api.method_post(uri, body=body) if resp.status_code == 201: alarm_id = resp.headers["x-object-id"] return self.get(alarm_id)
[ "def", "create", "(", "self", ",", "check", ",", "notification_plan", ",", "criteria", "=", "None", ",", "disabled", "=", "False", ",", "label", "=", "None", ",", "name", "=", "None", ",", "metadata", "=", "None", ")", ":", "uri", "=", "\"/%s\"", "%"...
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 the statement. This alarm language is documented online in the Cloud Monitoring section of http://docs.rackspace.com.
[ "Creates", "an", "alarm", "that", "binds", "the", "check", "on", "the", "given", "entity", "with", "a", "notification", "plan", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L489-L518
17,926
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorCheckManager.create_check
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 else: uri = "/%s" % self.uri_base try: resp = self.api.method_post(uri, body=body)[0] except exc.BadRequest as e: msg = e.message dtls = e.details match = _invalid_key_pat.match(msg) if match: missing = match.groups()[0].replace("details.", "") if missing in details: errmsg = "".join(["The value passed for '%s' in the ", "details parameter is not valid."]) % missing else: errmsg = "".join(["The required value for the '%s' ", "setting is missing from the 'details' ", "parameter."]) % missing utils.update_exc(e, errmsg) raise e else: if msg == "Validation error": # Info is in the 'details' raise exc.InvalidMonitoringCheckDetails("Validation " "failed. Error: '%s'." % dtls) # its something other than validation error; probably # limits exceeded, but raise it instead of failing silently raise e else: if resp.status_code == 201: check_id = resp.headers["x-object-id"] return self.get(check_id) # don't fail silently here either; raise an error # if we get an unexpected response code raise exc.ClientException("Unknown response code creating check;" " expected 201, got %s" % resp.status_code)
python
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): 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 else: uri = "/%s" % self.uri_base try: resp = self.api.method_post(uri, body=body)[0] except exc.BadRequest as e: msg = e.message dtls = e.details match = _invalid_key_pat.match(msg) if match: missing = match.groups()[0].replace("details.", "") if missing in details: errmsg = "".join(["The value passed for '%s' in the ", "details parameter is not valid."]) % missing else: errmsg = "".join(["The required value for the '%s' ", "setting is missing from the 'details' ", "parameter."]) % missing utils.update_exc(e, errmsg) raise e else: if msg == "Validation error": # Info is in the 'details' raise exc.InvalidMonitoringCheckDetails("Validation " "failed. Error: '%s'." % dtls) # its something other than validation error; probably # limits exceeded, but raise it instead of failing silently raise e else: if resp.status_code == 201: check_id = resp.headers["x-object-id"] return self.get(check_id) # don't fail silently here either; raise an error # if we get an unexpected response code raise exc.ClientException("Unknown response code creating check;" " expected 201, got %s" % resp.status_code)
[ "def", "create_check", "(", "self", ",", "label", "=", "None", ",", "name", "=", "None", ",", "check_type", "=", "None", ",", "details", "=", "None", ",", "disabled", "=", "False", ",", "metadata", "=", "None", ",", "monitoring_zones_poll", "=", "None", ...
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."
[ "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", ...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L546-L626
17,927
pycontribs/pyrax
pyrax/cloudmonitoring.py
_EntityFilteringManger.list
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" % (uri, utils.get_id(entity)) resp, resp_body = self._list(uri, return_raw=True) return resp_body
python
def list(self, entity=None): uri = "/%s" % self.uri_base if entity: uri = "%s?entityId=%s" % (uri, utils.get_id(entity)) resp, resp_body = self._list(uri, return_raw=True) return resp_body
[ "def", "list", "(", "self", ",", "entity", "=", "None", ")", ":", "uri", "=", "\"/%s\"", "%", "self", ".", "uri_base", "if", "entity", ":", "uri", "=", "\"%s?entityId=%s\"", "%", "(", "uri", ",", "utils", ".", "get_id", "(", "entity", ")", ")", "re...
Returns a dictionary of data, optionally filtered for a given entity.
[ "Returns", "a", "dictionary", "of", "data", "optionally", "filtered", "for", "a", "given", "entity", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L685-L693
17,928
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorEntityManager._create_body
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} if ip_addresses: body["ip_addresses"] = ip_addresses if agent: body["agent_id"] = utils.get_id(agent) if metadata: body["metadata"] = metadata return body
python
def _create_body(self, name, label=None, agent=None, ip_addresses=None, metadata=None): label = label or name if ip_addresses is not None: body = {"label": label} if ip_addresses: body["ip_addresses"] = ip_addresses if agent: body["agent_id"] = utils.get_id(agent) if metadata: body["metadata"] = metadata return body
[ "def", "_create_body", "(", "self", ",", "name", ",", "label", "=", "None", ",", "agent", "=", "None", ",", "ip_addresses", "=", "None", ",", "metadata", "=", "None", ")", ":", "label", "=", "label", "or", "name", "if", "ip_addresses", "is", "not", "...
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.
[ "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", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L701-L717
17,929
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorEntityManager.update_entity
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: body["metadata"] = metadata if body: uri = "/%s/%s" % (self.uri_base, utils.get_id(entity)) resp, body = self.api.method_put(uri, body=body)
python
def update_entity(self, entity, agent=None, metadata=None): body = {} if agent: body["agent_id"] = utils.get_id(agent) if metadata: body["metadata"] = metadata if body: uri = "/%s/%s" % (self.uri_base, utils.get_id(entity)) resp, body = self.api.method_put(uri, body=body)
[ "def", "update_entity", "(", "self", ",", "entity", ",", "agent", "=", "None", ",", "metadata", "=", "None", ")", ":", "body", "=", "{", "}", "if", "agent", ":", "body", "[", "\"agent_id\"", "]", "=", "utils", ".", "get_id", "(", "agent", ")", "if"...
Updates the specified entity's values with the supplied parameters.
[ "Updates", "the", "specified", "entity", "s", "values", "with", "the", "supplied", "parameters", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L720-L731
17,930
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorCheck.get
def get(self): """Reloads the check with its current values.""" new = self.manager.get(self) if new: self._add_details(new._info)
python
def get(self): new = self.manager.get(self) if new: self._add_details(new._info)
[ "def", "get", "(", "self", ")", ":", "new", "=", "self", ".", "manager", ".", "get", "(", "self", ")", "if", "new", ":", "self", ".", "_add_details", "(", "new", ".", "_info", ")" ]
Reloads the check with its current values.
[ "Reloads", "the", "check", "with", "its", "current", "values", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L789-L793
17,931
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorCheck.list_metrics
def list_metrics(self, limit=None, marker=None, return_next=False): """ Returns a list of all the metrics associated with this check. """ return self._metrics_manager.list(limit=limit, marker=marker, return_next=return_next)
python
def list_metrics(self, limit=None, marker=None, return_next=False): return self._metrics_manager.list(limit=limit, marker=marker, return_next=return_next)
[ "def", "list_metrics", "(", "self", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "return_next", "=", "False", ")", ":", "return", "self", ".", "_metrics_manager", ".", "list", "(", "limit", "=", "limit", ",", "marker", "=", "marker", ","...
Returns a list of all the metrics associated with this check.
[ "Returns", "a", "list", "of", "all", "the", "metrics", "associated", "with", "this", "check", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L817-L822
17,932
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorCheck.create_alarm
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. """ return self.manager.create_alarm(self.entity, self, notification_plan, criteria=criteria, disabled=disabled, label=label, name=name, metadata=metadata)
python
def create_alarm(self, notification_plan, criteria=None, disabled=False, label=None, name=None, metadata=None): return self.manager.create_alarm(self.entity, self, notification_plan, criteria=criteria, disabled=disabled, label=label, name=name, metadata=metadata)
[ "def", "create_alarm", "(", "self", ",", "notification_plan", ",", "criteria", "=", "None", ",", "disabled", "=", "False", ",", "label", "=", "None", ",", "name", "=", "None", ",", "metadata", "=", "None", ")", ":", "return", "self", ".", "manager", "....
Creates an alarm that binds this check with a notification plan.
[ "Creates", "an", "alarm", "that", "binds", "this", "check", "with", "a", "notification", "plan", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L856-L863
17,933
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorAlarm.get
def get(self): """ Fetches the current state of the alarm from the API and updates the object. """ new_alarm = self.entity.get_alarm(self) if new_alarm: self._add_details(new_alarm._info)
python
def get(self): new_alarm = self.entity.get_alarm(self) if new_alarm: self._add_details(new_alarm._info)
[ "def", "get", "(", "self", ")", ":", "new_alarm", "=", "self", ".", "entity", ".", "get_alarm", "(", "self", ")", "if", "new_alarm", ":", "self", ".", "_add_details", "(", "new_alarm", ".", "_info", ")" ]
Fetches the current state of the alarm from the API and updates the object.
[ "Fetches", "the", "current", "state", "of", "the", "alarm", "from", "the", "API", "and", "updates", "the", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L978-L985
17,934
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorClient.list_metrics
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. """ return entity.list_metrics(check, limit=limit, marker=marker, return_next=return_next)
python
def list_metrics(self, entity, check, limit=None, marker=None, return_next=False): return entity.list_metrics(check, limit=limit, marker=marker, return_next=return_next)
[ "def", "list_metrics", "(", "self", ",", "entity", ",", "check", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "return_next", "=", "False", ")", ":", "return", "entity", ".", "list_metrics", "(", "check", ",", "limit", "=", "limit", ",", ...
Returns a list of all the metrics associated with the specified check.
[ "Returns", "a", "list", "of", "all", "the", "metrics", "associated", "with", "the", "specified", "check", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L1183-L1189
17,935
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorClient.create_notification_plan
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 when a monitoring check triggers an alarm. """ return self._notification_plan_manager.create(label=label, name=name, critical_state=critical_state, ok_state=ok_state, warning_state=warning_state)
python
def create_notification_plan(self, label=None, name=None, critical_state=None, ok_state=None, warning_state=None): return self._notification_plan_manager.create(label=label, name=name, critical_state=critical_state, ok_state=ok_state, warning_state=warning_state)
[ "def", "create_notification_plan", "(", "self", ",", "label", "=", "None", ",", "name", "=", "None", ",", "critical_state", "=", "None", ",", "ok_state", "=", "None", ",", "warning_state", "=", "None", ")", ":", "return", "self", ".", "_notification_plan_man...
Creates a notification plan to be executed when a monitoring check triggers an alarm.
[ "Creates", "a", "notification", "plan", "to", "be", "executed", "when", "a", "monitoring", "check", "triggers", "an", "alarm", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L1279-L1287
17,936
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorClient.update_alarm
def update_alarm(self, entity, alarm, criteria=None, disabled=False, label=None, name=None, metadata=None): """ Updates an existing alarm on the given entity. """ return entity.update_alarm(alarm, criteria=criteria, disabled=disabled, label=label, name=name, metadata=metadata)
python
def update_alarm(self, entity, alarm, criteria=None, disabled=False, label=None, name=None, metadata=None): return entity.update_alarm(alarm, criteria=criteria, disabled=disabled, label=label, name=name, metadata=metadata)
[ "def", "update_alarm", "(", "self", ",", "entity", ",", "alarm", ",", "criteria", "=", "None", ",", "disabled", "=", "False", ",", "label", "=", "None", ",", "name", "=", "None", ",", "metadata", "=", "None", ")", ":", "return", "entity", ".", "updat...
Updates an existing alarm on the given entity.
[ "Updates", "an", "existing", "alarm", "on", "the", "given", "entity", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L1321-L1327
17,937
pycontribs/pyrax
pyrax/cloudmonitoring.py
CloudMonitorClient.list_alarms
def list_alarms(self, entity, limit=None, marker=None, return_next=False): """ Returns a list of all the alarms created on the specified entity. """ return entity.list_alarms(limit=limit, marker=marker, return_next=return_next)
python
def list_alarms(self, entity, limit=None, marker=None, return_next=False): return entity.list_alarms(limit=limit, marker=marker, return_next=return_next)
[ "def", "list_alarms", "(", "self", ",", "entity", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "return_next", "=", "False", ")", ":", "return", "entity", ".", "list_alarms", "(", "limit", "=", "limit", ",", "marker", "=", "marker", ",", ...
Returns a list of all the alarms created on the specified entity.
[ "Returns", "a", "list", "of", "all", "the", "alarms", "created", "on", "the", "specified", "entity", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudmonitoring.py#L1331-L1336
17,938
pycontribs/pyrax
pyrax/object_storage.py
assure_container
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 the name container = self.get(container) return fnc(self, container, *args, **kwargs) return _wrapped
python
def assure_container(fnc): @wraps(fnc) def _wrapped(self, container, *args, **kwargs): if not isinstance(container, Container): # Must be the name container = self.get(container) return fnc(self, container, *args, **kwargs) return _wrapped
[ "def", "assure_container", "(", "fnc", ")", ":", "@", "wraps", "(", "fnc", ")", "def", "_wrapped", "(", "self", ",", "container", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "container", ",", "Container", ")",...
Assures that whether a Container or a name of a container is passed, a Container object is available.
[ "Assures", "that", "whether", "a", "Container", "or", "a", "name", "of", "a", "container", "is", "passed", "a", "Container", "object", "is", "available", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L68-L79
17,939
pycontribs/pyrax
pyrax/object_storage.py
_massage_metakeys
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()): if not k.lower().startswith(lowprefix): k = "%s%s" % (prfx, k) ret[k] = v return ret
python
def _massage_metakeys(dct, prfx): lowprefix = prfx.lower() ret = {} for k, v in list(dct.items()): if not k.lower().startswith(lowprefix): k = "%s%s" % (prfx, k) ret[k] = v return ret
[ "def", "_massage_metakeys", "(", "dct", ",", "prfx", ")", ":", "lowprefix", "=", "prfx", ".", "lower", "(", ")", "ret", "=", "{", "}", "for", "k", ",", "v", "in", "list", "(", "dct", ".", "items", "(", ")", ")", ":", "if", "not", "k", ".", "l...
Returns a copy of the supplied dictionary, prefixing any keys that do not begin with the specified prefix accordingly.
[ "Returns", "a", "copy", "of", "the", "supplied", "dictionary", "prefixing", "any", "keys", "that", "do", "not", "begin", "with", "the", "specified", "prefix", "accordingly", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L82-L93
17,940
pycontribs/pyrax
pyrax/object_storage.py
get_file_size
def get_file_size(fileobj): """ Returns the size of a file-like object. """ currpos = fileobj.tell() fileobj.seek(0, 2) total_size = fileobj.tell() fileobj.seek(currpos) return total_size
python
def get_file_size(fileobj): currpos = fileobj.tell() fileobj.seek(0, 2) total_size = fileobj.tell() fileobj.seek(currpos) return total_size
[ "def", "get_file_size", "(", "fileobj", ")", ":", "currpos", "=", "fileobj", ".", "tell", "(", ")", "fileobj", ".", "seek", "(", "0", ",", "2", ")", "total_size", "=", "fileobj", ".", "tell", "(", ")", "fileobj", ".", "seek", "(", "currpos", ")", "...
Returns the size of a file-like object.
[ "Returns", "the", "size", "of", "a", "file", "-", "like", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L147-L155
17,941
pycontribs/pyrax
pyrax/object_storage.py
Container._set_cdn_defaults
def _set_cdn_defaults(self): """Sets all the CDN-related attributes to default values.""" if self._cdn_enabled is FAULT: self._cdn_enabled = False self._cdn_uri = None self._cdn_ttl = DEFAULT_CDN_TTL self._cdn_ssl_uri = None self._cdn_streaming_uri = None self._cdn_ios_uri = None self._cdn_log_retention = False
python
def _set_cdn_defaults(self): if self._cdn_enabled is FAULT: self._cdn_enabled = False self._cdn_uri = None self._cdn_ttl = DEFAULT_CDN_TTL self._cdn_ssl_uri = None self._cdn_streaming_uri = None self._cdn_ios_uri = None self._cdn_log_retention = False
[ "def", "_set_cdn_defaults", "(", "self", ")", ":", "if", "self", ".", "_cdn_enabled", "is", "FAULT", ":", "self", ".", "_cdn_enabled", "=", "False", "self", ".", "_cdn_uri", "=", "None", "self", ".", "_cdn_ttl", "=", "DEFAULT_CDN_TTL", "self", ".", "_cdn_s...
Sets all the CDN-related attributes to default values.
[ "Sets", "all", "the", "CDN", "-", "related", "attributes", "to", "default", "values", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L196-L205
17,942
pycontribs/pyrax
pyrax/object_storage.py
Container._fetch_cdn_data
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 for key, value in headers.items(): low_key = key.lower() if low_key == "x-cdn-uri": self._cdn_uri = value elif low_key == "x-ttl": self._cdn_ttl = int(value) elif low_key == "x-cdn-ssl-uri": self._cdn_ssl_uri = value elif low_key == "x-cdn-streaming-uri": self._cdn_streaming_uri = value elif low_key == "x-cdn-ios-uri": self._cdn_ios_uri = value elif low_key == "x-log-retention": self._cdn_log_retention = (value == "True")
python
def _fetch_cdn_data(self): 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 for key, value in headers.items(): low_key = key.lower() if low_key == "x-cdn-uri": self._cdn_uri = value elif low_key == "x-ttl": self._cdn_ttl = int(value) elif low_key == "x-cdn-ssl-uri": self._cdn_ssl_uri = value elif low_key == "x-cdn-streaming-uri": self._cdn_streaming_uri = value elif low_key == "x-cdn-ios-uri": self._cdn_ios_uri = value elif low_key == "x-log-retention": self._cdn_log_retention = (value == "True")
[ "def", "_fetch_cdn_data", "(", "self", ")", ":", "if", "self", ".", "_cdn_enabled", "is", "FAULT", ":", "headers", "=", "self", ".", "manager", ".", "fetch_cdn_data", "(", "self", ")", "else", ":", "headers", "=", "{", "}", "# Set defaults in case not all he...
Fetches the container's CDN data from the CDN service
[ "Fetches", "the", "container", "s", "CDN", "data", "from", "the", "CDN", "service" ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L208-L234
17,943
pycontribs/pyrax
pyrax/object_storage.py
Container.get_object
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. """ if isinstance(item, six.string_types): item = self.object_manager.get(item) return item
python
def get_object(self, item): if isinstance(item, six.string_types): item = self.object_manager.get(item) return item
[ "def", "get_object", "(", "self", ",", "item", ")", ":", "if", "isinstance", "(", "item", ",", "six", ".", "string_types", ")", ":", "item", "=", "self", ".", "object_manager", ".", "get", "(", "item", ")", "return", "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.
[ "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", ...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L321-L329
17,944
pycontribs/pyrax
pyrax/object_storage.py
Container.store_object
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, 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. """ return self.create(obj_name=obj_name, data=data, content_type=content_type, etag=etag, content_encoding=content_encoding, ttl=ttl, return_none=return_none, headers=headers)
python
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): return self.create(obj_name=obj_name, data=data, content_type=content_type, etag=etag, content_encoding=content_encoding, ttl=ttl, return_none=return_none, headers=headers)
[ "def", "store_object", "(", "self", ",", "obj_name", ",", "data", ",", "content_type", "=", "None", ",", "etag", "=", "None", ",", "content_encoding", "=", "None", ",", "ttl", "=", "None", ",", "return_none", "=", "False", ",", "headers", "=", "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, 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.
[ "Creates", "a", "new", "object", "in", "this", "container", "and", "populates", "it", "with", "the", "given", "data", ".", "A", "StorageObject", "reference", "to", "the", "uploaded", "file", "will", "be", "returned", "unless", "return_none", "is", "set", "to...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L433-L448
17,945
pycontribs/pyrax
pyrax/object_storage.py
Container.upload_file
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 be stored in seconds in the `ttl` parameter. If this is specified, the object will be deleted after that number of seconds. 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. """ return self.create(file_or_path=file_or_path, obj_name=obj_name, content_type=content_type, etag=etag, content_encoding=content_encoding, headers=headers, content_length=content_length, ttl=ttl, return_none=return_none)
python
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): return self.create(file_or_path=file_or_path, obj_name=obj_name, content_type=content_type, etag=etag, content_encoding=content_encoding, headers=headers, content_length=content_length, ttl=ttl, return_none=return_none)
[ "def", "upload_file", "(", "self", ",", "file_or_path", ",", "obj_name", "=", "None", ",", "content_type", "=", "None", ",", "etag", "=", "None", ",", "return_none", "=", "False", ",", "content_encoding", "=", "None", ",", "ttl", "=", "None", ",", "conte...
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 be stored in seconds in the `ttl` parameter. If this is specified, the object will be deleted after that number of seconds. 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.
[ "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",...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L451-L478
17,946
pycontribs/pyrax
pyrax/object_storage.py
Container.delete
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, each object will be deleted first, and then the container. """ return self.manager.delete(self, del_objects=del_objects)
python
def delete(self, del_objects=False): return self.manager.delete(self, del_objects=del_objects)
[ "def", "delete", "(", "self", ",", "del_objects", "=", "False", ")", ":", "return", "self", ".", "manager", ".", "delete", "(", "self", ",", "del_objects", "=", "del_objects", ")" ]
Deletes this Container. If the container contains objects, the command will fail unless 'del_objects' is passed as True. In that case, each object will be deleted first, and then the container.
[ "Deletes", "this", "Container", ".", "If", "the", "container", "contains", "objects", "the", "command", "will", "fail", "unless", "del_objects", "is", "passed", "as", "True", ".", "In", "that", "case", "each", "object", "will", "be", "deleted", "first", "and...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L546-L552
17,947
pycontribs/pyrax
pyrax/object_storage.py
Container.delete_object_in_seconds
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 no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more. """ return self.manager.delete_object_in_seconds(self, obj, seconds)
python
def delete_object_in_seconds(self, obj, seconds, extra_info=None): return self.manager.delete_object_in_seconds(self, obj, seconds)
[ "def", "delete_object_in_seconds", "(", "self", ",", "obj", ",", "seconds", ",", "extra_info", "=", "None", ")", ":", "return", "self", ".", "manager", ".", "delete_object_in_seconds", "(", "self", ",", "obj", ",", "seconds", ")" ]
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 no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
[ "Sets", "the", "object", "in", "this", "container", "to", "be", "deleted", "after", "the", "specified", "number", "of", "seconds", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L565-L574
17,948
pycontribs/pyrax
pyrax/object_storage.py
Container.change_object_content_type
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 None. Failure during the put will result in an exception. """ return self.manager.change_object_content_type(self, obj, new_ctype, guess=guess)
python
def change_object_content_type(self, obj, new_ctype, guess=False): return self.manager.change_object_content_type(self, obj, new_ctype, guess=guess)
[ "def", "change_object_content_type", "(", "self", ",", "obj", ",", "new_ctype", ",", "guess", "=", "False", ")", ":", "return", "self", ".", "manager", ".", "change_object_content_type", "(", "self", ",", "obj", ",", "new_ctype", ",", "guess", "=", "guess", ...
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 None. Failure during the put will result in an exception.
[ "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",...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L633-L642
17,949
pycontribs/pyrax
pyrax/object_storage.py
Container.get_temp_url
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 it in directly and potentially save an API call to retrieve it. If you don't pass in the key, and don't wish to use any cached value, pass `cached=False`. """ return self.manager.get_temp_url(self, obj, seconds, method=method, key=key, cached=cached)
python
def get_temp_url(self, obj, seconds, method="GET", key=None, cached=True): return self.manager.get_temp_url(self, obj, seconds, method=method, key=key, cached=cached)
[ "def", "get_temp_url", "(", "self", ",", "obj", ",", "seconds", ",", "method", "=", "\"GET\"", ",", "key", "=", "None", ",", "cached", "=", "True", ")", ":", "return", "self", ".", "manager", ".", "get_temp_url", "(", "self", ",", "obj", ",", "second...
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 it in directly and potentially save an API call to retrieve it. If you don't pass in the key, and don't wish to use any cached value, pass `cached=False`.
[ "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", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L645-L659
17,950
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.list
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, "end_marker": end_marker}) if qs: uri = "%s?%s" % (uri, qs) resp, resp_body = self.api.method_get(uri) return [Container(self, res, loaded=False) for res in resp_body if res]
python
def list(self, limit=None, marker=None, end_marker=None, prefix=None): uri = "/%s" % self.uri_base qs = utils.dict_to_qs({"marker": marker, "limit": limit, "prefix": prefix, "end_marker": end_marker}) if qs: uri = "%s?%s" % (uri, qs) resp, resp_body = self.api.method_get(uri) return [Container(self, res, loaded=False) for res in resp_body if res]
[ "def", "list", "(", "self", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "end_marker", "=", "None", ",", "prefix", "=", "None", ")", ":", "uri", "=", "\"/%s\"", "%", "self", ".", "uri_base", "qs", "=", "utils", ".", "dict_to_qs", "("...
Swift doesn't return listings in the same format as the rest of OpenStack, so this method has to be overriden.
[ "Swift", "doesn", "t", "return", "listings", "in", "the", "same", "format", "as", "the", "rest", "of", "OpenStack", "so", "this", "method", "has", "to", "be", "overriden", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L788-L800
17,951
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.get
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 data = {"total_bytes": int(hdrs.get("x-container-bytes-used", "0")), "object_count": int(hdrs.get("x-container-object-count", "0")), "name": name} return Container(self, data, loaded=False)
python
def get(self, container): name = utils.get_name(container) uri = "/%s" % name resp, resp_body = self.api.method_head(uri) hdrs = resp.headers data = {"total_bytes": int(hdrs.get("x-container-bytes-used", "0")), "object_count": int(hdrs.get("x-container-object-count", "0")), "name": name} return Container(self, data, loaded=False)
[ "def", "get", "(", "self", ",", "container", ")", ":", "name", "=", "utils", ".", "get_name", "(", "container", ")", "uri", "=", "\"/%s\"", "%", "name", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_head", "(", "uri", ")", "hdrs", ...
Returns a Container matching the specified container name. If no such container exists, a NoSuchContainer exception is raised.
[ "Returns", "a", "Container", "matching", "the", "specified", "container", "name", ".", "If", "no", "such", "container", "exists", "a", "NoSuchContainer", "exception", "is", "raised", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L804-L816
17,952
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.create
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) num_obj = int(hresp.headers.get("x-container-object-count", "0")) num_bytes = int(hresp.headers.get("x-container-bytes-used", "0")) cont_info = {"name": name, "object_count": num_obj, "total_bytes": num_bytes} return Container(self, cont_info) elif resp.status_code == 400: raise exc.ClientException("Container creation failed: %s" % resp_body)
python
def create(self, name, metadata=None, prefix=None, *args, **kwargs): 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) num_obj = int(hresp.headers.get("x-container-object-count", "0")) num_bytes = int(hresp.headers.get("x-container-bytes-used", "0")) cont_info = {"name": name, "object_count": num_obj, "total_bytes": num_bytes} return Container(self, cont_info) elif resp.status_code == 400: raise exc.ClientException("Container creation failed: %s" % resp_body)
[ "def", "create", "(", "self", ",", "name", ",", "metadata", "=", "None", ",", "prefix", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "uri", "=", "\"/%s\"", "%", "name", "headers", "=", "{", "}", "if", "prefix", "is", "None", ...
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.
[ "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"...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L819-L843
17,953
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.fetch_cdn_data
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" % name try: resp, resp_body = self.api.cdn_request(uri, "HEAD") except exc.NotCDNEnabled: return {} return resp.headers
python
def fetch_cdn_data(self, container): name = utils.get_name(container) uri = "/%s" % name try: resp, resp_body = self.api.cdn_request(uri, "HEAD") except exc.NotCDNEnabled: return {} return resp.headers
[ "def", "fetch_cdn_data", "(", "self", ",", "container", ")", ":", "name", "=", "utils", ".", "get_name", "(", "container", ")", "uri", "=", "\"/%s\"", "%", "name", "try", ":", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "cdn_request", "(", ...
Returns a dict containing the CDN information for the specified container. If the container is not CDN-enabled, returns an empty dict.
[ "Returns", "a", "dict", "containing", "the", "CDN", "information", "for", "the", "specified", "container", ".", "If", "the", "container", "is", "not", "CDN", "-", "enabled", "returns", "an", "empty", "dict", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L868-L879
17,954
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.get_headers
def get_headers(self, container): """ Return the headers for the specified container. """ uri = "/%s" % utils.get_name(container) resp, resp_body = self.api.method_head(uri) return resp.headers
python
def get_headers(self, container): uri = "/%s" % utils.get_name(container) resp, resp_body = self.api.method_head(uri) return resp.headers
[ "def", "get_headers", "(", "self", ",", "container", ")", ":", "uri", "=", "\"/%s\"", "%", "utils", ".", "get_name", "(", "container", ")", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_head", "(", "uri", ")", "return", "resp", ".", ...
Return the headers for the specified container.
[ "Return", "the", "headers", "for", "the", "specified", "container", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L893-L899
17,955
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.get_account_metadata
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 list(headers.items()): lowkey = hkey.lower() if lowkey.startswith(low_prefix): cleaned = hkey.replace(low_prefix, "").replace("-", "_") ret[cleaned] = hval return ret
python
def get_account_metadata(self, prefix=None): headers = self.get_account_headers() if prefix is None: prefix = ACCOUNT_META_PREFIX low_prefix = prefix.lower() ret = {} for hkey, hval in list(headers.items()): lowkey = hkey.lower() if lowkey.startswith(low_prefix): cleaned = hkey.replace(low_prefix, "").replace("-", "_") ret[cleaned] = hval return ret
[ "def", "get_account_metadata", "(", "self", ",", "prefix", "=", "None", ")", ":", "headers", "=", "self", ".", "get_account_headers", "(", ")", "if", "prefix", "is", "None", ":", "prefix", "=", "ACCOUNT_META_PREFIX", "low_prefix", "=", "prefix", ".", "lower"...
Returns a dictionary containing metadata about the account.
[ "Returns", "a", "dictionary", "containing", "metadata", "about", "the", "account", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L902-L916
17,956
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.delete_account_metadata
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) for ckey in curr_meta: curr_meta[ckey] = "" new_meta = _massage_metakeys(curr_meta, prefix) uri = "/" resp, resp_body = self.api.method_post(uri, headers=new_meta) return 200 <= resp.status_code <= 299
python
def delete_account_metadata(self, prefix=None): # Add the metadata prefix, if needed. if prefix is None: prefix = ACCOUNT_META_PREFIX curr_meta = self.get_account_metadata(prefix=prefix) for ckey in curr_meta: curr_meta[ckey] = "" new_meta = _massage_metakeys(curr_meta, prefix) uri = "/" resp, resp_body = self.api.method_post(uri, headers=new_meta) return 200 <= resp.status_code <= 299
[ "def", "delete_account_metadata", "(", "self", ",", "prefix", "=", "None", ")", ":", "# Add the metadata prefix, if needed.", "if", "prefix", "is", "None", ":", "prefix", "=", "ACCOUNT_META_PREFIX", "curr_meta", "=", "self", ".", "get_account_metadata", "(", "prefix...
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.
[ "Removes", "all", "metadata", "matching", "the", "specified", "prefix", "from", "the", "account", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L948-L965
17,957
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.remove_metadata_key
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 is done. """ meta_dict = {key: ""} return self.set_metadata(container, meta_dict)
python
def remove_metadata_key(self, container, key): meta_dict = {key: ""} return self.set_metadata(container, meta_dict)
[ "def", "remove_metadata_key", "(", "self", ",", "container", ",", "key", ")", ":", "meta_dict", "=", "{", "key", ":", "\"\"", "}", "return", "self", ".", "set_metadata", "(", "container", ",", "meta_dict", ")" ]
Removes the specified key from the container's metadata. If the key does not exist in the metadata, nothing is done.
[ "Removes", "the", "specified", "key", "from", "the", "container", "s", "metadata", ".", "If", "the", "key", "does", "not", "exist", "in", "the", "metadata", "nothing", "is", "done", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1016-L1022
17,958
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.delete_metadata
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 = {} curr_meta = self.get_metadata(container, prefix=prefix) for ckey in curr_meta: new_meta[ckey] = "" uri = "/%s" % utils.get_name(container) resp, resp_body = self.api.method_post(uri, headers=new_meta) return 200 <= resp.status_code <= 299
python
def delete_metadata(self, container, prefix=None): # Add the metadata prefix, if needed. if prefix is None: prefix = CONTAINER_META_PREFIX new_meta = {} curr_meta = self.get_metadata(container, prefix=prefix) for ckey in curr_meta: new_meta[ckey] = "" uri = "/%s" % utils.get_name(container) resp, resp_body = self.api.method_post(uri, headers=new_meta) return 200 <= resp.status_code <= 299
[ "def", "delete_metadata", "(", "self", ",", "container", ",", "prefix", "=", "None", ")", ":", "# Add the metadata prefix, if needed.", "if", "prefix", "is", "None", ":", "prefix", "=", "CONTAINER_META_PREFIX", "new_meta", "=", "{", "}", "curr_meta", "=", "self"...
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.
[ "Removes", "all", "of", "the", "container", "s", "metadata", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1026-L1044
17,959
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.get_cdn_metadata
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)) resp, resp_body = self.api.cdn_request(uri, "HEAD") ret = dict(resp.headers) # Remove non-CDN headers ret.pop("content-length", None) ret.pop("content-type", None) ret.pop("date", None) return ret
python
def get_cdn_metadata(self, container): uri = "%s/%s" % (self.uri_base, utils.get_name(container)) resp, resp_body = self.api.cdn_request(uri, "HEAD") ret = dict(resp.headers) # Remove non-CDN headers ret.pop("content-length", None) ret.pop("content-type", None) ret.pop("date", None) return ret
[ "def", "get_cdn_metadata", "(", "self", ",", "container", ")", ":", "uri", "=", "\"%s/%s\"", "%", "(", "self", ".", "uri_base", ",", "utils", ".", "get_name", "(", "container", ")", ")", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "cdn_requ...
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.
[ "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",...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1048-L1062
17,960
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.list_public_containers
def list_public_containers(self): """ Returns a list of the names of all CDN-enabled containers. """ resp, resp_body = self.api.cdn_request("", "GET") return [cont["name"] for cont in resp_body]
python
def list_public_containers(self): resp, resp_body = self.api.cdn_request("", "GET") return [cont["name"] for cont in resp_body]
[ "def", "list_public_containers", "(", "self", ")", ":", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "cdn_request", "(", "\"\"", ",", "\"GET\"", ")", "return", "[", "cont", "[", "\"name\"", "]", "for", "cont", "in", "resp_body", "]" ]
Returns a list of the names of all CDN-enabled containers.
[ "Returns", "a", "list", "of", "the", "names", "of", "all", "CDN", "-", "enabled", "containers", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1157-L1162
17,961
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager._set_cdn_access
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 public and ttl: headers["X-Ttl"] = ttl self.api.cdn_request("/%s" % utils.get_name(container), method="PUT", headers=headers)
python
def _set_cdn_access(self, container, public, ttl=None): headers = {"X-Cdn-Enabled": "%s" % public} if public and ttl: headers["X-Ttl"] = ttl self.api.cdn_request("/%s" % utils.get_name(container), method="PUT", headers=headers)
[ "def", "_set_cdn_access", "(", "self", ",", "container", ",", "public", ",", "ttl", "=", "None", ")", ":", "headers", "=", "{", "\"X-Cdn-Enabled\"", ":", "\"%s\"", "%", "public", "}", "if", "public", "and", "ttl", ":", "headers", "[", "\"X-Ttl\"", "]", ...
Enables or disables CDN access for the specified container, and optionally sets the TTL for the container when enabling access.
[ "Enables", "or", "disables", "CDN", "access", "for", "the", "specified", "container", "and", "optionally", "sets", "the", "TTL", "for", "the", "container", "when", "enabling", "access", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1182-L1191
17,962
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.get_cdn_log_retention
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" % utils.get_name(container), method="HEAD") return resp.headers.get("x-log-retention").lower() == "true"
python
def get_cdn_log_retention(self, container): resp, resp_body = self.api.cdn_request("/%s" % utils.get_name(container), method="HEAD") return resp.headers.get("x-log-retention").lower() == "true"
[ "def", "get_cdn_log_retention", "(", "self", ",", "container", ")", ":", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "cdn_request", "(", "\"/%s\"", "%", "utils", ".", "get_name", "(", "container", ")", ",", "method", "=", "\"HEAD\"", ")", "re...
Returns the status of the setting for CDN log retention for the specified container.
[ "Returns", "the", "status", "of", "the", "setting", "for", "CDN", "log", "retention", "for", "the", "specified", "container", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1195-L1202
17,963
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.set_cdn_log_retention
def set_cdn_log_retention(self, container, enabled): """ Enables or disables whether CDN access logs for the specified container are collected and stored on Cloud Files. """ headers = {"X-Log-Retention": "%s" % enabled} self.api.cdn_request("/%s" % utils.get_name(container), method="PUT", headers=headers)
python
def set_cdn_log_retention(self, container, enabled): headers = {"X-Log-Retention": "%s" % enabled} self.api.cdn_request("/%s" % utils.get_name(container), method="PUT", headers=headers)
[ "def", "set_cdn_log_retention", "(", "self", ",", "container", ",", "enabled", ")", ":", "headers", "=", "{", "\"X-Log-Retention\"", ":", "\"%s\"", "%", "enabled", "}", "self", ".", "api", ".", "cdn_request", "(", "\"/%s\"", "%", "utils", ".", "get_name", ...
Enables or disables whether CDN access logs for the specified container are collected and stored on Cloud Files.
[ "Enables", "or", "disables", "whether", "CDN", "access", "logs", "for", "the", "specified", "container", "are", "collected", "and", "stored", "on", "Cloud", "Files", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1206-L1213
17,964
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.get_container_streaming_uri
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" % utils.get_name(container), method="HEAD") return resp.headers.get("x-cdn-streaming-uri")
python
def get_container_streaming_uri(self, container): resp, resp_body = self.api.cdn_request("/%s" % utils.get_name(container), method="HEAD") return resp.headers.get("x-cdn-streaming-uri")
[ "def", "get_container_streaming_uri", "(", "self", ",", "container", ")", ":", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "cdn_request", "(", "\"/%s\"", "%", "utils", ".", "get_name", "(", "container", ")", ",", "method", "=", "\"HEAD\"", ")",...
Returns the URI for streaming content, or None if CDN is not enabled.
[ "Returns", "the", "URI", "for", "streaming", "content", "or", "None", "if", "CDN", "is", "not", "enabled", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1217-L1223
17,965
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.set_web_index_page
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. """ headers = {"X-Container-Meta-Web-Index": "%s" % page} self.api.cdn_request("/%s" % utils.get_name(container), method="POST", headers=headers)
python
def set_web_index_page(self, container, page): headers = {"X-Container-Meta-Web-Index": "%s" % page} self.api.cdn_request("/%s" % utils.get_name(container), method="POST", headers=headers)
[ "def", "set_web_index_page", "(", "self", ",", "container", ",", "page", ")", ":", "headers", "=", "{", "\"X-Container-Meta-Web-Index\"", ":", "\"%s\"", "%", "page", "}", "self", ".", "api", ".", "cdn_request", "(", "\"/%s\"", "%", "utils", ".", "get_name", ...
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.
[ "Sets", "the", "header", "indicating", "the", "index", "page", "in", "a", "container", "when", "creating", "a", "static", "website", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1237-L1247
17,966
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.list_objects
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 returned; if you need to access more than that, set the 'full_listing' parameter to True. """ if full_listing: return container.list_all(prefix=prefix) return container.list(limit=limit, marker=marker, prefix=prefix, delimiter=delimiter, end_marker=end_marker)
python
def list_objects(self, container, limit=None, marker=None, prefix=None, delimiter=None, end_marker=None, full_listing=False): if full_listing: return container.list_all(prefix=prefix) return container.list(limit=limit, marker=marker, prefix=prefix, delimiter=delimiter, end_marker=end_marker)
[ "def", "list_objects", "(", "self", ",", "container", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "prefix", "=", "None", ",", "delimiter", "=", "None", ",", "end_marker", "=", "None", ",", "full_listing", "=", "False", ")", ":", "if", ...
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 returned; if you need to access more than that, set the 'full_listing' parameter to True.
[ "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", "delimit...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1278-L1291
17,967
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.list_object_names
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 returned; if you need to access more than that, set the 'full_listing' parameter to True. """ return container.list_object_names(marker=marker, limit=limit, prefix=prefix, delimiter=delimiter, end_marker=end_marker, full_listing=full_listing)
python
def list_object_names(self, container, marker=None, limit=None, prefix=None, delimiter=None, end_marker=None, full_listing=False): return container.list_object_names(marker=marker, limit=limit, prefix=prefix, delimiter=delimiter, end_marker=end_marker, full_listing=full_listing)
[ "def", "list_object_names", "(", "self", ",", "container", ",", "marker", "=", "None", ",", "limit", "=", "None", ",", "prefix", "=", "None", ",", "delimiter", "=", "None", ",", "end_marker", "=", "None", ",", "full_listing", "=", "False", ")", ":", "r...
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 returned; if you need to access more than that, set the 'full_listing' parameter to True.
[ "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", "p...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1295-L1306
17,968
pycontribs/pyrax
pyrax/object_storage.py
ContainerManager.change_object_content_type
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: # Test against the CDN url to guess the content-type. obj_url = "%s/%s" % (container.cdn_uri, oname) new_ctype = mimetypes.guess_type(obj_url)[0] return self.copy_object(container, obj, container, content_type=new_ctype)
python
def change_object_content_type(self, container, obj, new_ctype, guess=False): cname = utils.get_name(container) oname = utils.get_name(obj) if guess and container.cdn_enabled: # Test against the CDN url to guess the content-type. obj_url = "%s/%s" % (container.cdn_uri, oname) new_ctype = mimetypes.guess_type(obj_url)[0] return self.copy_object(container, obj, container, content_type=new_ctype)
[ "def", "change_object_content_type", "(", "self", ",", "container", ",", "obj", ",", "new_ctype", ",", "guess", "=", "False", ")", ":", "cname", "=", "utils", ".", "get_name", "(", "container", ")", "oname", "=", "utils", ".", "get_name", "(", "obj", ")"...
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.
[ "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", ...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1496-L1512
17,969
pycontribs/pyrax
pyrax/object_storage.py
StorageObject.copy
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. """ return self.container.copy_object(self, new_container, new_obj_name=new_obj_name)
python
def copy(self, new_container, new_obj_name=None, extra_info=None): return self.container.copy_object(self, new_container, new_obj_name=new_obj_name)
[ "def", "copy", "(", "self", ",", "new_container", ",", "new_obj_name", "=", "None", ",", "extra_info", "=", "None", ")", ":", "return", "self", ".", "container", ".", "copy_object", "(", "self", ",", "new_container", ",", "new_obj_name", "=", "new_obj_name",...
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.
[ "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", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1639-L1646
17,970
pycontribs/pyrax
pyrax/object_storage.py
StorageObject.move
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 successful copy. This means that this storage_object reference will no longer be valid. """ return self.container.move_object(self, new_container, new_obj_name=new_obj_name)
python
def move(self, new_container, new_obj_name=None, extra_info=None): return self.container.move_object(self, new_container, new_obj_name=new_obj_name)
[ "def", "move", "(", "self", ",", "new_container", ",", "new_obj_name", "=", "None", ",", "extra_info", "=", "None", ")", ":", "return", "self", ".", "container", ".", "move_object", "(", "self", ",", "new_container", ",", "new_obj_name", "=", "new_obj_name",...
Works just like copy_object, except that this object is deleted after a successful copy. This means that this storage_object reference will no longer be valid.
[ "Works", "just", "like", "copy_object", "except", "that", "this", "object", "is", "deleted", "after", "a", "successful", "copy", ".", "This", "means", "that", "this", "storage_object", "reference", "will", "no", "longer", "be", "valid", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1649-L1656
17,971
pycontribs/pyrax
pyrax/object_storage.py
StorageObject.get_temp_url
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. The only methods supported are GET and PUT. Anything else will raise an InvalidTemporaryURLMethod exception. """ return self.container.get_temp_url(self, seconds=seconds, method=method)
python
def get_temp_url(self, seconds, method="GET"): return self.container.get_temp_url(self, seconds=seconds, method=method)
[ "def", "get_temp_url", "(", "self", ",", "seconds", ",", "method", "=", "\"GET\"", ")", ":", "return", "self", ".", "container", ".", "get_temp_url", "(", "self", ",", "seconds", "=", "seconds", ",", "method", "=", "method", ")" ]
Returns a URL that can be used to access this object. The URL will expire after `seconds` seconds. The only methods supported are GET and PUT. Anything else will raise an InvalidTemporaryURLMethod exception.
[ "Returns", "a", "URL", "that", "can", "be", "used", "to", "access", "this", "object", ".", "The", "URL", "will", "expire", "after", "seconds", "seconds", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1715-L1724
17,972
pycontribs/pyrax
pyrax/object_storage.py
StorageObjectManager.get
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, "bytes": content_length, "content_type": hdrs.get("content-type"), "hash": hdrs.get("etag"), "last_modified": hdrs.get("last-modified"), "timestamp": hdrs.get("x-timestamp"), } return StorageObject(self, data, loaded=True)
python
def get(self, obj): 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, "bytes": content_length, "content_type": hdrs.get("content-type"), "hash": hdrs.get("etag"), "last_modified": hdrs.get("last-modified"), "timestamp": hdrs.get("x-timestamp"), } return StorageObject(self, data, loaded=True)
[ "def", "get", "(", "self", ",", "obj", ")", ":", "name", "=", "utils", ".", "get_name", "(", "obj", ")", "uri", "=", "\"/%s/%s\"", "%", "(", "self", ".", "uri_base", ",", "name", ")", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "metho...
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.
[ "Gets", "the", "information", "about", "the", "specified", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1783-L1805
17,973
pycontribs/pyrax
pyrax/object_storage.py
StorageObjectManager._upload
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) seg_name = "%s.%s" % (obj_name, sequence) with utils.SelfDeletingTempfile() as tmpname: with open(tmpname, "wb") as tmp: tmp.write(content.read(MAX_FILE_SIZE)) with open(tmpname, "rb") as tmp: # We have to calculate the etag for each segment etag = utils.get_checksum(tmp) self._store_object(seg_name, content=tmp, etag=etag, chunked=False, headers=headers) # Upload the manifest headers.pop("ETag", "") headers["X-Object-Manifest"] = "%s/%s." % (self.name, obj_name) self._store_object(obj_name, content=None, headers=headers)
python
def _upload(self, obj_name, content, content_type, content_encoding, content_length, etag, chunked, chunk_size, headers): 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) seg_name = "%s.%s" % (obj_name, sequence) with utils.SelfDeletingTempfile() as tmpname: with open(tmpname, "wb") as tmp: tmp.write(content.read(MAX_FILE_SIZE)) with open(tmpname, "rb") as tmp: # We have to calculate the etag for each segment etag = utils.get_checksum(tmp) self._store_object(seg_name, content=tmp, etag=etag, chunked=False, headers=headers) # Upload the manifest headers.pop("ETag", "") headers["X-Object-Manifest"] = "%s/%s." % (self.name, obj_name) self._store_object(obj_name, content=None, headers=headers)
[ "def", "_upload", "(", "self", ",", "obj_name", ",", "content", ",", "content_type", ",", "content_encoding", ",", "content_length", ",", "etag", ",", "chunked", ",", "chunk_size", ",", "headers", ")", ":", "if", "content_type", "is", "not", "None", ":", "...
Handles the uploading of content, including working around the 5GB maximum file size.
[ "Handles", "the", "uploading", "of", "content", "including", "working", "around", "the", "5GB", "maximum", "file", "size", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1881-L1924
17,974
pycontribs/pyrax
pyrax/object_storage.py
StorageObjectManager._store_object
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: headers["ETag"] = etag if not headers.get("Content-Type"): headers["Content-Type"] = None uri = "/%s/%s" % (self.uri_base, obj_name) resp, resp_body = self.api.method_put(uri, data=content, headers=headers)
python
def _store_object(self, obj_name, content, etag=None, chunked=False, chunk_size=None, headers=None): 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: headers["ETag"] = etag if not headers.get("Content-Type"): headers["Content-Type"] = None uri = "/%s/%s" % (self.uri_base, obj_name) resp, resp_body = self.api.method_put(uri, data=content, headers=headers)
[ "def", "_store_object", "(", "self", ",", "obj_name", ",", "content", ",", "etag", "=", "None", ",", "chunked", "=", "False", ",", "chunk_size", "=", "None", ",", "headers", "=", "None", ")", ":", "head_etag", "=", "headers", ".", "pop", "(", "\"ETag\"...
Handles the low-level creation of a storage object and the uploading of the contents of that object.
[ "Handles", "the", "low", "-", "level", "creation", "of", "a", "storage", "object", "and", "the", "uploading", "of", "the", "contents", "of", "that", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1927-L1945
17,975
pycontribs/pyrax
pyrax/object_storage.py
StorageObjectManager._fetch_chunker
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) pos = endpos + 1 if not resp_body: # End of file return yield resp_body total_bytes += len(resp_body) if total_bytes >= max_size: return
python
def _fetch_chunker(self, uri, chunk_size, size, obj_size): 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) pos = endpos + 1 if not resp_body: # End of file return yield resp_body total_bytes += len(resp_body) if total_bytes >= max_size: return
[ "def", "_fetch_chunker", "(", "self", ",", "uri", ",", "chunk_size", ",", "size", ",", "obj_size", ")", ":", "pos", "=", "0", "total_bytes", "=", "0", "size", "=", "size", "or", "obj_size", "max_size", "=", "min", "(", "size", ",", "obj_size", ")", "...
Returns a generator that returns an object in chunks.
[ "Returns", "a", "generator", "that", "returns", "an", "object", "in", "chunks", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L1991-L2011
17,976
pycontribs/pyrax
pyrax/object_storage.py
StorageObjectManager.remove_metadata_key
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 is done. """ meta_dict = {key: ""} return self.set_metadata(obj, meta_dict)
python
def remove_metadata_key(self, obj, key): meta_dict = {key: ""} return self.set_metadata(obj, meta_dict)
[ "def", "remove_metadata_key", "(", "self", ",", "obj", ",", "key", ")", ":", "meta_dict", "=", "{", "key", ":", "\"\"", "}", "return", "self", ".", "set_metadata", "(", "obj", ",", "meta_dict", ")" ]
Removes the specified key from the object's metadata. If the key does not exist in the metadata, nothing is done.
[ "Removes", "the", "specified", "key", "from", "the", "object", "s", "metadata", ".", "If", "the", "key", "does", "not", "exist", "in", "the", "metadata", "nothing", "is", "done", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2169-L2175
17,977
pycontribs/pyrax
pyrax/object_storage.py
StorageClient._configure_cdn
def _configure_cdn(self): """ Initialize CDN-related endpoints, if available. """ ident = self.identity cdn_svc = ident.services.get("object_cdn") if cdn_svc: ep = cdn_svc.endpoints.get(self.region_name) if ep: self.cdn_management_url = ep.public_url
python
def _configure_cdn(self): ident = self.identity cdn_svc = ident.services.get("object_cdn") if cdn_svc: ep = cdn_svc.endpoints.get(self.region_name) if ep: self.cdn_management_url = ep.public_url
[ "def", "_configure_cdn", "(", "self", ")", ":", "ident", "=", "self", ".", "identity", "cdn_svc", "=", "ident", ".", "services", ".", "get", "(", "\"object_cdn\"", ")", "if", "cdn_svc", ":", "ep", "=", "cdn_svc", ".", "endpoints", ".", "get", "(", "sel...
Initialize CDN-related endpoints, if available.
[ "Initialize", "CDN", "-", "related", "endpoints", "if", "available", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2219-L2228
17,978
pycontribs/pyrax
pyrax/object_storage.py
StorageClient._backwards_aliases
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 self.delete_container = self.delete self.get_container_objects = self.list_container_objects self.get_container_object_names = self.list_container_object_names self.get_info = self.get_account_info
python
def _backwards_aliases(self): self.list_containers = self.list_container_names self.get_all_containers = self.list self.get_container = self.get self.create_container = self.create self.delete_container = self.delete self.get_container_objects = self.list_container_objects self.get_container_object_names = self.list_container_object_names self.get_info = self.get_account_info
[ "def", "_backwards_aliases", "(", "self", ")", ":", "self", ".", "list_containers", "=", "self", ".", "list_container_names", "self", ".", "get_all_containers", "=", "self", ".", "list", "self", ".", "get_container", "=", "self", ".", "get", "self", ".", "cr...
In order to keep this backwards-compatible with previous versions, alias the old names to the new methods.
[ "In", "order", "to", "keep", "this", "backwards", "-", "compatible", "with", "previous", "versions", "alias", "the", "old", "names", "to", "the", "new", "methods", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2231-L2243
17,979
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.get
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. """ if isinstance(item, six.string_types): item = super(StorageClient, self).get(item) return item
python
def get(self, item): if isinstance(item, six.string_types): item = super(StorageClient, self).get(item) return item
[ "def", "get", "(", "self", ",", "item", ")", ":", "if", "isinstance", "(", "item", ",", "six", ".", "string_types", ")", ":", "item", "=", "super", "(", "StorageClient", ",", "self", ")", ".", "get", "(", "item", ")", "return", "item" ]
Returns the container whose name is provided as 'item'. If 'item' is not a string, the original item is returned unchanged.
[ "Returns", "the", "container", "whose", "name", "is", "provided", "as", "item", ".", "If", "item", "is", "not", "a", "string", "the", "original", "item", "is", "returned", "unchanged", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2246-L2253
17,980
pycontribs/pyrax
pyrax/object_storage.py
StorageClient._configure_manager
def _configure_manager(self): """ Creates a manager to handle interacting with Containers. """ self._manager = ContainerManager(self, resource_class=Container, response_key="", uri_base="")
python
def _configure_manager(self): self._manager = ContainerManager(self, resource_class=Container, response_key="", uri_base="")
[ "def", "_configure_manager", "(", "self", ")", ":", "self", ".", "_manager", "=", "ContainerManager", "(", "self", ",", "resource_class", "=", "Container", ",", "response_key", "=", "\"\"", ",", "uri_base", "=", "\"\"", ")" ]
Creates a manager to handle interacting with Containers.
[ "Creates", "a", "manager", "to", "handle", "interacting", "with", "Containers", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2256-L2261
17,981
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.get_account_details
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()): lowkey = hkey.lower() if lowkey.startswith(acct_prefix): if not lowkey.startswith(meta_prefix): cleaned = hkey.replace(acct_prefix, "").replace("-", "_") try: # Most values are ints ret[cleaned] = int(hval) except ValueError: ret[cleaned] = hval return ret
python
def get_account_details(self): headers = self._manager.get_account_headers() acct_prefix = "x-account-" meta_prefix = ACCOUNT_META_PREFIX.lower() ret = {} for hkey, hval in list(headers.items()): lowkey = hkey.lower() if lowkey.startswith(acct_prefix): if not lowkey.startswith(meta_prefix): cleaned = hkey.replace(acct_prefix, "").replace("-", "_") try: # Most values are ints ret[cleaned] = int(hval) except ValueError: ret[cleaned] = hval return ret
[ "def", "get_account_details", "(", "self", ")", ":", "headers", "=", "self", ".", "_manager", ".", "get_account_headers", "(", ")", "acct_prefix", "=", "\"x-account-\"", "meta_prefix", "=", "ACCOUNT_META_PREFIX", ".", "lower", "(", ")", "ret", "=", "{", "}", ...
Returns a dictionary containing information about the account.
[ "Returns", "a", "dictionary", "containing", "information", "about", "the", "account", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2271-L2289
17,982
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.get_account_info
def get_account_info(self): """ Returns a tuple for the number of containers and total bytes in the account. """ headers = self._manager.get_account_headers() return (headers.get("x-account-container-count"), headers.get("x-account-bytes-used"))
python
def get_account_info(self): headers = self._manager.get_account_headers() return (headers.get("x-account-container-count"), headers.get("x-account-bytes-used"))
[ "def", "get_account_info", "(", "self", ")", ":", "headers", "=", "self", ".", "_manager", ".", "get_account_headers", "(", ")", "return", "(", "headers", ".", "get", "(", "\"x-account-container-count\"", ")", ",", "headers", ".", "get", "(", "\"x-account-byte...
Returns a tuple for the number of containers and total bytes in the account.
[ "Returns", "a", "tuple", "for", "the", "number", "of", "containers", "and", "total", "bytes", "in", "the", "account", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2292-L2299
17,983
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.get_temp_url_key
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 if not cached or not meta: key = "temp_url_key" meta = self.get_account_metadata().get(key) self._cached_temp_url_key = meta return meta
python
def get_temp_url_key(self, cached=True): meta = self._cached_temp_url_key if not cached or not meta: key = "temp_url_key" meta = self.get_account_metadata().get(key) self._cached_temp_url_key = meta return meta
[ "def", "get_temp_url_key", "(", "self", ",", "cached", "=", "True", ")", ":", "meta", "=", "self", ".", "_cached_temp_url_key", "if", "not", "cached", "or", "not", "meta", ":", "key", "=", "\"temp_url_key\"", "meta", "=", "self", ".", "get_account_metadata",...
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`.
[ "Returns", "the", "current", "TempURL", "key", "or", "None", "if", "it", "has", "not", "been", "set", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2342-L2354
17,984
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.set_temp_url_key
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(). """ if key is None: key = uuid.uuid4().hex meta = {"Temp-Url-Key": key} self.set_account_metadata(meta) self._cached_temp_url_key = key
python
def set_temp_url_key(self, key=None): if key is None: key = uuid.uuid4().hex meta = {"Temp-Url-Key": key} self.set_account_metadata(meta) self._cached_temp_url_key = key
[ "def", "set_temp_url_key", "(", "self", ",", "key", "=", "None", ")", ":", "if", "key", "is", "None", ":", "key", "=", "uuid", ".", "uuid4", "(", ")", ".", "hex", "meta", "=", "{", "\"Temp-Url-Key\"", ":", "key", "}", "self", ".", "set_account_metada...
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().
[ "Sets", "the", "key", "for", "the", "Temporary", "URL", "for", "the", "account", ".", "It", "should", "be", "a", "key", "that", "is", "secret", "to", "the", "owner", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2357-L2369
17,985
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.list
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. """ return self._manager.list(limit=limit, marker=marker, end_marker=end_marker, prefix=prefix)
python
def list(self, limit=None, marker=None, end_marker=None, prefix=None): return self._manager.list(limit=limit, marker=marker, end_marker=end_marker, prefix=prefix)
[ "def", "list", "(", "self", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "end_marker", "=", "None", ",", "prefix", "=", "None", ")", ":", "return", "self", ".", "_manager", ".", "list", "(", "limit", "=", "limit", ",", "marker", "=",...
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.
[ "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", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2389-L2396
17,986
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.list_container_object_names
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 self._manager.list_object_names(container, marker=marker, limit=limit, prefix=prefix, delimiter=delimiter, full_listing=full_listing)
python
def list_container_object_names(self, container, limit=None, marker=None, prefix=None, delimiter=None, full_listing=False): return self._manager.list_object_names(container, marker=marker, limit=limit, prefix=prefix, delimiter=delimiter, full_listing=full_listing)
[ "def", "list_container_object_names", "(", "self", ",", "container", ",", "limit", "=", "None", ",", "marker", "=", "None", ",", "prefix", "=", "None", ",", "delimiter", "=", "None", ",", "full_listing", "=", "False", ")", ":", "return", "self", ".", "_m...
Returns the names of all the objects in the specified container, optionally limited by the pagination parameters.
[ "Returns", "the", "names", "of", "all", "the", "objects", "in", "the", "specified", "container", "optionally", "limited", "by", "the", "pagination", "parameters", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2519-L2527
17,987
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.delete_container_metadata
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 prefix ('X-Container-Meta-') is removed. If you wish to remove all metadata beginning with a different prefix, you must specify that prefix. """ return self._manager.delete_metadata(container, prefix=prefix)
python
def delete_container_metadata(self, container, prefix=None): return self._manager.delete_metadata(container, prefix=prefix)
[ "def", "delete_container_metadata", "(", "self", ",", "container", ",", "prefix", "=", "None", ")", ":", "return", "self", ".", "_manager", ".", "delete_metadata", "(", "container", ",", "prefix", "=", "prefix", ")" ]
Removes all of thethe 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.
[ "Removes", "all", "of", "thethe", "container", "s", "metadata", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2564-L2573
17,988
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.list_container_objects
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 ignored. """ if full_listing: return self._manager.object_listing_iterator(container, prefix=prefix) return self._manager.list_objects(container, limit=limit, marker=marker, prefix=prefix, delimiter=delimiter, end_marker=end_marker)
python
def list_container_objects(self, container, limit=None, marker=None, prefix=None, delimiter=None, end_marker=None, full_listing=False): if full_listing: return self._manager.object_listing_iterator(container, prefix=prefix) return self._manager.list_objects(container, limit=limit, marker=marker, prefix=prefix, delimiter=delimiter, end_marker=end_marker)
[ "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 ignored.
[ "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", "delimite...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2631-L2648
17,989
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.store_object
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. """ return self.create_object(container, obj_name=obj_name, data=data, content_type=content_type, etag=etag, content_encoding=content_encoding, ttl=ttl, return_none=return_none, chunk_size=chunk_size, headers=headers, metadata=metadata)
python
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): return self.create_object(container, obj_name=obj_name, data=data, content_type=content_type, etag=etag, content_encoding=content_encoding, ttl=ttl, return_none=return_none, chunk_size=chunk_size, headers=headers, metadata=metadata)
[ "def", "store_object", "(", "self", ",", "container", ",", "obj_name", ",", "data", ",", "content_type", "=", "None", ",", "etag", "=", "None", ",", "content_encoding", "=", "None", ",", "ttl", "=", "None", ",", "return_none", "=", "False", ",", "chunk_s...
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.
[ "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", ...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2674-L2690
17,990
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.upload_file
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 should be stored in seconds in the `ttl` parameter. If this is specified, the object will be deleted after that number of seconds. 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. """ return self.create_object(container, file_or_path=file_or_path, obj_name=obj_name, content_type=content_type, etag=etag, content_encoding=content_encoding, ttl=ttl, headers=headers, metadata=metadata, return_none=return_none)
python
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): return self.create_object(container, file_or_path=file_or_path, obj_name=obj_name, content_type=content_type, etag=etag, content_encoding=content_encoding, ttl=ttl, headers=headers, metadata=metadata, return_none=return_none)
[ "def", "upload_file", "(", "self", ",", "container", ",", "file_or_path", ",", "obj_name", "=", "None", ",", "content_type", "=", "None", ",", "etag", "=", "None", ",", "content_encoding", "=", "None", ",", "ttl", "=", "None", ",", "content_length", "=", ...
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 should be stored in seconds in the `ttl` parameter. If this is specified, the object will be deleted after that number of seconds. 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.
[ "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", ...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2693-L2720
17,991
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.fetch_partial
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 entire object is returned. """ return self._manager.fetch_partial(container, obj, size)
python
def fetch_partial(self, container, obj, size): return self._manager.fetch_partial(container, obj, size)
[ "def", "fetch_partial", "(", "self", ",", "container", ",", "obj", ",", "size", ")", ":", "return", "self", ".", "_manager", ".", "fetch_partial", "(", "container", ",", "obj", ",", "size", ")" ]
Returns the first 'size' bytes of an object. If the object is smaller than the specified 'size' value, the entire object is returned.
[ "Returns", "the", "first", "size", "bytes", "of", "an", "object", ".", "If", "the", "object", "is", "smaller", "than", "the", "specified", "size", "value", "the", "entire", "object", "is", "returned", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2791-L2796
17,992
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.upload_folder
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 get_uploaded(uuid) will match the total_bytes for the upload. If you start an upload and need to cancel it, call cancel_folder_upload(uuid), passing the uuid returned by the initial call. It will then be up to you to either keep or delete the partially-uploaded content. If you specify a `ttl` parameter, the uploaded files will be deleted after that number of seconds. """ if not os.path.isdir(folder_path): raise exc.FolderNotFound("No such folder: '%s'" % folder_path) ignore = utils.coerce_to_list(ignore) total_bytes = utils.folder_size(folder_path, ignore) upload_key = str(uuid.uuid4()) self.folder_upload_status[upload_key] = {"continue": True, "total_bytes": total_bytes, "uploaded": 0, } self._upload_folder_in_background(folder_path, container, ignore, upload_key, ttl) return (upload_key, total_bytes)
python
def upload_folder(self, folder_path, container=None, ignore=None, ttl=None): if not os.path.isdir(folder_path): raise exc.FolderNotFound("No such folder: '%s'" % folder_path) ignore = utils.coerce_to_list(ignore) total_bytes = utils.folder_size(folder_path, ignore) upload_key = str(uuid.uuid4()) self.folder_upload_status[upload_key] = {"continue": True, "total_bytes": total_bytes, "uploaded": 0, } self._upload_folder_in_background(folder_path, container, ignore, upload_key, ttl) return (upload_key, total_bytes)
[ "def", "upload_folder", "(", "self", ",", "folder_path", ",", "container", "=", "None", ",", "ignore", "=", "None", ",", "ttl", "=", "None", ")", ":", "if", "not", "os", ".", "path", ".", "isdir", "(", "folder_path", ")", ":", "raise", "exc", ".", ...
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 get_uploaded(uuid) will match the total_bytes for the upload. If you start an upload and need to cancel it, call cancel_folder_upload(uuid), passing the uuid returned by the initial call. It will then be up to you to either keep or delete the partially-uploaded content. If you specify a `ttl` parameter, the uploaded files will be deleted after that number of seconds.
[ "Convenience", "method", "for", "uploading", "an", "entire", "folder", "including", "any", "sub", "-", "folders", "to", "Cloud", "Files", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2937-L2987
17,993
pycontribs/pyrax
pyrax/object_storage.py
StorageClient._upload_folder_in_background
def _upload_folder_in_background(self, folder_path, container, ignore, upload_key, ttl=None): """Runs the folder upload in the background.""" uploader = FolderUploader(folder_path, container, ignore, upload_key, self, ttl=ttl) uploader.start()
python
def _upload_folder_in_background(self, folder_path, container, ignore, upload_key, ttl=None): uploader = FolderUploader(folder_path, container, ignore, upload_key, self, ttl=ttl) uploader.start()
[ "def", "_upload_folder_in_background", "(", "self", ",", "folder_path", ",", "container", ",", "ignore", ",", "upload_key", ",", "ttl", "=", "None", ")", ":", "uploader", "=", "FolderUploader", "(", "folder_path", ",", "container", ",", "ignore", ",", "upload_...
Runs the folder upload in the background.
[ "Runs", "the", "folder", "upload", "in", "the", "background", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L2990-L2995
17,994
pycontribs/pyrax
pyrax/object_storage.py
StorageClient._sync_folder_to_container
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 = self._remote_files[fullname_with_prefix] obj_etag = obj.etag except KeyError: obj = None obj_etag = None if local_etag != obj_etag: if not ignore_timestamps: if obj: obj_time_str = obj.last_modified[:19] else: obj_time_str = EARLY_DATE_STR local_mod = datetime.datetime.utcfromtimestamp( os.stat(pth).st_mtime) local_mod_str = local_mod.isoformat() if obj_time_str >= local_mod_str: # Remote object is newer self._sync_summary["older"] += 1 if verbose: log.info("%s NOT UPLOADED because remote object is " "newer", fullname_with_prefix) log.info(" Local: %s Remote: %s" % ( local_mod_str, obj_time_str)) continue try: container.upload_file(pth, obj_name=fullname_with_prefix, etag=local_etag, return_none=True) self._sync_summary["uploaded"] += 1 if verbose: log.info("%s UPLOADED", fullname_with_prefix) except Exception as e: # Record the failure, and move on self._sync_summary["failed"] += 1 self._sync_summary["failure_reasons"].append("%s" % e) if verbose: log.error("%s UPLOAD FAILED. Exception: %s" % (fullname_with_prefix, e)) else: self._sync_summary["duplicate"] += 1 if verbose: log.info("%s NOT UPLOADED because it already exists", fullname_with_prefix) if delete and not prefix: self._delete_objects_not_in_list(container, object_prefix)
python
def _sync_folder_to_container(self, folder_path, container, prefix, delete, include_hidden, ignore, ignore_timestamps, object_prefix, verbose): 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 = self._remote_files[fullname_with_prefix] obj_etag = obj.etag except KeyError: obj = None obj_etag = None if local_etag != obj_etag: if not ignore_timestamps: if obj: obj_time_str = obj.last_modified[:19] else: obj_time_str = EARLY_DATE_STR local_mod = datetime.datetime.utcfromtimestamp( os.stat(pth).st_mtime) local_mod_str = local_mod.isoformat() if obj_time_str >= local_mod_str: # Remote object is newer self._sync_summary["older"] += 1 if verbose: log.info("%s NOT UPLOADED because remote object is " "newer", fullname_with_prefix) log.info(" Local: %s Remote: %s" % ( local_mod_str, obj_time_str)) continue try: container.upload_file(pth, obj_name=fullname_with_prefix, etag=local_etag, return_none=True) self._sync_summary["uploaded"] += 1 if verbose: log.info("%s UPLOADED", fullname_with_prefix) except Exception as e: # Record the failure, and move on self._sync_summary["failed"] += 1 self._sync_summary["failure_reasons"].append("%s" % e) if verbose: log.error("%s UPLOAD FAILED. Exception: %s" % (fullname_with_prefix, e)) else: self._sync_summary["duplicate"] += 1 if verbose: log.info("%s NOT UPLOADED because it already exists", fullname_with_prefix) if delete and not prefix: self._delete_objects_not_in_list(container, object_prefix)
[ "def", "_sync_folder_to_container", "(", "self", ",", "folder_path", ",", "container", ",", "prefix", ",", "delete", ",", "include_hidden", ",", "ignore", ",", "ignore_timestamps", ",", "object_prefix", ",", "verbose", ")", ":", "fnames", "=", "os", ".", "list...
This is the internal method that is called recursively to handle nested folder structures.
[ "This", "is", "the", "internal", "method", "that", "is", "called", "recursively", "to", "handle", "nested", "folder", "structures", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L3074-L3149
17,995
pycontribs/pyrax
pyrax/object_storage.py
StorageClient._delete_objects_not_in_list
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) to_delete = list(objnames.difference(localnames)) self._sync_summary["deleted"] += len(to_delete) # We don't need to wait around for this to complete. Store the thread # reference in case it is needed at some point. self._thread = self.bulk_delete(cont, to_delete, async_=True)
python
def _delete_objects_not_in_list(self, cont, object_prefix=""): objnames = set(cont.get_object_names(prefix=object_prefix, full_listing=True)) localnames = set(self._local_files) to_delete = list(objnames.difference(localnames)) self._sync_summary["deleted"] += len(to_delete) # We don't need to wait around for this to complete. Store the thread # reference in case it is needed at some point. self._thread = self.bulk_delete(cont, to_delete, async_=True)
[ "def", "_delete_objects_not_in_list", "(", "self", ",", "cont", ",", "object_prefix", "=", "\"\"", ")", ":", "objnames", "=", "set", "(", "cont", ".", "get_object_names", "(", "prefix", "=", "object_prefix", ",", "full_listing", "=", "True", ")", ")", "local...
Finds all the objects in the specified container that are not present in the self._local_files list, and deletes them.
[ "Finds", "all", "the", "objects", "in", "the", "specified", "container", "that", "are", "not", "present", "in", "the", "self", ".", "_local_files", "list", "and", "deletes", "them", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L3152-L3164
17,996
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.bulk_delete
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 HTTP return status code. '200 OK' indicates success errors - a list of any errors returned by the bulk delete call This isn't available in swiftclient yet, so it's using code patterned after the client code in that library. """ deleter = BulkDeleter(self, container, object_names) deleter.start() if async_: return deleter while not deleter.completed: time.sleep(self.bulk_delete_interval) return deleter.results
python
def bulk_delete(self, container, object_names, async_=False): deleter = BulkDeleter(self, container, object_names) deleter.start() if async_: return deleter while not deleter.completed: time.sleep(self.bulk_delete_interval) return deleter.results
[ "def", "bulk_delete", "(", "self", ",", "container", ",", "object_names", ",", "async_", "=", "False", ")", ":", "deleter", "=", "BulkDeleter", "(", "self", ",", "container", ",", "object_names", ")", "deleter", ".", "start", "(", ")", "if", "async_", ":...
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 HTTP return status code. '200 OK' indicates success errors - a list of any errors returned by the bulk delete call This isn't available in swiftclient yet, so it's using code patterned after the client code in that library.
[ "Deletes", "multiple", "objects", "from", "a", "container", "in", "a", "single", "call", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L3167-L3199
17,997
pycontribs/pyrax
pyrax/object_storage.py
StorageClient.cdn_request
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 # the container exists but is not CDN-enabled. try: mgt_uri = "%s%s" % (self.management_url, uri) resp, resp_body = self.method_head(mgt_uri) except exc.NotFound: raise raise exc.NotCDNEnabled("This container is not CDN-enabled.") return resp, resp_body
python
def cdn_request(self, uri, method, *args, **kwargs): 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 # the container exists but is not CDN-enabled. try: mgt_uri = "%s%s" % (self.management_url, uri) resp, resp_body = self.method_head(mgt_uri) except exc.NotFound: raise raise exc.NotCDNEnabled("This container is not CDN-enabled.") return resp, resp_body
[ "def", "cdn_request", "(", "self", ",", "uri", ",", "method", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "cdn_management_url", ":", "raise", "exc", ".", "NotCDNEnabled", "(", "\"CDN is not enabled for this service.\"", ")"...
If the service supports CDN, use this method to access CDN-specific URIs.
[ "If", "the", "service", "supports", "CDN", "use", "this", "method", "to", "access", "CDN", "-", "specific", "URIs", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L3202-L3222
17,998
pycontribs/pyrax
pyrax/object_storage.py
FolderUploader.upload_files_in_folder
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) obj_size = os.stat(full_path).st_size self.client.upload_file(self.container, full_path, obj_name=obj_name, return_none=True, ttl=self.ttl) self.client._update_progress(self.upload_key, obj_size)
python
def upload_files_in_folder(self, dirname, fnames): 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) obj_size = os.stat(full_path).st_size self.client.upload_file(self.container, full_path, obj_name=obj_name, return_none=True, ttl=self.ttl) self.client._update_progress(self.upload_key, obj_size)
[ "def", "upload_files_in_folder", "(", "self", ",", "dirname", ",", "fnames", ")", ":", "if", "utils", ".", "match_pattern", "(", "dirname", ",", "self", ".", "ignore", ")", ":", "return", "False", "good_names", "=", "(", "nm", "for", "nm", "in", "fnames"...
Handles the iteration across files within a folder.
[ "Handles", "the", "iteration", "across", "files", "within", "a", "folder", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L3282-L3296
17,999
pycontribs/pyrax
pyrax/object_storage.py
FolderUploader.run
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) for dirname, _, fnames in os.walk(self.root_folder): self.upload_files_in_folder(dirname, fnames)
python
def run(self): root_path, folder_name = os.path.split(self.root_folder) self.root_folder = os.path.join(root_path, folder_name) for dirname, _, fnames in os.walk(self.root_folder): self.upload_files_in_folder(dirname, fnames)
[ "def", "run", "(", "self", ")", ":", "root_path", ",", "folder_name", "=", "os", ".", "path", ".", "split", "(", "self", ".", "root_folder", ")", "self", ".", "root_folder", "=", "os", ".", "path", ".", "join", "(", "root_path", ",", "folder_name", "...
Starts the uploading thread.
[ "Starts", "the", "uploading", "thread", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/object_storage.py#L3299-L3304