Skip to content

Commit

Permalink
allow for HPSS env variables in htar
Browse files Browse the repository at this point in the history
  • Loading branch information
ndenny committed Jun 4, 2024
1 parent 68b1bb4 commit 1464830
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
11 changes: 7 additions & 4 deletions bin/bastion.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,16 @@ def configured(self):
def site(self, name):
return Site(name).configured(self.conf)

def vault(self, name):
def vault(self, name, site = None):
if ((name[0] == '{') and (name[-1] == '}')):
name = name[1:-1]
if name in self.conf['vaults']:
protocol = self.conf['vaults'][name]['protocol']
if protocol == 'HPSS':
return Bastion.HPSS.Vault(name).configured(self.conf)
opts = { }
if site is not None:
opts['client'] = site.host
return Bastion.HPSS.Vault(name, **opts).configured(self.conf)
else:
raise NotImplementedError
else:
Expand Down Expand Up @@ -210,12 +213,12 @@ def do_export_asset_manifest(self, comargs, comdex):
app = App().configured()
#app.run( )
comdex = dict(enumerate(sys.argv[1:]))
fortress = app.vault('fortress')
rusina = app.site('rusina')
fortress = app.vault('fortress', rusina)
ark = ARK(comdex[2])
ds = rusina.asset(ark)
fortress.provision(ark)


#bastion site {site} backup
#bastion zone {zone} backup
Expand Down
20 changes: 14 additions & 6 deletions lib/Bastion/HPSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,22 @@ def lsx(self, path = None):
class Vault(Bastion.Model.Vault):
def __init__(self, name, **kwargs):
self.name = name
self.host = kwargs.get('host', socket.gethostname())
self.server = kwargs.get('server', socket.gethostname())
self.login = kwargs.get('login', os.getlogin())
self.keytab = pathlib.Path( kwargs.get('keytab', "~/.private/hpss.unix.keytab") ).expanduser()
self.root = kwargs.get('root', None)
self.hpath = pathlib.Path( kwargs.get('hpath', '/opt/hsi') )
self.xpath = pathlib.Path( kwargs.get('xpath', (self.hpath / 'bin' / 'hsi')) )
self.xhtar = self.hpath / 'bin' / 'htar'
self._hsi = None
self.client = kwargs.get('client', socket.gethostname())

def configured(self, conf):
confkey = "vaults.{}".format(self.name)
if confkey in conf:
section = conf[confkey]
self.host = section['host']
self.login = section['login']
section = conf[confkey]
self.server = section['host']
self.login = section['login']
if 'root' in section:
self.root = pathlib.PurePosixPath( section['root'] )
return self
Expand Down Expand Up @@ -436,8 +437,15 @@ def push(self, asset, **kwargs):
'localf': localf
}

comargs = [str(opts['htar']), "-Hverify=1", "-c", "-v", "-f", "{site}/{zone}/{asset}/{blonde}.tar".format(**opts), "{localf}".format(**opts)]
proc = subprocess.run(comargs, capture_output = True, check = True)
exports = {
"HPSS_AUTH_METHOD": "keytab",
"HPSS_PRINCIPAL": self.login,
"HPSS_KEYTAB_PATH": str(self.keytab),
"HPSS_HOSTNAME": str(self.client)
}

comargs = [str(opts['htar']), "-c", "-f", "{site}/{zone}/{asset}/{blonde}.tar".format(**opts), "-v", "-Hverify=1", "{localf}".format(**opts)]
proc = subprocess.run(comargs, capture_output = True, check = False, env = exports)
stdout = proc.stdout.decode('utf-8')
stderr = proc.stderr.decode('utf-8')
flag = True if (proc.returncode == 0) else False
Expand Down
3 changes: 3 additions & 0 deletions lib/Bastion/Site.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def configured(self, conf):
if conf:
self._configured = True
condex = conf['sites'][self.name]
if 'host' in condex:
self.host = condex['host']

if 'logging' in condex:
self.logging.level = condex.get(asLogLevel, 'logging.level', logging.WARN)

Expand Down

0 comments on commit 1464830

Please sign in to comment.