Added ssh target
This commit is contained in:
parent
879bb6f79e
commit
3b6a4f3fc4
@ -67,6 +67,9 @@ class Packages:
|
||||
return os.path.join(os.getenv('HOME'), '.cache')
|
||||
|
||||
async def update(self, target):
|
||||
if not target.islocal:
|
||||
return await target.rexec(self.cmds['update'])
|
||||
|
||||
# run pkgmgr_setup functions ie. apk_setup
|
||||
cachedir = await getattr(self, self.mgr + '_setup')(target)
|
||||
|
||||
|
||||
16
shlax/cli.py
16
shlax/cli.py
@ -28,6 +28,12 @@ class TargetArgument(cli2.Argument):
|
||||
super().__init__(cmd, param, doc=self.__doc__, default=Target())
|
||||
self.alias = ['target', 't']
|
||||
|
||||
def cast(self, value):
|
||||
from shlax.targets.ssh import Ssh
|
||||
if '@' in value:
|
||||
user, host = value.split('@')
|
||||
return Ssh(host=host, user=user)
|
||||
|
||||
|
||||
class Command(cli2.Command):
|
||||
def setargs(self):
|
||||
@ -45,10 +51,16 @@ class Command(cli2.Command):
|
||||
|
||||
|
||||
class ActionCommand(cli2.Command):
|
||||
def setargs(self):
|
||||
super().setargs()
|
||||
self['target'] = TargetArgument(
|
||||
self,
|
||||
inspect.Parameter('target', inspect.Parameter.KEYWORD_ONLY),
|
||||
)
|
||||
|
||||
def call(self, *args, **kwargs):
|
||||
self.target = self.target(*args, **kwargs)
|
||||
from shlax.targets.base import Target
|
||||
return super().call(Target())
|
||||
return super().call(self['target'].value)
|
||||
|
||||
|
||||
class ConsoleScript(Group):
|
||||
|
||||
@ -17,6 +17,7 @@ class Target:
|
||||
self.output = Output()
|
||||
self.parent = None
|
||||
self.root = root or os.getcwd()
|
||||
self.islocal = getattr(self, 'islocal', True)
|
||||
|
||||
def __str__(self):
|
||||
return 'localhost'
|
||||
|
||||
16
shlax/targets/ssh.py
Normal file
16
shlax/targets/ssh.py
Normal file
@ -0,0 +1,16 @@
|
||||
from .base import Target
|
||||
|
||||
|
||||
class Ssh(Target):
|
||||
def __init__(self, *actions, host, user=None):
|
||||
self.host = host
|
||||
self.user = user
|
||||
self.islocal = False
|
||||
super().__init__(*actions)
|
||||
|
||||
async def exec(self, *args, user=None, **kwargs):
|
||||
_args = ['ssh', self.host]
|
||||
if user == 'root':
|
||||
_args += ['sudo']
|
||||
_args += [' '.join([str(a) for a in args])]
|
||||
return await self.parent.exec(*_args, **kwargs)
|
||||
Loading…
x
Reference in New Issue
Block a user