Enhance Policy routers apis
- Add realization apis to tier1 router resource - Get/Set/Unset edge cluster of a router Change-Id: I10a3f691b33e37e1cd8ec8094f4bfa89d7a96f35
This commit is contained in:
parent
2b9c5e8593
commit
08d67a9439
@ -30,6 +30,7 @@ SERVICES_PATH_PATTERN = TENANTS_PATH_PATTERN + "services/"
|
||||
ENFORCEMENT_POINT_PATTERN = (TENANTS_PATH_PATTERN +
|
||||
"sites/default/enforcement-points/")
|
||||
TRANSPORT_ZONE_PATTERN = ENFORCEMENT_POINT_PATTERN + "%s/transport-zones/"
|
||||
EDGE_CLUSTER_PATTERN = ENFORCEMENT_POINT_PATTERN + "%s/edge-clusters/"
|
||||
|
||||
REALIZATION_PATH = "infra/realized-state/realized-entities?intent_path=%s"
|
||||
|
||||
@ -328,6 +329,40 @@ class Tier1Def(RouterDef):
|
||||
return route_adv
|
||||
|
||||
|
||||
class RouterLocaleServiceDef(ResourceDef):
|
||||
|
||||
@staticmethod
|
||||
def resource_type():
|
||||
return 'LocaleServices'
|
||||
|
||||
def get_obj_dict(self):
|
||||
body = super(RouterLocaleServiceDef, self).get_obj_dict()
|
||||
self._set_attrs_in_body(body, ['edge_cluster_path'])
|
||||
return body
|
||||
|
||||
|
||||
class Tier0LocaleServiceDef(RouterLocaleServiceDef):
|
||||
|
||||
@property
|
||||
def path_pattern(self):
|
||||
return TIER0S_PATH_PATTERN + "%s/locale-services/"
|
||||
|
||||
@property
|
||||
def path_ids(self):
|
||||
return ('tenant', 'tier0_id', 'service_id')
|
||||
|
||||
|
||||
class Tier1LocaleServiceDef(RouterLocaleServiceDef):
|
||||
|
||||
@property
|
||||
def path_pattern(self):
|
||||
return TIER1S_PATH_PATTERN + "%s/locale-services/"
|
||||
|
||||
@property
|
||||
def path_ids(self):
|
||||
return ('tenant', 'tier1_id', 'service_id')
|
||||
|
||||
|
||||
class Subnet(object):
|
||||
def __init__(self, gateway_address, dhcp_ranges=None):
|
||||
self.gateway_address = gateway_address
|
||||
@ -392,7 +427,7 @@ class SegmentDef(BaseSegmentDef):
|
||||
def get_obj_dict(self):
|
||||
body = super(SegmentDef, self).get_obj_dict()
|
||||
if self.has_attr('tier1_id'):
|
||||
path = ""
|
||||
path = None
|
||||
if self.get_attr('tier1_id'):
|
||||
tier1 = Tier1Def(tier1_id=self.get_attr('tier1_id'),
|
||||
tenant=self.get_tenant())
|
||||
|
@ -580,6 +580,8 @@ class NsxPolicyIPProtocolServiceApi(NsxPolicyServiceBase):
|
||||
|
||||
class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
||||
"""NSX Tier1 API """
|
||||
LOCALE_SERVICE_SUFF = '-0'
|
||||
|
||||
@property
|
||||
def entry_def(self):
|
||||
return policy_defs.Tier1Def
|
||||
@ -663,6 +665,42 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
||||
tenant=tenant)
|
||||
self.policy_api.create_or_update(tier1_def)
|
||||
|
||||
def set_edge_cluster_path(self, tier1_id, edge_cluster_path,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT):
|
||||
# Supporting only a single locale-service per router for now
|
||||
# with the same id as the router id with a constant suffix
|
||||
t1service_def = policy_defs.Tier1LocaleServiceDef(
|
||||
tier1_id=tier1_id,
|
||||
service_id=tier1_id + self.LOCALE_SERVICE_SUFF,
|
||||
edge_cluster_path=edge_cluster_path,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT)
|
||||
self.policy_api.create_or_update(t1service_def)
|
||||
|
||||
def remove_edge_cluster(self, tier1_id,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT):
|
||||
# Supporting only a single locale-service per router for now
|
||||
# with the same id as the router id with a constant suffix
|
||||
t1service_def = policy_defs.Tier1LocaleServiceDef(
|
||||
tier1_id=tier1_id,
|
||||
service_id=tier1_id + self.LOCALE_SERVICE_SUFF,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT)
|
||||
self.policy_api.delete(t1service_def)
|
||||
|
||||
def get_realized_state(self, tier1_id,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT):
|
||||
tier1_def = self.entry_def(tier1_id=tier1_id, tenant=tenant)
|
||||
return self._get_realized_state(tier1_def)
|
||||
|
||||
def get_realized_id(self, tier1_id,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT):
|
||||
tier1_def = self.entry_def(tier1_id=tier1_id, tenant=tenant)
|
||||
return self._get_realized_id(tier1_def)
|
||||
|
||||
def get_realization_info(self, tier1_id,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT):
|
||||
tier1_def = self.entry_def(tier1_id=tier1_id, tenant=tenant)
|
||||
return self._get_realization_info(tier1_def)
|
||||
|
||||
|
||||
class NsxPolicyTier0Api(NsxPolicyResourceBase):
|
||||
"""NSX Tier0 API """
|
||||
@ -728,6 +766,17 @@ class NsxPolicyTier0Api(NsxPolicyResourceBase):
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
|
||||
def get_edge_cluster_path(self, tier0_id,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT):
|
||||
"""Get the edge_cluster path of a Tier0 router"""
|
||||
t0service_def = policy_defs.Tier0LocaleServiceDef(
|
||||
tier0_id=tier0_id,
|
||||
tenant=policy_constants.POLICY_INFRA_TENANT)
|
||||
services = self.policy_api.list(t0service_def)['results']
|
||||
for srv in services:
|
||||
if 'edge_cluster_path' in srv:
|
||||
return srv['edge_cluster_path']
|
||||
|
||||
|
||||
class NsxPolicyTier1SegmentApi(NsxPolicyResourceBase):
|
||||
"""NSX Tier1 Segment API """
|
||||
|
Loading…
x
Reference in New Issue
Block a user