"Fossies" - the Fresh Open Source Software Archive

Member "zun-7.0.0/zun/cmd/status.py" (14 Apr 2021, 2166 Bytes) of package /linux/misc/openstack/zun-7.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "status.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.0.0_vs_7.0.0.

    1 # Copyright (c) 2018 NEC, Corp.
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #    not use this file except in compliance with the License. You may obtain
    5 #    a copy of the License at
    6 #
    7 #         http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #    License for the specific language governing permissions and limitations
   13 #    under the License.
   14 
   15 import os
   16 import shutil
   17 import sys
   18 
   19 from oslo_upgradecheck import common_checks
   20 from oslo_upgradecheck import upgradecheck
   21 
   22 from zun.common.i18n import _
   23 import zun.conf
   24 
   25 CONF = zun.conf.CONF
   26 
   27 
   28 class Checks(upgradecheck.UpgradeCommands):
   29 
   30     """Contains upgrade checks
   31 
   32     Various upgrade checks should be added as separate methods in this class
   33     and added to _upgrade_checks tuple.
   34     """
   35 
   36     def _cmd_exists(self, cmd):
   37         try:
   38             return shutil.which(cmd) is not None
   39         except AttributeError:
   40             # shutil.which is not available in python 2.x so try an
   41             # alternative approach
   42             return any(
   43                 os.access(os.path.join(path, cmd), os.X_OK)
   44                 for path in os.environ["PATH"].split(os.pathsep)
   45             )
   46 
   47     def _numactl_check(self):
   48         """This is a check for existence of numactl binary
   49 
   50         It needs to be removed after adding any real upgrade check
   51         """
   52         if self._cmd_exists('numactl'):
   53             return upgradecheck.Result(upgradecheck.Code.SUCCESS)
   54         else:
   55             msg = _("The program 'numactl' is currently not installed.")
   56             return upgradecheck.Result(upgradecheck.Code.FAILURE, msg)
   57 
   58     _upgrade_checks = (
   59         (_('Numactl Check'), _numactl_check),
   60         (_('Policy File JSON to YAML Migration'),
   61          (common_checks.check_policy_json, {'conf': CONF})),
   62     )
   63 
   64 
   65 def main():
   66     return upgradecheck.main(
   67         CONF, project='zun', upgrade_command=Checks())
   68 
   69 
   70 if __name__ == '__main__':
   71     sys.exit(main())