|
| 1 | + |
| 2 | +# Copyright (C) 2018 The Board of Trustees of the Leland Stanford Junior |
| 3 | +# University. |
| 4 | +# Copyright (C) 2017-2018 Vanessa Sochat. |
| 5 | + |
| 6 | +# This program is free software: you can redistribute it and/or modify it |
| 7 | +# under the terms of the GNU Affero General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or (at your |
| 9 | +# option) any later version. |
| 10 | + |
| 11 | +# This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public |
| 14 | +# License for more details. |
| 15 | + |
| 16 | +# You should have received a copy of the GNU Affero General Public License |
| 17 | +# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | + |
| 20 | +from spython.logger import bot |
| 21 | +from spython.utils import run_command |
| 22 | + |
| 23 | + |
| 24 | +def instances(self): |
| 25 | + '''list instances. For Singularity, this is provided as a command sub |
| 26 | + group. |
| 27 | +
|
| 28 | + singularity instance.list |
| 29 | +
|
| 30 | + Return codes provided are different from standard linux: |
| 31 | + see https://github.com/singularityware/singularity/issues/1706 |
| 32 | +
|
| 33 | + Return Code -- Reason |
| 34 | + 0 -- Instances Found |
| 35 | + 1 -- No Instances, libexecdir value not found, functions file not found |
| 36 | + 255 -- Couldn't get UID |
| 37 | +
|
| 38 | + ''' |
| 39 | + |
| 40 | + self.check_install() |
| 41 | + |
| 42 | + cmd = self._init_command('instance.list') |
| 43 | + output = run_command(cmd, quiet=True) |
| 44 | + instances = None |
| 45 | + |
| 46 | + # Success, we have instances |
| 47 | + |
| 48 | + if output['return_code'] == 0: |
| 49 | + print(''.join(output['message'])) |
| 50 | + instances = output['message'][1:] |
| 51 | + |
| 52 | + # Couldn't get UID |
| 53 | + |
| 54 | + elif output['return_code'] == 255: |
| 55 | + bot.error("Couldn't get UID") |
| 56 | + |
| 57 | + |
| 58 | + # Return code of 0 |
| 59 | + else: |
| 60 | + bot.info('No instances found.') |
| 61 | + |
| 62 | + return instances |
0 commit comments