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
18,000
pycontribs/pyrax
samples/cloud_monitoring/util.py
option_chooser
def option_chooser(options, attr=None): """Given an iterable, enumerate its contents for a user to choose from. If the optional `attr` is not None, that attribute in each iterated object will be printed. This function will exit the program if the user chooses the escape option. """ for num, option in enumerate(options): if attr: print("%s: %s" % (num, getattr(option, attr))) else: print("%s: %s" % (num, option)) # Add an escape option escape_opt = num + 1 print("%s: I want to exit!" % escape_opt) choice = six.moves.input("Selection: ") try: ichoice = int(choice) if ichoice > escape_opt: raise ValueError except ValueError: print("Valid entries are the numbers 0-%s. Received '%s'." % (escape_opt, choice)) sys.exit() if ichoice == escape_opt: print("Bye!") sys.exit() return ichoice
python
def option_chooser(options, attr=None): for num, option in enumerate(options): if attr: print("%s: %s" % (num, getattr(option, attr))) else: print("%s: %s" % (num, option)) # Add an escape option escape_opt = num + 1 print("%s: I want to exit!" % escape_opt) choice = six.moves.input("Selection: ") try: ichoice = int(choice) if ichoice > escape_opt: raise ValueError except ValueError: print("Valid entries are the numbers 0-%s. Received '%s'." % (escape_opt, choice)) sys.exit() if ichoice == escape_opt: print("Bye!") sys.exit() return ichoice
[ "def", "option_chooser", "(", "options", ",", "attr", "=", "None", ")", ":", "for", "num", ",", "option", "in", "enumerate", "(", "options", ")", ":", "if", "attr", ":", "print", "(", "\"%s: %s\"", "%", "(", "num", ",", "getattr", "(", "option", ",",...
Given an iterable, enumerate its contents for a user to choose from. If the optional `attr` is not None, that attribute in each iterated object will be printed. This function will exit the program if the user chooses the escape option.
[ "Given", "an", "iterable", "enumerate", "its", "contents", "for", "a", "user", "to", "choose", "from", ".", "If", "the", "optional", "attr", "is", "not", "None", "that", "attribute", "in", "each", "iterated", "object", "will", "be", "printed", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/samples/cloud_monitoring/util.py#L24-L53
18,001
pycontribs/pyrax
pyrax/queueing.py
assure_queue
def assure_queue(fnc): """ Converts a queue ID or name passed as the 'queue' parameter to a Queue object. """ @wraps(fnc) def _wrapped(self, queue, *args, **kwargs): if not isinstance(queue, Queue): # Must be the ID queue = self._manager.get(queue) return fnc(self, queue, *args, **kwargs) return _wrapped
python
def assure_queue(fnc): @wraps(fnc) def _wrapped(self, queue, *args, **kwargs): if not isinstance(queue, Queue): # Must be the ID queue = self._manager.get(queue) return fnc(self, queue, *args, **kwargs) return _wrapped
[ "def", "assure_queue", "(", "fnc", ")", ":", "@", "wraps", "(", "fnc", ")", "def", "_wrapped", "(", "self", ",", "queue", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "queue", ",", "Queue", ")", ":", "# Mus...
Converts a queue ID or name passed as the 'queue' parameter to a Queue object.
[ "Converts", "a", "queue", "ID", "or", "name", "passed", "as", "the", "queue", "parameter", "to", "a", "Queue", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L54-L65
18,002
pycontribs/pyrax
pyrax/queueing.py
Queue.list
def list(self, include_claimed=False, echo=False, marker=None, limit=None): """ Returns a list of messages for this queue. By default only unclaimed messages are returned; if you want claimed messages included, pass `include_claimed=True`. Also, the requester's own messages are not returned by default; if you want them included, pass `echo=True`. The 'marker' and 'limit' parameters are used to control pagination of results. 'Marker' is the ID of the last message returned, while 'limit' controls the number of messages returned per reuqest (default=20). """ return self._message_manager.list(include_claimed=include_claimed, echo=echo, marker=marker, limit=limit)
python
def list(self, include_claimed=False, echo=False, marker=None, limit=None): return self._message_manager.list(include_claimed=include_claimed, echo=echo, marker=marker, limit=limit)
[ "def", "list", "(", "self", ",", "include_claimed", "=", "False", ",", "echo", "=", "False", ",", "marker", "=", "None", ",", "limit", "=", "None", ")", ":", "return", "self", ".", "_message_manager", ".", "list", "(", "include_claimed", "=", "include_cl...
Returns a list of messages for this queue. By default only unclaimed messages are returned; if you want claimed messages included, pass `include_claimed=True`. Also, the requester's own messages are not returned by default; if you want them included, pass `echo=True`. The 'marker' and 'limit' parameters are used to control pagination of results. 'Marker' is the ID of the last message returned, while 'limit' controls the number of messages returned per reuqest (default=20).
[ "Returns", "a", "list", "of", "messages", "for", "this", "queue", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L121-L135
18,003
pycontribs/pyrax
pyrax/queueing.py
Queue.list_by_claim
def list_by_claim(self, claim): """ Returns a list of all the messages from this queue that have been claimed by the specified claim. The claim can be either a claim ID or a QueueClaim object. """ if not isinstance(claim, QueueClaim): claim = self._claim_manager.get(claim) return claim.messages
python
def list_by_claim(self, claim): if not isinstance(claim, QueueClaim): claim = self._claim_manager.get(claim) return claim.messages
[ "def", "list_by_claim", "(", "self", ",", "claim", ")", ":", "if", "not", "isinstance", "(", "claim", ",", "QueueClaim", ")", ":", "claim", "=", "self", ".", "_claim_manager", ".", "get", "(", "claim", ")", "return", "claim", ".", "messages" ]
Returns a list of all the messages from this queue that have been claimed by the specified claim. The claim can be either a claim ID or a QueueClaim object.
[ "Returns", "a", "list", "of", "all", "the", "messages", "from", "this", "queue", "that", "have", "been", "claimed", "by", "the", "specified", "claim", ".", "The", "claim", "can", "be", "either", "a", "claim", "ID", "or", "a", "QueueClaim", "object", "." ...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L155-L163
18,004
pycontribs/pyrax
pyrax/queueing.py
QueueMessage._add_details
def _add_details(self, info): """ The 'id' and 'claim_id' attributes are not supplied directly, but included as part of the 'href' value. """ super(QueueMessage, self)._add_details(info) if self.href is None: return parsed = urllib.parse.urlparse(self.href) self.id = parsed.path.rsplit("/", 1)[-1] query = parsed.query if query: self.claim_id = query.split("claim_id=")[-1]
python
def _add_details(self, info): super(QueueMessage, self)._add_details(info) if self.href is None: return parsed = urllib.parse.urlparse(self.href) self.id = parsed.path.rsplit("/", 1)[-1] query = parsed.query if query: self.claim_id = query.split("claim_id=")[-1]
[ "def", "_add_details", "(", "self", ",", "info", ")", ":", "super", "(", "QueueMessage", ",", "self", ")", ".", "_add_details", "(", "info", ")", "if", "self", ".", "href", "is", "None", ":", "return", "parsed", "=", "urllib", ".", "parse", ".", "url...
The 'id' and 'claim_id' attributes are not supplied directly, but included as part of the 'href' value.
[ "The", "id", "and", "claim_id", "attributes", "are", "not", "supplied", "directly", "but", "included", "as", "part", "of", "the", "href", "value", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L244-L256
18,005
pycontribs/pyrax
pyrax/queueing.py
QueueClaim._add_details
def _add_details(self, info): """ The 'id' attribute is not supplied directly, but included as part of the 'href' value. Also, convert the dicts for messages into QueueMessage objects. """ msg_dicts = info.pop("messages", []) super(QueueClaim, self)._add_details(info) parsed = urllib.parse.urlparse(self.href) self.id = parsed.path.rsplit("/", 1)[-1] self.messages = [QueueMessage(self.manager._message_manager, item) for item in msg_dicts]
python
def _add_details(self, info): msg_dicts = info.pop("messages", []) super(QueueClaim, self)._add_details(info) parsed = urllib.parse.urlparse(self.href) self.id = parsed.path.rsplit("/", 1)[-1] self.messages = [QueueMessage(self.manager._message_manager, item) for item in msg_dicts]
[ "def", "_add_details", "(", "self", ",", "info", ")", ":", "msg_dicts", "=", "info", ".", "pop", "(", "\"messages\"", ",", "[", "]", ")", "super", "(", "QueueClaim", ",", "self", ")", ".", "_add_details", "(", "info", ")", "parsed", "=", "urllib", "....
The 'id' attribute is not supplied directly, but included as part of the 'href' value. Also, convert the dicts for messages into QueueMessage objects.
[ "The", "id", "attribute", "is", "not", "supplied", "directly", "but", "included", "as", "part", "of", "the", "href", "value", ".", "Also", "convert", "the", "dicts", "for", "messages", "into", "QueueMessage", "objects", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L276-L287
18,006
pycontribs/pyrax
pyrax/queueing.py
QueueMessageManager._iterate_list
def _iterate_list(self, include_claimed, echo, marker, limit): """ Recursive method to work around the hard limit of 10 items per call. """ ret = [] if limit is None: this_limit = MSG_LIMIT else: this_limit = min(MSG_LIMIT, limit) limit = limit - this_limit uri = "/%s?include_claimed=%s&echo=%s" % (self.uri_base, json.dumps(include_claimed), json.dumps(echo)) qs_parts = [] if marker is not None: qs_parts.append("marker=%s" % marker) if this_limit is not None: qs_parts.append("limit=%s" % this_limit) if qs_parts: uri = "%s&%s" % (uri, "&".join(qs_parts)) resp, resp_body = self._list(uri, return_raw=True) if not resp_body: return ret messages = resp_body.get(self.plural_response_key, []) ret = [QueueMessage(manager=self, info=item) for item in messages] marker = _parse_marker(resp_body) loop = 0 if ((limit is None) or limit > 0) and marker: loop += 1 ret.extend(self._iterate_list(include_claimed, echo, marker, limit)) return ret
python
def _iterate_list(self, include_claimed, echo, marker, limit): ret = [] if limit is None: this_limit = MSG_LIMIT else: this_limit = min(MSG_LIMIT, limit) limit = limit - this_limit uri = "/%s?include_claimed=%s&echo=%s" % (self.uri_base, json.dumps(include_claimed), json.dumps(echo)) qs_parts = [] if marker is not None: qs_parts.append("marker=%s" % marker) if this_limit is not None: qs_parts.append("limit=%s" % this_limit) if qs_parts: uri = "%s&%s" % (uri, "&".join(qs_parts)) resp, resp_body = self._list(uri, return_raw=True) if not resp_body: return ret messages = resp_body.get(self.plural_response_key, []) ret = [QueueMessage(manager=self, info=item) for item in messages] marker = _parse_marker(resp_body) loop = 0 if ((limit is None) or limit > 0) and marker: loop += 1 ret.extend(self._iterate_list(include_claimed, echo, marker, limit)) return ret
[ "def", "_iterate_list", "(", "self", ",", "include_claimed", ",", "echo", ",", "marker", ",", "limit", ")", ":", "ret", "=", "[", "]", "if", "limit", "is", "None", ":", "this_limit", "=", "MSG_LIMIT", "else", ":", "this_limit", "=", "min", "(", "MSG_LI...
Recursive method to work around the hard limit of 10 items per call.
[ "Recursive", "method", "to", "work", "around", "the", "hard", "limit", "of", "10", "items", "per", "call", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L314-L344
18,007
pycontribs/pyrax
pyrax/queueing.py
QueueMessageManager.delete
def delete(self, msg, claim_id=None): """ Deletes the specified message from its queue. If the message has been claimed, the ID of that claim must be passed as the 'claim_id' parameter. """ msg_id = utils.get_id(msg) if claim_id: uri = "/%s/%s?claim_id=%s" % (self.uri_base, msg_id, claim_id) else: uri = "/%s/%s" % (self.uri_base, msg_id) return self._delete(uri)
python
def delete(self, msg, claim_id=None): msg_id = utils.get_id(msg) if claim_id: uri = "/%s/%s?claim_id=%s" % (self.uri_base, msg_id, claim_id) else: uri = "/%s/%s" % (self.uri_base, msg_id) return self._delete(uri)
[ "def", "delete", "(", "self", ",", "msg", ",", "claim_id", "=", "None", ")", ":", "msg_id", "=", "utils", ".", "get_id", "(", "msg", ")", "if", "claim_id", ":", "uri", "=", "\"/%s/%s?claim_id=%s\"", "%", "(", "self", ".", "uri_base", ",", "msg_id", "...
Deletes the specified message from its queue. If the message has been claimed, the ID of that claim must be passed as the 'claim_id' parameter.
[ "Deletes", "the", "specified", "message", "from", "its", "queue", ".", "If", "the", "message", "has", "been", "claimed", "the", "ID", "of", "that", "claim", "must", "be", "passed", "as", "the", "claim_id", "parameter", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L347-L358
18,008
pycontribs/pyrax
pyrax/queueing.py
QueueMessageManager.list_by_ids
def list_by_ids(self, ids): """ If you wish to retrieve a list of messages from this queue and know the IDs of those messages, you can pass in a list of those IDs, and only the matching messages will be returned. This avoids pulling down all the messages in a queue and filtering on the client side. """ ids = utils.coerce_to_list(ids) uri = "/%s?ids=%s" % (self.uri_base, ",".join(ids)) # The API is not consistent in how it returns message lists, so this # workaround is needed. curr_prkey = self.plural_response_key self.plural_response_key = "" # BROKEN: API returns a list, not a dict. ret = self._list(uri) self.plural_response_key = curr_prkey return ret
python
def list_by_ids(self, ids): ids = utils.coerce_to_list(ids) uri = "/%s?ids=%s" % (self.uri_base, ",".join(ids)) # The API is not consistent in how it returns message lists, so this # workaround is needed. curr_prkey = self.plural_response_key self.plural_response_key = "" # BROKEN: API returns a list, not a dict. ret = self._list(uri) self.plural_response_key = curr_prkey return ret
[ "def", "list_by_ids", "(", "self", ",", "ids", ")", ":", "ids", "=", "utils", ".", "coerce_to_list", "(", "ids", ")", "uri", "=", "\"/%s?ids=%s\"", "%", "(", "self", ".", "uri_base", ",", "\",\"", ".", "join", "(", "ids", ")", ")", "# The API is not co...
If you wish to retrieve a list of messages from this queue and know the IDs of those messages, you can pass in a list of those IDs, and only the matching messages will be returned. This avoids pulling down all the messages in a queue and filtering on the client side.
[ "If", "you", "wish", "to", "retrieve", "a", "list", "of", "messages", "from", "this", "queue", "and", "know", "the", "IDs", "of", "those", "messages", "you", "can", "pass", "in", "a", "list", "of", "those", "IDs", "and", "only", "the", "matching", "mes...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L361-L377
18,009
pycontribs/pyrax
pyrax/queueing.py
QueueMessageManager.delete_by_ids
def delete_by_ids(self, ids): """ Deletes the messages whose IDs are passed in from this queue. """ ids = utils.coerce_to_list(ids) uri = "/%s?ids=%s" % (self.uri_base, ",".join(ids)) return self.api.method_delete(uri)
python
def delete_by_ids(self, ids): ids = utils.coerce_to_list(ids) uri = "/%s?ids=%s" % (self.uri_base, ",".join(ids)) return self.api.method_delete(uri)
[ "def", "delete_by_ids", "(", "self", ",", "ids", ")", ":", "ids", "=", "utils", ".", "coerce_to_list", "(", "ids", ")", "uri", "=", "\"/%s?ids=%s\"", "%", "(", "self", ".", "uri_base", ",", "\",\"", ".", "join", "(", "ids", ")", ")", "return", "self"...
Deletes the messages whose IDs are passed in from this queue.
[ "Deletes", "the", "messages", "whose", "IDs", "are", "passed", "in", "from", "this", "queue", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L380-L386
18,010
pycontribs/pyrax
pyrax/queueing.py
QueueManager.get
def get(self, id_): """ Need to customize, since Queues are not returned with normal response bodies. """ if self.api.queue_exists(id_): return Queue(self, {"queue": {"name": id_, "id_": id_}}, key="queue") raise exc.NotFound("The queue '%s' does not exist." % id_)
python
def get(self, id_): if self.api.queue_exists(id_): return Queue(self, {"queue": {"name": id_, "id_": id_}}, key="queue") raise exc.NotFound("The queue '%s' does not exist." % id_)
[ "def", "get", "(", "self", ",", "id_", ")", ":", "if", "self", ".", "api", ".", "queue_exists", "(", "id_", ")", ":", "return", "Queue", "(", "self", ",", "{", "\"queue\"", ":", "{", "\"name\"", ":", "id_", ",", "\"id_\"", ":", "id_", "}", "}", ...
Need to customize, since Queues are not returned with normal response bodies.
[ "Need", "to", "customize", "since", "Queues", "are", "not", "returned", "with", "normal", "response", "bodies", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L464-L471
18,011
pycontribs/pyrax
pyrax/queueing.py
QueueManager.get_stats
def get_stats(self, queue): """ Returns the message stats for the specified queue. """ uri = "/%s/%s/stats" % (self.uri_base, utils.get_id(queue)) resp, resp_body = self.api.method_get(uri) return resp_body.get("messages")
python
def get_stats(self, queue): uri = "/%s/%s/stats" % (self.uri_base, utils.get_id(queue)) resp, resp_body = self.api.method_get(uri) return resp_body.get("messages")
[ "def", "get_stats", "(", "self", ",", "queue", ")", ":", "uri", "=", "\"/%s/%s/stats\"", "%", "(", "self", ".", "uri_base", ",", "utils", ".", "get_id", "(", "queue", ")", ")", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_get", "("...
Returns the message stats for the specified queue.
[ "Returns", "the", "message", "stats", "for", "the", "specified", "queue", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L486-L492
18,012
pycontribs/pyrax
pyrax/queueing.py
QueueManager.get_metadata
def get_metadata(self, queue): """ Returns the metadata for the specified queue. """ uri = "/%s/%s/metadata" % (self.uri_base, utils.get_id(queue)) resp, resp_body = self.api.method_get(uri) return resp_body
python
def get_metadata(self, queue): uri = "/%s/%s/metadata" % (self.uri_base, utils.get_id(queue)) resp, resp_body = self.api.method_get(uri) return resp_body
[ "def", "get_metadata", "(", "self", ",", "queue", ")", ":", "uri", "=", "\"/%s/%s/metadata\"", "%", "(", "self", ".", "uri_base", ",", "utils", ".", "get_id", "(", "queue", ")", ")", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_get",...
Returns the metadata for the specified queue.
[ "Returns", "the", "metadata", "for", "the", "specified", "queue", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L495-L501
18,013
pycontribs/pyrax
pyrax/queueing.py
QueueClient._add_custom_headers
def _add_custom_headers(self, dct): """ Add the Client-ID header required by Cloud Queues """ if self.client_id is None: self.client_id = os.environ.get("CLOUD_QUEUES_ID") if self.client_id: dct["Client-ID"] = self.client_id
python
def _add_custom_headers(self, dct): if self.client_id is None: self.client_id = os.environ.get("CLOUD_QUEUES_ID") if self.client_id: dct["Client-ID"] = self.client_id
[ "def", "_add_custom_headers", "(", "self", ",", "dct", ")", ":", "if", "self", ".", "client_id", "is", "None", ":", "self", ".", "client_id", "=", "os", ".", "environ", ".", "get", "(", "\"CLOUD_QUEUES_ID\"", ")", "if", "self", ".", "client_id", ":", "...
Add the Client-ID header required by Cloud Queues
[ "Add", "the", "Client", "-", "ID", "header", "required", "by", "Cloud", "Queues" ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L537-L544
18,014
pycontribs/pyrax
pyrax/queueing.py
QueueClient._api_request
def _api_request(self, uri, method, **kwargs): """ Any request that involves messages must define the client ID. This handles all failures due to lack of client ID and raises the appropriate exception. """ try: return super(QueueClient, self)._api_request(uri, method, **kwargs) except exc.BadRequest as e: if ((e.code == "400") and (e.message == 'The "Client-ID" header is required.')): raise exc.QueueClientIDNotDefined("You must supply a client ID " "to work with Queue messages.") else: raise
python
def _api_request(self, uri, method, **kwargs): try: return super(QueueClient, self)._api_request(uri, method, **kwargs) except exc.BadRequest as e: if ((e.code == "400") and (e.message == 'The "Client-ID" header is required.')): raise exc.QueueClientIDNotDefined("You must supply a client ID " "to work with Queue messages.") else: raise
[ "def", "_api_request", "(", "self", ",", "uri", ",", "method", ",", "*", "*", "kwargs", ")", ":", "try", ":", "return", "super", "(", "QueueClient", ",", "self", ")", ".", "_api_request", "(", "uri", ",", "method", ",", "*", "*", "kwargs", ")", "ex...
Any request that involves messages must define the client ID. This handles all failures due to lack of client ID and raises the appropriate exception.
[ "Any", "request", "that", "involves", "messages", "must", "define", "the", "client", "ID", ".", "This", "handles", "all", "failures", "due", "to", "lack", "of", "client", "ID", "and", "raises", "the", "appropriate", "exception", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L547-L561
18,015
pycontribs/pyrax
pyrax/queueing.py
QueueClient.queue_exists
def queue_exists(self, name): """ Returns True or False, depending on the existence of the named queue. """ try: queue = self._manager.head(name) return True except exc.NotFound: return False
python
def queue_exists(self, name): try: queue = self._manager.head(name) return True except exc.NotFound: return False
[ "def", "queue_exists", "(", "self", ",", "name", ")", ":", "try", ":", "queue", "=", "self", ".", "_manager", ".", "head", "(", "name", ")", "return", "True", "except", "exc", ".", "NotFound", ":", "return", "False" ]
Returns True or False, depending on the existence of the named queue.
[ "Returns", "True", "or", "False", "depending", "on", "the", "existence", "of", "the", "named", "queue", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L591-L599
18,016
pycontribs/pyrax
pyrax/queueing.py
QueueClient.list_messages
def list_messages(self, queue, include_claimed=False, echo=False, marker=None, limit=None): """ Returns a list of messages for the specified queue. By default only unclaimed messages are returned; if you want claimed messages included, pass `include_claimed=True`. Also, the requester's own messages are not returned by default; if you want them included, pass `echo=True`. The 'marker' and 'limit' parameters are used to control pagination of results. 'Marker' is the ID of the last message returned, while 'limit' controls the number of messages returned per reuqest (default=20). """ return queue.list(include_claimed=include_claimed, echo=echo, marker=marker, limit=limit)
python
def list_messages(self, queue, include_claimed=False, echo=False, marker=None, limit=None): return queue.list(include_claimed=include_claimed, echo=echo, marker=marker, limit=limit)
[ "def", "list_messages", "(", "self", ",", "queue", ",", "include_claimed", "=", "False", ",", "echo", "=", "False", ",", "marker", "=", "None", ",", "limit", "=", "None", ")", ":", "return", "queue", ".", "list", "(", "include_claimed", "=", "include_cla...
Returns a list of messages for the specified queue. By default only unclaimed messages are returned; if you want claimed messages included, pass `include_claimed=True`. Also, the requester's own messages are not returned by default; if you want them included, pass `echo=True`. The 'marker' and 'limit' parameters are used to control pagination of results. 'Marker' is the ID of the last message returned, while 'limit' controls the number of messages returned per reuqest (default=20).
[ "Returns", "a", "list", "of", "messages", "for", "the", "specified", "queue", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L657-L672
18,017
pycontribs/pyrax
pyrax/queueing.py
QueueClient.claim_messages
def claim_messages(self, queue, ttl, grace, count=None): """ Claims up to `count` unclaimed messages from the specified queue. If count is not specified, the default is to claim 10 messages. The `ttl` parameter specifies how long the server should wait before releasing the claim. The ttl value MUST be between 60 and 43200 seconds. The `grace` parameter is the message grace period in seconds. The value of grace MUST be between 60 and 43200 seconds. The server extends the lifetime of claimed messages to be at least as long as the lifetime of the claim itself, plus a specified grace period to deal with crashed workers (up to 1209600 or 14 days including claim lifetime). If a claimed message would normally live longer than the grace period, its expiration will not be adjusted. Returns a QueueClaim object, whose 'messages' attribute contains the list of QueueMessage objects representing the claimed messages. """ return queue.claim_messages(ttl, grace, count=count)
python
def claim_messages(self, queue, ttl, grace, count=None): return queue.claim_messages(ttl, grace, count=count)
[ "def", "claim_messages", "(", "self", ",", "queue", ",", "ttl", ",", "grace", ",", "count", "=", "None", ")", ":", "return", "queue", ".", "claim_messages", "(", "ttl", ",", "grace", ",", "count", "=", "count", ")" ]
Claims up to `count` unclaimed messages from the specified queue. If count is not specified, the default is to claim 10 messages. The `ttl` parameter specifies how long the server should wait before releasing the claim. The ttl value MUST be between 60 and 43200 seconds. The `grace` parameter is the message grace period in seconds. The value of grace MUST be between 60 and 43200 seconds. The server extends the lifetime of claimed messages to be at least as long as the lifetime of the claim itself, plus a specified grace period to deal with crashed workers (up to 1209600 or 14 days including claim lifetime). If a claimed message would normally live longer than the grace period, its expiration will not be adjusted. Returns a QueueClaim object, whose 'messages' attribute contains the list of QueueMessage objects representing the claimed messages.
[ "Claims", "up", "to", "count", "unclaimed", "messages", "from", "the", "specified", "queue", ".", "If", "count", "is", "not", "specified", "the", "default", "is", "to", "claim", "10", "messages", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/queueing.py#L714-L733
18,018
pycontribs/pyrax
pyrax/cloudcdn.py
CloudCDNClient.list_services
def list_services(self, limit=None, marker=None): """List CDN services.""" return self._services_manager.list(limit=limit, marker=marker)
python
def list_services(self, limit=None, marker=None): return self._services_manager.list(limit=limit, marker=marker)
[ "def", "list_services", "(", "self", ",", "limit", "=", "None", ",", "marker", "=", "None", ")", ":", "return", "self", ".", "_services_manager", ".", "list", "(", "limit", "=", "limit", ",", "marker", "=", "marker", ")" ]
List CDN services.
[ "List", "CDN", "services", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudcdn.py#L144-L146
18,019
pycontribs/pyrax
pyrax/cloudcdn.py
CloudCDNClient.create_service
def create_service(self, name, flavor_id, domains, origins, restrictions=None, caching=None): """Create a new CDN service. Arguments: name: The name of the service. flavor_id: The ID of the flavor to use for this service. domains: A list of dictionaries, each of which has a required key "domain" and optional key "protocol" (the default protocol is http). origins: A list of dictionaries, each of which has a required key "origin" which is the URL or IP address to pull origin content from. Optional keys include "port" to use a port other than the default of 80, and "ssl" to enable SSL, which is disabled by default. caching: An optional """ return self._services_manager.create(name, flavor_id, domains, origins, restrictions, caching)
python
def create_service(self, name, flavor_id, domains, origins, restrictions=None, caching=None): return self._services_manager.create(name, flavor_id, domains, origins, restrictions, caching)
[ "def", "create_service", "(", "self", ",", "name", ",", "flavor_id", ",", "domains", ",", "origins", ",", "restrictions", "=", "None", ",", "caching", "=", "None", ")", ":", "return", "self", ".", "_services_manager", ".", "create", "(", "name", ",", "fl...
Create a new CDN service. Arguments: name: The name of the service. flavor_id: The ID of the flavor to use for this service. domains: A list of dictionaries, each of which has a required key "domain" and optional key "protocol" (the default protocol is http). origins: A list of dictionaries, each of which has a required key "origin" which is the URL or IP address to pull origin content from. Optional keys include "port" to use a port other than the default of 80, and "ssl" to enable SSL, which is disabled by default. caching: An optional
[ "Create", "a", "new", "CDN", "service", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudcdn.py#L152-L171
18,020
pycontribs/pyrax
pyrax/cloudcdn.py
CloudCDNClient.delete_assets
def delete_assets(self, service_id, url=None, all=False): """Delete CDN assets Arguments: service_id: The ID of the service to delete from. url: The URL at which to delete assets all: When True, delete all assets associated with the service_id. You cannot specifiy both url and all. """ self._services_manager.delete_assets(service_id, url, all)
python
def delete_assets(self, service_id, url=None, all=False): self._services_manager.delete_assets(service_id, url, all)
[ "def", "delete_assets", "(", "self", ",", "service_id", ",", "url", "=", "None", ",", "all", "=", "False", ")", ":", "self", ".", "_services_manager", ".", "delete_assets", "(", "service_id", ",", "url", ",", "all", ")" ]
Delete CDN assets Arguments: service_id: The ID of the service to delete from. url: The URL at which to delete assets all: When True, delete all assets associated with the service_id. You cannot specifiy both url and all.
[ "Delete", "CDN", "assets" ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudcdn.py#L190-L200
18,021
pycontribs/pyrax
pyrax/service_catalog.py
ServiceCatalog.url_for
def url_for(self, attr=None, filter_value=None, service_type=None, endpoint_type="publicURL", service_name=None, volume_service_name=None): """Fetches the public URL from the given service for a particular endpoint attribute. If none given, returns the first. See tests for sample service catalog.""" matching_endpoints = [] # We don't always get a service catalog back ... if "serviceCatalog" not in self.catalog["access"]: return None # Full catalog ... catalog = self.catalog["access"]["serviceCatalog"] for service in catalog: if service.get("type") != service_type: continue endpoints = service["endpoints"] for endpoint in endpoints: if not filter_value or endpoint.get(attr) == filter_value: endpoint["serviceName"] = service.get("name") matching_endpoints.append(endpoint) if not matching_endpoints: raise exc.EndpointNotFound() elif len(matching_endpoints) > 1: raise exc.AmbiguousEndpoints(endpoints=matching_endpoints) else: return matching_endpoints[0][endpoint_type]
python
def url_for(self, attr=None, filter_value=None, service_type=None, endpoint_type="publicURL", service_name=None, volume_service_name=None): matching_endpoints = [] # We don't always get a service catalog back ... if "serviceCatalog" not in self.catalog["access"]: return None # Full catalog ... catalog = self.catalog["access"]["serviceCatalog"] for service in catalog: if service.get("type") != service_type: continue endpoints = service["endpoints"] for endpoint in endpoints: if not filter_value or endpoint.get(attr) == filter_value: endpoint["serviceName"] = service.get("name") matching_endpoints.append(endpoint) if not matching_endpoints: raise exc.EndpointNotFound() elif len(matching_endpoints) > 1: raise exc.AmbiguousEndpoints(endpoints=matching_endpoints) else: return matching_endpoints[0][endpoint_type]
[ "def", "url_for", "(", "self", ",", "attr", "=", "None", ",", "filter_value", "=", "None", ",", "service_type", "=", "None", ",", "endpoint_type", "=", "\"publicURL\"", ",", "service_name", "=", "None", ",", "volume_service_name", "=", "None", ")", ":", "m...
Fetches the public URL from the given service for a particular endpoint attribute. If none given, returns the first. See tests for sample service catalog.
[ "Fetches", "the", "public", "URL", "from", "the", "given", "service", "for", "a", "particular", "endpoint", "attribute", ".", "If", "none", "given", "returns", "the", "first", ".", "See", "tests", "for", "sample", "service", "catalog", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/service_catalog.py#L34-L61
18,022
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancer._add_details
def _add_details(self, info): """Override the base behavior to add Nodes, VirtualIPs, etc.""" for (key, val) in six.iteritems(info): if key == "nodes": val = [Node(parent=self, **nd) for nd in val] elif key == "sessionPersistence": val = val['persistenceType'] elif key == "cluster": val = val['name'] elif key == "virtualIps": key = "virtual_ips" val = [VirtualIP(parent=self, **vip) for vip in val] setattr(self, key, val)
python
def _add_details(self, info): for (key, val) in six.iteritems(info): if key == "nodes": val = [Node(parent=self, **nd) for nd in val] elif key == "sessionPersistence": val = val['persistenceType'] elif key == "cluster": val = val['name'] elif key == "virtualIps": key = "virtual_ips" val = [VirtualIP(parent=self, **vip) for vip in val] setattr(self, key, val)
[ "def", "_add_details", "(", "self", ",", "info", ")", ":", "for", "(", "key", ",", "val", ")", "in", "six", ".", "iteritems", "(", "info", ")", ":", "if", "key", "==", "\"nodes\"", ":", "val", "=", "[", "Node", "(", "parent", "=", "self", ",", ...
Override the base behavior to add Nodes, VirtualIPs, etc.
[ "Override", "the", "base", "behavior", "to", "add", "Nodes", "VirtualIPs", "etc", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L94-L106
18,023
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancer.set_metadata_for_node
def set_metadata_for_node(self, node, metadata): """ Sets the metadata for the specified node to the supplied dictionary of values. Any existing metadata is cleared. """ return self.manager.set_metadata(self, metadata, node=node)
python
def set_metadata_for_node(self, node, metadata): return self.manager.set_metadata(self, metadata, node=node)
[ "def", "set_metadata_for_node", "(", "self", ",", "node", ",", "metadata", ")", ":", "return", "self", ".", "manager", ".", "set_metadata", "(", "self", ",", "metadata", ",", "node", "=", "node", ")" ]
Sets the metadata for the specified node to the supplied dictionary of values. Any existing metadata is cleared.
[ "Sets", "the", "metadata", "for", "the", "specified", "node", "to", "the", "supplied", "dictionary", "of", "values", ".", "Any", "existing", "metadata", "is", "cleared", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L324-L329
18,024
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancer.update_metadata_for_node
def update_metadata_for_node(self, node, metadata): """ Updates the existing metadata for the specified node with the supplied dictionary. """ return self.manager.update_metadata(self, metadata, node=node)
python
def update_metadata_for_node(self, node, metadata): return self.manager.update_metadata(self, metadata, node=node)
[ "def", "update_metadata_for_node", "(", "self", ",", "node", ",", "metadata", ")", ":", "return", "self", ".", "manager", ".", "update_metadata", "(", "self", ",", "metadata", ",", "node", "=", "node", ")" ]
Updates the existing metadata for the specified node with the supplied dictionary.
[ "Updates", "the", "existing", "metadata", "for", "the", "specified", "node", "with", "the", "supplied", "dictionary", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L332-L337
18,025
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager._create_body
def _create_body(self, name, port=None, protocol=None, nodes=None, virtual_ips=None, algorithm=None, halfClosed=None, accessList=None, connectionLogging=None, connectionThrottle=None, healthMonitor=None, metadata=None, timeout=None, sessionPersistence=None, httpsRedirect=None): """ Used to create the dict required to create a load balancer instance. """ required = (virtual_ips, port, protocol) if not all(required): raise exc.MissingLoadBalancerParameters("Load Balancer creation " "requires at least one virtual IP, a protocol, and a port.") nodes = utils.coerce_to_list(nodes) virtual_ips = utils.coerce_to_list(virtual_ips) bad_conditions = [node.condition for node in nodes if node.condition.upper() not in ("ENABLED", "DISABLED")] if bad_conditions: raise exc.InvalidNodeCondition("Nodes for new load balancer must be " "created in either 'ENABLED' or 'DISABLED' condition; " "received the following invalid conditions: %s" % ", ".join(set(bad_conditions))) node_dicts = [nd.to_dict() for nd in nodes] vip_dicts = [vip.to_dict() for vip in virtual_ips] body = {"loadBalancer": { "name": name, "port": port, "protocol": protocol, "nodes": node_dicts, "virtualIps": vip_dicts, "algorithm": algorithm or "RANDOM", "halfClosed": halfClosed, "accessList": accessList, "connectionLogging": connectionLogging, "connectionThrottle": connectionThrottle, "healthMonitor": healthMonitor, "metadata": metadata, "timeout": timeout, "sessionPersistence": sessionPersistence, "httpsRedirect": httpsRedirect, }} return body
python
def _create_body(self, name, port=None, protocol=None, nodes=None, virtual_ips=None, algorithm=None, halfClosed=None, accessList=None, connectionLogging=None, connectionThrottle=None, healthMonitor=None, metadata=None, timeout=None, sessionPersistence=None, httpsRedirect=None): required = (virtual_ips, port, protocol) if not all(required): raise exc.MissingLoadBalancerParameters("Load Balancer creation " "requires at least one virtual IP, a protocol, and a port.") nodes = utils.coerce_to_list(nodes) virtual_ips = utils.coerce_to_list(virtual_ips) bad_conditions = [node.condition for node in nodes if node.condition.upper() not in ("ENABLED", "DISABLED")] if bad_conditions: raise exc.InvalidNodeCondition("Nodes for new load balancer must be " "created in either 'ENABLED' or 'DISABLED' condition; " "received the following invalid conditions: %s" % ", ".join(set(bad_conditions))) node_dicts = [nd.to_dict() for nd in nodes] vip_dicts = [vip.to_dict() for vip in virtual_ips] body = {"loadBalancer": { "name": name, "port": port, "protocol": protocol, "nodes": node_dicts, "virtualIps": vip_dicts, "algorithm": algorithm or "RANDOM", "halfClosed": halfClosed, "accessList": accessList, "connectionLogging": connectionLogging, "connectionThrottle": connectionThrottle, "healthMonitor": healthMonitor, "metadata": metadata, "timeout": timeout, "sessionPersistence": sessionPersistence, "httpsRedirect": httpsRedirect, }} return body
[ "def", "_create_body", "(", "self", ",", "name", ",", "port", "=", "None", ",", "protocol", "=", "None", ",", "nodes", "=", "None", ",", "virtual_ips", "=", "None", ",", "algorithm", "=", "None", ",", "halfClosed", "=", "None", ",", "accessList", "=", ...
Used to create the dict required to create a load balancer instance.
[ "Used", "to", "create", "the", "dict", "required", "to", "create", "a", "load", "balancer", "instance", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L479-L519
18,026
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.add_nodes
def add_nodes(self, lb, nodes): """Adds the list of nodes to the specified load balancer.""" if not isinstance(nodes, (list, tuple)): nodes = [nodes] node_dicts = [nd.to_dict() for nd in nodes] resp, body = self.api.method_post("/loadbalancers/%s/nodes" % lb.id, body={"nodes": node_dicts}) return resp, body
python
def add_nodes(self, lb, nodes): if not isinstance(nodes, (list, tuple)): nodes = [nodes] node_dicts = [nd.to_dict() for nd in nodes] resp, body = self.api.method_post("/loadbalancers/%s/nodes" % lb.id, body={"nodes": node_dicts}) return resp, body
[ "def", "add_nodes", "(", "self", ",", "lb", ",", "nodes", ")", ":", "if", "not", "isinstance", "(", "nodes", ",", "(", "list", ",", "tuple", ")", ")", ":", "nodes", "=", "[", "nodes", "]", "node_dicts", "=", "[", "nd", ".", "to_dict", "(", ")", ...
Adds the list of nodes to the specified load balancer.
[ "Adds", "the", "list", "of", "nodes", "to", "the", "specified", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L522-L529
18,027
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.delete_node
def delete_node(self, loadbalancer, node): """Removes the node from its load balancer.""" lb = node.parent if not lb: raise exc.UnattachedNode("No parent Load Balancer for this node " "could be determined.") resp, body = self.api.method_delete("/loadbalancers/%s/nodes/%s" % (lb.id, node.id)) return resp, body
python
def delete_node(self, loadbalancer, node): lb = node.parent if not lb: raise exc.UnattachedNode("No parent Load Balancer for this node " "could be determined.") resp, body = self.api.method_delete("/loadbalancers/%s/nodes/%s" % (lb.id, node.id)) return resp, body
[ "def", "delete_node", "(", "self", ",", "loadbalancer", ",", "node", ")", ":", "lb", "=", "node", ".", "parent", "if", "not", "lb", ":", "raise", "exc", ".", "UnattachedNode", "(", "\"No parent Load Balancer for this node \"", "\"could be determined.\"", ")", "r...
Removes the node from its load balancer.
[ "Removes", "the", "node", "from", "its", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L532-L540
18,028
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.add_virtualip
def add_virtualip(self, lb, vip): """Adds the VirtualIP to the specified load balancer.""" resp, body = self.api.method_post("/loadbalancers/%s/virtualips" % lb.id, body=vip.to_dict()) return resp, body
python
def add_virtualip(self, lb, vip): resp, body = self.api.method_post("/loadbalancers/%s/virtualips" % lb.id, body=vip.to_dict()) return resp, body
[ "def", "add_virtualip", "(", "self", ",", "lb", ",", "vip", ")", ":", "resp", ",", "body", "=", "self", ".", "api", ".", "method_post", "(", "\"/loadbalancers/%s/virtualips\"", "%", "lb", ".", "id", ",", "body", "=", "vip", ".", "to_dict", "(", ")", ...
Adds the VirtualIP to the specified load balancer.
[ "Adds", "the", "VirtualIP", "to", "the", "specified", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L557-L561
18,029
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.delete_virtualip
def delete_virtualip(self, loadbalancer, vip): """Deletes the VirtualIP from its load balancer.""" lb = vip.parent if not lb: raise exc.UnattachedVirtualIP("No parent Load Balancer for this " "VirtualIP could be determined.") resp, body = self.api.method_delete("/loadbalancers/%s/virtualips/%s" % (lb.id, vip.id)) return resp, body
python
def delete_virtualip(self, loadbalancer, vip): lb = vip.parent if not lb: raise exc.UnattachedVirtualIP("No parent Load Balancer for this " "VirtualIP could be determined.") resp, body = self.api.method_delete("/loadbalancers/%s/virtualips/%s" % (lb.id, vip.id)) return resp, body
[ "def", "delete_virtualip", "(", "self", ",", "loadbalancer", ",", "vip", ")", ":", "lb", "=", "vip", ".", "parent", "if", "not", "lb", ":", "raise", "exc", ".", "UnattachedVirtualIP", "(", "\"No parent Load Balancer for this \"", "\"VirtualIP could be determined.\""...
Deletes the VirtualIP from its load balancer.
[ "Deletes", "the", "VirtualIP", "from", "its", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L564-L572
18,030
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.add_access_list
def add_access_list(self, loadbalancer, access_list): """ Adds the access list provided to the load balancer. The 'access_list' should be a list of dicts in the following format: [{"address": "192.0.43.10", "type": "DENY"}, {"address": "192.0.43.11", "type": "ALLOW"}, ... {"address": "192.0.43.99", "type": "DENY"}, ] If no access list exists, it is created. If an access list already exists, it is updated with the provided list. """ req_body = {"accessList": access_list} uri = "/loadbalancers/%s/accesslist" % utils.get_id(loadbalancer) resp, body = self.api.method_post(uri, body=req_body) return body
python
def add_access_list(self, loadbalancer, access_list): req_body = {"accessList": access_list} uri = "/loadbalancers/%s/accesslist" % utils.get_id(loadbalancer) resp, body = self.api.method_post(uri, body=req_body) return body
[ "def", "add_access_list", "(", "self", ",", "loadbalancer", ",", "access_list", ")", ":", "req_body", "=", "{", "\"accessList\"", ":", "access_list", "}", "uri", "=", "\"/loadbalancers/%s/accesslist\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "res...
Adds the access list provided to the load balancer. The 'access_list' should be a list of dicts in the following format: [{"address": "192.0.43.10", "type": "DENY"}, {"address": "192.0.43.11", "type": "ALLOW"}, ... {"address": "192.0.43.99", "type": "DENY"}, ] If no access list exists, it is created. If an access list already exists, it is updated with the provided list.
[ "Adds", "the", "access", "list", "provided", "to", "the", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L584-L602
18,031
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.delete_access_list
def delete_access_list(self, loadbalancer): """ Removes the access list from this load balancer. """ uri = "/loadbalancers/%s/accesslist" % utils.get_id(loadbalancer) resp, body = self.api.method_delete(uri) return body
python
def delete_access_list(self, loadbalancer): uri = "/loadbalancers/%s/accesslist" % utils.get_id(loadbalancer) resp, body = self.api.method_delete(uri) return body
[ "def", "delete_access_list", "(", "self", ",", "loadbalancer", ")", ":", "uri", "=", "\"/loadbalancers/%s/accesslist\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "resp", ",", "body", "=", "self", ".", "api", ".", "method_delete", "(", "uri", ")...
Removes the access list from this load balancer.
[ "Removes", "the", "access", "list", "from", "this", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L605-L611
18,032
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.get_health_monitor
def get_health_monitor(self, loadbalancer): """ Returns a dict representing the health monitor for the load balancer. If no monitor has been configured, returns an empty dict. """ uri = "/loadbalancers/%s/healthmonitor" % utils.get_id(loadbalancer) resp, body = self.api.method_get(uri) return body.get("healthMonitor", {})
python
def get_health_monitor(self, loadbalancer): uri = "/loadbalancers/%s/healthmonitor" % utils.get_id(loadbalancer) resp, body = self.api.method_get(uri) return body.get("healthMonitor", {})
[ "def", "get_health_monitor", "(", "self", ",", "loadbalancer", ")", ":", "uri", "=", "\"/loadbalancers/%s/healthmonitor\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "resp", ",", "body", "=", "self", ".", "api", ".", "method_get", "(", "uri", ")...
Returns a dict representing the health monitor for the load balancer. If no monitor has been configured, returns an empty dict.
[ "Returns", "a", "dict", "representing", "the", "health", "monitor", "for", "the", "load", "balancer", ".", "If", "no", "monitor", "has", "been", "configured", "returns", "an", "empty", "dict", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L635-L643
18,033
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.add_connection_throttle
def add_connection_throttle(self, loadbalancer, maxConnectionRate=None, maxConnections=None, minConnections=None, rateInterval=None): """ Creates or updates the connection throttling information for the load balancer. When first creating the connection throttle, all 4 parameters must be supplied. When updating an existing connection throttle, at least one of the parameters must be supplied. """ settings = {} if maxConnectionRate: settings["maxConnectionRate"] = maxConnectionRate if maxConnections: settings["maxConnections"] = maxConnections if minConnections: settings["minConnections"] = minConnections if rateInterval: settings["rateInterval"] = rateInterval req_body = {"connectionThrottle": settings} uri = "/loadbalancers/%s/connectionthrottle" % utils.get_id(loadbalancer) resp, body = self.api.method_put(uri, body=req_body) return body
python
def add_connection_throttle(self, loadbalancer, maxConnectionRate=None, maxConnections=None, minConnections=None, rateInterval=None): settings = {} if maxConnectionRate: settings["maxConnectionRate"] = maxConnectionRate if maxConnections: settings["maxConnections"] = maxConnections if minConnections: settings["minConnections"] = minConnections if rateInterval: settings["rateInterval"] = rateInterval req_body = {"connectionThrottle": settings} uri = "/loadbalancers/%s/connectionthrottle" % utils.get_id(loadbalancer) resp, body = self.api.method_put(uri, body=req_body) return body
[ "def", "add_connection_throttle", "(", "self", ",", "loadbalancer", ",", "maxConnectionRate", "=", "None", ",", "maxConnections", "=", "None", ",", "minConnections", "=", "None", ",", "rateInterval", "=", "None", ")", ":", "settings", "=", "{", "}", "if", "m...
Creates or updates the connection throttling information for the load balancer. When first creating the connection throttle, all 4 parameters must be supplied. When updating an existing connection throttle, at least one of the parameters must be supplied.
[ "Creates", "or", "updates", "the", "connection", "throttling", "information", "for", "the", "load", "balancer", ".", "When", "first", "creating", "the", "connection", "throttle", "all", "4", "parameters", "must", "be", "supplied", ".", "When", "updating", "an", ...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L700-L720
18,034
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.get_ssl_termination
def get_ssl_termination(self, loadbalancer): """ Returns a dict representing the SSL termination configuration for the load balancer. If SSL termination has not been configured, returns an empty dict. """ uri = "/loadbalancers/%s/ssltermination" % utils.get_id(loadbalancer) try: resp, body = self.api.method_get(uri) except exc.NotFound: # For some reason, instead of returning an empty dict like the # other API GET calls, this raises a 404. return {} return body.get("sslTermination", {})
python
def get_ssl_termination(self, loadbalancer): uri = "/loadbalancers/%s/ssltermination" % utils.get_id(loadbalancer) try: resp, body = self.api.method_get(uri) except exc.NotFound: # For some reason, instead of returning an empty dict like the # other API GET calls, this raises a 404. return {} return body.get("sslTermination", {})
[ "def", "get_ssl_termination", "(", "self", ",", "loadbalancer", ")", ":", "uri", "=", "\"/loadbalancers/%s/ssltermination\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "try", ":", "resp", ",", "body", "=", "self", ".", "api", ".", "method_get", ...
Returns a dict representing the SSL termination configuration for the load balancer. If SSL termination has not been configured, returns an empty dict.
[ "Returns", "a", "dict", "representing", "the", "SSL", "termination", "configuration", "for", "the", "load", "balancer", ".", "If", "SSL", "termination", "has", "not", "been", "configured", "returns", "an", "empty", "dict", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L731-L744
18,035
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.get_metadata
def get_metadata(self, loadbalancer, node=None, raw=False): """ Returns the current metadata for the load balancer. If 'node' is provided, returns the current metadata for that node. """ if node: uri = "/loadbalancers/%s/nodes/%s/metadata" % ( utils.get_id(loadbalancer), utils.get_id(node)) else: uri = "/loadbalancers/%s/metadata" % utils.get_id(loadbalancer) resp, body = self.api.method_get(uri) meta = body.get("metadata", []) if raw: return meta ret = dict([(itm["key"], itm["value"]) for itm in meta]) return ret
python
def get_metadata(self, loadbalancer, node=None, raw=False): if node: uri = "/loadbalancers/%s/nodes/%s/metadata" % ( utils.get_id(loadbalancer), utils.get_id(node)) else: uri = "/loadbalancers/%s/metadata" % utils.get_id(loadbalancer) resp, body = self.api.method_get(uri) meta = body.get("metadata", []) if raw: return meta ret = dict([(itm["key"], itm["value"]) for itm in meta]) return ret
[ "def", "get_metadata", "(", "self", ",", "loadbalancer", ",", "node", "=", "None", ",", "raw", "=", "False", ")", ":", "if", "node", ":", "uri", "=", "\"/loadbalancers/%s/nodes/%s/metadata\"", "%", "(", "utils", ".", "get_id", "(", "loadbalancer", ")", ","...
Returns the current metadata for the load balancer. If 'node' is provided, returns the current metadata for that node.
[ "Returns", "the", "current", "metadata", "for", "the", "load", "balancer", ".", "If", "node", "is", "provided", "returns", "the", "current", "metadata", "for", "that", "node", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L801-L816
18,036
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.set_metadata
def set_metadata(self, loadbalancer, metadata, node=None): """ Sets the metadata for the load balancer to the supplied dictionary of values. Any existing metadata is cleared. If 'node' is provided, the metadata for that node is set instead of for the load balancer. """ # Delete any existing metadata self.delete_metadata(loadbalancer, node=node) # Convert the metadata dict into the list format metadata_list = [{"key": key, "value": val} for key, val in metadata.items()] if node: uri = "/loadbalancers/%s/nodes/%s/metadata" % ( utils.get_id(loadbalancer), utils.get_id(node)) else: uri = "/loadbalancers/%s/metadata" % utils.get_id(loadbalancer) req_body = {"metadata": metadata_list} resp, body = self.api.method_post(uri, body=req_body) return body
python
def set_metadata(self, loadbalancer, metadata, node=None): # Delete any existing metadata self.delete_metadata(loadbalancer, node=node) # Convert the metadata dict into the list format metadata_list = [{"key": key, "value": val} for key, val in metadata.items()] if node: uri = "/loadbalancers/%s/nodes/%s/metadata" % ( utils.get_id(loadbalancer), utils.get_id(node)) else: uri = "/loadbalancers/%s/metadata" % utils.get_id(loadbalancer) req_body = {"metadata": metadata_list} resp, body = self.api.method_post(uri, body=req_body) return body
[ "def", "set_metadata", "(", "self", ",", "loadbalancer", ",", "metadata", ",", "node", "=", "None", ")", ":", "# Delete any existing metadata", "self", ".", "delete_metadata", "(", "loadbalancer", ",", "node", "=", "node", ")", "# Convert the metadata dict into the ...
Sets the metadata for the load balancer to the supplied dictionary of values. Any existing metadata is cleared. If 'node' is provided, the metadata for that node is set instead of for the load balancer.
[ "Sets", "the", "metadata", "for", "the", "load", "balancer", "to", "the", "supplied", "dictionary", "of", "values", ".", "Any", "existing", "metadata", "is", "cleared", ".", "If", "node", "is", "provided", "the", "metadata", "for", "that", "node", "is", "s...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L819-L837
18,037
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.update_metadata
def update_metadata(self, loadbalancer, metadata, node=None): """ Updates the existing metadata with the supplied dictionary. If 'node' is supplied, the metadata for that node is updated instead of for the load balancer. """ # Get the existing metadata md = self.get_metadata(loadbalancer, raw=True) id_lookup = dict([(itm["key"], itm["id"]) for itm in md]) metadata_list = [] # Updates must be done individually for key, val in metadata.items(): try: meta_id = id_lookup[key] if node: uri = "/loadbalancers/%s/nodes/%s/metadata/%s" % ( utils.get_id(loadbalancer), utils.get_id(node), meta_id) else: uri = "/loadbalancers/%s/metadata" % utils.get_id(loadbalancer) req_body = {"meta": {"value": val}} resp, body = self.api.method_put(uri, body=req_body) except KeyError: # Not an existing key; add to metadata_list metadata_list.append({"key": key, "value": val}) if metadata_list: # New items; POST them if node: uri = "/loadbalancers/%s/nodes/%s/metadata" % ( utils.get_id(loadbalancer), utils.get_id(node)) else: uri = "/loadbalancers/%s/metadata" % utils.get_id(loadbalancer) req_body = {"metadata": metadata_list} resp, body = self.api.method_post(uri, body=req_body)
python
def update_metadata(self, loadbalancer, metadata, node=None): # Get the existing metadata md = self.get_metadata(loadbalancer, raw=True) id_lookup = dict([(itm["key"], itm["id"]) for itm in md]) metadata_list = [] # Updates must be done individually for key, val in metadata.items(): try: meta_id = id_lookup[key] if node: uri = "/loadbalancers/%s/nodes/%s/metadata/%s" % ( utils.get_id(loadbalancer), utils.get_id(node), meta_id) else: uri = "/loadbalancers/%s/metadata" % utils.get_id(loadbalancer) req_body = {"meta": {"value": val}} resp, body = self.api.method_put(uri, body=req_body) except KeyError: # Not an existing key; add to metadata_list metadata_list.append({"key": key, "value": val}) if metadata_list: # New items; POST them if node: uri = "/loadbalancers/%s/nodes/%s/metadata" % ( utils.get_id(loadbalancer), utils.get_id(node)) else: uri = "/loadbalancers/%s/metadata" % utils.get_id(loadbalancer) req_body = {"metadata": metadata_list} resp, body = self.api.method_post(uri, body=req_body)
[ "def", "update_metadata", "(", "self", ",", "loadbalancer", ",", "metadata", ",", "node", "=", "None", ")", ":", "# Get the existing metadata", "md", "=", "self", ".", "get_metadata", "(", "loadbalancer", ",", "raw", "=", "True", ")", "id_lookup", "=", "dict...
Updates the existing metadata with the supplied dictionary. If 'node' is supplied, the metadata for that node is updated instead of for the load balancer.
[ "Updates", "the", "existing", "metadata", "with", "the", "supplied", "dictionary", ".", "If", "node", "is", "supplied", "the", "metadata", "for", "that", "node", "is", "updated", "instead", "of", "for", "the", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L840-L873
18,038
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.delete_metadata
def delete_metadata(self, loadbalancer, keys=None, node=None): """ Deletes metadata items specified by the 'keys' parameter. If no value for 'keys' is provided, all metadata is deleted. If 'node' is supplied, the metadata for that node is deleted instead of the load balancer. """ if keys and not isinstance(keys, (list, tuple)): keys = [keys] md = self.get_metadata(loadbalancer, node=node, raw=True) if keys: md = [dct for dct in md if dct["key"] in keys] if not md: # Nothing to do; log it? Raise an error? return id_list = "&".join(["id=%s" % itm["id"] for itm in md]) if node: uri = "/loadbalancers/%s/nodes/%s/metadata?%s" % ( utils.get_id(loadbalancer), utils.get_id(node), id_list) else: uri = "/loadbalancers/%s/metadata?%s" % ( utils.get_id(loadbalancer), id_list) resp, body = self.api.method_delete(uri) return body
python
def delete_metadata(self, loadbalancer, keys=None, node=None): if keys and not isinstance(keys, (list, tuple)): keys = [keys] md = self.get_metadata(loadbalancer, node=node, raw=True) if keys: md = [dct for dct in md if dct["key"] in keys] if not md: # Nothing to do; log it? Raise an error? return id_list = "&".join(["id=%s" % itm["id"] for itm in md]) if node: uri = "/loadbalancers/%s/nodes/%s/metadata?%s" % ( utils.get_id(loadbalancer), utils.get_id(node), id_list) else: uri = "/loadbalancers/%s/metadata?%s" % ( utils.get_id(loadbalancer), id_list) resp, body = self.api.method_delete(uri) return body
[ "def", "delete_metadata", "(", "self", ",", "loadbalancer", ",", "keys", "=", "None", ",", "node", "=", "None", ")", ":", "if", "keys", "and", "not", "isinstance", "(", "keys", ",", "(", "list", ",", "tuple", ")", ")", ":", "keys", "=", "[", "keys"...
Deletes metadata items specified by the 'keys' parameter. If no value for 'keys' is provided, all metadata is deleted. If 'node' is supplied, the metadata for that node is deleted instead of the load balancer.
[ "Deletes", "metadata", "items", "specified", "by", "the", "keys", "parameter", ".", "If", "no", "value", "for", "keys", "is", "provided", "all", "metadata", "is", "deleted", ".", "If", "node", "is", "supplied", "the", "metadata", "for", "that", "node", "is...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L876-L898
18,039
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.set_error_page
def set_error_page(self, loadbalancer, html): """ A single custom error page may be added per account load balancer with an HTTP protocol. Page updates will override existing content. If a custom error page is deleted, or the load balancer is changed to a non-HTTP protocol, the default error page will be restored. """ uri = "/loadbalancers/%s/errorpage" % utils.get_id(loadbalancer) req_body = {"errorpage": {"content": html}} resp, body = self.api.method_put(uri, body=req_body) return body
python
def set_error_page(self, loadbalancer, html): uri = "/loadbalancers/%s/errorpage" % utils.get_id(loadbalancer) req_body = {"errorpage": {"content": html}} resp, body = self.api.method_put(uri, body=req_body) return body
[ "def", "set_error_page", "(", "self", ",", "loadbalancer", ",", "html", ")", ":", "uri", "=", "\"/loadbalancers/%s/errorpage\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "req_body", "=", "{", "\"errorpage\"", ":", "{", "\"content\"", ":", "html",...
A single custom error page may be added per account load balancer with an HTTP protocol. Page updates will override existing content. If a custom error page is deleted, or the load balancer is changed to a non-HTTP protocol, the default error page will be restored.
[ "A", "single", "custom", "error", "page", "may", "be", "added", "per", "account", "load", "balancer", "with", "an", "HTTP", "protocol", ".", "Page", "updates", "will", "override", "existing", "content", ".", "If", "a", "custom", "error", "page", "is", "del...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L912-L922
18,040
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.get_session_persistence
def get_session_persistence(self, loadbalancer): """ Returns the session persistence setting for the given load balancer. """ uri = "/loadbalancers/%s/sessionpersistence" % utils.get_id(loadbalancer) resp, body = self.api.method_get(uri) ret = body["sessionPersistence"].get("persistenceType", "") return ret
python
def get_session_persistence(self, loadbalancer): uri = "/loadbalancers/%s/sessionpersistence" % utils.get_id(loadbalancer) resp, body = self.api.method_get(uri) ret = body["sessionPersistence"].get("persistenceType", "") return ret
[ "def", "get_session_persistence", "(", "self", ",", "loadbalancer", ")", ":", "uri", "=", "\"/loadbalancers/%s/sessionpersistence\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "resp", ",", "body", "=", "self", ".", "api", ".", "method_get", "(", "...
Returns the session persistence setting for the given load balancer.
[ "Returns", "the", "session", "persistence", "setting", "for", "the", "given", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L974-L981
18,041
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.set_session_persistence
def set_session_persistence(self, loadbalancer, val): """ Sets the session persistence for the given load balancer. """ val = val.upper() uri = "/loadbalancers/%s/sessionpersistence" % utils.get_id(loadbalancer) req_body = {"sessionPersistence": { "persistenceType": val, }} resp, body = self.api.method_put(uri, body=req_body) return body
python
def set_session_persistence(self, loadbalancer, val): val = val.upper() uri = "/loadbalancers/%s/sessionpersistence" % utils.get_id(loadbalancer) req_body = {"sessionPersistence": { "persistenceType": val, }} resp, body = self.api.method_put(uri, body=req_body) return body
[ "def", "set_session_persistence", "(", "self", ",", "loadbalancer", ",", "val", ")", ":", "val", "=", "val", ".", "upper", "(", ")", "uri", "=", "\"/loadbalancers/%s/sessionpersistence\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "req_body", "=",...
Sets the session persistence for the given load balancer.
[ "Sets", "the", "session", "persistence", "for", "the", "given", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L984-L994
18,042
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.get_connection_logging
def get_connection_logging(self, loadbalancer): """ Returns the connection logging setting for the given load balancer. """ uri = "/loadbalancers/%s/connectionlogging" % utils.get_id(loadbalancer) resp, body = self.api.method_get(uri) ret = body.get("connectionLogging", {}).get("enabled", False) return ret
python
def get_connection_logging(self, loadbalancer): uri = "/loadbalancers/%s/connectionlogging" % utils.get_id(loadbalancer) resp, body = self.api.method_get(uri) ret = body.get("connectionLogging", {}).get("enabled", False) return ret
[ "def", "get_connection_logging", "(", "self", ",", "loadbalancer", ")", ":", "uri", "=", "\"/loadbalancers/%s/connectionlogging\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "resp", ",", "body", "=", "self", ".", "api", ".", "method_get", "(", "ur...
Returns the connection logging setting for the given load balancer.
[ "Returns", "the", "connection", "logging", "setting", "for", "the", "given", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1006-L1013
18,043
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager.set_connection_logging
def set_connection_logging(self, loadbalancer, val): """ Sets the connection logging for the given load balancer. """ uri = "/loadbalancers/%s/connectionlogging" % utils.get_id(loadbalancer) val = str(val).lower() req_body = {"connectionLogging": { "enabled": val, }} resp, body = self.api.method_put(uri, body=req_body) return body
python
def set_connection_logging(self, loadbalancer, val): uri = "/loadbalancers/%s/connectionlogging" % utils.get_id(loadbalancer) val = str(val).lower() req_body = {"connectionLogging": { "enabled": val, }} resp, body = self.api.method_put(uri, body=req_body) return body
[ "def", "set_connection_logging", "(", "self", ",", "loadbalancer", ",", "val", ")", ":", "uri", "=", "\"/loadbalancers/%s/connectionlogging\"", "%", "utils", ".", "get_id", "(", "loadbalancer", ")", "val", "=", "str", "(", "val", ")", ".", "lower", "(", ")",...
Sets the connection logging for the given load balancer.
[ "Sets", "the", "connection", "logging", "for", "the", "given", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1016-L1026
18,044
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerManager._get_lb
def _get_lb(self, lb_or_id): """ Accepts either a loadbalancer or the ID of a loadbalancer, and returns the CloudLoadBalancer instance. """ if isinstance(lb_or_id, CloudLoadBalancer): ret = lb_or_id else: ret = self.get(lb_or_id) return ret
python
def _get_lb(self, lb_or_id): if isinstance(lb_or_id, CloudLoadBalancer): ret = lb_or_id else: ret = self.get(lb_or_id) return ret
[ "def", "_get_lb", "(", "self", ",", "lb_or_id", ")", ":", "if", "isinstance", "(", "lb_or_id", ",", "CloudLoadBalancer", ")", ":", "ret", "=", "lb_or_id", "else", ":", "ret", "=", "self", ".", "get", "(", "lb_or_id", ")", "return", "ret" ]
Accepts either a loadbalancer or the ID of a loadbalancer, and returns the CloudLoadBalancer instance.
[ "Accepts", "either", "a", "loadbalancer", "or", "the", "ID", "of", "a", "loadbalancer", "and", "returns", "the", "CloudLoadBalancer", "instance", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1052-L1061
18,045
pycontribs/pyrax
pyrax/cloudloadbalancers.py
Node.to_dict
def to_dict(self): """Convert this Node to a dict representation for passing to the API.""" return {"address": self.address, "port": self.port, "condition": self.condition, "type": self.type, "id": self.id, }
python
def to_dict(self): return {"address": self.address, "port": self.port, "condition": self.condition, "type": self.type, "id": self.id, }
[ "def", "to_dict", "(", "self", ")", ":", "return", "{", "\"address\"", ":", "self", ".", "address", ",", "\"port\"", ":", "self", ".", "port", ",", "\"condition\"", ":", "self", ".", "condition", ",", "\"type\"", ":", "self", ".", "type", ",", "\"id\""...
Convert this Node to a dict representation for passing to the API.
[ "Convert", "this", "Node", "to", "a", "dict", "representation", "for", "passing", "to", "the", "API", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1099-L1106
18,046
pycontribs/pyrax
pyrax/cloudloadbalancers.py
Node.update
def update(self): """ Pushes any local changes to the object up to the actual load balancer node. """ diff = self._diff() if not diff: # Nothing to do! return self.parent.update_node(self, diff)
python
def update(self): diff = self._diff() if not diff: # Nothing to do! return self.parent.update_node(self, diff)
[ "def", "update", "(", "self", ")", ":", "diff", "=", "self", ".", "_diff", "(", ")", "if", "not", "diff", ":", "# Nothing to do!", "return", "self", ".", "parent", ".", "update_node", "(", "self", ",", "diff", ")" ]
Pushes any local changes to the object up to the actual load balancer node.
[ "Pushes", "any", "local", "changes", "to", "the", "object", "up", "to", "the", "actual", "load", "balancer", "node", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1157-L1166
18,047
pycontribs/pyrax
pyrax/cloudloadbalancers.py
Node.get_device
def get_device(self): """ Returns a reference to the device that is represented by this node. Returns None if no such device can be determined. """ addr = self.address servers = [server for server in pyrax.cloudservers.list() if addr in server.networks.get("private", "")] try: return servers[0] except IndexError: return None
python
def get_device(self): addr = self.address servers = [server for server in pyrax.cloudservers.list() if addr in server.networks.get("private", "")] try: return servers[0] except IndexError: return None
[ "def", "get_device", "(", "self", ")", ":", "addr", "=", "self", ".", "address", "servers", "=", "[", "server", "for", "server", "in", "pyrax", ".", "cloudservers", ".", "list", "(", ")", "if", "addr", "in", "server", ".", "networks", ".", "get", "("...
Returns a reference to the device that is represented by this node. Returns None if no such device can be determined.
[ "Returns", "a", "reference", "to", "the", "device", "that", "is", "represented", "by", "this", "node", ".", "Returns", "None", "if", "no", "such", "device", "can", "be", "determined", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1169-L1180
18,048
pycontribs/pyrax
pyrax/cloudloadbalancers.py
VirtualIP.to_dict
def to_dict(self): """ Convert this VirtualIP to a dict representation for passing to the API. """ if self.id: return {"id": self.id} return {"type": self.type, "ipVersion": self.ip_version}
python
def to_dict(self): if self.id: return {"id": self.id} return {"type": self.type, "ipVersion": self.ip_version}
[ "def", "to_dict", "(", "self", ")", ":", "if", "self", ".", "id", ":", "return", "{", "\"id\"", ":", "self", ".", "id", "}", "return", "{", "\"type\"", ":", "self", ".", "type", ",", "\"ipVersion\"", ":", "self", ".", "ip_version", "}" ]
Convert this VirtualIP to a dict representation for passing to the API.
[ "Convert", "this", "VirtualIP", "to", "a", "dict", "representation", "for", "passing", "to", "the", "API", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1210-L1217
18,049
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerClient.allowed_domains
def allowed_domains(self): """ This property lists the allowed domains for a load balancer. The allowed domains are restrictions set for the allowed domain names used for adding load balancer nodes. In order to submit a domain name as an address for the load balancer node to add, the user must verify that the domain is valid by using the List Allowed Domains call. Once verified, simply supply the domain name in place of the node's address in the add_nodes() call. """ if self._allowed_domains is None: uri = "/loadbalancers/alloweddomains" resp, body = self.method_get(uri) dom_list = body["allowedDomains"] self._allowed_domains = [itm["allowedDomain"]["name"] for itm in dom_list] return self._allowed_domains
python
def allowed_domains(self): if self._allowed_domains is None: uri = "/loadbalancers/alloweddomains" resp, body = self.method_get(uri) dom_list = body["allowedDomains"] self._allowed_domains = [itm["allowedDomain"]["name"] for itm in dom_list] return self._allowed_domains
[ "def", "allowed_domains", "(", "self", ")", ":", "if", "self", ".", "_allowed_domains", "is", "None", ":", "uri", "=", "\"/loadbalancers/alloweddomains\"", "resp", ",", "body", "=", "self", ".", "method_get", "(", "uri", ")", "dom_list", "=", "body", "[", ...
This property lists the allowed domains for a load balancer. The allowed domains are restrictions set for the allowed domain names used for adding load balancer nodes. In order to submit a domain name as an address for the load balancer node to add, the user must verify that the domain is valid by using the List Allowed Domains call. Once verified, simply supply the domain name in place of the node's address in the add_nodes() call.
[ "This", "property", "lists", "the", "allowed", "domains", "for", "a", "load", "balancer", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1267-L1284
18,050
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerClient.algorithms
def algorithms(self): """ Returns a list of available load balancing algorithms. """ if self._algorithms is None: uri = "/loadbalancers/algorithms" resp, body = self.method_get(uri) self._algorithms = [alg["name"] for alg in body["algorithms"]] return self._algorithms
python
def algorithms(self): if self._algorithms is None: uri = "/loadbalancers/algorithms" resp, body = self.method_get(uri) self._algorithms = [alg["name"] for alg in body["algorithms"]] return self._algorithms
[ "def", "algorithms", "(", "self", ")", ":", "if", "self", ".", "_algorithms", "is", "None", ":", "uri", "=", "\"/loadbalancers/algorithms\"", "resp", ",", "body", "=", "self", ".", "method_get", "(", "uri", ")", "self", ".", "_algorithms", "=", "[", "alg...
Returns a list of available load balancing algorithms.
[ "Returns", "a", "list", "of", "available", "load", "balancing", "algorithms", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1288-L1296
18,051
pycontribs/pyrax
pyrax/cloudloadbalancers.py
CloudLoadBalancerClient.protocols
def protocols(self): """ Returns a list of available load balancing protocols. """ if self._protocols is None: uri = "/loadbalancers/protocols" resp, body = self.method_get(uri) self._protocols = [proto["name"] for proto in body["protocols"]] return self._protocols
python
def protocols(self): if self._protocols is None: uri = "/loadbalancers/protocols" resp, body = self.method_get(uri) self._protocols = [proto["name"] for proto in body["protocols"]] return self._protocols
[ "def", "protocols", "(", "self", ")", ":", "if", "self", ".", "_protocols", "is", "None", ":", "uri", "=", "\"/loadbalancers/protocols\"", "resp", ",", "body", "=", "self", ".", "method_get", "(", "uri", ")", "self", ".", "_protocols", "=", "[", "proto",...
Returns a list of available load balancing protocols.
[ "Returns", "a", "list", "of", "available", "load", "balancing", "protocols", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/cloudloadbalancers.py#L1300-L1308
18,052
pycontribs/pyrax
samples/autoscale/create_scaling_group.py
safe_int
def safe_int(val, allow_zero=True): """ This function converts the six.moves.input values to integers. It handles invalid entries, and optionally forbids values of zero. """ try: ret = int(val) except ValueError: print("Sorry, '%s' is not a valid integer." % val) return False if not allow_zero and ret == 0: print("Please enter a non-zero integer.") return False return ret
python
def safe_int(val, allow_zero=True): try: ret = int(val) except ValueError: print("Sorry, '%s' is not a valid integer." % val) return False if not allow_zero and ret == 0: print("Please enter a non-zero integer.") return False return ret
[ "def", "safe_int", "(", "val", ",", "allow_zero", "=", "True", ")", ":", "try", ":", "ret", "=", "int", "(", "val", ")", "except", "ValueError", ":", "print", "(", "\"Sorry, '%s' is not a valid integer.\"", "%", "val", ")", "return", "False", "if", "not", ...
This function converts the six.moves.input values to integers. It handles invalid entries, and optionally forbids values of zero.
[ "This", "function", "converts", "the", "six", ".", "moves", ".", "input", "values", "to", "integers", ".", "It", "handles", "invalid", "entries", "and", "optionally", "forbids", "values", "of", "zero", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/samples/autoscale/create_scaling_group.py#L33-L46
18,053
pycontribs/pyrax
pyrax/exceptions.py
from_response
def from_response(response, body): """ Return an instance of a ClientException or subclass based on an httplib2 response. Usage:: resp, body = http.request(...) if resp.status_code != 200: raise exception_from_response(resp, body) """ if isinstance(response, dict): status = response.get("status_code") else: status = response.status_code cls = _code_map.get(int(status), ClientException) # import pyrax # pyrax.utils.trace() request_id = response.headers.get("x-compute-request-id") if body: message = "n/a" details = "n/a" if isinstance(body, dict): message = body.get("message") details = body.get("details") if message is details is None: error = body[next(iter(body))] if isinstance(error, dict): message = error.get("message", None) details = error.get("details", None) else: message = error details = None else: message = body return cls(code=status, message=message, details=details, request_id=request_id) else: return cls(code=status, request_id=request_id)
python
def from_response(response, body): if isinstance(response, dict): status = response.get("status_code") else: status = response.status_code cls = _code_map.get(int(status), ClientException) # import pyrax # pyrax.utils.trace() request_id = response.headers.get("x-compute-request-id") if body: message = "n/a" details = "n/a" if isinstance(body, dict): message = body.get("message") details = body.get("details") if message is details is None: error = body[next(iter(body))] if isinstance(error, dict): message = error.get("message", None) details = error.get("details", None) else: message = error details = None else: message = body return cls(code=status, message=message, details=details, request_id=request_id) else: return cls(code=status, request_id=request_id)
[ "def", "from_response", "(", "response", ",", "body", ")", ":", "if", "isinstance", "(", "response", ",", "dict", ")", ":", "status", "=", "response", ".", "get", "(", "\"status_code\"", ")", "else", ":", "status", "=", "response", ".", "status_code", "c...
Return an instance of a ClientException or subclass based on an httplib2 response. Usage:: resp, body = http.request(...) if resp.status_code != 200: raise exception_from_response(resp, body)
[ "Return", "an", "instance", "of", "a", "ClientException", "or", "subclass", "based", "on", "an", "httplib2", "response", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/exceptions.py#L451-L491
18,054
pycontribs/pyrax
pyrax/image.py
assure_image
def assure_image(fnc): """ Converts a image ID passed as the 'image' parameter to a image object. """ @wraps(fnc) def _wrapped(self, img, *args, **kwargs): if not isinstance(img, Image): # Must be the ID img = self._manager.get(img) return fnc(self, img, *args, **kwargs) return _wrapped
python
def assure_image(fnc): @wraps(fnc) def _wrapped(self, img, *args, **kwargs): if not isinstance(img, Image): # Must be the ID img = self._manager.get(img) return fnc(self, img, *args, **kwargs) return _wrapped
[ "def", "assure_image", "(", "fnc", ")", ":", "@", "wraps", "(", "fnc", ")", "def", "_wrapped", "(", "self", ",", "img", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "img", ",", "Image", ")", ":", "# Must be...
Converts a image ID passed as the 'image' parameter to a image object.
[ "Converts", "a", "image", "ID", "passed", "as", "the", "image", "parameter", "to", "a", "image", "object", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L34-L44
18,055
pycontribs/pyrax
pyrax/image.py
ImageManager.list_all
def list_all(self, name=None, visibility=None, member_status=None, owner=None, tag=None, status=None, size_min=None, size_max=None, sort_key=None, sort_dir=None): """ Returns all of the images in one call, rather than in paginated batches. """ def strip_version(uri): """ The 'next' uri contains a redundant version number. We need to strip it to use in the method_get() call. """ pos = uri.find("/images") return uri[pos:] obj_class = self.resource_class resp, resp_body = self.list(name=name, visibility=visibility, member_status=member_status, owner=owner, tag=tag, status=status, size_min=size_min, size_max=size_max, sort_key=sort_key, sort_dir=sort_dir, return_raw=True) data = resp_body.get(self.plural_response_key, resp_body) next_uri = strip_version(resp_body.get("next", "")) ret = [obj_class(manager=self, info=res) for res in data if res] while next_uri: resp, resp_body = self.api.method_get(next_uri) data = resp_body.get(self.plural_response_key, resp_body) next_uri = strip_version(resp_body.get("next", "")) ret.extend([obj_class(manager=self, info=res) for res in data if res]) return ret
python
def list_all(self, name=None, visibility=None, member_status=None, owner=None, tag=None, status=None, size_min=None, size_max=None, sort_key=None, sort_dir=None): def strip_version(uri): """ The 'next' uri contains a redundant version number. We need to strip it to use in the method_get() call. """ pos = uri.find("/images") return uri[pos:] obj_class = self.resource_class resp, resp_body = self.list(name=name, visibility=visibility, member_status=member_status, owner=owner, tag=tag, status=status, size_min=size_min, size_max=size_max, sort_key=sort_key, sort_dir=sort_dir, return_raw=True) data = resp_body.get(self.plural_response_key, resp_body) next_uri = strip_version(resp_body.get("next", "")) ret = [obj_class(manager=self, info=res) for res in data if res] while next_uri: resp, resp_body = self.api.method_get(next_uri) data = resp_body.get(self.plural_response_key, resp_body) next_uri = strip_version(resp_body.get("next", "")) ret.extend([obj_class(manager=self, info=res) for res in data if res]) return ret
[ "def", "list_all", "(", "self", ",", "name", "=", "None", ",", "visibility", "=", "None", ",", "member_status", "=", "None", ",", "owner", "=", "None", ",", "tag", "=", "None", ",", "status", "=", "None", ",", "size_min", "=", "None", ",", "size_max"...
Returns all of the images in one call, rather than in paginated batches.
[ "Returns", "all", "of", "the", "images", "in", "one", "call", "rather", "than", "in", "paginated", "batches", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L223-L252
18,056
pycontribs/pyrax
pyrax/image.py
ImageManager.update_image_member
def update_image_member(self, img_id, status): """ Updates the image whose ID is given with the status specified. This must be called by the user whose project_id is in the members for the image. If called by the owner of the image, an InvalidImageMember exception will be raised. Valid values for 'status' include: pending accepted rejected Any other value will result in an InvalidImageMemberStatus exception being raised. """ if status not in ("pending", "accepted", "rejected"): raise exc.InvalidImageMemberStatus("The status value must be one " "of 'accepted', 'rejected', or 'pending'. Received: '%s'" % status) api = self.api project_id = api.identity.tenant_id uri = "/%s/%s/members/%s" % (self.uri_base, img_id, project_id) body = {"status": status} try: resp, resp_body = self.api.method_put(uri, body=body) except exc.NotFound as e: raise exc.InvalidImageMember("The update member request could not " "be completed. No member request for that image was found.")
python
def update_image_member(self, img_id, status): if status not in ("pending", "accepted", "rejected"): raise exc.InvalidImageMemberStatus("The status value must be one " "of 'accepted', 'rejected', or 'pending'. Received: '%s'" % status) api = self.api project_id = api.identity.tenant_id uri = "/%s/%s/members/%s" % (self.uri_base, img_id, project_id) body = {"status": status} try: resp, resp_body = self.api.method_put(uri, body=body) except exc.NotFound as e: raise exc.InvalidImageMember("The update member request could not " "be completed. No member request for that image was found.")
[ "def", "update_image_member", "(", "self", ",", "img_id", ",", "status", ")", ":", "if", "status", "not", "in", "(", "\"pending\"", ",", "\"accepted\"", ",", "\"rejected\"", ")", ":", "raise", "exc", ".", "InvalidImageMemberStatus", "(", "\"The status value must...
Updates the image whose ID is given with the status specified. This must be called by the user whose project_id is in the members for the image. If called by the owner of the image, an InvalidImageMember exception will be raised. Valid values for 'status' include: pending accepted rejected Any other value will result in an InvalidImageMemberStatus exception being raised.
[ "Updates", "the", "image", "whose", "ID", "is", "given", "with", "the", "status", "specified", ".", "This", "must", "be", "called", "by", "the", "user", "whose", "project_id", "is", "in", "the", "members", "for", "the", "image", ".", "If", "called", "by"...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L319-L345
18,057
pycontribs/pyrax
pyrax/image.py
ImageMemberManager.create
def create(self, name, *args, **kwargs): """ Need to wrap the default call to handle exceptions. """ try: return super(ImageMemberManager, self).create(name, *args, **kwargs) except Exception as e: if e.http_status == 403: raise exc.UnsharableImage("You cannot share a public image.") else: raise
python
def create(self, name, *args, **kwargs): try: return super(ImageMemberManager, self).create(name, *args, **kwargs) except Exception as e: if e.http_status == 403: raise exc.UnsharableImage("You cannot share a public image.") else: raise
[ "def", "create", "(", "self", ",", "name", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "try", ":", "return", "super", "(", "ImageMemberManager", ",", "self", ")", ".", "create", "(", "name", ",", "*", "args", ",", "*", "*", "kwargs", ")"...
Need to wrap the default call to handle exceptions.
[ "Need", "to", "wrap", "the", "default", "call", "to", "handle", "exceptions", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L361-L371
18,058
pycontribs/pyrax
pyrax/image.py
ImageTasksManager.create
def create(self, name, *args, **kwargs): """ Standard task creation, but first check for the existence of the containers, and raise an exception if they don't exist. """ cont = kwargs.get("cont") if cont: # Verify that it exists. If it doesn't, a NoSuchContainer exception # will be raised. api = self.api rgn = api.region_name cf = api.identity.object_store[rgn].client cf.get_container(cont) return super(ImageTasksManager, self).create(name, *args, **kwargs)
python
def create(self, name, *args, **kwargs): cont = kwargs.get("cont") if cont: # Verify that it exists. If it doesn't, a NoSuchContainer exception # will be raised. api = self.api rgn = api.region_name cf = api.identity.object_store[rgn].client cf.get_container(cont) return super(ImageTasksManager, self).create(name, *args, **kwargs)
[ "def", "create", "(", "self", ",", "name", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "cont", "=", "kwargs", ".", "get", "(", "\"cont\"", ")", "if", "cont", ":", "# Verify that it exists. If it doesn't, a NoSuchContainer exception", "# will be raised."...
Standard task creation, but first check for the existence of the containers, and raise an exception if they don't exist.
[ "Standard", "task", "creation", "but", "first", "check", "for", "the", "existence", "of", "the", "containers", "and", "raise", "an", "exception", "if", "they", "don", "t", "exist", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L420-L433
18,059
pycontribs/pyrax
pyrax/image.py
JSONSchemaManager.images
def images(self): """ Returns a json-schema document that represents an image members entity, which is a container of image member entities. """ uri = "/%s/images" % self.uri_base resp, resp_body = self.api.method_get(uri) return resp_body
python
def images(self): uri = "/%s/images" % self.uri_base resp, resp_body = self.api.method_get(uri) return resp_body
[ "def", "images", "(", "self", ")", ":", "uri", "=", "\"/%s/images\"", "%", "self", ".", "uri_base", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_get", "(", "uri", ")", "return", "resp_body" ]
Returns a json-schema document that represents an image members entity, which is a container of image member entities.
[ "Returns", "a", "json", "-", "schema", "document", "that", "represents", "an", "image", "members", "entity", "which", "is", "a", "container", "of", "image", "member", "entities", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L448-L455
18,060
pycontribs/pyrax
pyrax/image.py
JSONSchemaManager.image
def image(self): """ Returns a json-schema document that represents a single image entity. """ uri = "/%s/image" % self.uri_base resp, resp_body = self.api.method_get(uri) return resp_body
python
def image(self): uri = "/%s/image" % self.uri_base resp, resp_body = self.api.method_get(uri) return resp_body
[ "def", "image", "(", "self", ")", ":", "uri", "=", "\"/%s/image\"", "%", "self", ".", "uri_base", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_get", "(", "uri", ")", "return", "resp_body" ]
Returns a json-schema document that represents a single image entity.
[ "Returns", "a", "json", "-", "schema", "document", "that", "represents", "a", "single", "image", "entity", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L458-L464
18,061
pycontribs/pyrax
pyrax/image.py
JSONSchemaManager.image_tasks
def image_tasks(self): """ Returns a json-schema document that represents a container of tasks entities. """ uri = "/%s/tasks" % self.uri_base resp, resp_body = self.api.method_get(uri) return resp_body
python
def image_tasks(self): uri = "/%s/tasks" % self.uri_base resp, resp_body = self.api.method_get(uri) return resp_body
[ "def", "image_tasks", "(", "self", ")", ":", "uri", "=", "\"/%s/tasks\"", "%", "self", ".", "uri_base", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_get", "(", "uri", ")", "return", "resp_body" ]
Returns a json-schema document that represents a container of tasks entities.
[ "Returns", "a", "json", "-", "schema", "document", "that", "represents", "a", "container", "of", "tasks", "entities", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L487-L494
18,062
pycontribs/pyrax
pyrax/image.py
JSONSchemaManager.image_task
def image_task(self): """ Returns a json-schema document that represents an task entity. """ uri = "/%s/task" % self.uri_base resp, resp_body = self.api.method_get(uri) return resp_body
python
def image_task(self): uri = "/%s/task" % self.uri_base resp, resp_body = self.api.method_get(uri) return resp_body
[ "def", "image_task", "(", "self", ")", ":", "uri", "=", "\"/%s/task\"", "%", "self", ".", "uri_base", "resp", ",", "resp_body", "=", "self", ".", "api", ".", "method_get", "(", "uri", ")", "return", "resp_body" ]
Returns a json-schema document that represents an task entity.
[ "Returns", "a", "json", "-", "schema", "document", "that", "represents", "an", "task", "entity", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L497-L503
18,063
pycontribs/pyrax
pyrax/image.py
ImageClient.export_task
def export_task(self, img, cont): """ Creates a task to export the specified image to the swift container named in the 'cont' parameter. If the container does not exist, a NoSuchContainer exception is raised. The 'img' parameter can be either an Image object or the ID of an image. If these do not correspond to a valid image, a NotFound exception is raised. """ return self._tasks_manager.create("export", img=img, cont=cont)
python
def export_task(self, img, cont): return self._tasks_manager.create("export", img=img, cont=cont)
[ "def", "export_task", "(", "self", ",", "img", ",", "cont", ")", ":", "return", "self", ".", "_tasks_manager", ".", "create", "(", "\"export\"", ",", "img", "=", "img", ",", "cont", "=", "cont", ")" ]
Creates a task to export the specified image to the swift container named in the 'cont' parameter. If the container does not exist, a NoSuchContainer exception is raised. The 'img' parameter can be either an Image object or the ID of an image. If these do not correspond to a valid image, a NotFound exception is raised.
[ "Creates", "a", "task", "to", "export", "the", "specified", "image", "to", "the", "swift", "container", "named", "in", "the", "cont", "parameter", ".", "If", "the", "container", "does", "not", "exist", "a", "NoSuchContainer", "exception", "is", "raised", "."...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L670-L680
18,064
pycontribs/pyrax
pyrax/image.py
ImageClient.import_task
def import_task(self, img, cont, img_format=None, img_name=None): """ Creates a task to import the specified image from the swift container named in the 'cont' parameter. The new image will be named the same as the object in the container unless you specify a value for the 'img_name' parameter. By default it is assumed that the image is in 'vhd' format; if it is another format, you must specify that in the 'img_format' parameter. """ return self._tasks_manager.create("import", img=img, cont=cont, img_format=img_format, img_name=img_name)
python
def import_task(self, img, cont, img_format=None, img_name=None): return self._tasks_manager.create("import", img=img, cont=cont, img_format=img_format, img_name=img_name)
[ "def", "import_task", "(", "self", ",", "img", ",", "cont", ",", "img_format", "=", "None", ",", "img_name", "=", "None", ")", ":", "return", "self", ".", "_tasks_manager", ".", "create", "(", "\"import\"", ",", "img", "=", "img", ",", "cont", "=", "...
Creates a task to import the specified image from the swift container named in the 'cont' parameter. The new image will be named the same as the object in the container unless you specify a value for the 'img_name' parameter. By default it is assumed that the image is in 'vhd' format; if it is another format, you must specify that in the 'img_format' parameter.
[ "Creates", "a", "task", "to", "import", "the", "specified", "image", "from", "the", "swift", "container", "named", "in", "the", "cont", "parameter", ".", "The", "new", "image", "will", "be", "named", "the", "same", "as", "the", "object", "in", "the", "co...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/image.py#L683-L694
18,065
pycontribs/pyrax
pyrax/__init__.py
set_setting
def set_setting(key, val, env=None): """ Changes the value of the specified key in the current environment, or in another environment if specified. """ return settings.set(key, val, env=env)
python
def set_setting(key, val, env=None): return settings.set(key, val, env=env)
[ "def", "set_setting", "(", "key", ",", "val", ",", "env", "=", "None", ")", ":", "return", "settings", ".", "set", "(", "key", ",", "val", ",", "env", "=", "env", ")" ]
Changes the value of the specified key in the current environment, or in another environment if specified.
[ "Changes", "the", "value", "of", "the", "specified", "key", "in", "the", "current", "environment", "or", "in", "another", "environment", "if", "specified", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L376-L381
18,066
pycontribs/pyrax
pyrax/__init__.py
create_context
def create_context(id_type=None, env=None, username=None, password=None, tenant_id=None, tenant_name=None, api_key=None, verify_ssl=None): """ Returns an instance of the specified identity class, or if none is specified, an instance of the current setting for 'identity_class'. You may optionally set the environment by passing the name of that environment in the 'env' parameter. """ if env: set_environment(env) return _create_identity(id_type=id_type, username=username, password=password, tenant_id=tenant_id, tenant_name=tenant_name, api_key=api_key, verify_ssl=verify_ssl, return_context=True)
python
def create_context(id_type=None, env=None, username=None, password=None, tenant_id=None, tenant_name=None, api_key=None, verify_ssl=None): if env: set_environment(env) return _create_identity(id_type=id_type, username=username, password=password, tenant_id=tenant_id, tenant_name=tenant_name, api_key=api_key, verify_ssl=verify_ssl, return_context=True)
[ "def", "create_context", "(", "id_type", "=", "None", ",", "env", "=", "None", ",", "username", "=", "None", ",", "password", "=", "None", ",", "tenant_id", "=", "None", ",", "tenant_name", "=", "None", ",", "api_key", "=", "None", ",", "verify_ssl", "...
Returns an instance of the specified identity class, or if none is specified, an instance of the current setting for 'identity_class'. You may optionally set the environment by passing the name of that environment in the 'env' parameter.
[ "Returns", "an", "instance", "of", "the", "specified", "identity", "class", "or", "if", "none", "is", "specified", "an", "instance", "of", "the", "current", "setting", "for", "identity_class", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L390-L403
18,067
pycontribs/pyrax
pyrax/__init__.py
_create_identity
def _create_identity(id_type=None, username=None, password=None, tenant_id=None, tenant_name=None, api_key=None, verify_ssl=None, return_context=False): """ Creates an instance of the current identity_class and assigns it to the module-level name 'identity' by default. If 'return_context' is True, the module-level 'identity' is untouched, and instead the instance is returned. """ if id_type: cls = _import_identity(id_type) else: cls = settings.get("identity_class") if not cls: raise exc.IdentityClassNotDefined("No identity class has " "been defined for the current environment.") if verify_ssl is None: verify_ssl = get_setting("verify_ssl") context = cls(username=username, password=password, tenant_id=tenant_id, tenant_name=tenant_name, api_key=api_key, verify_ssl=verify_ssl) if return_context: return context else: global identity identity = context
python
def _create_identity(id_type=None, username=None, password=None, tenant_id=None, tenant_name=None, api_key=None, verify_ssl=None, return_context=False): if id_type: cls = _import_identity(id_type) else: cls = settings.get("identity_class") if not cls: raise exc.IdentityClassNotDefined("No identity class has " "been defined for the current environment.") if verify_ssl is None: verify_ssl = get_setting("verify_ssl") context = cls(username=username, password=password, tenant_id=tenant_id, tenant_name=tenant_name, api_key=api_key, verify_ssl=verify_ssl) if return_context: return context else: global identity identity = context
[ "def", "_create_identity", "(", "id_type", "=", "None", ",", "username", "=", "None", ",", "password", "=", "None", ",", "tenant_id", "=", "None", ",", "tenant_name", "=", "None", ",", "api_key", "=", "None", ",", "verify_ssl", "=", "None", ",", "return_...
Creates an instance of the current identity_class and assigns it to the module-level name 'identity' by default. If 'return_context' is True, the module-level 'identity' is untouched, and instead the instance is returned.
[ "Creates", "an", "instance", "of", "the", "current", "identity_class", "and", "assigns", "it", "to", "the", "module", "-", "level", "name", "identity", "by", "default", ".", "If", "return_context", "is", "True", "the", "module", "-", "level", "identity", "is...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L406-L429
18,068
pycontribs/pyrax
pyrax/__init__.py
_assure_identity
def _assure_identity(fnc): """Ensures that the 'identity' attribute is not None.""" def _wrapped(*args, **kwargs): if identity is None: _create_identity() return fnc(*args, **kwargs) return _wrapped
python
def _assure_identity(fnc): def _wrapped(*args, **kwargs): if identity is None: _create_identity() return fnc(*args, **kwargs) return _wrapped
[ "def", "_assure_identity", "(", "fnc", ")", ":", "def", "_wrapped", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "identity", "is", "None", ":", "_create_identity", "(", ")", "return", "fnc", "(", "*", "args", ",", "*", "*", "kwargs", ...
Ensures that the 'identity' attribute is not None.
[ "Ensures", "that", "the", "identity", "attribute", "is", "not", "None", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L432-L438
18,069
pycontribs/pyrax
pyrax/__init__.py
_require_auth
def _require_auth(fnc): """Authentication decorator.""" @wraps(fnc) @_assure_identity def _wrapped(*args, **kwargs): if not identity.authenticated: msg = "Authentication required before calling '%s'." % fnc.__name__ raise exc.NotAuthenticated(msg) return fnc(*args, **kwargs) return _wrapped
python
def _require_auth(fnc): @wraps(fnc) @_assure_identity def _wrapped(*args, **kwargs): if not identity.authenticated: msg = "Authentication required before calling '%s'." % fnc.__name__ raise exc.NotAuthenticated(msg) return fnc(*args, **kwargs) return _wrapped
[ "def", "_require_auth", "(", "fnc", ")", ":", "@", "wraps", "(", "fnc", ")", "@", "_assure_identity", "def", "_wrapped", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "identity", ".", "authenticated", ":", "msg", "=", "\"Authenticat...
Authentication decorator.
[ "Authentication", "decorator", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L441-L450
18,070
pycontribs/pyrax
pyrax/__init__.py
_safe_region
def _safe_region(region=None, context=None): """Value to use when no region is specified.""" ret = region or settings.get("region") context = context or identity if not ret: # Nothing specified; get the default from the identity object. if not context: _create_identity() context = identity ret = context.get_default_region() if not ret: # Use the first available region try: ret = regions[0] except IndexError: ret = "" return ret
python
def _safe_region(region=None, context=None): ret = region or settings.get("region") context = context or identity if not ret: # Nothing specified; get the default from the identity object. if not context: _create_identity() context = identity ret = context.get_default_region() if not ret: # Use the first available region try: ret = regions[0] except IndexError: ret = "" return ret
[ "def", "_safe_region", "(", "region", "=", "None", ",", "context", "=", "None", ")", ":", "ret", "=", "region", "or", "settings", ".", "get", "(", "\"region\"", ")", "context", "=", "context", "or", "identity", "if", "not", "ret", ":", "# Nothing specifi...
Value to use when no region is specified.
[ "Value", "to", "use", "when", "no", "region", "is", "specified", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L453-L469
18,071
pycontribs/pyrax
pyrax/__init__.py
auth_with_token
def auth_with_token(token, tenant_id=None, tenant_name=None, region=None): """ If you already have a valid token and either a tenant ID or name, you can call this to configure the identity and available services. """ global regions, services identity.auth_with_token(token, tenant_id=tenant_id, tenant_name=tenant_name) regions = tuple(identity.regions) services = tuple(identity.services.keys()) connect_to_services(region=region)
python
def auth_with_token(token, tenant_id=None, tenant_name=None, region=None): global regions, services identity.auth_with_token(token, tenant_id=tenant_id, tenant_name=tenant_name) regions = tuple(identity.regions) services = tuple(identity.services.keys()) connect_to_services(region=region)
[ "def", "auth_with_token", "(", "token", ",", "tenant_id", "=", "None", ",", "tenant_name", "=", "None", ",", "region", "=", "None", ")", ":", "global", "regions", ",", "services", "identity", ".", "auth_with_token", "(", "token", ",", "tenant_id", "=", "te...
If you already have a valid token and either a tenant ID or name, you can call this to configure the identity and available services.
[ "If", "you", "already", "have", "a", "valid", "token", "and", "either", "a", "tenant", "ID", "or", "name", "you", "can", "call", "this", "to", "configure", "the", "identity", "and", "available", "services", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L473-L483
18,072
pycontribs/pyrax
pyrax/__init__.py
set_credentials
def set_credentials(username, api_key=None, password=None, region=None, tenant_id=None, authenticate=True): """ Set the credentials directly, and then try to authenticate. If the region is passed, it will authenticate against the proper endpoint for that region, and set the default region for connections. """ global regions, services pw_key = password or api_key region = _safe_region(region) tenant_id = tenant_id or settings.get("tenant_id") identity.set_credentials(username=username, password=pw_key, tenant_id=tenant_id, region=region, authenticate=authenticate) regions = tuple(identity.regions) services = tuple(identity.services.keys()) connect_to_services(region=region)
python
def set_credentials(username, api_key=None, password=None, region=None, tenant_id=None, authenticate=True): global regions, services pw_key = password or api_key region = _safe_region(region) tenant_id = tenant_id or settings.get("tenant_id") identity.set_credentials(username=username, password=pw_key, tenant_id=tenant_id, region=region, authenticate=authenticate) regions = tuple(identity.regions) services = tuple(identity.services.keys()) connect_to_services(region=region)
[ "def", "set_credentials", "(", "username", ",", "api_key", "=", "None", ",", "password", "=", "None", ",", "region", "=", "None", ",", "tenant_id", "=", "None", ",", "authenticate", "=", "True", ")", ":", "global", "regions", ",", "services", "pw_key", "...
Set the credentials directly, and then try to authenticate. If the region is passed, it will authenticate against the proper endpoint for that region, and set the default region for connections.
[ "Set", "the", "credentials", "directly", "and", "then", "try", "to", "authenticate", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L487-L503
18,073
pycontribs/pyrax
pyrax/__init__.py
keyring_auth
def keyring_auth(username=None, region=None, authenticate=True): """ Use the password stored within the keyring to authenticate. If a username is supplied, that name is used; otherwise, the keyring_username value from the config file is used. If there is no username defined, or if the keyring module is not installed, or there is no password set for the given username, the appropriate errors will be raised. If the region is passed, it will authenticate against the proper endpoint for that region, and set the default region for connections. """ if not keyring: # Module not installed raise exc.KeyringModuleNotInstalled("The 'keyring' Python module is " "not installed on this system.") if username is None: username = settings.get("keyring_username") if not username: raise exc.KeyringUsernameMissing("No username specified for keyring " "authentication.") password = keyring.get_password("pyrax", username) if password is None: raise exc.KeyringPasswordNotFound("No password was found for the " "username '%s'." % username) set_credentials(username, password, region=region, authenticate=authenticate)
python
def keyring_auth(username=None, region=None, authenticate=True): if not keyring: # Module not installed raise exc.KeyringModuleNotInstalled("The 'keyring' Python module is " "not installed on this system.") if username is None: username = settings.get("keyring_username") if not username: raise exc.KeyringUsernameMissing("No username specified for keyring " "authentication.") password = keyring.get_password("pyrax", username) if password is None: raise exc.KeyringPasswordNotFound("No password was found for the " "username '%s'." % username) set_credentials(username, password, region=region, authenticate=authenticate)
[ "def", "keyring_auth", "(", "username", "=", "None", ",", "region", "=", "None", ",", "authenticate", "=", "True", ")", ":", "if", "not", "keyring", ":", "# Module not installed", "raise", "exc", ".", "KeyringModuleNotInstalled", "(", "\"The 'keyring' Python modul...
Use the password stored within the keyring to authenticate. If a username is supplied, that name is used; otherwise, the keyring_username value from the config file is used. If there is no username defined, or if the keyring module is not installed, or there is no password set for the given username, the appropriate errors will be raised. If the region is passed, it will authenticate against the proper endpoint for that region, and set the default region for connections.
[ "Use", "the", "password", "stored", "within", "the", "keyring", "to", "authenticate", ".", "If", "a", "username", "is", "supplied", "that", "name", "is", "used", ";", "otherwise", "the", "keyring_username", "value", "from", "the", "config", "file", "is", "us...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L536-L563
18,074
pycontribs/pyrax
pyrax/__init__.py
clear_credentials
def clear_credentials(): """De-authenticate by clearing all the names back to None.""" global identity, regions, services, cloudservers, cloudfiles, cloud_cdn global cloud_loadbalancers, cloud_databases, cloud_blockstorage, cloud_dns global cloud_networks, cloud_monitoring, autoscale, images, queues identity = None regions = tuple() services = tuple() cloudservers = None cloudfiles = None cloud_cdn = None cloud_loadbalancers = None cloud_databases = None cloud_blockstorage = None cloud_dns = None cloud_networks = None cloud_monitoring = None autoscale = None images = None queues = None
python
def clear_credentials(): global identity, regions, services, cloudservers, cloudfiles, cloud_cdn global cloud_loadbalancers, cloud_databases, cloud_blockstorage, cloud_dns global cloud_networks, cloud_monitoring, autoscale, images, queues identity = None regions = tuple() services = tuple() cloudservers = None cloudfiles = None cloud_cdn = None cloud_loadbalancers = None cloud_databases = None cloud_blockstorage = None cloud_dns = None cloud_networks = None cloud_monitoring = None autoscale = None images = None queues = None
[ "def", "clear_credentials", "(", ")", ":", "global", "identity", ",", "regions", ",", "services", ",", "cloudservers", ",", "cloudfiles", ",", "cloud_cdn", "global", "cloud_loadbalancers", ",", "cloud_databases", ",", "cloud_blockstorage", ",", "cloud_dns", "global"...
De-authenticate by clearing all the names back to None.
[ "De", "-", "authenticate", "by", "clearing", "all", "the", "names", "back", "to", "None", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L587-L606
18,075
pycontribs/pyrax
pyrax/__init__.py
connect_to_services
def connect_to_services(region=None): """Establishes authenticated connections to the various cloud APIs.""" global cloudservers, cloudfiles, cloud_loadbalancers, cloud_databases global cloud_blockstorage, cloud_dns, cloud_networks, cloud_monitoring global autoscale, images, queues, cloud_cdn cloudservers = connect_to_cloudservers(region=region) cloudfiles = connect_to_cloudfiles(region=region) cloud_cdn = connect_to_cloud_cdn(region=region) cloud_loadbalancers = connect_to_cloud_loadbalancers(region=region) cloud_databases = connect_to_cloud_databases(region=region) cloud_blockstorage = connect_to_cloud_blockstorage(region=region) cloud_dns = connect_to_cloud_dns(region=region) cloud_networks = connect_to_cloud_networks(region=region) cloud_monitoring = connect_to_cloud_monitoring(region=region) autoscale = connect_to_autoscale(region=region) images = connect_to_images(region=region) queues = connect_to_queues(region=region)
python
def connect_to_services(region=None): global cloudservers, cloudfiles, cloud_loadbalancers, cloud_databases global cloud_blockstorage, cloud_dns, cloud_networks, cloud_monitoring global autoscale, images, queues, cloud_cdn cloudservers = connect_to_cloudservers(region=region) cloudfiles = connect_to_cloudfiles(region=region) cloud_cdn = connect_to_cloud_cdn(region=region) cloud_loadbalancers = connect_to_cloud_loadbalancers(region=region) cloud_databases = connect_to_cloud_databases(region=region) cloud_blockstorage = connect_to_cloud_blockstorage(region=region) cloud_dns = connect_to_cloud_dns(region=region) cloud_networks = connect_to_cloud_networks(region=region) cloud_monitoring = connect_to_cloud_monitoring(region=region) autoscale = connect_to_autoscale(region=region) images = connect_to_images(region=region) queues = connect_to_queues(region=region)
[ "def", "connect_to_services", "(", "region", "=", "None", ")", ":", "global", "cloudservers", ",", "cloudfiles", ",", "cloud_loadbalancers", ",", "cloud_databases", "global", "cloud_blockstorage", ",", "cloud_dns", ",", "cloud_networks", ",", "cloud_monitoring", "glob...
Establishes authenticated connections to the various cloud APIs.
[ "Establishes", "authenticated", "connections", "to", "the", "various", "cloud", "APIs", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L620-L636
18,076
pycontribs/pyrax
pyrax/__init__.py
_get_service_endpoint
def _get_service_endpoint(context, svc, region=None, public=True): """ Parses the services dict to get the proper endpoint for the given service. """ region = _safe_region(region) # If a specific context is passed, use that. Otherwise, use the global # identity reference. context = context or identity url_type = {True: "public", False: "private"}[public] svc_obj = context.services.get(svc) if not svc_obj: return None ep = svc_obj.endpoints.get(region, {}).get(url_type) if not ep: # Try the "ALL" region, and substitute the actual region ep = svc_obj.endpoints.get("ALL", {}).get(url_type) return ep
python
def _get_service_endpoint(context, svc, region=None, public=True): region = _safe_region(region) # If a specific context is passed, use that. Otherwise, use the global # identity reference. context = context or identity url_type = {True: "public", False: "private"}[public] svc_obj = context.services.get(svc) if not svc_obj: return None ep = svc_obj.endpoints.get(region, {}).get(url_type) if not ep: # Try the "ALL" region, and substitute the actual region ep = svc_obj.endpoints.get("ALL", {}).get(url_type) return ep
[ "def", "_get_service_endpoint", "(", "context", ",", "svc", ",", "region", "=", "None", ",", "public", "=", "True", ")", ":", "region", "=", "_safe_region", "(", "region", ")", "# If a specific context is passed, use that. Otherwise, use the global", "# identity referen...
Parses the services dict to get the proper endpoint for the given service.
[ "Parses", "the", "services", "dict", "to", "get", "the", "proper", "endpoint", "for", "the", "given", "service", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L639-L655
18,077
pycontribs/pyrax
pyrax/__init__.py
connect_to_cloudservers
def connect_to_cloudservers(region=None, context=None, verify_ssl=None, **kwargs): """Creates a client for working with cloud servers.""" context = context or identity _cs_auth_plugin.discover_auth_systems() id_type = get_setting("identity_type") if id_type != "keystone": auth_plugin = _cs_auth_plugin.load_plugin(id_type) else: auth_plugin = None region = _safe_region(region, context=context) mgt_url = _get_service_endpoint(context, "compute", region) cloudservers = None if not mgt_url: # Service is not available return if verify_ssl is None: insecure = not get_setting("verify_ssl") else: insecure = not verify_ssl try: extensions = nc.discover_extensions(_cs_max_version) except AttributeError: extensions = None clt_class = _cs_client.get_client_class(_cs_max_version) cloudservers = clt_class(context.username, context.password, project_id=context.tenant_id, auth_url=context.auth_endpoint, auth_system=id_type, region_name=region, service_type="compute", auth_plugin=auth_plugin, insecure=insecure, extensions=extensions, http_log_debug=_http_debug, **kwargs) agt = cloudservers.client.USER_AGENT cloudservers.client.USER_AGENT = _make_agent_name(agt) cloudservers.client.management_url = mgt_url cloudservers.client.auth_token = context.token cloudservers.exceptions = _cs_exceptions # Add some convenience methods cloudservers.list_images = cloudservers.images.list cloudservers.list_flavors = cloudservers.flavors.list cloudservers.list = cloudservers.servers.list def list_base_images(): """ Returns a list of all base images; excludes any images created by this account. """ return [image for image in cloudservers.images.list() if not hasattr(image, "server")] def list_snapshots(): """ Returns a list of all images created by this account; in other words, it excludes all the base images. """ return [image for image in cloudservers.images.list() if hasattr(image, "server")] def find_images_by_name(expr): """ Returns a list of images whose name contains the specified expression. The value passed is treated as a regular expression, allowing for more specific searches than simple wildcards. The matching is done in a case-insensitive manner. """ return [image for image in cloudservers.images.list() if re.search(expr, image.name, re.I)] cloudservers.list_base_images = list_base_images cloudservers.list_snapshots = list_snapshots cloudservers.find_images_by_name = find_images_by_name cloudservers.identity = identity return cloudservers
python
def connect_to_cloudservers(region=None, context=None, verify_ssl=None, **kwargs): context = context or identity _cs_auth_plugin.discover_auth_systems() id_type = get_setting("identity_type") if id_type != "keystone": auth_plugin = _cs_auth_plugin.load_plugin(id_type) else: auth_plugin = None region = _safe_region(region, context=context) mgt_url = _get_service_endpoint(context, "compute", region) cloudservers = None if not mgt_url: # Service is not available return if verify_ssl is None: insecure = not get_setting("verify_ssl") else: insecure = not verify_ssl try: extensions = nc.discover_extensions(_cs_max_version) except AttributeError: extensions = None clt_class = _cs_client.get_client_class(_cs_max_version) cloudservers = clt_class(context.username, context.password, project_id=context.tenant_id, auth_url=context.auth_endpoint, auth_system=id_type, region_name=region, service_type="compute", auth_plugin=auth_plugin, insecure=insecure, extensions=extensions, http_log_debug=_http_debug, **kwargs) agt = cloudservers.client.USER_AGENT cloudservers.client.USER_AGENT = _make_agent_name(agt) cloudservers.client.management_url = mgt_url cloudservers.client.auth_token = context.token cloudservers.exceptions = _cs_exceptions # Add some convenience methods cloudservers.list_images = cloudservers.images.list cloudservers.list_flavors = cloudservers.flavors.list cloudservers.list = cloudservers.servers.list def list_base_images(): """ Returns a list of all base images; excludes any images created by this account. """ return [image for image in cloudservers.images.list() if not hasattr(image, "server")] def list_snapshots(): """ Returns a list of all images created by this account; in other words, it excludes all the base images. """ return [image for image in cloudservers.images.list() if hasattr(image, "server")] def find_images_by_name(expr): """ Returns a list of images whose name contains the specified expression. The value passed is treated as a regular expression, allowing for more specific searches than simple wildcards. The matching is done in a case-insensitive manner. """ return [image for image in cloudservers.images.list() if re.search(expr, image.name, re.I)] cloudservers.list_base_images = list_base_images cloudservers.list_snapshots = list_snapshots cloudservers.find_images_by_name = find_images_by_name cloudservers.identity = identity return cloudservers
[ "def", "connect_to_cloudservers", "(", "region", "=", "None", ",", "context", "=", "None", ",", "verify_ssl", "=", "None", ",", "*", "*", "kwargs", ")", ":", "context", "=", "context", "or", "identity", "_cs_auth_plugin", ".", "discover_auth_systems", "(", "...
Creates a client for working with cloud servers.
[ "Creates", "a", "client", "for", "working", "with", "cloud", "servers", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L658-L727
18,078
pycontribs/pyrax
pyrax/__init__.py
connect_to_cloud_cdn
def connect_to_cloud_cdn(region=None): """Creates a client for working with cloud loadbalancers.""" global default_region # (nicholaskuechler/keekz) 2017-11-30 - Not a very elegant solution... # Cloud CDN only exists in 2 regions: DFW and LON # But this isn't playing nicely with the identity service catalog results. # US auth based regions (DFW, ORD, IAD, SYD, HKG) need to use CDN in DFW # UK auth based regions (LON) need to use CDN in LON if region in ['DFW', 'IAD', 'ORD', 'SYD', 'HKG']: return _create_client(ep_name="cdn", region="DFW") elif region in ['LON']: return _create_client(ep_name="cdn", region="LON") else: if default_region in ['DFW', 'IAD', 'ORD', 'SYD', 'HKG']: return _create_client(ep_name="cdn", region="DFW") elif default_region in ['LON']: return _create_client(ep_name="cdn", region="LON") else: return _create_client(ep_name="cdn", region=region)
python
def connect_to_cloud_cdn(region=None): global default_region # (nicholaskuechler/keekz) 2017-11-30 - Not a very elegant solution... # Cloud CDN only exists in 2 regions: DFW and LON # But this isn't playing nicely with the identity service catalog results. # US auth based regions (DFW, ORD, IAD, SYD, HKG) need to use CDN in DFW # UK auth based regions (LON) need to use CDN in LON if region in ['DFW', 'IAD', 'ORD', 'SYD', 'HKG']: return _create_client(ep_name="cdn", region="DFW") elif region in ['LON']: return _create_client(ep_name="cdn", region="LON") else: if default_region in ['DFW', 'IAD', 'ORD', 'SYD', 'HKG']: return _create_client(ep_name="cdn", region="DFW") elif default_region in ['LON']: return _create_client(ep_name="cdn", region="LON") else: return _create_client(ep_name="cdn", region=region)
[ "def", "connect_to_cloud_cdn", "(", "region", "=", "None", ")", ":", "global", "default_region", "# (nicholaskuechler/keekz) 2017-11-30 - Not a very elegant solution...", "# Cloud CDN only exists in 2 regions: DFW and LON", "# But this isn't playing nicely with the identity service catalog r...
Creates a client for working with cloud loadbalancers.
[ "Creates", "a", "client", "for", "working", "with", "cloud", "loadbalancers", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L767-L785
18,079
pycontribs/pyrax
pyrax/__init__.py
connect_to_images
def connect_to_images(region=None, public=True): """Creates a client for working with Images.""" return _create_client(ep_name="image", region=region, public=public)
python
def connect_to_images(region=None, public=True): return _create_client(ep_name="image", region=region, public=public)
[ "def", "connect_to_images", "(", "region", "=", "None", ",", "public", "=", "True", ")", ":", "return", "_create_client", "(", "ep_name", "=", "\"image\"", ",", "region", "=", "region", ",", "public", "=", "public", ")" ]
Creates a client for working with Images.
[ "Creates", "a", "client", "for", "working", "with", "Images", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L818-L820
18,080
pycontribs/pyrax
pyrax/__init__.py
connect_to_queues
def connect_to_queues(region=None, public=True): """Creates a client for working with Queues.""" return _create_client(ep_name="queues", region=region, public=public)
python
def connect_to_queues(region=None, public=True): return _create_client(ep_name="queues", region=region, public=public)
[ "def", "connect_to_queues", "(", "region", "=", "None", ",", "public", "=", "True", ")", ":", "return", "_create_client", "(", "ep_name", "=", "\"queues\"", ",", "region", "=", "region", ",", "public", "=", "public", ")" ]
Creates a client for working with Queues.
[ "Creates", "a", "client", "for", "working", "with", "Queues", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L823-L825
18,081
pycontribs/pyrax
pyrax/__init__.py
Settings.get
def get(self, key, env=None): """ Returns the config setting for the specified environment. If no environment is specified, the value for the current environment is returned. If an unknown key or environment is passed, None is returned. """ if env is None: env = self.environment try: ret = self._settings[env][key] except KeyError: ret = None if ret is None: # See if it's set in the environment if key == "identity_class": # This is defined via the identity_type env_var = self.env_dct.get("identity_type") ityp = os.environ.get(env_var) if ityp: return _import_identity(ityp) else: env_var = self.env_dct.get(key) if env_var is not None: ret = os.environ.get(env_var) return ret
python
def get(self, key, env=None): if env is None: env = self.environment try: ret = self._settings[env][key] except KeyError: ret = None if ret is None: # See if it's set in the environment if key == "identity_class": # This is defined via the identity_type env_var = self.env_dct.get("identity_type") ityp = os.environ.get(env_var) if ityp: return _import_identity(ityp) else: env_var = self.env_dct.get(key) if env_var is not None: ret = os.environ.get(env_var) return ret
[ "def", "get", "(", "self", ",", "key", ",", "env", "=", "None", ")", ":", "if", "env", "is", "None", ":", "env", "=", "self", ".", "environment", "try", ":", "ret", "=", "self", ".", "_settings", "[", "env", "]", "[", "key", "]", "except", "Key...
Returns the config setting for the specified environment. If no environment is specified, the value for the current environment is returned. If an unknown key or environment is passed, None is returned.
[ "Returns", "the", "config", "setting", "for", "the", "specified", "environment", ".", "If", "no", "environment", "is", "specified", "the", "value", "for", "the", "current", "environment", "is", "returned", ".", "If", "an", "unknown", "key", "or", "environment"...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L183-L207
18,082
pycontribs/pyrax
pyrax/__init__.py
Settings.set
def set(self, key, val, env=None): """ Changes the value for the setting specified by 'key' to the new value. By default this will change the current environment, but you can change values in other environments by passing the name of that environment as the 'env' parameter. """ if env is None: env = self.environment else: if env not in self._settings: raise exc.EnvironmentNotFound("There is no environment named " "'%s'." % env) dct = self._settings[env] if key not in dct: raise exc.InvalidSetting("The setting '%s' is not defined." % key) dct[key] = val if key == "identity_type": # If setting the identity_type, also change the identity_class. dct["identity_class"] = _import_identity(val) elif key == "region": if not identity: return current = identity.region if current == val: return if "LON" in (current, val): # This is an outlier, as it has a separate auth identity.region = val elif key == "verify_ssl": if not identity: return identity.verify_ssl = val
python
def set(self, key, val, env=None): if env is None: env = self.environment else: if env not in self._settings: raise exc.EnvironmentNotFound("There is no environment named " "'%s'." % env) dct = self._settings[env] if key not in dct: raise exc.InvalidSetting("The setting '%s' is not defined." % key) dct[key] = val if key == "identity_type": # If setting the identity_type, also change the identity_class. dct["identity_class"] = _import_identity(val) elif key == "region": if not identity: return current = identity.region if current == val: return if "LON" in (current, val): # This is an outlier, as it has a separate auth identity.region = val elif key == "verify_ssl": if not identity: return identity.verify_ssl = val
[ "def", "set", "(", "self", ",", "key", ",", "val", ",", "env", "=", "None", ")", ":", "if", "env", "is", "None", ":", "env", "=", "self", ".", "environment", "else", ":", "if", "env", "not", "in", "self", ".", "_settings", ":", "raise", "exc", ...
Changes the value for the setting specified by 'key' to the new value. By default this will change the current environment, but you can change values in other environments by passing the name of that environment as the 'env' parameter.
[ "Changes", "the", "value", "for", "the", "setting", "specified", "by", "key", "to", "the", "new", "value", ".", "By", "default", "this", "will", "change", "the", "current", "environment", "but", "you", "can", "change", "values", "in", "other", "environments"...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L210-L242
18,083
pycontribs/pyrax
pyrax/__init__.py
Settings.read_config
def read_config(self, config_file): """ Parses the specified configuration file and stores the values. Raises an InvalidConfigurationFile exception if the file is not well-formed. """ cfg = ConfigParser.SafeConfigParser() try: cfg.read(config_file) except ConfigParser.MissingSectionHeaderError as e: # The file exists, but doesn't have the correct format. raise exc.InvalidConfigurationFile(e) def safe_get(section, option, default=None): try: return cfg.get(section, option) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): return default # A common mistake is including credentials in the config file. If any # values are found, issue a warning so that the developer can correct # this problem. creds_found = False for section in cfg.sections(): if section == "settings": section_name = "default" self._default_set = True else: section_name = section # Check for included credentials for key in ("username", "password", "api_key"): if creds_found: break if safe_get(section, key): creds_found = True dct = self._settings[section_name] = {} dct["region"] = safe_get(section, "region", default_region) ityp = safe_get(section, "identity_type") if ityp: dct["identity_type"] = _id_type(ityp) dct["identity_class"] = _import_identity(ityp) # Handle both the old and new names for this setting. debug = safe_get(section, "debug") if debug is None: debug = safe_get(section, "http_debug", "False") dct["http_debug"] = debug == "True" verify_ssl = safe_get(section, "verify_ssl", "True") dct["verify_ssl"] = verify_ssl == "True" dct["keyring_username"] = safe_get(section, "keyring_username") dct["encoding"] = safe_get(section, "encoding", default_encoding) dct["auth_endpoint"] = safe_get(section, "auth_endpoint") dct["tenant_name"] = safe_get(section, "tenant_name") dct["tenant_id"] = safe_get(section, "tenant_id") use_servicenet = safe_get(section, "use_servicenet", "False") dct["use_servicenet"] = use_servicenet == "True" app_agent = safe_get(section, "custom_user_agent") if app_agent: # Customize the user-agent string with the app name. dct["user_agent"] = "%s %s" % (app_agent, USER_AGENT) else: dct["user_agent"] = USER_AGENT # If this is the first section, make it the default if not self._default_set: self._settings["default"] = self._settings[section] self._default_set = True if creds_found: warnings.warn("Login credentials were detected in your .pyrax.cfg " "file. These have been ignored, but you should remove " "them and either place them in a credential file, or " "consider using another means of authentication. More " "information on the use of credential files can be found " "in the 'docs/getting_started.md' document.")
python
def read_config(self, config_file): cfg = ConfigParser.SafeConfigParser() try: cfg.read(config_file) except ConfigParser.MissingSectionHeaderError as e: # The file exists, but doesn't have the correct format. raise exc.InvalidConfigurationFile(e) def safe_get(section, option, default=None): try: return cfg.get(section, option) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): return default # A common mistake is including credentials in the config file. If any # values are found, issue a warning so that the developer can correct # this problem. creds_found = False for section in cfg.sections(): if section == "settings": section_name = "default" self._default_set = True else: section_name = section # Check for included credentials for key in ("username", "password", "api_key"): if creds_found: break if safe_get(section, key): creds_found = True dct = self._settings[section_name] = {} dct["region"] = safe_get(section, "region", default_region) ityp = safe_get(section, "identity_type") if ityp: dct["identity_type"] = _id_type(ityp) dct["identity_class"] = _import_identity(ityp) # Handle both the old and new names for this setting. debug = safe_get(section, "debug") if debug is None: debug = safe_get(section, "http_debug", "False") dct["http_debug"] = debug == "True" verify_ssl = safe_get(section, "verify_ssl", "True") dct["verify_ssl"] = verify_ssl == "True" dct["keyring_username"] = safe_get(section, "keyring_username") dct["encoding"] = safe_get(section, "encoding", default_encoding) dct["auth_endpoint"] = safe_get(section, "auth_endpoint") dct["tenant_name"] = safe_get(section, "tenant_name") dct["tenant_id"] = safe_get(section, "tenant_id") use_servicenet = safe_get(section, "use_servicenet", "False") dct["use_servicenet"] = use_servicenet == "True" app_agent = safe_get(section, "custom_user_agent") if app_agent: # Customize the user-agent string with the app name. dct["user_agent"] = "%s %s" % (app_agent, USER_AGENT) else: dct["user_agent"] = USER_AGENT # If this is the first section, make it the default if not self._default_set: self._settings["default"] = self._settings[section] self._default_set = True if creds_found: warnings.warn("Login credentials were detected in your .pyrax.cfg " "file. These have been ignored, but you should remove " "them and either place them in a credential file, or " "consider using another means of authentication. More " "information on the use of credential files can be found " "in the 'docs/getting_started.md' document.")
[ "def", "read_config", "(", "self", ",", "config_file", ")", ":", "cfg", "=", "ConfigParser", ".", "SafeConfigParser", "(", ")", "try", ":", "cfg", ".", "read", "(", "config_file", ")", "except", "ConfigParser", ".", "MissingSectionHeaderError", "as", "e", ":...
Parses the specified configuration file and stores the values. Raises an InvalidConfigurationFile exception if the file is not well-formed.
[ "Parses", "the", "specified", "configuration", "file", "and", "stores", "the", "values", ".", "Raises", "an", "InvalidConfigurationFile", "exception", "if", "the", "file", "is", "not", "well", "-", "formed", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/__init__.py#L272-L343
18,084
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSRecord.update
def update(self, data=None, priority=None, ttl=None, comment=None): """ Modifies this record. """ return self.manager.update_record(self.domain_id, self, data=data, priority=priority, ttl=ttl, comment=comment)
python
def update(self, data=None, priority=None, ttl=None, comment=None): return self.manager.update_record(self.domain_id, self, data=data, priority=priority, ttl=ttl, comment=comment)
[ "def", "update", "(", "self", ",", "data", "=", "None", ",", "priority", "=", "None", ",", "ttl", "=", "None", ",", "comment", "=", "None", ")", ":", "return", "self", ".", "manager", ".", "update_record", "(", "self", ".", "domain_id", ",", "self", ...
Modifies this record.
[ "Modifies", "this", "record", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L70-L75
18,085
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSDomain.delete
def delete(self, delete_subdomains=False): """ Deletes this domain and all of its resource records. If this domain has subdomains, each subdomain will now become a root domain. If you wish to also delete any subdomains, pass True to 'delete_subdomains'. """ self.manager.delete(self, delete_subdomains=delete_subdomains)
python
def delete(self, delete_subdomains=False): self.manager.delete(self, delete_subdomains=delete_subdomains)
[ "def", "delete", "(", "self", ",", "delete_subdomains", "=", "False", ")", ":", "self", ".", "manager", ".", "delete", "(", "self", ",", "delete_subdomains", "=", "delete_subdomains", ")" ]
Deletes this domain and all of its resource records. If this domain has subdomains, each subdomain will now become a root domain. If you wish to also delete any subdomains, pass True to 'delete_subdomains'.
[ "Deletes", "this", "domain", "and", "all", "of", "its", "resource", "records", ".", "If", "this", "domain", "has", "subdomains", "each", "subdomain", "will", "now", "become", "a", "root", "domain", ".", "If", "you", "wish", "to", "also", "delete", "any", ...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L97-L103
18,086
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSDomain.list_subdomains
def list_subdomains(self, limit=None, offset=None): """ Returns a list of all subdomains for this domain. """ return self.manager.list_subdomains(self, limit=limit, offset=offset)
python
def list_subdomains(self, limit=None, offset=None): return self.manager.list_subdomains(self, limit=limit, offset=offset)
[ "def", "list_subdomains", "(", "self", ",", "limit", "=", "None", ",", "offset", "=", "None", ")", ":", "return", "self", ".", "manager", ".", "list_subdomains", "(", "self", ",", "limit", "=", "limit", ",", "offset", "=", "offset", ")" ]
Returns a list of all subdomains for this domain.
[ "Returns", "a", "list", "of", "all", "subdomains", "for", "this", "domain", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L163-L167
18,087
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSDomain.list_records
def list_records(self, limit=None, offset=None): """ Returns a list of all records configured for this domain. """ return self.manager.list_records(self, limit=limit, offset=offset)
python
def list_records(self, limit=None, offset=None): return self.manager.list_records(self, limit=limit, offset=offset)
[ "def", "list_records", "(", "self", ",", "limit", "=", "None", ",", "offset", "=", "None", ")", ":", "return", "self", ".", "manager", ".", "list_records", "(", "self", ",", "limit", "=", "limit", ",", "offset", "=", "offset", ")" ]
Returns a list of all records configured for this domain.
[ "Returns", "a", "list", "of", "all", "records", "configured", "for", "this", "domain", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L170-L174
18,088
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSDomain.search_records
def search_records(self, record_type, name=None, data=None): """ Returns a list of all records configured for this domain that match the supplied search criteria. """ return self.manager.search_records(self, record_type=record_type, name=name, data=data)
python
def search_records(self, record_type, name=None, data=None): return self.manager.search_records(self, record_type=record_type, name=name, data=data)
[ "def", "search_records", "(", "self", ",", "record_type", ",", "name", "=", "None", ",", "data", "=", "None", ")", ":", "return", "self", ".", "manager", ".", "search_records", "(", "self", ",", "record_type", "=", "record_type", ",", "name", "=", "name"...
Returns a list of all records configured for this domain that match the supplied search criteria.
[ "Returns", "a", "list", "of", "all", "records", "configured", "for", "this", "domain", "that", "match", "the", "supplied", "search", "criteria", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L177-L183
18,089
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSDomain.update_record
def update_record(self, record, data=None, priority=None, ttl=None, comment=None): """ Modifies an existing record for this domain. """ return self.manager.update_record(self, record, data=data, priority=priority, ttl=ttl, comment=comment)
python
def update_record(self, record, data=None, priority=None, ttl=None, comment=None): return self.manager.update_record(self, record, data=data, priority=priority, ttl=ttl, comment=comment)
[ "def", "update_record", "(", "self", ",", "record", ",", "data", "=", "None", ",", "priority", "=", "None", ",", "ttl", "=", "None", ",", "comment", "=", "None", ")", ":", "return", "self", ".", "manager", ".", "update_record", "(", "self", ",", "rec...
Modifies an existing record for this domain.
[ "Modifies", "an", "existing", "record", "for", "this", "domain", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L228-L234
18,090
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager._create_body
def _create_body(self, name, emailAddress, ttl=3600, comment=None, subdomains=None, records=None): """ Creates the appropriate dict for creating a new domain. """ if subdomains is None: subdomains = [] if records is None: records = [] body = {"domains": [{ "name": name, "emailAddress": emailAddress, "ttl": ttl, "comment": comment, "subdomains": { "domains": subdomains }, "recordsList": { "records": records }, }]} return body
python
def _create_body(self, name, emailAddress, ttl=3600, comment=None, subdomains=None, records=None): if subdomains is None: subdomains = [] if records is None: records = [] body = {"domains": [{ "name": name, "emailAddress": emailAddress, "ttl": ttl, "comment": comment, "subdomains": { "domains": subdomains }, "recordsList": { "records": records }, }]} return body
[ "def", "_create_body", "(", "self", ",", "name", ",", "emailAddress", ",", "ttl", "=", "3600", ",", "comment", "=", "None", ",", "subdomains", "=", "None", ",", "records", "=", "None", ")", ":", "if", "subdomains", "is", "None", ":", "subdomains", "=",...
Creates the appropriate dict for creating a new domain.
[ "Creates", "the", "appropriate", "dict", "for", "creating", "a", "new", "domain", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L301-L322
18,091
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager._reset_paging
def _reset_paging(self, service, body=None): """ Resets the internal attributes when there is no current paging request. """ if service == "all": for svc in self._paging.keys(): svc_dct = self._paging[svc] svc_dct["next_uri"] = svc_dct["prev_uri"] = None svc_dct["total_entries"] = None return svc_dct = self._paging[service] svc_dct["next_uri"] = svc_dct["prev_uri"] = None svc_dct["total_entries"] = None if not body: return svc_dct["total_entries"] = body.get("totalEntries") links = body.get("links") uri_base = self.uri_base if links: for link in links: href = link["href"] pos = href.index(uri_base) page_uri = href[pos - 1:] if link["rel"] == "next": svc_dct["next_uri"] = page_uri elif link["rel"] == "previous": svc_dct["prev_uri"] = page_uri
python
def _reset_paging(self, service, body=None): if service == "all": for svc in self._paging.keys(): svc_dct = self._paging[svc] svc_dct["next_uri"] = svc_dct["prev_uri"] = None svc_dct["total_entries"] = None return svc_dct = self._paging[service] svc_dct["next_uri"] = svc_dct["prev_uri"] = None svc_dct["total_entries"] = None if not body: return svc_dct["total_entries"] = body.get("totalEntries") links = body.get("links") uri_base = self.uri_base if links: for link in links: href = link["href"] pos = href.index(uri_base) page_uri = href[pos - 1:] if link["rel"] == "next": svc_dct["next_uri"] = page_uri elif link["rel"] == "previous": svc_dct["prev_uri"] = page_uri
[ "def", "_reset_paging", "(", "self", ",", "service", ",", "body", "=", "None", ")", ":", "if", "service", "==", "\"all\"", ":", "for", "svc", "in", "self", ".", "_paging", ".", "keys", "(", ")", ":", "svc_dct", "=", "self", ".", "_paging", "[", "sv...
Resets the internal attributes when there is no current paging request.
[ "Resets", "the", "internal", "attributes", "when", "there", "is", "no", "current", "paging", "request", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L342-L368
18,092
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager.list
def list(self, limit=None, offset=None): """Gets a list of all domains, or optionally a page of domains.""" uri = "/%s%s" % (self.uri_base, self._get_pagination_qs(limit, offset)) return self._list(uri)
python
def list(self, limit=None, offset=None): uri = "/%s%s" % (self.uri_base, self._get_pagination_qs(limit, offset)) return self._list(uri)
[ "def", "list", "(", "self", ",", "limit", "=", "None", ",", "offset", "=", "None", ")", ":", "uri", "=", "\"/%s%s\"", "%", "(", "self", ".", "uri_base", ",", "self", ".", "_get_pagination_qs", "(", "limit", ",", "offset", ")", ")", "return", "self", ...
Gets a list of all domains, or optionally a page of domains.
[ "Gets", "a", "list", "of", "all", "domains", "or", "optionally", "a", "page", "of", "domains", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L382-L385
18,093
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager.list_previous_page
def list_previous_page(self): """ When paging through results, this will return the previous page, using the same limit. If there are no more results, a NoMoreResults exception will be raised. """ uri = self._paging.get("domain", {}).get("prev_uri") if uri is None: raise exc.NoMoreResults("There are no previous pages of domains " "to list.") return self._list(uri)
python
def list_previous_page(self): uri = self._paging.get("domain", {}).get("prev_uri") if uri is None: raise exc.NoMoreResults("There are no previous pages of domains " "to list.") return self._list(uri)
[ "def", "list_previous_page", "(", "self", ")", ":", "uri", "=", "self", ".", "_paging", ".", "get", "(", "\"domain\"", ",", "{", "}", ")", ".", "get", "(", "\"prev_uri\"", ")", "if", "uri", "is", "None", ":", "raise", "exc", ".", "NoMoreResults", "("...
When paging through results, this will return the previous page, using the same limit. If there are no more results, a NoMoreResults exception will be raised.
[ "When", "paging", "through", "results", "this", "will", "return", "the", "previous", "page", "using", "the", "same", "limit", ".", "If", "there", "are", "no", "more", "results", "a", "NoMoreResults", "exception", "will", "be", "raised", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L410-L420
18,094
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager.list_next_page
def list_next_page(self): """ When paging through results, this will return the next page, using the same limit. If there are no more results, a NoMoreResults exception will be raised. """ uri = self._paging.get("domain", {}).get("next_uri") if uri is None: raise exc.NoMoreResults("There are no more pages of domains to " "list.") return self._list(uri)
python
def list_next_page(self): uri = self._paging.get("domain", {}).get("next_uri") if uri is None: raise exc.NoMoreResults("There are no more pages of domains to " "list.") return self._list(uri)
[ "def", "list_next_page", "(", "self", ")", ":", "uri", "=", "self", ".", "_paging", ".", "get", "(", "\"domain\"", ",", "{", "}", ")", ".", "get", "(", "\"next_uri\"", ")", "if", "uri", "is", "None", ":", "raise", "exc", ".", "NoMoreResults", "(", ...
When paging through results, this will return the next page, using the same limit. If there are no more results, a NoMoreResults exception will be raised.
[ "When", "paging", "through", "results", "this", "will", "return", "the", "next", "page", "using", "the", "same", "limit", ".", "If", "there", "are", "no", "more", "results", "a", "NoMoreResults", "exception", "will", "be", "raised", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L423-L433
18,095
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager._retry_get
def _retry_get(self, uri): """ Handles GET calls to the Cloud DNS API in order to retry on empty body responses. """ for i in six.moves.range(DEFAULT_RETRY): resp, body = self.api.method_get(uri) if body: return resp, body # Tried too many times raise exc.ServiceResponseFailure("The Cloud DNS service failed to " "respond to the request.")
python
def _retry_get(self, uri): for i in six.moves.range(DEFAULT_RETRY): resp, body = self.api.method_get(uri) if body: return resp, body # Tried too many times raise exc.ServiceResponseFailure("The Cloud DNS service failed to " "respond to the request.")
[ "def", "_retry_get", "(", "self", ",", "uri", ")", ":", "for", "i", "in", "six", ".", "moves", ".", "range", "(", "DEFAULT_RETRY", ")", ":", "resp", ",", "body", "=", "self", ".", "api", ".", "method_get", "(", "uri", ")", "if", "body", ":", "ret...
Handles GET calls to the Cloud DNS API in order to retry on empty body responses.
[ "Handles", "GET", "calls", "to", "the", "Cloud", "DNS", "API", "in", "order", "to", "retry", "on", "empty", "body", "responses", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L449-L460
18,096
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager._process_async_error
def _process_async_error(self, resp_body, error_class): """ The DNS API does not return a consistent format for their error messages. This abstracts out the differences in order to present a single unified message in the exception to be raised. """ def _fmt_error(err): # Remove the cumbersome Java-esque message details = err.get("details", "").replace("\n", " ") if not details: details = err.get("message", "") return "%s (%s)" % (details, err.get("code", "")) error = resp_body.get("error", "") if "failedItems" in error: # Multi-error response faults = error.get("failedItems", {}).get("faults", []) msgs = [_fmt_error(fault) for fault in faults] msg = "\n".join(msgs) else: msg = _fmt_error(error) raise error_class(msg)
python
def _process_async_error(self, resp_body, error_class): def _fmt_error(err): # Remove the cumbersome Java-esque message details = err.get("details", "").replace("\n", " ") if not details: details = err.get("message", "") return "%s (%s)" % (details, err.get("code", "")) error = resp_body.get("error", "") if "failedItems" in error: # Multi-error response faults = error.get("failedItems", {}).get("faults", []) msgs = [_fmt_error(fault) for fault in faults] msg = "\n".join(msgs) else: msg = _fmt_error(error) raise error_class(msg)
[ "def", "_process_async_error", "(", "self", ",", "resp_body", ",", "error_class", ")", ":", "def", "_fmt_error", "(", "err", ")", ":", "# Remove the cumbersome Java-esque message", "details", "=", "err", ".", "get", "(", "\"details\"", ",", "\"\"", ")", ".", "...
The DNS API does not return a consistent format for their error messages. This abstracts out the differences in order to present a single unified message in the exception to be raised.
[ "The", "DNS", "API", "does", "not", "return", "a", "consistent", "format", "for", "their", "error", "messages", ".", "This", "abstracts", "out", "the", "differences", "in", "order", "to", "present", "a", "single", "unified", "message", "in", "the", "exceptio...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L521-L542
18,097
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager.delete
def delete(self, domain, delete_subdomains=False): """ Deletes the specified domain and all of its resource records. If the domain has subdomains, each subdomain will now become a root domain. If you wish to also delete any subdomains, pass True to 'delete_subdomains'. """ uri = "/%s/%s" % (self.uri_base, utils.get_id(domain)) if delete_subdomains: uri = "%s?deleteSubdomains=true" % uri resp, resp_body = self._async_call(uri, method="DELETE", error_class=exc.DomainDeletionFailed, has_response=False)
python
def delete(self, domain, delete_subdomains=False): uri = "/%s/%s" % (self.uri_base, utils.get_id(domain)) if delete_subdomains: uri = "%s?deleteSubdomains=true" % uri resp, resp_body = self._async_call(uri, method="DELETE", error_class=exc.DomainDeletionFailed, has_response=False)
[ "def", "delete", "(", "self", ",", "domain", ",", "delete_subdomains", "=", "False", ")", ":", "uri", "=", "\"/%s/%s\"", "%", "(", "self", ".", "uri_base", ",", "utils", ".", "get_id", "(", "domain", ")", ")", "if", "delete_subdomains", ":", "uri", "="...
Deletes the specified domain and all of its resource records. If the domain has subdomains, each subdomain will now become a root domain. If you wish to also delete any subdomains, pass True to 'delete_subdomains'.
[ "Deletes", "the", "specified", "domain", "and", "all", "of", "its", "resource", "records", ".", "If", "the", "domain", "has", "subdomains", "each", "subdomain", "will", "now", "become", "a", "root", "domain", ".", "If", "you", "wish", "to", "also", "delete...
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L576-L586
18,098
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager.list_subdomains
def list_subdomains(self, domain, limit=None, offset=None): """ Returns a list of all subdomains of the specified domain. """ # The commented-out uri is the official API, but it is # horribly slow. # uri = "/domains/%s/subdomains" % utils.get_id(domain) uri = "/domains?name=%s" % domain.name page_qs = self._get_pagination_qs(limit, offset) if page_qs: uri = "%s&%s" % (uri, page_qs[1:]) return self._list_subdomains(uri, domain.id)
python
def list_subdomains(self, domain, limit=None, offset=None): # The commented-out uri is the official API, but it is # horribly slow. # uri = "/domains/%s/subdomains" % utils.get_id(domain) uri = "/domains?name=%s" % domain.name page_qs = self._get_pagination_qs(limit, offset) if page_qs: uri = "%s&%s" % (uri, page_qs[1:]) return self._list_subdomains(uri, domain.id)
[ "def", "list_subdomains", "(", "self", ",", "domain", ",", "limit", "=", "None", ",", "offset", "=", "None", ")", ":", "# The commented-out uri is the official API, but it is", "# horribly slow.", "# uri = \"/domains/%s/subdomains\" % utils.get_id(domain)", "uri", "=",...
Returns a list of all subdomains of the specified domain.
[ "Returns", "a", "list", "of", "all", "subdomains", "of", "the", "specified", "domain", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L701-L712
18,099
pycontribs/pyrax
pyrax/clouddns.py
CloudDNSManager.list_subdomains_previous_page
def list_subdomains_previous_page(self): """ When paging through subdomain results, this will return the previous page, using the same limit. If there are no more results, a NoMoreResults exception will be raised. """ uri = self._paging.get("subdomain", {}).get("prev_uri") if uri is None: raise exc.NoMoreResults("There are no previous pages of subdomains " "to list.") return self._list_subdomains(uri)
python
def list_subdomains_previous_page(self): uri = self._paging.get("subdomain", {}).get("prev_uri") if uri is None: raise exc.NoMoreResults("There are no previous pages of subdomains " "to list.") return self._list_subdomains(uri)
[ "def", "list_subdomains_previous_page", "(", "self", ")", ":", "uri", "=", "self", ".", "_paging", ".", "get", "(", "\"subdomain\"", ",", "{", "}", ")", ".", "get", "(", "\"prev_uri\"", ")", "if", "uri", "is", "None", ":", "raise", "exc", ".", "NoMoreR...
When paging through subdomain results, this will return the previous page, using the same limit. If there are no more results, a NoMoreResults exception will be raised.
[ "When", "paging", "through", "subdomain", "results", "this", "will", "return", "the", "previous", "page", "using", "the", "same", "limit", ".", "If", "there", "are", "no", "more", "results", "a", "NoMoreResults", "exception", "will", "be", "raised", "." ]
9ddfd5064b3a292d7337906f3b2d5dce95b50b99
https://github.com/pycontribs/pyrax/blob/9ddfd5064b3a292d7337906f3b2d5dce95b50b99/pyrax/clouddns.py#L724-L734