def modify_state(_): _config = config[0] d = group.modify_state( partial(controller.obey_config_change, self.log, transaction_id(request), _config, launch_config=None)) return d
def _do_obey_config_change(result): group_id = result['id'] config = result['groupConfiguration'] group = self.store.get_scaling_group(self.log, self.tenant_id, group_id) d = group.modify_state(partial(controller.obey_config_change, self.log, transaction_id(request), config)) return d.addCallback(lambda _: result)
def pause_scaling_group(self, request): """ Pause a scaling group. This means that no scaling policies will get executed (execution will be rejected). This is an idempotent operation - pausing an already paused group does nothing. """ group = self.store.get_scaling_group(self.log, self.tenant_id, self.group_id) return controller.pause_scaling_group(self.log, transaction_id(request), group)
def resume_scaling_group(self, request): """ Resume a scaling group. This means that scaling policies will now get executed as usual. This is an idempotent operation - resuming an already running group does nothing. """ group = self.store.get_scaling_group(self.log, self.tenant_id, self.group_id) return controller.resume_scaling_group(self.log, transaction_id(request), group)
def _get_launch_and_obey_config_change(scaling_group, state): d = scaling_group.view_launch_config() d.addCallback(partial( controller.obey_config_change, self.log, transaction_id(request), data, scaling_group, state)) return d
def execute_policy((tenant_id, group_id, policy_id)): bound_log = self.log.bind(tenant_id=tenant_id, scaling_group_id=group_id, policy_id=policy_id) logl[0] = bound_log group = self.store.get_scaling_group(bound_log, tenant_id, group_id) return group.modify_state(partial(controller.maybe_execute_scaling_policy, bound_log, transaction_id(request), policy_id=policy_id))
def delete_server(self, request, server_id): """ Delete a server from the group. """ group = self.store.get_scaling_group(self.log, self.tenant_id, self.scaling_group_id) d = group.modify_state( partial(remove_server_from_group, self.log.bind(server_id=server_id), transaction_id(request), server_id, extract_bool_arg(request, 'replace', True))) return d
def delete_scaling_group(self, request): """ Delete a scaling group if there are no entities belonging to the scaling group. If successful, no response body will be returned. """ group = self.store.get_scaling_group(self.log, self.tenant_id, self.group_id) force = extract_bool_arg(request, 'force', False) return controller.delete_group( self.dispatcher, log, transaction_id(request), group, force)
def resume_scaling_group(self, request): """ Resume a scaling group. This means that scaling policies will now get executed as usual. This is an idempotent operation - resuming an already running group does nothing. """ group = self.store.get_scaling_group( self.log, self.tenant_id, self.group_id) return controller.resume_scaling_group( self.log, transaction_id(request), group, self.dispatcher)
def pause_scaling_group(self, request): """ Pause a scaling group. This means that no scaling policies will get executed (execution will be rejected). This is an idempotent operation - pausing an already paused group does nothing. """ group = self.store.get_scaling_group( self.log, self.tenant_id, self.group_id) return controller.pause_scaling_group( self.log, transaction_id(request), group, self.dispatcher)
def execute_policy((tenant_id, group_id, policy_id)): bound_log = self.log.bind(tenant_id=tenant_id, scaling_group_id=group_id, policy_id=policy_id) logl[0] = bound_log group = self.store.get_scaling_group(bound_log, tenant_id, group_id) return controller.modify_and_trigger( self.dispatcher, group, bound_log_kwargs(bound_log), partial(controller.maybe_execute_scaling_policy, bound_log, transaction_id(request), policy_id=policy_id), modify_state_reason='execute_webhook')
def _do_obey_config_change(result): group_id = result['id'] config = result['groupConfiguration'] launch = result['launchConfiguration'] group = self.store.get_scaling_group( self.log, self.tenant_id, group_id) log = self.log.bind(scaling_group_id=group_id) d = controller.modify_and_trigger( self.dispatcher, group, bound_log_kwargs(log), partial( controller.obey_config_change, log, transaction_id(request), config, launch_config=launch), modify_state_reason='create_new_scaling_group') return d.addCallback(lambda _: result)
def execute_policy(self, request): """ Execute this scaling policy. TBD: Response body. Example response:: {} """ group = self.store.get_scaling_group(self.log, self.tenant_id, self.scaling_group_id) d = group.modify_state(partial(controller.maybe_execute_scaling_policy, self.log, transaction_id(request), policy_id=self.policy_id)) d.addCallback(lambda _: "{}") # Return value TBD return d
def delete_server(self, request, server_id): """ Delete a server from the group. """ group = self.store.get_scaling_group(self.log, self.tenant_id, self.scaling_group_id) log = self.log.bind(server_id=server_id) d = controller.modify_and_trigger( self.dispatcher, group, bound_log_kwargs(log), partial(controller.remove_server_from_group, self.dispatcher, log, transaction_id(request), server_id, extract_bool_arg(request, 'replace', True), extract_bool_arg(request, 'purge', True)), modify_state_reason='delete_server') return d
def delete_server(self, request, server_id): """ Delete a server from the group. """ group = self.store.get_scaling_group( self.log, self.tenant_id, self.scaling_group_id) log = self.log.bind(server_id=server_id) d = controller.modify_and_trigger( self.dispatcher, group, bound_log_kwargs(log), partial(controller.remove_server_from_group, self.dispatcher, log, transaction_id(request), server_id, extract_bool_arg(request, 'replace', True), extract_bool_arg(request, 'purge', True)), modify_state_reason='delete_server') return d
def execute_policy(self, request): """ Execute this scaling policy. TBD: Response body. Example response:: {} """ group = self.store.get_scaling_group(self.log, self.tenant_id, self.scaling_group_id) d = controller.modify_and_trigger( self.dispatcher, group, bound_log_kwargs(self.log), partial(controller.maybe_execute_scaling_policy, self.log, transaction_id(request), policy_id=self.policy_id), modify_state_reason='execute_policy') d.addCallback(lambda _: "{}") # Return value TBD return d
def foo(self, request): transaction_ids.append(transaction_id(request)) return 'ok'
def _do_obey_config_change(_, group): return group.modify_state( partial(controller.obey_config_change, self.log, transaction_id(request), data))
def foo(self, request, log): transaction_ids.append(transaction_id(request)) return 'ok'