From 2279014db18329d25e0609ad0defe548ae9c0427 Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Sun, 21 Feb 2021 19:04:36 -0600 Subject: [PATCH] calculate IP version for allocate_ip; increment to v1.0.3 --- pom.xml | 2 +- src/main/python/allocate_ip/requirements.txt | 3 ++- src/main/python/allocate_ip/source.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 4e72487..c830ca5 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ conditions of the subcomponent's license, as noted in the LICENSE file. phpIPAM phpIPAM integration for vRA - 1.0.2 + 1.0.3 false true diff --git a/src/main/python/allocate_ip/requirements.txt b/src/main/python/allocate_ip/requirements.txt index 27bb602..88574fe 100644 --- a/src/main/python/allocate_ip/requirements.txt +++ b/src/main/python/allocate_ip/requirements.txt @@ -1,2 +1,3 @@ requests==2.21.0 -datetime \ No newline at end of file +datetime +ipaddress \ No newline at end of file diff --git a/src/main/python/allocate_ip/source.py b/src/main/python/allocate_ip/source.py index 7bdbd39..fa9e2e1 100644 --- a/src/main/python/allocate_ip/source.py +++ b/src/main/python/allocate_ip/source.py @@ -15,6 +15,7 @@ import requests from vra_ipam_utils.ipam import IPAM import logging from datetime import datetime +import ipaddress """ Example payload @@ -153,10 +154,11 @@ def allocate_in_range(range_id, resource, allocation, context, endpoint, bundle) allocate_req = requests.post(allocate_uri, data=payload, headers=token, verify=cert) allocate_req = allocate_req.json() if allocate_req['success']: + version = ipaddress.ip_address(allocate_req['data']).version result = { "ipAllocationId": allocation['id'], "ipRangeId": range_id, - "ipVersion": "IPv4", + "ipVersion": "IPv" + str(version), "ipAddresses": [allocate_req['data']] } logging.info(f"Successfully reserved {str(result['ipAddresses'])} for {vmName}.")