Skip to content

Commit

Permalink
Merge pull request #373 from ycombinator/gh-360/undef
Browse files Browse the repository at this point in the history
Enabling undef lint check
  • Loading branch information
kenperkins committed Dec 9, 2014
2 parents 8f4bf99 + de4b836 commit 7c3b978
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 139 deletions.
4 changes: 2 additions & 2 deletions .jshintrc
Expand Up @@ -22,7 +22,7 @@
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : false, // true: Require all non-global variables to be declared (prevents global leaks)
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // true: Require all defined variables be used
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
"maxparams" : false, // {int} Max number of formal params allowed per function
Expand Down Expand Up @@ -71,7 +71,7 @@
"dojo" : false, // Dojo Toolkit
"jasmine" : false, // Jasmine
"jquery" : false, // jQuery
"mocha" : false, // Mocha
"mocha" : true, // Mocha
"mootools" : false, // MooTools
"node" : true, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
Expand Down
4 changes: 3 additions & 1 deletion examples/compute/joyent.js
@@ -1,4 +1,6 @@
var pkgcloud = require('../../lib/pkgcloud');
var fs = require('fs'),
path = require('path'),
pkgcloud = require('../../lib/pkgcloud');

//
// Joyent requires a username / password or key / keyId combo.
Expand Down
230 changes: 116 additions & 114 deletions lib/pkgcloud/azure/utils/azureApi.js
Expand Up @@ -32,6 +32,8 @@ var MINIMUM_POLL_INTERVAL = exports.MINIMUM_POLL_INTERVAL = 3000;

// Declaring variables for helper functions defined later
var createVM, createLinuxVM, createWindowsVM, validateCreateOptions, getServer,
getServers, rebootServer, stopServer, deleteHostedService, destroyServer, createImage,
captureServer, deleteImage, destroyImage, getMediaLinkUrl, createEndpoints,
makeTemplateRequest, createHostedService, addCertificate, getHostedServices,
deleteServer, getOSImage, deleteOSDisk, deleteOSBlob, getServersFromServices,
getServersFromService, isVM, getHostedServiceProperties, pollRequestStatus,
Expand Down Expand Up @@ -138,119 +140,6 @@ exports.createServer = function (client, options, callback) {
);
};

createVM = function (client, options, vmOptions, callback) {
// check OS type of image to determine if we are creating a linux or windows VM
switch (vmOptions.image.OS.toLowerCase()) {
case 'linux':
createLinuxVM(client, options, vmOptions, callback);
break;
case 'windows':
createWindowsVM(client, options, vmOptions, callback);
break;
default:
callback(errs.create({message: 'Unknown Image OS: ' + vmOptions.image.OS}));
break;
}
};

getMediaLinkUrl = function (storageAccount, fileName) {
return 'http://' + storageAccount + '.' + STORAGE_ENDPOINT + '/vhd/' + fileName;
};

createEndpoints = function (ports) {
var endPoints = '',
template = templates.loadSync('endpoint.xml');

(ports || []).forEach(function (port) {
endPoints += templates.compileSync(template, port);
});
return endPoints;
};

createLinuxVM = function (client, options, vmOptions, callback) {
var path = client.subscriptionId + '/services/hostedservices/' + options.name + '/deployments';
var mediaLink = getMediaLinkUrl(client.config.storageAccount, options.name + '.vhd');
var label = new Buffer(options.name).toString('base64');

var configParams = {
NAME: options.name,
LABEL_BASE64: label,
USERNAME: options.username,
PASSWORD: options.password,
SSH_CERTIFICATE_FINGERPRINT: vmOptions.sshCertInfo.fingerprint,
PORT: options.ssh.port || '22',
LOCAL_PORT: options.ssh.localPort || '22',
ROLESIZE: options.flavor,
ENDPOINTS: createEndpoints(options.ports),
OS_SOURCE_IMAGE_NAME: vmOptions.image.Name,
OS_IMAGE_MEDIALINK: mediaLink
};

makeTemplateRequest(client, path, 'linuxDeployment.xml', configParams, callback);
};

createWindowsVM = function (client, options, vmOptions, callback) {
var path = client.subscriptionId + '/services/hostedservices/' + options.name + '/deployments';
var mediaLink = getMediaLinkUrl(client.config.storageAccount, options.name + '.vhd');
var label = new Buffer(options.name).toString('base64');

var configParams = {
NAME: options.name,
COMPUTER_NAME: options.computerName || options.name.slice(0, 15),
LABEL_BASE64: label,
PASSWORD: options.password,
ROLESIZE: options.flavor,
ENDPOINTS: createEndpoints(options.ports),
OS_SOURCE_IMAGE_NAME: vmOptions.image.Name,
OS_IMAGE_MEDIALINK: mediaLink
};

makeTemplateRequest(client, path, 'windowsDeployment.xml', configParams, callback);
};

