blob: 676c26296b7fc6928354765665e055ee8f0ee2ab [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
Pau Espin Pedrole1a58bd2020-04-10 20:46:07 +020020from ..core import log
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020021from ..core import schema
22
23def on_register_schemas():
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020024 resource_schema = RunNode.schema()
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020025 schema.register_resource_schema('run_node', resource_schema)
26
Pau Espin Pedrol116a2c42020-02-11 17:41:13 +010027
28class RunNode(log.Origin):
29
30 T_LOCAL = 'local'
31 T_REM_SSH = 'ssh'
32
Andre Puschmann3fc74d32021-03-10 20:32:45 +010033 def __init__(self, type=None, run_addr=None, ssh_user=None, ssh_addr=None, run_label=None, label=None, ssh_port=None, adb_serial_id=None):
Pau Espin Pedrol116a2c42020-02-11 17:41:13 +010034 super().__init__(log.C_RUN, 'runnode')
35 self._type = type
36 self._run_addr = run_addr
37 self._ssh_user = ssh_user
38 self._ssh_addr = ssh_addr
Pau Espin Pedrol6e0b6fb2020-05-25 19:49:29 +020039 self._run_label = run_label
Andre Puschmann3fc74d32021-03-10 20:32:45 +010040 self._label = label
Nils Fürste2af2b152020-11-23 11:57:41 +010041 self._ssh_port = ssh_port
Nils Fürstea8263f42020-11-23 14:45:15 +010042 self._adb_serial_id = adb_serial_id
Pau Espin Pedrol116a2c42020-02-11 17:41:13 +010043 if not self._type:
44 raise log.Error('run_type not set')
45 if not self._run_addr:
46 raise log.Error('run_addr not set')
47 if self._type == RunNode.T_LOCAL and (self._ssh_user or self._ssh_addr):
48 raise log.Error('run_type=%s but ssh info set' % RunNode.T_LOCAL)
49 if self._type == RunNode.T_REM_SSH and not (self._ssh_user and self._ssh_addr):
50 raise log.Error('run_type=%s but ssh info NOT set' % RunNode.T_LOCAL)
51
52 if self._type == RunNode.T_LOCAL:
53 self.set_name('run-' + self._run_addr)
54 else:
55 self.set_name('run-' + self._run_addr + "(" + self._ssh_user + '@' + self._ssh_addr + ")")
56
57 @classmethod
58 def from_conf(cls, conf):
Pau Espin Pedrol6e0b6fb2020-05-25 19:49:29 +020059 return cls(conf.get('run_type', None), conf.get('run_addr', None),
60 conf.get('ssh_user', None), conf.get('ssh_addr', None),
Andre Puschmann3fc74d32021-03-10 20:32:45 +010061 conf.get('run_label', None), conf.get('label', None),
62 conf.get('ssh_port', None), conf.get('adb_serial_id', None))
Pau Espin Pedrol116a2c42020-02-11 17:41:13 +010063
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020064 @classmethod
65 def schema(cls):
66 resource_schema = {
67 'run_type': schema.STR,
68 'run_addr': schema.IPV4,
69 'ssh_user': schema.STR,
70 'ssh_addr': schema.IPV4,
71 'run_label': schema.STR,
Andre Puschmann3fc74d32021-03-10 20:32:45 +010072 'label': schema.STR,
Nils Fürste2af2b152020-11-23 11:57:41 +010073 'ssh_port': schema.STR,
Nils Fürstea8263f42020-11-23 14:45:15 +010074 'adb_serial_id': schema.STR,
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020075 }
76 return resource_schema
77
Pau Espin Pedrol116a2c42020-02-11 17:41:13 +010078 def is_local(self):
79 return self._type == RunNode.T_LOCAL
80
81 def __str__(self):
82 return self.name()
83
84 def run_type(self):
85 return self._type
86
87 def run_addr(self):
88 return self._run_addr
89
90 def ssh_user(self):
91 return self._ssh_user
92
93 def ssh_addr(self):
94 return self._ssh_addr
95
Pau Espin Pedrol6e0b6fb2020-05-25 19:49:29 +020096 def run_label(self):
97 return self._run_label
98
Andre Puschmann3fc74d32021-03-10 20:32:45 +010099 def label(self):
100 return self._label
101
Nils Fürste2af2b152020-11-23 11:57:41 +0100102 def ssh_port(self):
103 return self._ssh_port
104
Nils Fürstea8263f42020-11-23 14:45:15 +0100105 def adb_serial_id(self):
106 return self._adb_serial_id
107
Pau Espin Pedrol116a2c42020-02-11 17:41:13 +0100108# vim: expandtab tabstop=4 shiftwidth=4