Mount support
This commit is contained in:
Родитель
eae0908265
Коммит
68126aaf23
|
@ -33,6 +33,7 @@
|
|||
"dependencies": {
|
||||
"commander": "^2.14.1",
|
||||
"readline-sync": "^1.4.9",
|
||||
"request": "^2.87.0"
|
||||
"request": "^2.87.0",
|
||||
"tmp": "^0.0.33"
|
||||
}
|
||||
}
|
||||
|
|
80
src/pit.js
80
src/pit.js
|
@ -1,12 +1,13 @@
|
|||
#! /usr/bin/env node
|
||||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
const tmp = require('tmp')
|
||||
const path = require('path')
|
||||
const httpfs = require('httpfs')
|
||||
const program = require('commander')
|
||||
const request = require('request')
|
||||
const readlineSync = require('readline-sync')
|
||||
const { execSync, execFileSync } = require('child_process')
|
||||
const { exec, execFile, spawn, spawnSync, execSync, execFileSync } = require('child_process')
|
||||
|
||||
const USER_FILE = '.pituser.txt'
|
||||
const CONNECT_FILE = '.pitconnect.txt'
|
||||
|
@ -523,7 +524,7 @@ program
|
|||
.description('removes an entity from the system')
|
||||
.on('--help', function() {
|
||||
printIntro()
|
||||
printExample('pit remove user:paul')
|
||||
printExample('pit remove user:anna')
|
||||
printExample('pit remove node:machine1')
|
||||
printExample('pit remove job:123')
|
||||
printExample('pit remove alias:gtx1070')
|
||||
|
@ -570,7 +571,7 @@ program
|
|||
.description('gets a property of an entity')
|
||||
.on('--help', function() {
|
||||
printIntro()
|
||||
printExample('pit get user:paul email')
|
||||
printExample('pit get user:anna email')
|
||||
printExample('pit get node:machine1 address')
|
||||
printExample('pit get alias:gtx1070 name')
|
||||
printExample('pit get job:123 autoshare')
|
||||
|
@ -672,7 +673,7 @@ program
|
|||
printIntro()
|
||||
printExample('pit add-group node:machine1 professors')
|
||||
printExample('pit add-group node:machine1:0 students')
|
||||
printExample('pit add-group user:paul students')
|
||||
printExample('pit add-group user:anna students')
|
||||
printExample('pit add-group job:123 students')
|
||||
printLine()
|
||||
printEntityHelp(entityUser, entityNode, entityJob, 'node:<node name>:<resource index>')
|
||||
|
@ -926,34 +927,71 @@ program
|
|||
})
|
||||
|
||||
program
|
||||
.command('mount <entity> <mountpoint>')
|
||||
.description('mounts an entitie\'s directory to a local mountpoint (an empty directory) and waits for Ctrl-C to unmount again')
|
||||
.command('mount <entity> [mountpoint]')
|
||||
.description('mounts the data directory of an entity to a local mountpoint')
|
||||
.option('--shell', 'starts a shell in the mounted directory. The mount will be automatically unmounted upon shell exit.')
|
||||
.on('--help', function() {
|
||||
printIntro()
|
||||
printExample('pit mount home ~/pithome')
|
||||
printExample('pit mount job:1234 ./job1234')
|
||||
printExample('pit mount home')
|
||||
printExample('pit mount user:anna ~/annahome')
|
||||
printExample('pit mount --shell job:1234')
|
||||
printExample('pit mount group:students ./students')
|
||||
printExample('pit mount shared ./shared')
|
||||
printLine()
|
||||
printLine('"entity" is the entity whose data directory will be mounted')
|
||||
printEntityHelp('home', entityUser, entityJob, entityGroup, 'shared')
|
||||
printLine('Home and group directories are write-enabled.')
|
||||
printLine('"mountpoint" is the directory where the data directory will be mounted onto. Has to be empty. If omitted, a temporary directory will be used as mountpoint and automatically deleted on unmounting.')
|
||||
printLine('Home and group directories are write-enabled, all others are read-only.')
|
||||
})
|
||||
.action((entity, mountpoint) => {
|
||||
let endpoint = '/shared'
|
||||
.action((entity, mountpoint, options) => {
|
||||
let endpoint
|
||||
entity = parseEntity(entity)
|
||||
if (entity.type == 'home') {
|
||||
endpoint = '/users/~/fs'
|
||||
} else if (entity.type == 'group' || entity.type == 'user' || entity.type == 'job') {
|
||||
endpoint = '/' + entity.plural + '/' + entity.id + '/fs'
|
||||
} else if (entity.type == 'shared') {
|
||||
endpoint = '/shared'
|
||||
} else {
|
||||
fail('Unsupported entity type "' + entity.type + '"')
|
||||
}
|
||||
getConnectionSettings(connection => {
|
||||
if (mountpoint) {
|
||||
mountpoint = { name: mountpoint, removeCallback: () => {} }
|
||||
} else {
|
||||
mountpoint = tmp.dirSync()
|
||||
}
|
||||
let mountOptions = {
|
||||
headers: { 'X-Auth-Token': connection.token },
|
||||
cache: true,
|
||||
blocksize: 10 * 1024 * 1024
|
||||
}
|
||||
if (connection.ca) {
|
||||
mountOptions.certificate = connection.ca
|
||||
}
|
||||
httpfs.mount(
|
||||
connection.url + endpoint,
|
||||
mountpoint,
|
||||
{
|
||||
headers: { 'X-Auth-Token': connection.token },
|
||||
certificate: connection.ca,
|
||||
cache: true,
|
||||
blocksize: 10 * 1024 * 1024
|
||||
},
|
||||
mountpoint.name,
|
||||
mountOptions,
|
||||
(err, mount) => {
|
||||
if (err) { throw err }
|
||||
console.log('press Ctrl-C to unmount')
|
||||
globalunmount = mount.unmount
|
||||
if (err) {
|
||||
fail(err)
|
||||
}
|
||||
let unmount = () => mount.unmount(err => {
|
||||
if (err) {
|
||||
console.error('problem unmounting filesystem:', err)
|
||||
} else {
|
||||
mountpoint.removeCallback()
|
||||
}
|
||||
})
|
||||
if (options.shell) {
|
||||
console.log('secondary shell: call "exit" to end and unmount')
|
||||
let sh = spawn(process.env.SHELL || 'bash', ['-i'], { stdio: 'inherit', cwd: mountpoint.name })
|
||||
sh.on('close', unmount)
|
||||
} else {
|
||||
console.log('press Ctrl-C to unmount')
|
||||
globalunmount = unmount
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -179,6 +179,10 @@ oauth-sign@~0.8.2:
|
|||
version "0.8.2"
|
||||
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
|
||||
|
||||
os-tmpdir@~1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
|
||||
|
||||
performance-now@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
|
||||
|
@ -238,6 +242,12 @@ sshpk@^1.7.0:
|
|||
jsbn "~0.1.0"
|
||||
tweetnacl "~0.14.0"
|
||||
|
||||
tmp@^0.0.33:
|
||||
version "0.0.33"
|
||||
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
|
||||
dependencies:
|
||||
os-tmpdir "~1.0.2"
|
||||
|
||||
tough-cookie@~2.3.3:
|
||||
version "2.3.4"
|
||||
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655"
|
||||
|
|
Загрузка…
Ссылка в новой задаче