Skip to content

Commit 7cc924b

Browse files
authored
Merge pull request #21 from Onemind-Services-LLC/master
Added status code to the response
2 parents 4dc0ed3 + 8bc3027 commit 7cc924b

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 3.0.1
4+
5+
- Added status code to the response
6+
37
## 3.0.0
48

59
- Updated actions generated to cover all routes available in the NetBox 3.1 API.

actions/lib/action.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
__all__ = [
6-
'NetboxBaseAction'
6+
"NetboxBaseAction"
77
]
88

99

@@ -18,35 +18,35 @@ def make_request(self, endpoint_uri, http_action, **kwargs):
1818
"""Logic to make all types of requests
1919
"""
2020

21-
if self.config['use_https']:
22-
url = 'https://'
21+
if self.config["use_https"]:
22+
url = "https://"
2323
else:
24-
url = 'http://'
24+
url = "http://"
2525

26-
url = url + self.config['hostname'] + "/api" + endpoint_uri
26+
url = url + self.config["hostname"] + "/api" + endpoint_uri
2727

2828
headers = {
29-
'Authorization': 'Token ' + self.config['api_token'],
30-
'Accept': 'application/json',
31-
'Content-Type': 'application/json',
29+
"Authorization": "Token " + self.config["api_token"],
30+
"Accept": "application/json",
31+
"Content-Type": "application/json",
3232
}
3333

3434
# transform `id__in` if present
35-
if kwargs.get('id__in'):
36-
kwargs['id__in'] = ','.join(kwargs['id__in'])
37-
self.logger.debug('id__in transformed to {}'.format(kwargs['id__in']))
35+
if kwargs.get("id__in"):
36+
kwargs["id__in"] = ",".join(kwargs["id__in"])
37+
self.logger.debug("id__in transformed to {}".format(kwargs["id__in"]))
3838

3939
# transform `tags` if present
40-
if kwargs.get('tags'):
41-
kwargs['tags'] = ','.join(kwargs['tags'])
42-
self.logger.debug('tags transformed to {}'.format(kwargs['tags']))
40+
if kwargs.get("tags"):
41+
kwargs["tags"] = ",".join(kwargs["tags"])
42+
self.logger.debug("tags transformed to {}".format(kwargs["tags"]))
4343

4444
# strip values which have a None value if we are making a write request
4545
if http_action != "get":
4646
kwargs = {key: value for key, value in kwargs.items() if value is not None}
4747

4848
self.logger.debug("Calling base {} with kwargs: {}".format(http_action, kwargs))
49-
verify = self.config['ssl_verify']
49+
verify = self.config["ssl_verify"]
5050

5151
r = None
5252

@@ -65,11 +65,10 @@ def make_request(self, endpoint_uri, http_action, **kwargs):
6565
elif http_action == "delete":
6666
r = requests.delete(url, verify=verify, headers=headers)
6767
self.logger.info("Delete of ID {} returned status code {}".format(
68-
kwargs['id'],
68+
kwargs["id"],
6969
r.status_code)
7070
)
71-
return r.status_code == 204
7271

7372
if r:
74-
return {'raw': r.json()}
75-
return {'raw': {}}
73+
return {"raw": r.json(), "status": r.status_code}
74+
return {"raw": {}, "status": 404}

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords:
66
- networking
77
- ipam
88
- dcim
9-
version: 3.0.0
9+
version: 3.0.1
1010
author: John Anderson, Jefferson White
1111
1212
python_versions:

0 commit comments

Comments
 (0)