Skip to content

Commit e104f10

Browse files
author
avijenkins
committed
Updated assets for python
Signed-off-by: avijenkins <svc.avi-jenkins@broadcom.com>
1 parent fa9c1d9 commit e104f10

File tree

2 files changed

+103
-8
lines changed

2 files changed

+103
-8
lines changed

python/avi/sdk/samples/clone_vs.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,7 @@ Changelog:
354354

355355
* Add support for modifying pool server hostname when mapping servers
356356
* Update examples in the readme
357+
358+
2.0.10:
359+
360+
* Add support for cloning a VS with an ICAP Profile across clouds

python/avi/sdk/samples/clone_vs.py

Lines changed: 99 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
urllib3.disable_warnings()
3232

33-
AVICLONE_VERSION = [2, 0, 9]
33+
AVICLONE_VERSION = [2, 0, 10]
3434

3535
# Try to obtain the terminal width to allow spprint() to wrap output neatly.
3636
# If unable to determine, assume terminal width is 70 characters
@@ -96,7 +96,8 @@ class AviClone:
9696
'vs-authprofile': 'client_auth/auth_profile_ref',
9797
'vs-ssoauthprofile': 'sso_policy/default_auth_profile_ref',
9898
'vs-ssopolicy': 'sso_policy_ref',
99-
'vs-botpolicy': 'bot_policy_ref'
99+
'vs-botpolicy': 'bot_policy_ref',
100+
'vs-icapprofile': 'icap_request_profile_refs'
100101
}
101102
VALID_VS_OVERRIDE_REF_OBJECTS = {
102103
'vsoverride-appprofile': 'override_application_profile_ref',
@@ -144,6 +145,9 @@ class AviClone:
144145
'hm-sslkeyandcertificate':
145146
'https_monitor/ssl_attributes/ssl_key_and_certificate_ref'
146147
}
148+
VALID_ICAPPROFILE_REF_OBJECTS = {
149+
'icap-poolgroup': 'pool_group_ref'
150+
}
147151

