blob: 88555a6c93b0097f9ca2627901e86766de569e93 [file] [log] [blame]
Pau Espin Pedrol116a2c42020-02-11 17:41:13 +01001# osmo_gsm_tester: run_node: object holding information on a target env to run stuff.
2#
3# Copyright (C) 2020 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Pau Espin Pedrol <pespin@sysmocom.de>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20from . import log
21
22class RunNode(log.Origin):
23
24 T_LOCAL = 'local'
25 T_REM_SSH = 'ssh'
26
27 def __init__(self, type=None, run_addr=None, ssh_user=None, ssh_addr=None):
28 super().__init__(log.C_RUN, 'runnode')
29 self._type = type
30 self._run_addr = run_addr
31 self._ssh_user = ssh_user
32 self._ssh_addr = ssh_addr
33 if not self._type:
34 raise log.Error('run_type not set')
35 if not self._run_addr:
36 raise log.Error('run_addr not set')
37 if self._type == RunNode.T_LOCAL and (self._ssh_user or self._ssh_addr):
38 raise log.Error('run_type=%s but ssh info set' % RunNode.T_LOCAL)
39 if self._type == RunNode.T_REM_SSH and not (self._ssh_user and self._ssh_addr):
40 raise log.Error('run_type=%s but ssh info NOT set' % RunNode.T_LOCAL)
41
42 if self._type == RunNode.T_LOCAL:
43 self.set_name('run-' + self._run_addr)
44 else:
45 self.set_name('run-' + self._run_addr + "(" + self._ssh_user + '@' + self._ssh_addr + ")")
46
47 @classmethod
48 def from_conf(cls, conf):
49 return cls(conf.get('run_type', None), conf.get('run_addr', None), conf.get('ssh_user', None), conf.get('ssh_addr', None))
50
51 def is_local(self):
52 return self._type == RunNode.T_LOCAL
53
54 def __str__(self):
55 return self.name()
56
57 def run_type(self):
58 return self._type
59
60 def run_addr(self):
61 return self._run_addr
62
63 def ssh_user(self):
64 return self._ssh_user
65
66 def ssh_addr(self):
67 return self._ssh_addr
68
69# vim: expandtab tabstop=4 shiftwidth=4