Skip to content

Commit 7a78756

Browse files
authored
v0.5.0 release (#10)
* added proper content type header to all requests * convert data to json * strip None values on write request
1 parent 0bb9375 commit 7a78756

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Change Log
2+
## 0.5.0
3+
- Added proper application/json Content-Type header to all requests
24
## 0.4.2
35
- Changed the `id` parameter on `ipam_post_available_ips` to `prefix_id` so it does not auto convert to a detail route
46
## 0.4.1

actions/lib/action.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,34 @@ def _make_request(self, endpoint_uri, http_action, **kwargs):
2828

2929
headers = {
3030
'Authorization': 'Token ' + self.config['api_token'],
31-
'Accept': 'application/json'
31+
'Accept': 'application/json',
32+
'Content-Type': 'application/json',
3233
}
3334

3435
# transform `in__id` if present
3536
if kwargs.get('id__in'):
3637
kwargs['id__in'] = ','.join(kwargs['id__in'])
3738
self.logger.debug('id__in transformed to {}'.format(kwargs['id__in']))
3839

40+
# strip values which have a None value if we are making a write request
41+
if http_action != "GET":
42+
kwargs = {key: value for key, value in kwargs.items() if value is not None}
43+
3944
if http_action == "GET":
4045
self.logger.debug("Calling base get with kwargs: {}".format(kwargs))
4146
r = requests.get(url, verify=self.config['ssl_verify'], headers=headers, params=kwargs)
4247

4348
elif http_action == "POST":
4449
self.logger.debug("Calling base post with kwargs: {}".format(kwargs))
45-
r = requests.post(url, verify=self.config['ssl_verify'], headers=headers, data=kwargs)
50+
r = requests.post(url, verify=self.config['ssl_verify'], headers=headers, json=kwargs)
4651

4752
elif http_action == "PUT":
4853
self.logger.debug("Calling base put with kwargs: {}".format(kwargs))
49-
r = requests.put(url, verify=self.config['ssl_verify'], headers=headers, data=kwargs)
54+
r = requests.put(url, verify=self.config['ssl_verify'], headers=headers, json=kwargs)
5055

5156
elif http_action == "PATCH":
5257
self.logger.debug("Calling base patch with kwargs: {}".format(kwargs))
53-
r = requests.patch(url, verify=self.config['ssl_verify'], headers=headers, data=kwargs)
58+
r = requests.patch(url, verify=self.config['ssl_verify'], headers=headers, json=kwargs)
5459

5560
return {'raw': r.json()}
5661

pack.yaml

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

0 commit comments

Comments
 (0)