def sync_netscaler_config(collector, stack, **kwargs): """Sync netscaler configuration with the specified netscaler""" logging.captureWarnings(True) logging.getLogger("py.warnings").setLevel(logging.ERROR) configuration = collector.configuration if stack.netscaler is NotSpecified or stack.netscaler.configuration is NotSpecified: raise BespinError("Please configure {netscaler.configuration}") if stack.netscaler.syncable_environments is not NotSpecified: if configuration["environment"] not in stack.netscaler.syncable_environments: raise BespinError("Sorry, can only sync netscaler config for particular environments", wanted=configuration["environment"], available=list(stack.netscaler.syncable_environments)) for_layers = [] all_configuration = {} for vkey, value in stack.netscaler.configuration.items(): for key, thing in value.items(): if thing.environments is NotSpecified or configuration["environment"] in thing.environments: for_layers.append(thing.long_name) all_configuration[thing.long_name] = thing if vkey not in all_configuration: all_configuration[vkey] = {} all_configuration[vkey][key] = thing layers = Layers(for_layers, all_stacks=all_configuration) layers.add_all_to_layers() stack.netscaler.syncing_configuration = True with stack.netscaler as netscaler: for layer in layers.layered: for _, thing in layer: netscaler.sync(all_configuration, configuration["environment"], thing)
def layered(self, stacks, only_pushable=False): """Yield layers of stacks""" if only_pushable: operate_on = dict((stack, instance) for stack, instance in stacks.items() if instance.stack_index) else: operate_on = stacks layers = Layers(operate_on, all_stacks=stacks) layers.add_all_to_layers() return layers.layered