148152
def __init__(self, source_api, dest_api=None, flags=None, tenant=None,
149153
other_tenant=None, other_cloud=None,
@@ -296,7 +300,7 @@ def _get_obj_info(self, obj_type, obj=None, obj_name=None,
296300
else:
297301
obj = api_to_use.get_object_by_name(obj_type, obj_name,
298302
tenant_uuid=tenant_uuid,
299-
params=({"cloud_uuid": cloud_uuid}
303+
params=({'cloud_uuid': cloud_uuid}
300304
if cloud_uuid else {}))
301305

302306
if obj is None and obj_type == 'tenant':
@@ -366,7 +370,7 @@ def get_new_name(self, object_type, new_name, force_unique_name=False):
366370

367371
def clone_object(self, old_name, new_name, object_type=None,
368372
force_clone=None, force_unique_name=False,
369-
old_obj=None):
373+
old_obj=None, skip_uniqueness_check=False):
370374
"""
371375
Clones an object other than a Virtual Service or GSLB Service
372376
@@ -388,6 +392,9 @@ def clone_object(self, old_name, new_name, object_type=None,
388392
appending an index number
389393
:param old_obj: Existing object to clone - can be specified instead
390394
of passing old_name if the object is already available
395+
:param skip_uniqueness_check: Skip check for unique object naming
396+
check to support object types that allow
397+
duplicate names across clouds/tenants
391398
:return: tuple - json representation of the cloned object, list of
392399
additional objects created if any
393400
:rtype: tuple
@@ -442,7 +449,9 @@ def clone_object(self, old_name, new_name, object_type=None,
442449
logger.debug('Cloning %s "%s" to "%s"', object_type,
443450
old_name, new_name)
444451

445-
new_name = self.get_new_name(object_type, new_name, force_unique_name)
452+
if not skip_uniqueness_check:
453+
new_name = self.get_new_name(object_type, new_name,
454+
force_unique_name)
446455

447456
# Remove unique attributes and rename object
448457

@@ -1439,6 +1448,45 @@ def _processobject_analyticsprofile(self, obj, force_clone):
14391448

14401449
return created_objs, warnings
14411450

1451+
def _processobject_icapprofile(self, obj, force_clone):
1452+
"""
1453+
Performs icapprofile-specific manipulations on the cloned
1454+
object
1455+
"""
1456+
1457+
logger.debug('Running _process_icapprofile')
1458+
1459+
created_objs = []
1460+
warnings = []
1461+
1462+
if self.oc_obj:
1463+
1464+
# Moving to a different cloud, so we will need to force
1465+
# clone the referenced pool group
1466+
1467+
obj['cloud_ref'] = self.oc_obj['url']
1468+
force_clone = list(set(force_clone + ['icap-poolgroup']))
1469+
1470+
try:
1471+
valid_ref_objects = self.VALID_ICAPPROFILE_REF_OBJECTS
1472+
1473+
# Process generic references, re-using or cloning referenced
1474+
# objects as necessary
1475+
1476+
created_objs, warnings = self._process_refs(parent_obj=obj,
1477+
refs=valid_ref_objects,
1478+
force_clone=force_clone)
1479+
1480+
except Exception as ex:
1481+
# If an exception occurred, delete any intermediate objects we
1482+
# have created
1483+
1484+
self.delete_objects(created_objs)
1485+
1486+
raise
1487+
1488+
return created_objs, warnings
1489+
14421490
def _process_refs(self, parent_obj, refs, force_clone, name=None):
14431491

14441492
# Process references in the object based on a ref list and
@@ -2412,6 +2460,49 @@ def clone_vs(self, old_vs_name, new_vs_name, enable_vs=False,
24122460
vsvip_obj.pop('vrf_context_ref', None)
24132461
vsvip_obj.pop('tier1_lr', None)
24142462

2463+
# If VS has an ICAP profile and is moving to a different cloud
2464+
# then check first for an ICAP profile with the same name in
2465+
# the target cloud, otherwise clone the ICAP profile to the
2466+
# target cloud, preserving the name.
2467+
2468+
if ('vs-icapprofile' not in force_clone and
2469+
'icap_request_profile_refs' in v_obj):
2470+
irp_refs = v_obj['icap_request_profile_refs']
2471+
new_irp_refs = []
2472+
2473+
for irp in irp_refs:
2474+
irp_path = irp.split('/api/')[1]
2475+
2476+
irp_obj = self.api.get(irp_path,
2477+
tenant_uuid=self.tenant_uuid).json()
2478+
irp_name = irp_obj['name']
2479+
2480+
i_obj = self.dest_api.get_object_by_name(
2481+
'icapprofile', irp_name,
2482+
tenant_uuid=self.otenant_uuid,
2483+
params={'cloud_uuid': self.ocloud_uuid}
2484+
)
2485+
2486+
if not i_obj:
2487+
(i_obj, i_created_objs,
2488+
i_warnings) = self.clone_object(
2489+
old_name=irp_path,
2490+
new_name=irp_name,
2491+
force_clone=force_clone,
2492+
force_unique_name=False,
2493+
skip_uniqueness_check=True
2494+
)
2495+
2496+
created_objs.append(i_obj)
2497+
created_objs.extend(i_created_objs)
2498+
warnings.extend(i_warnings)
2499+
2500+
new_irp_refs.append(i_obj['url'])
2501+
2502+
v_obj['icap_request_profile_refs'] = new_irp_refs
2503+
2504+
2505+
24152506
# Update VRF or T1_LR reference if a target VRF is specified
24162507
if vsvip_obj and not(manual_vsvip):
24172508
if self.ov_obj:
@@ -2705,7 +2796,8 @@ def clone_vs(self, old_vs_name, new_vs_name, enable_vs=False,
27052796
set(AviClone.VALID_SSLCERT_REF_OBJECTS.keys()) |
27062797
set(AviClone.VALID_SSOPOLICY_REF_OBJECTS.keys()) |
27072798
set(AviClone.VALID_HEALTHMONITOR_REF_OBJECTS.keys()) |
2708-
set(AviClone.VALID_OAUTHSETTINGS_REF_OBJECTS.keys()))
2799+
set(AviClone.VALID_OAUTHSETTINGS_REF_OBJECTS.keys()) |
2800+
set(AviClone.VALID_ICAPPROFILE_REF_OBJECTS.keys()))
27092801

27102802
parser = argparse.ArgumentParser(
27112803
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -3286,5 +3378,4 @@ def flag_map(x): return x if x is None else (x == 'true')
32863378
pass
32873379
cl.delete_objects(all_created_objs)
32883380
else:
3289-
parser.print_help()
3290-
3381+
parser.print_help()

0 commit comments

Comments
 (0)