|
@@ -53,7 +53,7 @@ import shutil |
|
|
import socket |
|
|
import socket |
|
|
import sqlalchemy |
|
|
import sqlalchemy |
|
|
from sqlalchemy import create_engine, select, insert, func, delete |
|
|
from sqlalchemy import create_engine, select, insert, func, delete |
|
|
from sqlalchemy.orm import sessionmaker |
|
|
|
|
|
|
|
|
from sqlalchemy.orm import sessionmaker, aliased |
|
|
import string |
|
|
import string |
|
|
import subprocess |
|
|
import subprocess |
|
|
import sys |
|
|
import sys |
|
@@ -945,28 +945,36 @@ def printhost(host): |
|
|
|
|
|
|
|
|
@init_datastructs |
|
|
@init_datastructs |
|
|
def cmd_mapping(options, persona, objstr, cache): |
|
|
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) |
|
|
objstr.loadobj(m) |
|
|
|
|
|
|
|
|