Browse Source

make mapping alone print out existing mappings..

main
John-Mark Gurney 1 year ago
parent
commit
5d82d5930a
2 changed files with 31 additions and 18 deletions
  1. +5
    -0
      ui/fixtures/cmd.mapping.json
  2. +26
    -18
      ui/medashare/cli.py

+ 5
- 0
ui/fixtures/cmd.mapping.json View File

@@ -98,5 +98,10 @@
"special": "verify store object cnt",
"comment": "but didn't create an additional FileObject",
"count": 5
},
{
"title": "just mapping lists them",
"cmd": [ "mapping" ],
"stdout_re": "^efdb5d9c-d123-4b30-aaa8-45a9ea8f6053:/.*subdir/mapa <-> ceaa4862-dd00-41ba-9787-7480ec1b2679:/.*subdir/mapb\n$"
}
]

+ 26
- 18
ui/medashare/cli.py View File

@@ -53,7 +53,7 @@ import shutil
import socket
import sqlalchemy
from sqlalchemy import create_engine, select, insert, func, delete
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker, aliased
import string
import subprocess
import sys
@@ -945,28 +945,36 @@ def printhost(host):

@init_datastructs
def cmd_mapping(options, persona, objstr, cache):
if options.mapping is not None:
parts = [ x.split(':', 1) for x in options.mapping ]
if options.mapping is None:
maps = objstr.get_by_type('mapping')

if len(parts[0]) == 1:
parts[0] = [ hostuuid(), parts[0][0] ]
maps = (' <-> '.join(i['mapping']) for i in maps)

if parts[0][0] == hostuuid():
parts[0][1] = str(pathlib.Path(parts[0][1]).resolve())
for i in maps:
print(i)
return

if parts[1][1][0] != '/':
print('ERROR: host path must be absolute, is %s.' %
repr(parts[1][1][0]), file=sys.stderr)
sys.exit(1)
parts = [ x.split(':', 1) for x in options.mapping ]

try:
[ objstr.get_host(x[0]) for x in parts ]
except KeyError as e:
print('ERROR: Unable to find host %s' %
str(e.args[0]), file=sys.stderr)
sys.exit(1)
if len(parts[0]) == 1:
parts[0] = [ hostuuid(), parts[0][0] ]

if parts[0][0] == hostuuid():
parts[0][1] = str(pathlib.Path(parts[0][1]).resolve())

if parts[1][1][0] != '/':
print('ERROR: host path must be absolute, is %s.' %
repr(parts[1][1][0]), file=sys.stderr)
sys.exit(1)

try:
[ objstr.get_host(x[0]) for x in parts ]
except KeyError as e:
print('ERROR: Unable to find host %s' %
str(e.args[0]), file=sys.stderr)
sys.exit(1)

m = persona.Mapping(mapping=[ ':'.join(x) for x in parts ])
m = persona.Mapping(mapping=[ ':'.join(x) for x in parts ])

objstr.loadobj(m)



Loading…
Cancel
Save