Skip to content

Commit bb73eda

Browse files
author
Aaron Sierra
committed
vultr: Drop deprecated v1 API support
The v1 API became completely unsupported by Vultr on August 14, 2023. https://docs.vultr.com/vultr-api-v1-to-v2-transition-strategies
1 parent 0d129b7 commit bb73eda

21 files changed

Lines changed: 4 additions & 2300 deletions

libcloud/common/vultr.py

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222
__all__ = [
2323
"API_HOST",
24-
"VultrConnection",
2524
"VultrException",
26-
"VultrResponse",
2725
"DEFAULT_API_VERSION",
2826
"VultrResponseV2",
2927
"VultrConnectionV2",
@@ -37,93 +35,6 @@
3735
DEFAULT_API_VERSION = "2"
3836

3937

40-
class VultrResponse(JsonResponse):
41-
objects = None
42-
error_dict = {} # type: Dict[str, str]
43-
errors = None
44-
ERROR_CODE_MAP = {
45-
400: "Invalid API location. Check the URL that you are using.",
46-
403: "Invalid or missing API key. Check that your API key is present"
47-
+ " and matches your assigned key.",
48-
405: "Invalid HTTP method. Check that the method (POST|GET) matches"
49-
+ " what the documentation indicates.",
50-
412: "Request failed. Check the response body for a more detailed" + " description.",
51-
500: "Internal server error. Try again at a later time.",
52-
503: "Rate limit hit. API requests are limited to an average of 1/s."
53-
+ " Try your request again later.",
54-
}
55-
56-
def __init__(self, response, connection):
57-
self.errors = []
58-
super().__init__(response=response, connection=connection)
59-
self.objects, self.errors = self.parse_body_and_errors()
60-
if not self.success():
61-
raise self._make_excp(self.errors[0])
62-
63-
def parse_body_and_errors(self):
64-
"""
65-
Returns JSON data in a python list.
66-
"""
67-
json_objects = []
68-
errors = []
69-
70-
if self.status in self.ERROR_CODE_MAP:
71-
self.error_dict["ERRORCODE"] = self.status
72-
self.error_dict["ERRORMESSAGE"] = self.ERROR_CODE_MAP[self.status]
73-
errors.append(self.error_dict)
74-
75-
js = super().parse_body()
76-
if isinstance(js, dict):
77-
js = [js]
78-
79-
json_objects.append(js)
80-
81-
return (json_objects, errors)
82-
83-
def _make_excp(self, error):
84-
"""
85-
Convert API error to a VultrException instance
86-
"""
87-
88-
return VultrException(error["ERRORCODE"], error["ERRORMESSAGE"])
89-
90-
def success(self):
91-
return len(self.errors) == 0
92-
93-
94-
class VultrConnection(ConnectionKey):
95-
"""
96-
A connection to the Vultr API
97-
"""
98-
99-
host = API_HOST
100-
responseCls = VultrResponse
101-
102-
def add_default_params(self, params):
103-
"""
104-
Returns default params such as api_key which is
105-
needed to perform an action.Returns a dictionary.
106-
Example:/v1/server/upgrade_plan?api_key=self.key
107-
"""
108-
params["api_key"] = self.key
109-
110-
return params
111-
112-
def add_default_headers(self, headers):
113-
"""
114-
Returns default headers such as content-type.
115-
Returns a dictionary.
116-
"""
117-
headers["Content-Type"] = "application/x-www-form-urlencoded"
118-
headers["Accept"] = "text/plain"
119-
120-
return headers
121-
122-
def set_path(self):
123-
self.path = "/v/"
124-
return self.path
125-
126-
12738
class VultrResponseV2(JsonResponse):
12839
valid_response_codes = [
12940
httplib.OK,

0 commit comments

Comments
 (0)