Add resource type to resource definitions

On the NSX each resource has a resource-type and could be searched by it.
The new property of the resources can be used when using search_by_tags

Change-Id: I120bc9e31faa2bebb13f24a0ccbac314f8b2a1bf
This commit is contained in:
Adit Sarfaty 2017-07-11 16:14:33 +03:00
parent ccba8c3a28
commit 4686b560e1
3 changed files with 64 additions and 0 deletions

View File

@ -38,6 +38,10 @@ class NsxLibPortMirror(utils.NsxLibApiBase):
def uri_segment(self):
return 'mirror-sessions'
@property
def resource_type(self):
return 'PortMirroringSession'
def create_session(self, source_ports, dest_ports, direction,
description, name, tags):
"""Create a PortMirror Session on the backend.
@ -76,6 +80,10 @@ class NsxLibBridgeEndpoint(utils.NsxLibApiBase):
def uri_segment(self):
return 'bridge-endpoints'
@property
def resource_type(self):
return 'BridgeEndpoint'
def create(self, device_name, seg_id, tags):
"""Create a bridge endpoint on the backend.
@ -106,6 +114,10 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
def uri_segment(self):
return 'logical-switches'
@property
def resource_type(self):
return 'LogicalSwitch'
def create(self, display_name, transport_zone_id, tags,
replication_mode=nsx_constants.MTEP,
admin_state=True, vlan_id=None, ip_pool_id=None,
@ -290,6 +302,10 @@ class NsxLibSwitchingProfile(utils.NsxLibApiBase):
class NsxLibQosSwitchingProfile(NsxLibSwitchingProfile):
@property
def resource_type(self):
return 'QosSwitchingProfile'
def _build_args(self, tags, name=None, description=None):
body = {"resource_type": "QosSwitchingProfile",
"tags": tags}
@ -435,6 +451,10 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase):
def uri_segment(self):
return 'logical-routers'
@property
def resource_type(self):
return 'LogicalRouter'
def _delete_resource_by_values(self, resource,
skip_not_found=True,
strict_mode=True,
@ -623,6 +643,10 @@ class NsxLibEdgeCluster(utils.NsxLibApiBase):
def uri_segment(self):
return 'edge-clusters'
@property
def resource_type(self):
return 'EdgeCluster'
class NsxLibTransportZone(utils.NsxLibApiBase):
@ -630,6 +654,10 @@ class NsxLibTransportZone(utils.NsxLibApiBase):
def uri_segment(self):
return 'transport-zones'
@property
def resource_type(self):
return 'TransportZone'
class NsxLibDhcpProfile(utils.NsxLibApiBase):
@ -637,6 +665,10 @@ class NsxLibDhcpProfile(utils.NsxLibApiBase):
def uri_segment(self):
return 'dhcp/server-profiles'
@property
def resource_type(self):
return 'DhcpProfile'
class NsxLibMetadataProxy(utils.NsxLibApiBase):
@ -644,6 +676,10 @@ class NsxLibMetadataProxy(utils.NsxLibApiBase):
def uri_segment(self):
return 'md-proxies'
@property
def resource_type(self):
return 'MetadataProxy'
class NsxLibBridgeCluster(utils.NsxLibApiBase):
@ -651,6 +687,10 @@ class NsxLibBridgeCluster(utils.NsxLibApiBase):
def uri_segment(self):
return 'bridge-clusters'
@property
def resource_type(self):
return 'BridgeCluster'
class NsxLibIpBlockSubnet(utils.NsxLibApiBase):
@ -658,6 +698,10 @@ class NsxLibIpBlockSubnet(utils.NsxLibApiBase):
def uri_segment(self):
return 'pools/ip-subnets'
@property
def resource_type(self):
return 'IpBlockSubnet'
def create(self, ip_block_id, subnet_size):
"""Create a IP block subnet on the backend."""
body = {'size': subnet_size,
@ -678,3 +722,7 @@ class NsxLibIpBlock(utils.NsxLibApiBase):
@property
def uri_segment(self):
return 'pools/ip-blocks'
@property
def resource_type(self):
return 'IpBlock'

View File

@ -71,6 +71,10 @@ class LogicalPort(utils.NsxLibApiBase):
def uri_segment(self):
return 'logical-ports'
@property
def resource_type(self):
return 'LogicalPort'
def _build_body_attrs(
self, display_name=None,
admin_state=True, tags=None,
@ -418,6 +422,10 @@ class LogicalDhcpServer(utils.NsxLibApiBase):
def uri_segment(self):
return 'dhcp/servers'
@property
def resource_type(self):
return 'LogicalDhcpServer'
def _construct_server(self, body, dhcp_profile_id=None, server_ip=None,
name=None, dns_nameservers=None, domain_name=None,
gateway_ip=False, options=None, tags=None):
@ -507,6 +515,10 @@ class IpPool(utils.NsxLibApiBase):
def uri_segment(self):
return 'pools/ip-pools'
@property
def resource_type(self):
return 'IpPool'
def _generate_ranges(self, cidr, gateway_ip):
"""Create list of ranges from the given cidr.

View File

@ -146,6 +146,10 @@ class NsxLibApiBase(object):
def uri_segment(self):
pass
@abc.abstractproperty
def resource_type(self):
pass
def get_path(self, resource=None):
if resource:
return '%s/%s' % (self.uri_segment, resource)