github.com/enmand/kubernetes@v1.2.0-alpha.0/docs/getting-started-guides/coreos/azure/lib/cloud_config.js (about) 1 var _ = require('underscore'); 2 var fs = require('fs'); 3 var yaml = require('js-yaml'); 4 var colors = require('colors/safe'); 5 6 var write_cloud_config_from_object = function (data, output_file) { 7 try { 8 fs.writeFileSync(output_file, [ 9 '#cloud-config', 10 yaml.safeDump(data), 11 ].join("\n")); 12 return output_file; 13 } catch (e) { 14 console.log(colors.red(e)); 15 } 16 }; 17 18 exports.generate_environment_file_entry_from_object = function (hostname, environ) { 19 var data = { 20 hostname: hostname, 21 environ_array: _.map(environ, function (value, key) { 22 return [key.toUpperCase(), JSON.stringify(value.toString())].join('='); 23 }), 24 }; 25 26 return { 27 permissions: '0600', 28 owner: 'root', 29 content: _.template("<%= environ_array.join('\\n') %>\n")(data), 30 path: _.template("/etc/weave.<%= hostname %>.env")(data), 31 }; 32 }; 33 34 exports.process_template = function (input_file, output_file, processor) { 35 var data = {}; 36 try { 37 data = yaml.safeLoad(fs.readFileSync(input_file, 'utf8')); 38 } catch (e) { 39 console.log(colors.red(e)); 40 } 41 return write_cloud_config_from_object(processor(_.clone(data)), output_file); 42 }; 43 44 exports.write_files_from = function (local_dir, remote_dir) { 45 try { 46 return _.map(fs.readdirSync(local_dir), function (fn) { 47 return { 48 path: [remote_dir, fn].join('/'), 49 owner: 'root', 50 permissions: '0640', 51 encoding: 'base64', 52 content: fs.readFileSync([local_dir, fn].join('/')).toString('base64'), 53 }; 54 }); 55 } catch (e) { 56 console.log(colors.red(e)); 57 } 58 };