Updating for tc2
It seems webspace name is now affinitized to data center
This commit is contained in:
Родитель
d00559f51b
Коммит
9720f4a2f1
103
lib/cli/cli.js
103
lib/cli/cli.js
|
@ -11,27 +11,40 @@ var Table = require('easy-table');
|
|||
var cli = new commander.Command();
|
||||
cli.output = log;
|
||||
|
||||
log.setLevel = function (level) {
|
||||
cli.output.remove(cli.output.transports.Console);
|
||||
cli.output.add(cli.output.transports.Console, { level: level });
|
||||
cli.output.cli();
|
||||
log.reset = function (options) {
|
||||
log.format = options;
|
||||
log.level = options.level;
|
||||
log.stripColors = options.stripColors;
|
||||
log.remove(log.transports.Console);
|
||||
log.add(log.transports.Console, options);
|
||||
log.cli();
|
||||
if (options.json) {
|
||||
log.padLevels = false;
|
||||
}
|
||||
};
|
||||
|
||||
log.setLevel('info');
|
||||
log.reset({ level: 'info' });
|
||||
//log['default'].transports.console.level = 'silly';
|
||||
//log['default'].transports.console.json = true;
|
||||
|
||||
log.json = function (level, data) {
|
||||
if (arguments.length == 1) {
|
||||
data = level;
|
||||
level = 'data';
|
||||
}
|
||||
var lines = eyes.inspect(data, level, { stream: false });
|
||||
lines.split('\n').forEach(function (line) {
|
||||
// eyes all is "cyan" by default, so this property accessor will
|
||||
// fix the entry/exit color codes of the line. it's needed because we're
|
||||
// splitting the eyes formatting and inserting winston formatting where it
|
||||
// wasn't before.
|
||||
log.log(level, line[eyes.defaults.styles.all]);
|
||||
});
|
||||
if (log.format.json) {
|
||||
log.log(level, typeof data, data);
|
||||
}
|
||||
else {
|
||||
var lines = eyes.inspect(data, level, { stream: false });
|
||||
lines.split('\n').forEach(function (line) {
|
||||
// eyes all is "cyan" by default, so this property accessor will
|
||||
// fix the entry/exit color codes of the line. it's needed because we're
|
||||
// splitting the eyes formatting and inserting winston formatting where it
|
||||
// wasn't before.
|
||||
log.log(level, line[eyes.defaults.styles.all]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -41,30 +54,36 @@ log.table = function (level, data, transform) {
|
|||
data = level;
|
||||
level = 'data';
|
||||
}
|
||||
var table = new Table();
|
||||
table.LeftPadder = Table.LeftPadder;
|
||||
table.padLeft = Table.padLeft;
|
||||
table.RightPadder = Table.RightPadder;
|
||||
table.padRight = Table.padRight;
|
||||
|
||||
if (data.forEach) {
|
||||
data.forEach(function (item) { transform(table, item); table.newLine(); });
|
||||
if (log.format.json) {
|
||||
log.log(level, "table", data);
|
||||
}
|
||||
else {
|
||||
for (var item in data) {
|
||||
transform(table, item);
|
||||
table.newLine();
|
||||
}
|
||||
}
|
||||
var table = new Table();
|
||||
table.LeftPadder = Table.LeftPadder;
|
||||
table.padLeft = Table.padLeft;
|
||||
table.RightPadder = Table.RightPadder;
|
||||
table.padRight = Table.padRight;
|
||||
|
||||
var lines = table.toString();
|
||||
lines.substring(0, lines.length - 1).split('\n').forEach(function (line) {
|
||||
log.log(level, line);
|
||||
});
|
||||
if (data.forEach) {
|
||||
data.forEach(function (item) { transform(table, item); table.newLine(); });
|
||||
}
|
||||
else {
|
||||
for (var item in data) {
|
||||
transform(table, item);
|
||||
table.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
var lines = table.toString();
|
||||
lines.substring(0, lines.length - 1).split('\n').forEach(function (line) {
|
||||
log.log(level, line);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function enableNestedCommands(command) {
|
||||
command.option('-v, --verbose', 'use verbose output');
|
||||
command.option('--json', 'use json output');
|
||||
|
||||
command.categories = {};
|
||||
|
||||
|
@ -85,9 +104,13 @@ function enableNestedCommands(command) {
|
|||
var raw = command.normalize(command.rawArgs.slice(2));
|
||||
|
||||
var verbose = 0;
|
||||
var json = 0;
|
||||
var category = '*';
|
||||
for (var i = 0, len = raw.length; i < len; ++i) {
|
||||
if (raw[i] === '-v' || raw[i] === '--verbose') {
|
||||
if (raw[i] === '--json') {
|
||||
++json;
|
||||
}
|
||||
else if (raw[i] === '-v' || raw[i] === '--verbose') {
|
||||
++verbose;
|
||||
} else if (category === '*') {
|
||||
category = raw[i];
|
||||
|
@ -95,10 +118,20 @@ function enableNestedCommands(command) {
|
|||
args.push(raw[i]);
|
||||
}
|
||||
}
|
||||
if (verbose == 1) {
|
||||
log.setLevel('verbose');
|
||||
} else if (verbose >= 2) {
|
||||
log.setLevel('silly');
|
||||
|
||||
if (verbose || json) {
|
||||
var opts = {};
|
||||
if (verbose == 1) {
|
||||
opts.level = 'verbose';
|
||||
}
|
||||
if (verbose >= 2) {
|
||||
opts.level = 'silly';
|
||||
}
|
||||
if (json) {
|
||||
opts.json = true;
|
||||
opts.stripColors = true;
|
||||
}
|
||||
log.reset(opts);
|
||||
}
|
||||
|
||||
if (!command.categories[category]) {
|
||||
|
|
|
@ -60,29 +60,40 @@ exports.init = function (cli) {
|
|||
log.info('Listing your web sites');
|
||||
log.verbose('Subscription ', subscription);
|
||||
|
||||
log.json(site);
|
||||
|
||||
getChannel()
|
||||
.path(subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites/')
|
||||
.path('services/webspaces/northeuropewebspace/sites/')
|
||||
.GET(function (err, data) {
|
||||
if (err) {
|
||||
log.error(err.Message);
|
||||
log.verbose('Error', clean(err));
|
||||
}
|
||||
else {
|
||||
for (var index in data.Site) {
|
||||
log.data('Site', {
|
||||
Name: data.Site[index].Name,
|
||||
State: data.Site[index].State,
|
||||
UsageState: data.Site[index].UsageState
|
||||
});
|
||||
log.verbose('Site', clean(data.Site[index]));
|
||||
}
|
||||
|
||||
data.Site = isArray(data.Site) ? data.Site : [data.Site];
|
||||
log.json('verbose', data);
|
||||
|
||||
log.table(data.Site, function (row, site) {
|
||||
row.cell('Name', site.Name);
|
||||
row.cell('State', site.State);
|
||||
row.cell('Host names', clean(site).HostNames);
|
||||
});
|
||||
// for (var index in data.Site) {
|
||||
// log.data('Site', {
|
||||
// Name: data.Site[index].Name,
|
||||
// State: data.Site[index].State,
|
||||
// UsageState: data.Site[index].UsageState
|
||||
// });
|
||||
// log.verbose('Site', clean(data.Site[index]));
|
||||
// }
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function isArray(testObject) {
|
||||
return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
|
||||
}
|
||||
|
||||
site.command('show <name>')
|
||||
.description('Show details for a web sites.')
|
||||
.option('-s, --subscription <id>', 'use the subscription id')
|
||||
|
@ -150,7 +161,7 @@ exports.init = function (cli) {
|
|||
|
||||
getChannel()
|
||||
.path(subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites/')
|
||||
.path('services/webspaces/northeuropewebspace/sites/')
|
||||
.path(name)
|
||||
.DELETE(function (err, thing) {
|
||||
console.log(thing);
|
||||
|
@ -167,7 +178,7 @@ exports.init = function (cli) {
|
|||
|
||||
getChannel()
|
||||
.path(subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites/')
|
||||
.path('services/webspaces/northeuropewebspace/sites/')
|
||||
.path(name)
|
||||
.header('Content-Type', 'application/xml')
|
||||
.POST(function (req) {
|
||||
|
@ -192,7 +203,7 @@ exports.init = function (cli) {
|
|||
|
||||
getChannel()
|
||||
.path(subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites/')
|
||||
.path('services/webspaces/northeuropewebspace/sites/')
|
||||
.path(name)
|
||||
.header('Content-Type', 'application/xml')
|
||||
.PUT(function (req) {
|
||||
|
@ -219,7 +230,7 @@ exports.init = function (cli) {
|
|||
|
||||
getChannel()
|
||||
.path(options.subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites/')
|
||||
.path('services/webspaces/northeuropewebspace/sites/')
|
||||
.header('Content-Type', 'application/xml')
|
||||
.POST(
|
||||
writers.Site.xml(options.site),
|
||||
|
@ -244,7 +255,7 @@ exports.init = function (cli) {
|
|||
|
||||
getChannel()
|
||||
.path(options.subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites/')
|
||||
.path('services/webspaces/northeuropewebspace/sites/')
|
||||
.path(options.site.name)
|
||||
.path('repository')
|
||||
.POST(
|
||||
|
@ -265,7 +276,7 @@ exports.init = function (cli) {
|
|||
site.doSiteGet = function (options, done, failed) {
|
||||
getChannel()
|
||||
.path(options.subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites')
|
||||
.path('services/webspaces/northeuropewebspace/sites')
|
||||
.path(options.site.name)
|
||||
.GET(
|
||||
function (err, result) {
|
||||
|
@ -284,7 +295,7 @@ exports.init = function (cli) {
|
|||
site.doSiteConfigGet = function (options, done, failed) {
|
||||
getChannel()
|
||||
.path(options.subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites')
|
||||
.path('services/webspaces/northeuropewebspace/sites')
|
||||
.path(options.site.name)
|
||||
.path('config')
|
||||
.GET(
|
||||
|
@ -304,7 +315,7 @@ exports.init = function (cli) {
|
|||
site.doRepositoryGet = function (options, done, failed) {
|
||||
getChannel()
|
||||
.path(options.subscription)
|
||||
.path('services/webspaces/ctpwebspace/sites')
|
||||
.path('services/webspaces/northeuropewebspace/sites')
|
||||
.path(options.site.name)
|
||||
.path('repository')
|
||||
.GET(
|
||||
|
@ -332,7 +343,8 @@ exports.init = function (cli) {
|
|||
req.write('<Site xmlns="http://schemas.microsoft.com/windowsazure">');
|
||||
req.write('<HostNames>');
|
||||
req.write('<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">');
|
||||
req.write(site.name + '.antint0.antares-test.windows-int.net');
|
||||
req.write(site.name + '.antdir0.antares-test.windows-int.net');
|
||||
|
||||
req.write('</string>');
|
||||
// req.write('<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">');
|
||||
// req.write('www.' + site.name + '.antint0.antares-test.windows-int.net');
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
|
||||
var fs = require('fs');
|
||||
var pfx2pem = require('../../util/certificates/pkcs').pfx2pem;
|
||||
var Channel = require('../channel');
|
||||
|
||||
|
||||
exports.init = function (waz) {
|
||||
var cli = waz;
|
||||
function getChannel() {
|
||||
var pem = cli.category('account').managementCertificate();
|
||||
|
||||
var channel = new Channel({
|
||||
host: 'umapi-tc2.rdfetest.dnsdemo4.com',
|
||||
port: 8443,
|
||||
key: pem,
|
||||
cert: pem
|
||||
}).header('x-ms-version', '2011-02-25');
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
var space = waz.category('space')
|
||||
.description('Commands to manage your Azure web spaces.');
|
||||
|
||||
space.command('show [name]')
|
||||
.description('Show info about a web space.')
|
||||
.option('-s, --subscription <id>', 'use the subscription id')
|
||||
.action(function (name, options) {
|
||||
|
||||
var subscription = options.subscription || waz.category('account').defaultSubscriptionId();
|
||||
|
||||
getChannel()
|
||||
.header('x-ms-version', '2011-02-25')
|
||||
.path(subscription)
|
||||
.path('services/webspaces')
|
||||
.path(name || '')
|
||||
.GET(function (err, thing) {
|
||||
console.log(thing);
|
||||
});
|
||||
});
|
||||
|
||||
space.command('delete <name>')
|
||||
.description('Kill a web space.')
|
||||
.option('-s, --subscription <id>', 'use the subscription id')
|
||||
.action(function (name, options) {
|
||||
|
||||
var subscription = options.subscription || waz.category('account').defaultSubscriptionId();
|
||||
|
||||
channel
|
||||
.header('x-ms-version', '2011-02-25')
|
||||
.path(subscription)
|
||||
.path('services/webspaces')
|
||||
.path(name)
|
||||
.DELETE(function (err, thing) {
|
||||
console.log(thing);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
space.command('create <name>')
|
||||
.description('Create a web space.')
|
||||
.option('-s, --subscription <id>', 'use the subscription id')
|
||||
.option('-p, --plan <plan>', 'use the plan')
|
||||
.action(function (name, options) {
|
||||
|
||||
var subscription = options.subscription || waz.category('account').defaultSubscriptionId();
|
||||
|
||||
channel
|
||||
.header('x-ms-version', '2011-02-25')
|
||||
.path(subscription)
|
||||
.path('services/webspaces/')
|
||||
.header('Content-Type', 'application/xml')
|
||||
.POST(function (req) {
|
||||
req.write('<WebSpace xmlns="http://schemas.microsoft.com/windowsazure">');
|
||||
req.write('<Name>');
|
||||
req.write(name);
|
||||
req.write('</Name>');
|
||||
req.write('<Plan>');
|
||||
req.write(options.plan || 'Plan 1');
|
||||
req.write('</Plan>');
|
||||
req.write('<Subscription>');
|
||||
req.write(subscription);
|
||||
req.write('</Subscription>');
|
||||
req.write('</WebSpace>');
|
||||
|
||||
req.end();
|
||||
},
|
||||
function (err, thing) {
|
||||
console.log(thing);
|
||||
});
|
||||
});
|
||||
};
|
Загрузка…
Ссылка в новой задаче