def nodepool_rewrite_config(): args = get_args_or_die( parse_nodepool_rewrite_config_args, issues_for_nodepool_rewrite_config ) env = NodepoolConfigEnv( get_params_or_die(args.openrc), args.image_name, args.min_ready, args.rackspace_password, args.key_name, iad_max=args.iad_max, ord_max=args.ord_max, dfw_max=args.dfw_max ) nodepool_config_file = data.nodepool_config(env.as_dict()) with remote.connect(args.username, args.host, args.port) as connection: connection.put( data.install_script('nodepool_rewrite_config.sh'), 'nodepool_rewrite_config.sh' ) connection.put( nodepool_config_file, 'nodepool.yaml' ) connection.run('bash nodepool_rewrite_config.sh') connection.run('rm -f nodepool_rewrite_config.sh') connection.run('rm -f nodepool.yaml')
def nodepool_configure(): args = get_args_or_die( _parse_nodepool_configure_args, _issues_for_nodepool_configure_args ) env = NodepoolConfigEnv( get_params_or_die(args.openrc), args.image_name, args.min_ready, args.rackspace_password, args.key_name, iad_max=args.iad_max, ord_max=args.ord_max, dfw_max=args.dfw_max ) env.project_config_branch = args.project_config_branch nodepool_config_file = data.nodepool_config(env.as_dict()) with remote.connect(args.username, args.host, args.port) as connection: connection.put( data.install_script('nodepool_rewrite_config.sh'), 'nodepool_rewrite_config.sh' ) connection.put( data.install_script('nodepool_config.sh'), 'nodepool_config.sh' ) connection.put( data.install_script('functions.sh'), 'functions.sh' ) connection.put( nodepool_config_file, 'nodepool.yaml' ) connection.put( args.nodepool_keyfile, 'nodepool.priv' ) connection.put( args.jenkins_keyfile, 'jenkins.priv' ) connection.run('%s bash nodepool_config.sh' % env.bashline) connection.run('rm -f nodepool_config.sh') connection.run('rm -f nodepool.yaml') connection.run('rm -f nodepool.priv') connection.run('rm -f jenkins.priv') connection.run('rm -f functions.sh') connection.run('rm -f nodepool_rewrite_config.sh')
def nodepool_upload_keys(): args = get_args_or_die( _parse_nodepool_upload_keys_args, _issues_for_nodepool_upload_keys_args ) env = NodepoolConfigEnv( get_params_or_die(args.openrc), 'ignored', 'ignored', 'ignored', args.key_name, ) nodepool_config_file = data.nodepool_config(env.as_dict()) nova_commands = NovaCommands(env) regions = image_provider_regions() with remote.connect(args.username, args.host, args.port) as connection: key_exists_in_regions = [] for region in regions: result = connection.run( nova_commands.keypair_show(region, env.key_name), ignore_failures=True, ) if result.succeeded: key_exists_in_regions.append(region) if key_exists_in_regions and not args.remove: raise SystemExit( 'Keypair "{keypair}" already exists at regions: {regions}' ' Please remove them manually or use --remove'.format( keypair=env.key_name, regions=','.join(key_exists_in_regions) ) ) if args.remove: for region in key_exists_in_regions: connection.run( nova_commands.keypair_delete(region, env.key_name) ) for region in regions: result = connection.run( nova_commands.keypair_add( region, env.key_name, '{home}/.ssh/id_rsa.pub'.format(home=env.home)) )
def image_provider_regions(): nodepool_config = yaml.load(data.nodepool_config(dict())) used_providers = [] for label in nodepool_config['labels']: for provider in label['providers']: used_providers.append(provider['name']) regions = [] for provider in nodepool_config['providers']: if provider['name'] in used_providers: regions.append(provider['region-name']) return regions