Skip to content

Commit

Permalink
Added the dhcp_options feature in the b1_ipam_subnet module (#11)
Browse files Browse the repository at this point in the history
* Added the dhcp_options feature in the b1_ipam_subnet module

* Added dhcp_options to argument_spec in b1_ipam_subnet

Co-authored-by: Krishna Ramabhadran <[email protected]>
  • Loading branch information
krishna-ramabhadran and Krishna Ramabhadran authored Apr 8, 2022
1 parent 27ade64 commit d316e41
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,21 @@ def flatten_dict_object(self,key,data):
for k,v in i.items():
payload[k]=v
return payload

def dhcp_options(self, key, data, dhcp_option_codes):
"""Create a list of DHCP option dicts"""
payload = []
for i in data[key]:
for k, v in i.items():
dhcp_option = {}
for item in dhcp_option_codes:
if item["name"] == k:
dhcp_option_code = item["id"]
break
if dhcp_option_code:
dhcp_option["option_code"] = dhcp_option_code
dhcp_option["option_value"] = v
dhcp_option["type"] = "option"
payload.append(dhcp_option)
return payload

Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ def create_subnet(data):
payload['comment'] = data['comment'] if 'comment' in data.keys() else ''
if 'tags' in data.keys() and data['tags']!=None:
payload['tags']=helper.flatten_dict_object('tags',data)
if "dhcp_options" in data.keys() and data["dhcp_options"] != None:
dhcp_option_codes = connector.get("/api/ddi/v1/dhcp/option_code")
if (
"results" in dhcp_option_codes[2].keys()
and len(dhcp_option_codes[2]["results"]) > 0
):
payload["dhcp_options"] = helper.dhcp_options(
"dhcp_options", data, dhcp_option_codes[2]["results"]
)
else:
return (
True,
False,
{
"status": "400",
"response": "Error in fetching DHCP option codes",
"data": data,
},
)
return connector.create('/api/ddi/v1/ipam/subnet', payload)
else:
return(True, False, {'status': '400', 'response': 'Address or IP Space not defined','data':data})
Expand Down Expand Up @@ -315,6 +334,7 @@ def main():
space=dict(type='str'),
dhcp_host=dict(type='str'),
comment=dict(type='str'),
dhcp_options=dict(type="list", elements="dict", default=[{}])
tags=dict(type='list', elements='dict', default=[{}]),
state=dict(type='str', default='present', choices=['present','absent','get'])
)
Expand Down

0 comments on commit d316e41

Please sign in to comment.