| Total Complexity | 9 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | import requests |
||
| 5 | class SuggestNextIp(Action): |
||
| 6 | def run(self, subnet_id=None, subnet=None, name=None, vrf_group_id=None, vrf_group=None, |
||
| 7 | reserved_ip=None): |
||
| 8 | d42_server = self.config.get('d42_server', None) |
||
| 9 | if not d42_server: |
||
| 10 | raise ValueError('"d42_server" config value is required') |
||
| 11 | |||
| 12 | d42_username = self.config.get('d42_username', None) |
||
| 13 | if not d42_username: |
||
| 14 | raise ValueError('"d42_username" config value is required') |
||
| 15 | |||
| 16 | d42_password = self.config.get('d42_password', None) |
||
| 17 | if not d42_password: |
||
| 18 | raise ValueError('"d42_password" config value is required') |
||
| 19 | |||
| 20 | protocol = self.config.get('protocol', 'http') |
||
| 21 | |||
| 22 | verify = False |
||
| 23 | if self.config.get('verify_certificate', None) == 'true' and protocol == 'https': |
||
| 24 | verify = True |
||
| 25 | |||
| 26 | if not subnet_id and not subnet and not name: |
||
| 27 | raise ValueError('"subnet_id" or "subnet" or "name" value is required') |
||
| 28 | |||
| 29 | response = requests.get("%s://%s%s" % (protocol, d42_server, "/api/1.0/suggest_ip/"), |
||
| 30 | params={ |
||
| 31 | "subnet_id": subnet_id, |
||
| 32 | "subnet": subnet, |
||
| 33 | "name": name, |
||
| 34 | "vrf_group_id": vrf_group_id, |
||
| 35 | "vrf_group": vrf_group, |
||
| 36 | "reserved_ip": reserved_ip, |
||
| 37 | }, auth=(d42_username, d42_password), verify=verify) |
||
| 38 | |||
| 39 | return response.json()["ip"] |
||
| 40 |