Updated machine util for latest docker-machine bin

Signed-off-by: French Ben <me+git@frenchben.com>
This commit is contained in:
French Ben 2015-10-23 16:50:44 -07:00
Родитель 003d6719ec
Коммит 0d49744158
1 изменённых файлов: 14 добавлений и 30 удалений

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

@ -34,29 +34,8 @@ var DockerMachine = {
return null;
}
},
info: function (machineName = this.name()) {
return util.exec([this.command(), 'ls']).then(stdout => {
var lines = stdout.trim().split('\n').filter(line => line.indexOf('time=') === -1);
var machines = {};
lines.slice(1, lines.length).forEach(line => {
var tokens = line.trim().split(/[\s]+/).filter(token => token !== '*');
var machine = {
name: tokens[0],
driver: tokens[1],
state: tokens[2],
url: tokens[3] || ''
};
machines[machine.name] = machine;
});
if (machines[machineName]) {
return Promise.resolve(machines[machineName]);
} else {
return Promise.reject(new Error('Machine does not exist.'));
}
});
},
exists: function (machineName = this.name()) {
return this.info(machineName).then(() => {
return this.status(machineName).then(() => {
return true;
}).catch(() => {
return false;
@ -82,6 +61,11 @@ var DockerMachine = {
return Promise.resolve(stdout.trim().replace('\n', ''));
});
},
url: function (machineName = this.name()) {
return util.exec([this.command(), 'url', machineName]).then(stdout => {
return Promise.resolve(stdout.trim().replace('\n', ''));
});
},
regenerateCerts: function (machineName = this.name()) {
return util.exec([this.command(), 'tls-regenerate-certs', '-f', machineName]);
},
@ -122,7 +106,7 @@ var DockerMachine = {
return line.indexOf('-/+ buffers') !== -1;
});
var tokens = dataline.split(' ');
tokens = tokens.filter(function(token) {
tokens = tokens.filter((token) => {
return token !== '';
});
var usedGb = parseInt(tokens[2], 10) / 1000;
@ -141,24 +125,24 @@ var DockerMachine = {
});
},
dockerTerminal: function (cmd, machineName = this.name()) {
if(util.isWindows()) {
if (util.isWindows()) {
cmd = cmd || '';
this.info(machineName).then(machine => {
this.url(machineName).then(machineUrl => {
util.exec('start powershell.exe ' + cmd,
{env: {
'DOCKER_HOST' : machine.url,
'DOCKER_CERT_PATH' : path.join(util.home(), '.docker/machine/machines/' + machine.name),
'DOCKER_HOST': machineUrl,
'DOCKER_CERT_PATH': path.join(util.home(), '.docker/machine/machines/' + machineName),
'DOCKER_TLS_VERIFY': 1
}
});
});
} else {
cmd = cmd || process.env.SHELL;
this.info(machineName).then(machine => {
util.exec([path.join(process.env.RESOURCES_PATH, 'terminal'), `DOCKER_HOST=${machine.url} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machine.name)} DOCKER_TLS_VERIFY=1 ${cmd}`]).then(() => {});
this.url(machineName).then(machineUrl => {
util.exec([path.join(process.env.RESOURCES_PATH, 'terminal'), `DOCKER_HOST=${machineUrl} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machineName)} DOCKER_TLS_VERIFY=1 ${cmd}`]).then(() => {});
});
}
},
}
};
module.exports = DockerMachine;