def create(bosslet_config): """Create the configuration and launch.""" if console.confirm("Rebuild multilambda", default=True): pre_init(bosslet_config) config = create_config(bosslet_config) config.create()
def update(bosslet_config): if console.confirm("Rebuild multilambda", default=True): pre_init(bosslet_config) update_lambda_code(bosslet_config) config = create_config(bosslet_config) config.update()
def create(bosslet_config): if console.confirm('Build multilambda', default = True): pre_init(bosslet_config) config = create_config(bosslet_config) config.create() post_init(bosslet_config)
def update(bosslet_config): if const.REDIS_THROTTLE_TYPE is not None: rebuild_lambdas = console.confirm("Rebuild lambdas", default=True) else: rebuild_lambdas = False if rebuild_lambdas: pre_init(bosslet_config) config = create_config(bosslet_config) config.update() if rebuild_lambdas: freshen_lambda(bosslet_config, bosslet_config.names.cache_throttle.lambda_)
def delete(bosslet_config): session = bosslet_config.session domain = bosslet_config.INTERNAL_DOMAIN names = bosslet_config.names if not console.confirm( "All data will be lost. Are you sure you want to proceed?"): raise BossManageCanceled() aws.route53_delete_records(session, domain, names.endpoint.dns) # Other configs may define SQS queues and we shouldn't delete them aws.sqs_delete_all( session, domain) # !!! TODO FIX this so it doesn't bork the stack aws.policy_delete_all(session, domain, '/ingest/') config = CloudFormationConfiguration('api', bosslet_config) config.delete()
def update(bosslet_config): # To correctly handle if a layer needs to be rebuilt build it # before the CF update and then refresh the code files after the # update. rebuild_lambdas = console.confirm("Rebuild lambdas", default=True) if rebuild_lambdas: pre_init(bosslet_config) user_data = build_user_data(bosslet_config) config = create_config(bosslet_config, user_data) config.update() if rebuild_lambdas: for lambda_name in get_lambdas(bosslet_config): freshen_lambda(bosslet_config, lambda_name) post_init(bosslet_config)
def delete(bosslet_config): # NOTE: CloudWatch logs for the DNS Lambda are not deleted if not console.confirm( "All data will be lost. Are you sure you want to proceed?"): raise BossManageCanceled() session = bosslet_config.session domain = bosslet_config.INTERNAL_DOMAIN names = bosslet_config.names aws.route53_delete_records(session, domain, names.auth.dns) aws.route53_delete_records(session, domain, names.vault.dns) aws.sns_unsubscribe_all(bosslet_config, names.dns.sns) config = CloudFormationConfiguration('core', bosslet_config) if config.existing_version( ) == 1: # Deleting a stack that has not been updated aws.route53_delete_records(session, domain, 'consul.' + domain) config.delete()
def pre_update(bosslet_config): # Alert about the change that will happen if not console.confirm( "This updated will recreate the Vault cluster, proceed?", default=False): raise BossManageCanceled() # Save the existing data do we can rebuild Vault path = export_path(bosslet_config) with bosslet_config.call.vault() as vault: vault_data = vault.export("secret/") with open(path, 'w') as outfile: json.dump(vault_data, outfile, indent=3, sort_keys=True) print("Vault data exported to {}".format(path)) # With version 2 the DNS records are now part of the CloudFormation template, so # remove the existing DNS record so the update can happen console.warning( "Removing existing Auth public DNS entry, so CloudFormation can manage the DNS record" ) aws.route53_delete_records(bosslet_config.session, bosslet_config.EXTERNAL_DOMAIN, bosslet_config.names.public_dns('auth'))
def load_tags(self): values = self.read_tags() for key in ('min', 'max', 'desired'): try: # Check to see if the loaded value is a number value = int(values[key]) except ValueError: # Not int msg = '{} value for {} is not an integer'.format( key, self.name) console.warning(msg) value = 0 except IndexError: # Doesn't exist value = 0 # ??? Is Zero a valid value? (use -1 instead?) # If loaded value is invalid, warn and set to 1 if key not in values or value == 0: if key not in values: fmt = 'No saved {} value for {}, setting to 1' else: fmt = 'Save {} value is zero, setting to 1' msg = fmt.format(key, self.name) console.warning(msg) value = 1 # Verify we won't override another value current = getattr(self, key) if current > 0 and current != value: fmt = 'Override curent {} value ({}) with loaded value ({}) ?' msg = fmt.format(key, current, value) if not console.confirm(msg): value = current setattr(self, key, value)
parser.add_argument("--dry-run", "-n", action="store_true", help="If the actions should be dry runned") parser.add_argument("action", choices=actions, metavar="action", help="Action to execute") parser.add_bosslet() args = parser.parse_args() DRY_RUN = args.dry_run bosslet_config = args.bosslet_config choice = console.confirm("Are you sure you want to proceed?", timeout=30) if not choice: sys.exit(0) print("Turning the {} bosslet {}...".format(args.bosslet_name, args.action)) try: if args.action == "on": startInstances(bosslet_config) elif args.action == "off": stopInstances(bosslet_config) except Exception as ex: print("Error due to {}".format(ex)) sys.exit(1)
if len(running) == 0: console.info("No unexpected running EC2 instances exist") if not args.quiet: for inst in unlabled: console.warning('Instance {} is not labeled'.format( inst['InstanceId'])) for name, inst in items(stopped): console.warning('Instance {} ({}) is stopped'.format( inst['InstanceId'], name)) if args.delete: for name, inst in items(running): console.debug('Deleting EC2 instance {} ({})'.format( inst['InstanceId'], name)) if console.confirm('Are you sure', default=False): for inst in running.values(): client.terminate_instances( InstanceIds=[inst['InstanceId']]) else: for name, inst in items(running): console.debug('Instance {} ({})'.format( inst['InstanceId'], name)) elif args.resource == 'sg': client = args.bosslet_config.session.client('ec2') packer_sgs = [] launch_sgs = [] kwargs = {} while kwargs.get('NextToken', '') is not None: