This commit is contained in:
Igor Zinkovsky 2012-05-22 10:26:16 -07:00
Родитель 050315a3a2
Коммит 52ba7142c9
1 изменённых файлов: 39 добавлений и 21 удалений

Просмотреть файл

@ -113,7 +113,7 @@ exports.init = function(cli) {
.option('-c, --connect', 'connect to existing VMs') .option('-c, --connect', 'connect to existing VMs')
.option('-l, --location <name>', 'location of the data center') .option('-l, --location <name>', 'location of the data center')
.option('-a, --affinity-group <name>', 'affinity group') .option('-a, --affinity-group <name>', 'affinity group')
.option('-t, --ssh [cert]', 'upload SSH and upload ssh cert to VM') // $TODO: make ssh work with create-from .option('-t, --ssh-cert <pem-file>', 'Upload SSH certificate')
.option('-s, --subscription <id>', 'use the subscription id') .option('-s, --subscription <id>', 'use the subscription id')
.execute(function(dnsName, roleFile, options, callback) { .execute(function(dnsName, roleFile, options, callback) {
@ -137,7 +137,8 @@ exports.init = function(cli) {
location: options.location, location: options.location,
dnsPrefix: dnsPrefix, dnsPrefix: dnsPrefix,
connect: options.connect, connect: options.connect,
role: role role: role,
sshCert: options.sshCert
}, callback); }, callback);
}); });
@ -495,7 +496,18 @@ exports.init = function(cli) {
if (options.role) { if (options.role) {
role = options.role; role = options.role;
logger.silly('role', role); logger.silly('role', role);
doSvcMgmtRoleCreate();
if (options.sshCert) {
loadSshCert();
progress = cli.progress('Configuring certificate');
configureCert(dnsPrefix, function() {
progress.end();
doSvcMgmtRoleCreate();
});
} else {
doSvcMgmtRoleCreate();
}
} else { } else {
// find the provided image // find the provided image
logger.verbose('looking for image ' + options.imageName); logger.verbose('looking for image ' + options.imageName);
@ -526,6 +538,17 @@ exports.init = function(cli) {
} }
}); });
} }
function loadSshCert() {
logger.silly('trying to open SSH cert: ' + options.sshCert);
pemSshCert = fs.readFileSync(options.sshCert);
var pemSshCertStr = pemSshCert.toString();
if (!utils.isPemCert(pemSshCertStr)) {
cmdCallback('Specified SSH certificate is not in PEM format');
}
sshFingerprint = utils.getCertFingerprint(pemSshCertStr);
}
function createDefaultRole(name, callback) { function createDefaultRole(name, callback) {
var inputEndPoints = []; var inputEndPoints = [];
@ -565,14 +588,7 @@ exports.init = function(cli) {
if (utils.isSha1Hash(options.sshCert)) { if (utils.isSha1Hash(options.sshCert)) {
sshFingerprint = options.sshCert; sshFingerprint = options.sshCert;
} else { } else {
logger.silly('trying to open SSH cert: ' + options.sshCert); loadSshCert();
pemSshCert = fs.readFileSync(options.sshCert);
var pemSshCertStr = pemSshCert.toString();
if (!utils.isPemCert(pemSshCertStr)) {
cmdCallback('Specified SSH certificate is not in PEM format');
}
sshFingerprint = utils.getCertFingerprint(pemSshCertStr);
} }
sshFingerprint = sshFingerprint.toUpperCase(); sshFingerprint = sshFingerprint.toUpperCase();
@ -615,7 +631,7 @@ exports.init = function(cli) {
if(configureSshCert) { if(configureSshCert) {
progress = cli.progress('Configuring certificate'); progress = cli.progress('Configuring certificate');
configureCert(dnsPrefix, function(error, response) { configureCert(dnsPrefix, function() {
progress.end(); progress.end();
logger.verbose('role:'); logger.verbose('role:');
logger.json('verbose', role); logger.json('verbose', role);
@ -662,16 +678,18 @@ exports.init = function(cli) {
} }
function configureCert(service, callback) { function configureCert(service, callback) {
provisioningConfig.SSH = { if (provisioningConfig) {
PublicKeys: [ { provisioningConfig.SSH = {
Fingerprint: sshFingerprint, PublicKeys: [ {
Path: '/home/' + options.userName + '/.ssh/authorized_keys' Fingerprint: sshFingerprint,
} Path: '/home/' + options.userName + '/.ssh/authorized_keys'
] }
}; ]
};
logger.silly('provisioningConfig with SSH:'); logger.silly('provisioningConfig with SSH:');
logger.silly(JSON.stringify(provisioningConfig)); logger.silly(JSON.stringify(provisioningConfig));
}
if (pemSshCert) { if (pemSshCert) {
logger.verbose('uploading cert'); logger.verbose('uploading cert');