def GetValidatedUpdateStatefulPolicyParams(args, current_stateful_policy): """Check stateful properties of update request; returns final device list.""" current_device_names = set( managed_instance_groups_utils.GetDeviceNamesFromStatefulPolicy( current_stateful_policy)) if args.add_stateful_disks: if any( args.add_stateful_disks.count(x) > 1 for x in args.add_stateful_disks): raise exceptions.InvalidArgumentException( parameter_name='update', message= ('When adding device names to Stateful Policy, please provide ' 'each name exactly once.')) if args.remove_stateful_disks: if any( args.remove_stateful_disks.count(x) > 1 for x in args.remove_stateful_disks): raise exceptions.InvalidArgumentException( parameter_name='update', message= ('When removing device names from Stateful Policy, please provide ' 'each name exactly once.')) add_set = set(args.add_stateful_disks or []) remove_set = set(args.remove_stateful_disks or []) intersection = add_set.intersection(remove_set) if intersection: raise exceptions.InvalidArgumentException( parameter_name='update', message= ('You cannot simultaneously add and remove the same device names {} to ' 'Stateful Policy.'.format(str(intersection)))) not_current_device_names = remove_set - current_device_names if not_current_device_names: raise exceptions.InvalidArgumentException( parameter_name='update', message=('Disks [{}] are not currently set as stateful, ' 'so they cannot be removed from Stateful Policy.'.format( str(not_current_device_names)))) already_added_device_names = current_device_names & add_set if already_added_device_names: raise exceptions.InvalidArgumentException( parameter_name='update', message=('Disks [{}] are currently set as stateful, ' 'so they cannot be added to Stateful Policy.')) final_disks = current_device_names.union(add_set).difference(remove_set) if final_disks and args.IsSpecified( 'stateful_names') and not args.GetValue('stateful_names'): raise exceptions.InvalidArgumentException( parameter_name='update', message= ('Stateful Policy is not empty, so you cannot mark instance names ' 'as non-stateful. Current device names are [{}]'.format( str(final_disks)))) return sorted(list(final_disks))
def ValidateUpdateStatefulPolicyParams(args, current_stateful_policy): """Check stateful properties of update request; returns final device list.""" current_device_names = set( managed_instance_groups_utils.GetDeviceNamesFromStatefulPolicy( current_stateful_policy)) update_disk_names = [] if args.update_stateful_disk: ValidateStatefulDisksDict(args.update_stateful_disk, '--update-stateful-disk') update_disk_names = [ stateful_disk.get('device-name') for stateful_disk in args.update_stateful_disk ] if args.remove_stateful_disks: if any( args.remove_stateful_disks.count(x) > 1 for x in args.remove_stateful_disks): raise exceptions.InvalidArgumentException( parameter_name='update', message= ('When removing device names from Stateful Policy, please provide ' 'each name exactly once.')) update_set = set(update_disk_names) remove_set = set(args.remove_stateful_disks or []) intersection = update_set.intersection(remove_set) if intersection: raise exceptions.InvalidArgumentException( parameter_name='update', message= ('You cannot simultaneously add and remove the same device names {} to ' 'Stateful Policy.'.format(six.text_type(intersection)))) not_current_device_names = remove_set - current_device_names if not_current_device_names: raise exceptions.InvalidArgumentException( parameter_name='update', message=('Disks [{}] are not currently set as stateful, ' 'so they cannot be removed from Stateful Policy.'.format( six.text_type(not_current_device_names)))) final_disks = current_device_names.union(update_set).difference(remove_set) return final_disks