Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Remove puppet-specific code. #11

Open
wants to merge 3 commits into from

1 participant

Commits on Mar 11, 2013
  1. @willwhite

    Remove puppet-specific code.

    willwhite authored
Commits on Mar 12, 2013
  1. @willwhite
  2. @willwhite
This page is out of date. Refresh to see the latest.
View
51 README.md
@@ -31,54 +31,3 @@ Get the hostname of all instances in my Swarm.
You can use multiple filters at once. This will list the hostanme for all database servers in the staging swarm.
node index.js --config config.json metadata --attribute dnsName --filter.Swarm staging --filter.Class database-server
-
-## Puppet ENC spec
-
-Swarm implements four special filters:
-
-* Class - corresponds to the ec2 tag PuppetClasses.
-* Parameter - corresponds to the ec2 tag PuppetParameters
-* Environment - corresponds to the ec2 tag PuppetEnvironment
-* ClassParameter - does not correspond to any ec2 tag; is a meta parameter. See below.
-
-which correspond to [the Puppet ENC spec](http://docs.puppetlabs.com/guides/external_nodes.html#enc-output-format).
-
-The following special ec2 tags which correspond to the special --filter(s) mentioned above should have the following format:
-
-### PuppetClasses
-
-A JSON object, such as
-
-```json
-{"common":null,"puppet":null,"ntp":{"ntpserver":"0.pool.ntp.org"},"aptsetup":{"additional_apt_repos":["deb localrepo.example.com/ubuntu lucid production","deb localrepo.example.com/ubuntu lucid vendor"]}}
-```
-
-### PuppetParameters
-
-A JSON object, such as
-
-```json
-{"ntp_servers":["0.pool.ntp.org","ntp.example.com"],"mail_server":"mail.example.com","iburst":true}
-```
-
-### PuppetEnvironment
-
-A string, such as
-
- production
-
-### Filter with special filters and ec2 tags
-
-Filter your ec2's using Swarm with commands like:
-
- node index.js --config config.json metadata --attribute dnsName --filter.Class ntp
-
- node index.js --config config.json metadata --attribute dnsName --filter.ClassParameter ntp:ntp_server
-
- node index.js --config config.json metadata --attribute dnsName --filter.Parameter ntp_servers
-
- node index.js --config config.json metadata --attribute dnsName --filter.Environment production
-
-Notice the ClassParameter filter is a class name and a parameter on that class separated by a colon. At present, swarm does not check the value of a paramter or class parameter, but instead filters based on whether or not that paramter or class paramter exists at all.
-
-
View
36 index.js
@@ -3,7 +3,6 @@
var Step = require('step');
var _ = require('underscore');
var fs = require('fs');
-var yamlish = require('yamlish');
var instanceMetadata = require('./lib/instance-metadata');
var ec2Api= require('./lib/ec2-api');
@@ -12,11 +11,10 @@ var optimist = require('optimist')
'Usage: $0 <command> [options]\n\n' +
'Available commands:\n' +
' list: list active swarms\n' +
- ' metadata: load given attribute from EC2 API\n' +
- ' classify: return list of puppet classes in YAML format suitable for use with puppet\'s ENC feature')
+ ' metadata: load given attribute from EC2 API\n')
.describe('config', 'Path to JSON configuration file that contains awsKey and awsSecret.')
.describe('attribute', 'The EC2 API instance attribute to load from the swarm. Required for the metadata command.')
- .describe('filter', 'Applies a filter to results based on EC2 instance attributes and tags. Use `filter.<attributeName>`. Multiple filters are applied with the AND operator. Required for the classify command and optional for the metadata command.')
+ .describe('filter', 'Applies a filter to results based on EC2 instance attributes and tags. Use `filter.<attributeName>`. Multiple filters are applied with the AND operator. Optional for the metadata command.')
.describe('awsKey', 'awsKey, overrides the value in gconfig file if both are provided.')
.describe('awsSecret', 'awsSecret, overrides the value in config file if both are provided.')
.default('regions', 'us-east-1,us-west-1,us-west-2,eu-west-1,ap-southeast-1,ap-northeast-1,sa-east-1');
@@ -29,18 +27,12 @@ if (argv.help) {
var command = argv._[0];
if (!command) command = 'list';
-if (!_(['list', 'metadata', 'classify']).include(command)) {
+if (!_(['list', 'metadata']).include(command)) {
optimist.showHelp();
console.error('Invalid command %s.', command);
process.exit(1);
}
-if (command === 'classify' && !argv.filter) {
- optimist.showHelp();
- console.error('Missing --filter option required for %s command.', command);
- process.exit(1);
-}
-
if (command === 'metadata' && !argv.attribute) {
optimist.showHelp();
console.error('Missing --attribute option required for %s command.', command);
@@ -108,28 +100,6 @@ swarm.metadata = function() {
}
-// ENC Interface for Puppet and EC2 Tags
-//
-// Accepts an EC2 private hostname as an argument. Looks up the tags
-// on the EC2 instance and outputs puppet classes as YAML.
-//
-// See puppet docs on ENC:
-// http://docs.puppetlabs.com/guides/external_nodes.html
-//
-swarm.classify = function() {
- Step(function() {
- ec2Api.loadInstances(ec2Api.createClients(config, regions), argv.filter, this);
- }, function(err, instances) {
- if (err) throw err;
- var instance = _(instances).first();
- var hash = {};
- if (instance['PuppetClasses']) hash['classes'] = JSON.parse(instance['PuppetClasses']);
- if (instance['PuppetParameters']) hash['parameters'] = JSON.parse(instance['PuppetParameters']);
- if (instance['PuppetEnvironment']) hash['environment'] = instance['PuppetEnvironment'];
- console.log(yamlish.encode(hash));
- });
-};
-
// If any supported arguments have the `_self` value we resolve then first, and
// then actually run the command.
Step(function() {
View
42 lib/ec2-api.js
@@ -63,45 +63,11 @@ exports.loadInstances = function(clients, filters, callback) {
return i;
});
- // Special filters
- var exclude = ['Class', 'Parameter', 'Environment', 'ClassParameter'];
-
_(filters).each(function(v, k) {
- if (_.indexOf(exclude, k) == -1) {
- i = i.filter(function(instance) {
- return _(instance[k]).isString() &&
- instance[k].toLowerCase() === v.toLowerCase();
- });
- } else {
- // Handle special filters
- i = i.filter(function(instance) {
- switch(k) {
- case 'Class':
- if (instance.PuppetClasses) {
- return _.has(JSON.parse(instance.PuppetClasses), filters.Class);
- } else { return false }
- case 'Parameter':
- // These are global parameters, not class parameters
- if (instance.PuppetParameters) {
- return _.has(JSON.parse(instance.PuppetParameters), filters.Parameter);
- } else { return false }
- case 'Environment':
- if (instance.PuppetEnvironment) {
- return instance.PuppetEnvironment === filters.Environment;
- } else { return false }
- case 'ClassParameter':
- if (instance.PuppetClasses) {
- var klass = filters.ClassParameter.split(':')[0];
- var param = filters.ClassParameter.split(':')[1];
- if (_.has(JSON.parse(instance.PuppetClasses), klass)) {
- return _.has(JSON.parse(instance.PuppetClasses)[klass], param)
- } else { return false; }
- } else { return false; }
- default:
- return false;
- }
- });
- }
+ i = i.filter(function(instance) {
+ return _(instance[k]).isString() &&
+ instance[k].toLowerCase() === v.toLowerCase();
+ });
});
return callback(null, i.value());
View
3  package.json
@@ -16,8 +16,7 @@
"underscore": "1.3.x",
"optimist": "0.3.x",
"step": "0.0.x",
- "get": "1.1.x",
- "yamlish": "0.0.x"
+ "get": "1.1.x"
},
"devDependencies": {}
}
View
3  puppet-classifier
@@ -1,3 +0,0 @@
-#!/usr/bin/env bash
-
-/usr/bin/swarm classify --config /usr/local/etc/swarm/settings.json --filter.instanceId=_self
Something went wrong with that request. Please try again.