Permit duplicate VNIs in templates with flag
Supports niche usecases whereby a network template should contain the same VNI(s) more than once.
This commit is contained in:
parent
d63cc2e661
commit
3bc500bc55
|
@ -7139,7 +7139,11 @@ class API_Provisioner_Template_Network_Net_Root(Resource):
|
||||||
"name": "vni",
|
"name": "vni",
|
||||||
"required": True,
|
"required": True,
|
||||||
"helptext": "A valid VNI must be specified.",
|
"helptext": "A valid VNI must be specified.",
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"name": "permit_duplicate",
|
||||||
|
"required": False,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@Authenticator
|
@Authenticator
|
||||||
|
@ -7155,6 +7159,11 @@ class API_Provisioner_Template_Network_Net_Root(Resource):
|
||||||
type: integer
|
type: integer
|
||||||
required: false
|
required: false
|
||||||
description: PVC network VNI
|
description: PVC network VNI
|
||||||
|
- in: query
|
||||||
|
name: permit_duplicate
|
||||||
|
type: boolean
|
||||||
|
required: false
|
||||||
|
description: Bypass checks to permit duplicate VNIs for niche usecases
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
|
@ -7168,7 +7177,7 @@ class API_Provisioner_Template_Network_Net_Root(Resource):
|
||||||
id: Message
|
id: Message
|
||||||
"""
|
"""
|
||||||
return api_provisioner.create_template_network_element(
|
return api_provisioner.create_template_network_element(
|
||||||
template, reqargs.get("vni", None)
|
template, reqargs.get("vni", None), reqargs.get("permit_duplicate", False)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -7206,13 +7215,27 @@ class API_Provisioner_Template_Network_Net_Element(Resource):
|
||||||
return _vni, 200
|
return _vni, 200
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
@RequestParser(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "permit_duplicate",
|
||||||
|
"required": False,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
@Authenticator
|
@Authenticator
|
||||||
def post(self, template, vni):
|
def post(self, template, vni, reqargs):
|
||||||
"""
|
"""
|
||||||
Create a new network {vni} in network template {template}
|
Create a new network {vni} in network template {template}
|
||||||
---
|
---
|
||||||
tags:
|
tags:
|
||||||
- provisioner / template
|
- provisioner / template
|
||||||
|
parameters:
|
||||||
|
- in: query
|
||||||
|
name: permit_duplicate
|
||||||
|
type: boolean
|
||||||
|
required: false
|
||||||
|
description: Bypass checks to permit duplicate VNIs for niche usecases
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
|
@ -7225,7 +7248,9 @@ class API_Provisioner_Template_Network_Net_Element(Resource):
|
||||||
type: object
|
type: object
|
||||||
id: Message
|
id: Message
|
||||||
"""
|
"""
|
||||||
return api_provisioner.create_template_network_element(template, vni)
|
return api_provisioner.create_template_network_element(
|
||||||
|
template, vni, reqargs.get("permit_duplicate", False)
|
||||||
|
)
|
||||||
|
|
||||||
@Authenticator
|
@Authenticator
|
||||||
def delete(self, template, vni):
|
def delete(self, template, vni):
|
||||||
|
|
|
@ -284,27 +284,28 @@ def create_template_network(name, mac_template=None):
|
||||||
return retmsg, retcode
|
return retmsg, retcode
|
||||||
|
|
||||||
|
|
||||||
def create_template_network_element(name, vni):
|
def create_template_network_element(name, vni, permit_duplicate=False):
|
||||||
if list_template_network(name, is_fuzzy=False)[-1] != 200:
|
if list_template_network(name, is_fuzzy=False)[-1] != 200:
|
||||||
retmsg = {"message": 'The network template "{}" does not exist.'.format(name)}
|
retmsg = {"message": 'The network template "{}" does not exist.'.format(name)}
|
||||||
retcode = 400
|
retcode = 400
|
||||||
return retmsg, retcode
|
return retmsg, retcode
|
||||||
|
|
||||||
networks, code = list_template_network_vnis(name)
|
if not permit_duplicate:
|
||||||
if code != 200:
|
networks, code = list_template_network_vnis(name)
|
||||||
networks = []
|
if code != 200:
|
||||||
found_vni = False
|
networks = []
|
||||||
for network in networks:
|
found_vni = False
|
||||||
if network["vni"] == vni:
|
for network in networks:
|
||||||
found_vni = True
|
if network["vni"] == vni:
|
||||||
if found_vni:
|
found_vni = True
|
||||||
retmsg = {
|
if found_vni:
|
||||||
"message": 'The VNI "{}" in network template "{}" already exists.'.format(
|
retmsg = {
|
||||||
vni, name
|
"message": 'The VNI "{}" in network template "{}" already exists.'.format(
|
||||||
)
|
vni, name
|
||||||
}
|
)
|
||||||
retcode = 400
|
}
|
||||||
return retmsg, retcode
|
retcode = 400
|
||||||
|
return retmsg, retcode
|
||||||
|
|
||||||
conn, cur = open_database(config)
|
conn, cur = open_database(config)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -4849,13 +4849,27 @@ def cli_provisioner_template_network_vni():
|
||||||
@connection_req
|
@connection_req
|
||||||
@click.argument("name")
|
@click.argument("name")
|
||||||
@click.argument("vni")
|
@click.argument("vni")
|
||||||
def cli_provisioner_template_network_vni_add(name, vni):
|
@click.option(
|
||||||
|
"-d",
|
||||||
|
"--permit-duplicate",
|
||||||
|
"permit_duplicate_flag",
|
||||||
|
is_flag=True,
|
||||||
|
default=False,
|
||||||
|
help="Permit a duplicate VNI if one already exists",
|
||||||
|
)
|
||||||
|
def cli_provisioner_template_network_vni_add(name, vni, permit_duplicate_flag):
|
||||||
"""
|
"""
|
||||||
Add a new network VNI to network template NAME.
|
Add a new network VNI to network template NAME.
|
||||||
|
|
||||||
Networks will be added to VMs in the order they are added and displayed within the template.
|
Networks will be added to VMs in the order they are added and displayed within the template.
|
||||||
|
|
||||||
|
NOTE: Normally, the API prevents duplicate VNIs from being added to the same network template
|
||||||
|
by returning an error, as this requirement is very niche. If you do not desire this behaviour,
|
||||||
|
use the "-d"/"--permit-duplicate" option to bypass the check.
|
||||||
"""
|
"""
|
||||||
params = dict()
|
params = dict()
|
||||||
|
if permit_duplicate_flag:
|
||||||
|
params["permit_duplicate"] = True
|
||||||
|
|
||||||
retcode, retdata = pvc.lib.provisioner.template_element_add(
|
retcode, retdata = pvc.lib.provisioner.template_element_add(
|
||||||
CLI_CONFIG, name, vni, params, element_type="net", template_type="network"
|
CLI_CONFIG, name, vni, params, element_type="net", template_type="network"
|
||||||
|
|
Loading…
Reference in New Issue