NSX|V: make use of granular API for getting DHCP binding
NSX 6.2.8 and 6.3.3 support the granular API: New GET api: GET https://<nsxmanagerIp>/api/4.0/edges/<edge-id>/dhcp/config/bindings/<binding-id> RESPONSE: <staticBinding> <autoConfigureDNS>false</autoConfigureDNS> <leaseTime>86400</leaseTime> <subnetMask>255.255.255.0</subnetMask> <bindingId>binding-1</bindingId> <vmId>vm-34</vmId> <vnicId>1</vnicId> <hostname>test</hostname> <vmName>3-vm_ubuntu_1404_srv_64-shared-1668-02458540-04f1-4508-8037-2f2ce5542b91</vmName> <ipAddress>12.12.12.1</ipAddress> </staticBinding> 2) Quering a binding with a invalid ID: GET https://<nsxmanagerIp>/api/4.0/edges/<edge-id>/dhcp/config/bindings/<binding-id> RESPONSE: <error> <details>[Dhcp] Static binding is not found: binding-2</details> <errorCode>12510</errorCode> <moduleName>vShield Edge</moduleName> </error> Change-Id: If1049035797c525344c46e1ae7f664a7b9daa4a1
This commit is contained in:
parent
a9da47b2fd
commit
c2d7155b70
@ -91,6 +91,15 @@ def is_nsxv_version_6_3(nsx_version):
|
|||||||
version.LooseVersion('6.3'))
|
version.LooseVersion('6.3'))
|
||||||
|
|
||||||
|
|
||||||
|
def is_nsxv_dhcp_binding_supported(nsx_version):
|
||||||
|
return ((version.LooseVersion(nsx_version) >=
|
||||||
|
version.LooseVersion('6.3.3')) or
|
||||||
|
(version.LooseVersion(nsx_version) >=
|
||||||
|
version.LooseVersion('6.2.8') and
|
||||||
|
version.LooseVersion(nsx_version) <
|
||||||
|
version.LooseVersion('6.3')))
|
||||||
|
|
||||||
|
|
||||||
def get_tags(**kwargs):
|
def get_tags(**kwargs):
|
||||||
tags = ([dict(tag=value, scope=key)
|
tags = ([dict(tag=value, scope=key)
|
||||||
for key, value in six.iteritems(kwargs)])
|
for key, value in six.iteritems(kwargs)])
|
||||||
|
@ -2118,7 +2118,7 @@ def get_dhcp_binding_mappings_for_hostname(nsxv_manager, edge_id):
|
|||||||
return bindings_get
|
return bindings_get
|
||||||
|
|
||||||
|
|
||||||
def get_dhcp_binding_for_binding_id(nsxv_manager, edge_id, binding_id):
|
def _get_dhcp_binding_for_binding_id(nsxv_manager, edge_id, binding_id):
|
||||||
dhcp_config = query_dhcp_service_config(nsxv_manager, edge_id)
|
dhcp_config = query_dhcp_service_config(nsxv_manager, edge_id)
|
||||||
if dhcp_config:
|
if dhcp_config:
|
||||||
for binding in dhcp_config['staticBindings']['staticBindings']:
|
for binding in dhcp_config['staticBindings']['staticBindings']:
|
||||||
@ -2126,6 +2126,25 @@ def get_dhcp_binding_for_binding_id(nsxv_manager, edge_id, binding_id):
|
|||||||
return binding
|
return binding
|
||||||
|
|
||||||
|
|
||||||
|
def _get_dhcp_binding(nsxv_manager, edge_id, binding_id):
|
||||||
|
try:
|
||||||
|
h, dhcp_binding = nsxv_manager.vcns.get_dhcp_binding(edge_id,
|
||||||
|
binding_id)
|
||||||
|
return dhcp_binding
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def get_dhcp_binding_for_binding_id(nsxv_manager, edge_id, binding_id):
|
||||||
|
# API for specific binding is supported in NSX 6.2.8 and 6.3.3 onwards
|
||||||
|
ver = nsxv_manager.vcns.get_version()
|
||||||
|
if c_utils.is_nsxv_dhcp_binding_supported(ver):
|
||||||
|
return _get_dhcp_binding(nsxv_manager, edge_id, binding_id)
|
||||||
|
else:
|
||||||
|
return _get_dhcp_binding_for_binding_id(nsxv_manager, edge_id,
|
||||||
|
binding_id)
|
||||||
|
|
||||||
|
|
||||||
def query_dhcp_service_config(nsxv_manager, edge_id):
|
def query_dhcp_service_config(nsxv_manager, edge_id):
|
||||||
"""Retrieve the current DHCP configuration from the edge."""
|
"""Retrieve the current DHCP configuration from the edge."""
|
||||||
_, dhcp_config = nsxv_manager.vcns.query_dhcp_configuration(edge_id)
|
_, dhcp_config = nsxv_manager.vcns.query_dhcp_configuration(edge_id)
|
||||||
|
@ -561,6 +561,13 @@ class Vcns(object):
|
|||||||
binding_id)
|
binding_id)
|
||||||
return self.do_request(HTTP_DELETE, uri, decode=False)
|
return self.do_request(HTTP_DELETE, uri, decode=False)
|
||||||
|
|
||||||
|
def get_dhcp_binding(self, edge_id, binding_id):
|
||||||
|
"""Get a dhcp static binding from the edge."""
|
||||||
|
uri = self._build_uri_path(edge_id,
|
||||||
|
DHCP_SERVICE, DHCP_BINDING_RESOURCE,
|
||||||
|
binding_id)
|
||||||
|
return self.do_request(HTTP_GET, uri, decode=False)
|
||||||
|
|
||||||
def create_security_group(self, request):
|
def create_security_group(self, request):
|
||||||
"""Creates a security group container in nsx.
|
"""Creates a security group container in nsx.
|
||||||
|
|
||||||
|
@ -304,6 +304,15 @@ class FakeVcns(object):
|
|||||||
response = ''
|
response = ''
|
||||||
return (header, response)
|
return (header, response)
|
||||||
|
|
||||||
|
def get_dhcp_binding(self, edge_id, binding_id):
|
||||||
|
if binding_id not in self._dhcp_bindings[edge_id]:
|
||||||
|
raise Exception(_("binding %s does not exist") % binding_id)
|
||||||
|
response = self._dhcp_bindings[edge_id][binding_id]
|
||||||
|
header = {
|
||||||
|
'status': 200
|
||||||
|
}
|
||||||
|
return (header, response)
|
||||||
|
|
||||||
def create_bridge(self, edge_id, request):
|
def create_bridge(self, edge_id, request):
|
||||||
if edge_id not in self._edges:
|
if edge_id not in self._edges:
|
||||||
raise Exception(_("Edge %s does not exist") % edge_id)
|
raise Exception(_("Edge %s does not exist") % edge_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user