captureServer = function (client, serverName, targetImageName, callback) {
// <subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roleinstances/<role-name>/operations
var path = client.subscriptionId + '/services/hostedservices/' +
serverName + '/deployments/' +
serverName + '/roleInstances/' +
serverName + '/Operations';

var configParams = {
NAME: targetImageName
};

makeTemplateRequest(client, path, 'captureRole.xml', configParams, callback);
};

var deleteImage = function (client, image, callback) {
// https://management.core.windows.net/<subscription-id>/services/images/<image-name>
var path = client.subscriptionId + '/services/images/' + image.Name;

var configParams = {
LABEL: image.LABEL
};

makeTemplateRequest(client, path, 'deleteImage.xml', configParams, callback);
};

validateCreateOptions = function (options, config, callback) {
if (typeof options === 'function') {
options = {};
}
options = options || {}; // no args

// check required options values
['flavor', 'image', 'name', 'username', 'password', 'location'].forEach(function (member) {
if (!options[member]) {
errs.handle(
errs.create({ message: 'options.' + member + ' is a required argument.' }),
callback
);
}
});
callback();
};

/**
* getServer
*/
Expand Down Expand Up @@ -345,7 +234,7 @@ rebootServer = exports.rebootServer = function (client, serviceName, callback) {
* POST https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roleinstances/<role-name>/operations
* A successful operation returns status code 201 (Created). Need to poll for success?
*/
var stopServer = exports.stopServer = function (client, serviceName, callback) {
stopServer = exports.stopServer = function (client, serviceName, callback) {
var path = client.subscriptionId + '/services/hostedservices/' +
serviceName + '/deployments/' +
serviceName + '/roleInstances/' +
Expand Down Expand Up @@ -681,6 +570,17 @@ createImage = exports.createImage = function (client, serverName, targetImageNam
);
};

deleteImage = function (client, image, callback) {
// https://management.core.windows.net/<subscription-id>/services/images/<image-name>
var path = client.subscriptionId + '/services/images/' + image.Name;

var configParams = {
LABEL: image.LABEL
};

makeTemplateRequest(client, path, 'deleteImage.xml', configParams, callback);
};

/**
* destroyImage()
* 1. get the requested image
Expand All @@ -701,6 +601,108 @@ destroyImage = exports.destroyImage = function (client, imageName, callback) {
);
};

createVM = function (client, options, vmOptions, callback) {
// check OS type of image to determine if we are creating a linux or windows VM
switch (vmOptions.image.OS.toLowerCase()) {
case 'linux':
createLinuxVM(client, options, vmOptions, callback);
break;
case 'windows':
createWindowsVM(client, options, vmOptions, callback);
break;
default:
callback(errs.create({message: 'Unknown Image OS: ' + vmOptions.image.OS}));
break;
}
};

getMediaLinkUrl = function (storageAccount, fileName) {
return 'http://' + storageAccount + '.' + STORAGE_ENDPOINT + '/vhd/' + fileName;
};

createEndpoints = function (ports) {
var endPoints = '',
template = templates.loadSync('endpoint.xml');

(ports || []).forEach(function (port) {
endPoints += templates.compileSync(template, port);
});
return endPoints;
};

createLinuxVM = function (client, options, vmOptions, callback) {
var path = client.subscriptionId + '/services/hostedservices/' + options.name + '/deployments';
var mediaLink = getMediaLinkUrl(client.config.storageAccount, options.name + '.vhd');
var label = new Buffer(options.name).toString('base64');

var configParams = {
NAME: options.name,
LABEL_BASE64: label,
USERNAME: options.username,
PASSWORD: options.password,
SSH_CERTIFICATE_FINGERPRINT: vmOptions.sshCertInfo.fingerprint,
PORT: options.ssh.port || '22',
LOCAL_PORT: options.ssh.localPort || '22',
ROLESIZE: options.flavor,
ENDPOINTS: createEndpoints(options.ports),
OS_SOURCE_IMAGE_NAME: vmOptions.image.Name,
OS_IMAGE_MEDIALINK: mediaLink
};

makeTemplateRequest(client, path, 'linuxDeployment.xml', configParams, callback);
};

createWindowsVM = function (client, options, vmOptions, callback) {
var path = client.subscriptionId + '/services/hostedservices/' + options.name + '/deployments';
var mediaLink = getMediaLinkUrl(client.config.storageAccount, options.name + '.vhd');
var label = new Buffer(options.name).toString('base64');

var configParams = {
NAME: options.name,
COMPUTER_NAME: options.computerName || options.name.slice(0, 15),
LABEL_BASE64: label,
PASSWORD: options.password,
ROLESIZE: options.flavor,
ENDPOINTS: createEndpoints(options.ports),
OS_SOURCE_IMAGE_NAME: vmOptions.image.Name,
OS_IMAGE_MEDIALINK: mediaLink
};

makeTemplateRequest(client, path, 'windowsDeployment.xml', configParams, callback);
};

captureServer = function (client, serverName, targetImageName, callback) {
// <subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roleinstances/<role-name>/operations
var path = client.subscriptionId + '/services/hostedservices/' +
serverName + '/deployments/' +
serverName + '/roleInstances/' +
serverName + '/Operations';

var configParams = {
NAME: targetImageName
};

makeTemplateRequest(client, path, 'captureRole.xml', configParams, callback);
};

validateCreateOptions = function (options, config, callback) {
if (typeof options === 'function') {
options = {};
}
options = options || {}; // no args

// check required options values
['flavor', 'image', 'name', 'username', 'password', 'location'].forEach(function (member) {
if (!options[member]) {
errs.handle(
errs.create({ message: 'options.' + member + ' is a required argument.' }),
callback
);
}
});
callback();
};

exports._updateMinimumPollInterval = function(interval) {
MINIMUM_POLL_INTERVAL = interval;
};
2 changes: 1 addition & 1 deletion lib/pkgcloud/hp/identity/hpIdentity.js
Expand Up @@ -11,7 +11,7 @@ var identity = require('../../openstack/context'),
Identity = identity.Identity,
util = require('util');

exports.Identity = HPIdentity = function (options) {
var HPIdentity = exports.Identity = function (options) {
this.options = options;
this.name = 'HPIdentity';

Expand Down
3 changes: 3 additions & 0 deletions lib/pkgcloud/openstack/network/client/networks.js
Expand Up @@ -10,6 +10,9 @@ var urlJoin = require('url-join');

var networksResourcePath = '/networks';

// Declaring variables for helper functions defined later
var _convertNetworkToWireFormat;

/**
* client.getNetworks
*
Expand Down
3 changes: 3 additions & 0 deletions lib/pkgcloud/openstack/network/client/ports.js
Expand Up @@ -10,6 +10,9 @@ var urlJoin = require('url-join');

var portsResourcePath = '/ports';

// Declaring variables for helper functions defined later
var _convertPortToWireFormat;

/**
* client.getPorts
*
Expand Down
3 changes: 3 additions & 0 deletions lib/pkgcloud/openstack/network/client/subnets.js
Expand Up @@ -10,6 +10,9 @@ var urlJoin = require('url-join');

var subnetsResourcePath = '/subnets';

// Declaring variables for helper functions defined later
var _convertSubnetToWireFormat;

/**
* client.getSubnets
*
Expand Down
1 change: 0 additions & 1 deletion lib/pkgcloud/openstack/storage/client/files.js
Expand Up @@ -175,7 +175,6 @@ exports.upload = function (options) {
*/
exports.download = function (options, callback) {
var self = this,
success = callback ? onDownload : null,
container = options.container,
inputStream,
apiStream;
Expand Down
2 changes: 1 addition & 1 deletion lib/pkgcloud/rackspace/identity/rackspaceIdentity.js
Expand Up @@ -12,7 +12,7 @@ var identity = require('../../openstack/context'),
Identity = identity.Identity,
util = require('util');

exports.Identity = RackspaceIdentity = function (options) {
var RackspaceIdentity = exports.Identity = function (options) {
this.options = options;
this.name = 'RackspaceIdentity';

Expand Down
6 changes: 5 additions & 1 deletion test/common/compute/server-test.js
Expand Up @@ -21,7 +21,7 @@ var azureOptions = require('../../fixtures/azure/azure-options.json');

// Declaring variables for helper functions defined later
var setupImagesMock, setupFlavorMock, setupServerMock, setupGetServersMock,
setupGetServerMock, serverStatusReply;
setupGetServerMock, setupRebootMock, serverStatusReply;

azureApi._updateMinimumPollInterval(mock ? 10 : azureApi.MINIMUM_POLL_INTERVAL);

Expand Down Expand Up @@ -579,6 +579,10 @@ setupGetServerMock = function (client, provider, servers) {
}
};

setupRebootMock = function() {
// TODO
};

//
//function batchThree(providerClient, providerName) {
// var name = providerName || 'rackspace',
Expand Down
18 changes: 0 additions & 18 deletions test/common/network/network-test.js
Expand Up @@ -484,21 +484,3 @@ setupGetNetworkMock = function (client, provider, servers) {
.replyWithFile(200, __dirname + '/../../fixtures/rackspace/network.json');
}
};

serverStatusReply = function (name, status) {

var template = helpers.loadFixture('azure/server-status-template.xml'),
params = {NAME: name, STATUS: status};

var result = _.template(template, params);
return result;
};

filterPath = function (path) {
var name = PATH.basename(path);
if (path.search('embed-detail=true') !== -1) {
return '/getStatus?name=' + name;
}

return path;
};

0 comments on commit 7c3b978

Please sign in to comment.